Skip to content

Commit

Permalink
Client first looks for governance proposal result in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Oct 11, 2023
1 parent 78ccf42 commit 464d93a
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,23 +1045,39 @@ pub async fn query_proposal_result<
return;
};

let is_author_steward = query_pgf_stewards(client)
.await
.iter()
.any(|steward| steward.address.eq(&proposal.author));
let tally_type = proposal.get_tally_type(is_author_steward);
let total_voting_power =
get_total_staked_tokens(client, proposal.voting_end_epoch).await;
let proposal_result_key =
governance_storage::get_proposal_result_key(proposal_id);
let proposal_result =
// Try to directly query the result in storage first
match query_storage_value(client, &proposal_result_key).await {
Ok(result) => result,
Err(_) => {
// If failure, run the tally
let is_author_steward = query_pgf_stewards(client)
.await
.iter()
.any(|steward| steward.address.eq(&proposal.author));
let tally_type = proposal.get_tally_type(is_author_steward);
let total_voting_power = get_total_staked_tokens(
client,
proposal.voting_end_epoch,
)
.await;

let votes = compute_proposal_votes(
client,
proposal_id,
proposal.voting_end_epoch,
)
.await;
let votes = compute_proposal_votes(
client,
proposal_id,
proposal.voting_end_epoch,
)
.await;

let proposal_result =
compute_proposal_result(votes, total_voting_power, tally_type);
compute_proposal_result(
votes,
total_voting_power,
tally_type,
)
}
};

display_line!(IO, "Proposal Id: {} ", proposal_id);
display_line!(IO, "{:4}{}", "", proposal_result);
Expand Down

0 comments on commit 464d93a

Please sign in to comment.