Skip to content

Commit

Permalink
Merge pull request #3677 from anoma/fraccaman/refactor-rpc-proposal
Browse files Browse the repository at this point in the history
sdk: use client instead of context
  • Loading branch information
mergify[bot] committed Aug 22, 2024
2 parents c9575a3 + e84448f commit de21f53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
3 changes: 2 additions & 1 deletion crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ pub async fn query_proposal_result<N: Namada>(

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;
Expand Down
35 changes: 15 additions & 20 deletions crates/sdk/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,49 +936,44 @@ pub async fn get_public_key_at<C: crate::queries::Client + Sync>(
}

/// Query the proposal result
pub async fn query_proposal_result<N: Namada>(
context: &N,
pub async fn query_proposal_result<C: crate::queries::Client + Sync>(
client: &C,
proposal_id: u64,
) -> Result<Option<ProposalResult>, 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::<N::Client, Option<ProposalResult>>(
RPC.vp()
.gov()
.proposal_result(context.client(), &proposal_id)
.await,
)?;
let stored_proposal_result = convert_response::<C, Option<ProposalResult>>(
RPC.vp().gov().proposal_result(client, &proposal_id).await,
)?;

let proposal_result = match stored_proposal_result {
Some(proposal_result) => proposal_result,
None => {
let tally_epoch = proposal.voting_end_epoch;
let tally_epoch = current_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();

Expand All @@ -988,7 +983,7 @@ pub async fn query_proposal_result<N: Namada>(
match vote.is_validator() {
true => {
let voting_power = get_validator_stake(
context.client(),
client,
tally_epoch,
&vote.validator,
)
Expand All @@ -1003,7 +998,7 @@ pub async fn query_proposal_result<N: Namada>(
}
false => {
let voting_power = get_bond_amount_at(
context.client(),
client,
&vote.delegator,
&vote.validator,
tally_epoch,
Expand Down

0 comments on commit de21f53

Please sign in to comment.