Skip to content

Commit 9eeee34

Browse files
author
CodeSandwich
committed
Add stake pool getter to JCLI
1 parent 9232472 commit 9eeee34

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

doc/jcli/rest.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,36 @@ YAML printed on success
477477
# timestamp of last time gossip was received from node if ever (optional)
478478
lastGossipReceived: "2019-10-14T00:45:59.419496188+00:00"
479479
```
480+
481+
## Get stake pool details
482+
483+
Fetches stake pool details
484+
485+
```
486+
jcli rest v0 stake-pool get <pool-id> <options>
487+
```
488+
489+
<pool-id> - hex-encoded pool ID
490+
491+
The options are
492+
493+
- -h <node_addr> - see [conventions](#conventions)
494+
- --debug - see [conventions](#conventions)
495+
- --output-format <format> - see [conventions](#conventions)
496+
497+
YAML printed on success
498+
499+
```yaml
500+
---
501+
tax: # pool reward
502+
fixed: 5 # what get subtracted as fixed value
503+
ratio: # ratio of tax after fixed amount is subtracted. Expressed as numerator/denominator
504+
numerator: 1
505+
denominator: 10000
506+
max: 100 # limit of tax (optional)
507+
total_stake: 2000000000000 # total stake pool value
508+
# bech32-encoded stake pool KES key
509+
kesPublicKey: kes25519-12-pk1q7susucqwje0lpetqzjgzncgcrjzx7e2guh900qszdjskkeyqpusf3p39r
510+
# bech32-encoded stake pool VRF key
511+
vrfPublicKey: vrf_pk1rcm4qm3q9dtwq22x9a4avnan7a3k987zvepuxwekzj3uyu6a8v0s6sdy0l
512+
```

jcli/src/jcli_app/rest/v0/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod node;
77
mod settings;
88
mod shutdown;
99
mod stake;
10+
mod stake_pool;
1011
mod stake_pools;
1112
mod tip;
1213
mod utxo;
@@ -33,6 +34,8 @@ pub enum V0 {
3334
Settings(settings::Settings),
3435
/// Stake information
3536
Stake(stake::Stake),
37+
/// Stake pool operations
38+
StakePool(stake_pool::StakePool),
3639
/// Stake pools operations
3740
StakePools(stake_pools::StakePools),
3841
/// Shutdown node
@@ -54,6 +57,7 @@ impl V0 {
5457
V0::Node(node) => node.exec(),
5558
V0::Settings(settings) => settings.exec(),
5659
V0::Stake(stake) => stake.exec(),
60+
V0::StakePool(stake_pool) => stake_pool.exec(),
5761
V0::StakePools(stake_pools) => stake_pools.exec(),
5862
V0::Shutdown(shutdown) => shutdown.exec(),
5963
V0::Tip(tip) => tip.exec(),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::jcli_app::rest::Error;
2+
use crate::jcli_app::utils::{DebugFlag, HostAddr, OutputFormat, RestApiSender};
3+
use structopt::StructOpt;
4+
5+
#[derive(StructOpt)]
6+
#[structopt(rename_all = "kebab-case")]
7+
pub enum StakePool {
8+
/// Get stake pool details
9+
Get {
10+
/// hex-encoded pool ID
11+
pool_id: String,
12+
#[structopt(flatten)]
13+
addr: HostAddr,
14+
#[structopt(flatten)]
15+
debug: DebugFlag,
16+
#[structopt(flatten)]
17+
output_format: OutputFormat,
18+
},
19+
}
20+
21+
impl StakePool {
22+
pub fn exec(self) -> Result<(), Error> {
23+
let StakePool::Get {
24+
pool_id,
25+
addr,
26+
debug,
27+
output_format,
28+
} = self;
29+
let url = addr
30+
.with_segments(&["v0", "stake_pool", &pool_id])?
31+
.into_url();
32+
let builder = reqwest::Client::new().get(url);
33+
let response = RestApiSender::new(builder, &debug).send()?;
34+
response.ok_response()?;
35+
let status = response.body().json_value()?;
36+
let formatted = output_format.format_json(status)?;
37+
println!("{}", formatted);
38+
Ok(())
39+
}
40+
}

0 commit comments

Comments
 (0)