Skip to content

Commit 8aa111e

Browse files
committed
feat: implement cli method for querying stakes
1 parent 1b9b7b7 commit 8aa111e

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/cli/node/json_rpc_client.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ use witnet_data_structures::{
4141
};
4242
use witnet_node::actors::{
4343
chain_manager::run_dr_locally,
44-
json_rpc::api::{AddrType, GetBlockChainParams, GetTransactionOutput, PeersResult},
44+
json_rpc::api::{
45+
AddrType, GetBlockChainParams, GetTransactionOutput, PeersResult, QueryStakesArgument,
46+
},
4547
messages::{
4648
AuthorizeStake, BuildDrt, BuildStakeParams, BuildStakeResponse, BuildVtt, GetBalanceTarget,
4749
GetReputationResult, MagicEither, SignalingInfo, StakeAuthorization,
@@ -1826,6 +1828,37 @@ pub fn priority(addr: SocketAddr, json: bool) -> Result<(), failure::Error> {
18261828
Ok(())
18271829
}
18281830

1831+
pub fn query_stakes(
1832+
addr: SocketAddr,
1833+
validator: Option<String>,
1834+
withdrawer: Option<String>,
1835+
) -> Result<(), failure::Error> {
1836+
let mut stream = start_client(addr)?;
1837+
let params = if validator.is_some() && withdrawer.is_some() {
1838+
Some(QueryStakesArgument::Key((
1839+
validator.unwrap(),
1840+
withdrawer.unwrap(),
1841+
)))
1842+
} else if validator.is_some() {
1843+
Some(QueryStakesArgument::Validator(validator.unwrap()))
1844+
} else if withdrawer.is_some() {
1845+
Some(QueryStakesArgument::Withdrawer(withdrawer.unwrap()))
1846+
} else {
1847+
None
1848+
};
1849+
1850+
let response = send_request(
1851+
&mut stream,
1852+
&format!(
1853+
r#"{{"jsonrpc": "2.0","method": "queryStakes", "params": {}, "id": 1}}"#,
1854+
serde_json::to_string(&params).unwrap()
1855+
),
1856+
)?;
1857+
log::info!("{}", response);
1858+
1859+
Ok(())
1860+
}
1861+
18291862
#[derive(Serialize, Deserialize)]
18301863
struct SignatureWithData {
18311864
address: String,

src/cli/node/with_node.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ pub fn exec_cmd(
290290
Command::AuthorizeStake { node, withdrawer } => {
291291
rpc::authorize_st(node.unwrap_or(default_jsonrpc), withdrawer)
292292
}
293+
Command::QueryStakes {
294+
node,
295+
withdrawer,
296+
validator,
297+
} => rpc::query_stakes(node.unwrap_or(default_jsonrpc), withdrawer, validator),
293298
}
294299
}
295300

@@ -785,6 +790,15 @@ pub enum Command {
785790
#[structopt(long = "withdrawer")]
786791
withdrawer: Option<String>,
787792
},
793+
QueryStakes {
794+
/// Socket address of the Witnet node to query
795+
#[structopt(short = "n", long = "node")]
796+
node: Option<SocketAddr>,
797+
#[structopt(short = "v", long = "validator")]
798+
validator: Option<String>,
799+
#[structopt(short = "w", long = "withdrawer")]
800+
withdrawer: Option<String>,
801+
},
788802
}
789803

790804
#[derive(Debug, StructOpt)]

0 commit comments

Comments
 (0)