Skip to content

Commit

Permalink
feat(jsonrpc): update queryStake to return the whole stake structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Dec 19, 2024
1 parent d1633f2 commit 42dfbcc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions data_structures/src/staking/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address>,
#[serde(skip)]
phantom_power: PhantomData<Power>,
}

Expand Down
2 changes: 1 addition & 1 deletion node/src/actors/chain_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ impl Handler<QueryStake> 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)
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/actors/json_rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ pub async fn query_stakes(params: Result<Option<QueryStakesArgument>, 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)
Expand Down
7 changes: 5 additions & 2 deletions node/src/actors/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -371,7 +371,10 @@ pub struct QueryStake {
}

impl Message for QueryStake {
type Result = Result<Wit, failure::Error>;
type Result = Result<
Vec<StakeEntry<WIT_DECIMAL_PLACES, PublicKeyHash, Wit, Epoch, u64, u64>>,
failure::Error,
>;
}

impl<Address> From<QueryStakesParams> for QueryStakesKey<Address>
Expand Down

0 comments on commit 42dfbcc

Please sign in to comment.