From 4343dce6d720df99a49f143fa02e7e2bbccc236f Mon Sep 17 00:00:00 2001 From: Gianmarco Fraccaroli Date: Wed, 21 Aug 2024 09:35:41 +0200 Subject: [PATCH] replace context with client --- crates/apps_lib/src/client/rpc.rs | 3 ++- crates/sdk/src/rpc.rs | 33 +++++++++++++------------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/crates/apps_lib/src/client/rpc.rs b/crates/apps_lib/src/client/rpc.rs index 160fdff26e..ee04757b7f 100644 --- a/crates/apps_lib/src/client/rpc.rs +++ b/crates/apps_lib/src/client/rpc.rs @@ -443,7 +443,8 @@ pub async fn query_proposal_result( let current_epoch = query_epoch(context.client()).await.unwrap(); let proposal_result = - namada_sdk::rpc::query_proposal_result(context, proposal_id).await; + namada_sdk::rpc::query_proposal_result(context.client(), proposal_id) + .await; let proposal_query = namada_sdk::rpc::query_proposal_by_id(context.client(), proposal_id) .await; diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index 7651822ce0..9e05411c4c 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -936,35 +936,30 @@ pub async fn get_public_key_at( } /// Query the proposal result -pub async fn query_proposal_result( - context: &N, +pub async fn query_proposal_result( + client: &C, proposal_id: u64, ) -> Result, Error> { - let proposal = query_proposal_by_id(context.client(), proposal_id).await?; + let proposal = query_proposal_by_id(client, proposal_id).await?; let proposal = if let Some(proposal) = proposal { proposal } else { return Ok(None); }; - let current_epoch = query_epoch(context.client()).await?; + let current_epoch = query_epoch(client).await?; if current_epoch < proposal.voting_start_epoch { - display_line!( - context.io(), + return Err(Error::Other(format!( "Proposal {} is still pending, voting period will start in {} \ epochs.", proposal_id, proposal.voting_end_epoch.0 - current_epoch.0 - ); + ))); } - let stored_proposal_result = - convert_response::>( - RPC.vp() - .gov() - .proposal_result(context.client(), &proposal_id) - .await, - )?; + let stored_proposal_result = convert_response::>( + RPC.vp().gov().proposal_result(client, &proposal_id).await, + )?; let proposal_result = match stored_proposal_result { Some(proposal_result) => proposal_result, @@ -972,13 +967,13 @@ pub async fn query_proposal_result( let tally_epoch = proposal.voting_end_epoch; let is_author_pgf_steward = - is_steward(context.client(), &proposal.author).await; - let votes = query_proposal_votes(context.client(), proposal_id) + is_steward(client, &proposal.author).await; + let votes = query_proposal_votes(client, proposal_id) .await .unwrap_or_default(); let tally_type = proposal.get_tally_type(is_author_pgf_steward); let total_active_voting_power = - get_total_active_voting_power(context.client(), tally_epoch) + get_total_active_voting_power(client, tally_epoch) .await .unwrap_or_default(); @@ -988,7 +983,7 @@ pub async fn query_proposal_result( match vote.is_validator() { true => { let voting_power = get_validator_stake( - context.client(), + client, tally_epoch, &vote.validator, ) @@ -1003,7 +998,7 @@ pub async fn query_proposal_result( } false => { let voting_power = get_bond_amount_at( - context.client(), + client, &vote.delegator, &vote.validator, tally_epoch,