Skip to content

Commit

Permalink
feat(CLI): implement method for querying stakes
Browse files Browse the repository at this point in the history
 Please enter the commit message for your changes. Lines starting
  • Loading branch information
Tommytrg committed Mar 18, 2024
1 parent 2e84cff commit ef7bf95
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/cli/node/json_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ use witnet_data_structures::{
};
use witnet_node::actors::{
chain_manager::run_dr_locally,
json_rpc::api::{AddrType, GetBlockChainParams, GetTransactionOutput, PeersResult},
json_rpc::api::{
AddrType, GetBlockChainParams, GetTransactionOutput, PeersResult, QueryStakesArgument,
},
messages::{
AuthorizeStake, BuildDrt, BuildStakeParams, BuildStakeResponse, BuildVtt, GetBalanceTarget,
GetReputationResult, MagicEither, SignalingInfo, StakeAuthorization,
Expand Down Expand Up @@ -1826,6 +1828,34 @@ pub fn priority(addr: SocketAddr, json: bool) -> Result<(), failure::Error> {
Ok(())
}

pub fn query_stakes(
addr: SocketAddr,
validator: Option<String>,
withdrawer: Option<String>,
) -> Result<(), failure::Error> {
let mut stream = start_client(addr)?;

let params = match (validator, withdrawer) {
(Some(validator), Some(withdrawer)) => {
Some(QueryStakesArgument::Key((validator, withdrawer)))
}
(Some(validator), _) => Some(QueryStakesArgument::Validator(validator)),
(_, Some(withdrawer)) => Some(QueryStakesArgument::Withdrawer(withdrawer)),
(None, None) => None,
};

let response = send_request(
&mut stream,
&format!(
r#"{{"jsonrpc": "2.0","method": "queryStakes", "params": {}, "id": 1}}"#,
serde_json::to_string(&params).unwrap()
),
)?;
log::info!("{}", response);

Ok(())
}

#[derive(Serialize, Deserialize)]
struct SignatureWithData {
address: String,
Expand Down
14 changes: 14 additions & 0 deletions src/cli/node/with_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ pub fn exec_cmd(
Command::AuthorizeStake { node, withdrawer } => {
rpc::authorize_st(node.unwrap_or(default_jsonrpc), withdrawer)
}
Command::QueryStakes {
node,
withdrawer,
validator,
} => rpc::query_stakes(node.unwrap_or(default_jsonrpc), withdrawer, validator),
}
}

Expand Down Expand Up @@ -785,6 +790,15 @@ pub enum Command {
#[structopt(long = "withdrawer")]
withdrawer: Option<String>,
},
QueryStakes {
/// Socket address of the Witnet node to query
#[structopt(short = "n", long = "node")]
node: Option<SocketAddr>,
#[structopt(short = "v", long = "validator")]
validator: Option<String>,
#[structopt(short = "w", long = "withdrawer")]
withdrawer: Option<String>,
},
}

#[derive(Debug, StructOpt)]
Expand Down

0 comments on commit ef7bf95

Please sign in to comment.