Skip to content

Commit

Permalink
Writes the result of a governance proposal in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Oct 11, 2023
1 parent 3f979bf commit 78ccf42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ where
)?;
let proposal_result =
compute_proposal_result(votes, total_voting_power, tally_type);
let proposal_result_key = gov_storage::get_proposal_result_key(id);
shell
.wl_storage
.write(&proposal_result_key, proposal_result)?;

let transfer_address = match proposal_result.result {
TallyResult::Passed => {
Expand Down
10 changes: 10 additions & 0 deletions core/src/ledger/governance/storage/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct Keys {
min_grace_epoch: &'static str,
counter: &'static str,
pending: &'static str,
result: &'static str,
}

/// Check if key is inside governance address space
Expand Down Expand Up @@ -459,6 +460,15 @@ pub fn get_proposal_execution_key(id: u64) -> Key {
.expect("Cannot obtain a storage key")
}

/// Get the proposal result key
pub fn get_proposal_result_key(id: u64) -> Key {
proposal_prefix()
.push(&id.to_string())
.expect("Cannot obtain a storage key")
.push(&Keys::VALUES.result.to_owned())
.expect("Cannot obtain a storage key")
}

/// Get proposal id from key
pub fn get_proposal_id(key: &Key) -> Option<u64> {
match key.get_at(2) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/ledger/governance/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl TallyType {
}

/// The result of a proposal
#[derive(Copy, Clone, BorshSerialize, BorshDeserialize)]
pub enum TallyResult {
/// Proposal was accepted with the associated value
Passed,
Expand Down Expand Up @@ -126,6 +127,7 @@ impl TallyResult {
}

/// The result with votes of a proposal
#[derive(Clone, Copy, BorshDeserialize, BorshSerialize)]
pub struct ProposalResult {
/// The result of a proposal
pub result: TallyResult,
Expand Down

0 comments on commit 78ccf42

Please sign in to comment.