From b99b596aa29bd7b3123761de01c7625a0ce583ab Mon Sep 17 00:00:00 2001 From: tommytrg Date: Wed, 18 Dec 2024 16:55:43 +0100 Subject: [PATCH] feat(jsonrpc): update queryStake to return the whole stake structure --- data_structures/src/staking/stake.rs | 2 ++ node/src/actors/chain_manager/handlers.rs | 2 +- node/src/actors/json_rpc/api.rs | 2 +- node/src/actors/messages.rs | 7 +++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/data_structures/src/staking/stake.rs b/data_structures/src/staking/stake.rs index 07a3404a3..7ddc55460 100644 --- a/data_structures/src/staking/stake.rs +++ b/data_structures/src/staking/stake.rs @@ -25,7 +25,9 @@ where /// The amount of stake and unstake actions. pub nonce: Nonce, // These two phantom fields are here just for the sake of specifying generics. + #[serde(skip)] phantom_address: PhantomData
, + #[serde(skip)] phantom_power: PhantomData, } diff --git a/node/src/actors/chain_manager/handlers.rs b/node/src/actors/chain_manager/handlers.rs index 2bf42f960..9cb33fe35 100644 --- a/node/src/actors/chain_manager/handlers.rs +++ b/node/src/actors/chain_manager/handlers.rs @@ -1458,7 +1458,7 @@ impl Handler for ChainManager { fn handle(&mut self, msg: QueryStake, _ctx: &mut Self::Context) -> Self::Result { // build address from public key hash - let stakes = self.chain_state.stakes.query_total_stake(msg.key); + let stakes = self.chain_state.stakes.query_stakes(msg.key); stakes.map_err(StakesError::from).map_err(Into::into) } diff --git a/node/src/actors/json_rpc/api.rs b/node/src/actors/json_rpc/api.rs index fe5518412..a3ba3a632 100644 --- a/node/src/actors/json_rpc/api.rs +++ b/node/src/actors/json_rpc/api.rs @@ -2226,7 +2226,7 @@ pub async fn query_stakes(params: Result, Error>) -> ChainManager::from_registry() .send(QueryStake { key }) .map(|res| match res { - Ok(Ok(staked_amount)) => serde_json::to_value(staked_amount).map_err(internal_error), + Ok(Ok(stakes)) => serde_json::to_value(stakes).map_err(internal_error), Ok(Err(e)) => { let err = internal_error_s(e); Err(err) diff --git a/node/src/actors/messages.rs b/node/src/actors/messages.rs index 8f1c40a3b..957ae58e0 100644 --- a/node/src/actors/messages.rs +++ b/node/src/actors/messages.rs @@ -36,7 +36,7 @@ use witnet_data_structures::{ transaction_factory::NodeBalance, types::{LastBeacon, ProtocolVersion}, utxo_pool::{UtxoInfo, UtxoSelectionStrategy}, - wit::Wit, + wit::{Wit, WIT_DECIMAL_PLACES}, }; use witnet_p2p::{ error::SessionsError, @@ -371,7 +371,10 @@ pub struct QueryStake { } impl Message for QueryStake { - type Result = Result; + type Result = Result< + Vec>, + failure::Error, + >; } impl
From for QueryStakesKey