Skip to content

Commit

Permalink
Merge pull request #3617 from anoma/fraccaman/governance-proposal-cli…
Browse files Browse the repository at this point in the history
…ent-better-hash

client: print sha256 of proposal wasm
  • Loading branch information
mergify[bot] authored Aug 13, 2024
2 parents 511f079 + 8cb793c commit f08d3f2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Display the hash of the proposal wasm code when querying proposals with
associated wasm payload. ([\#3617](https://github.com/anoma/namada/pull/3617))
21 changes: 17 additions & 4 deletions crates/governance/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::collections::{BTreeMap, BTreeSet};
use namada_core::address::Address;
use namada_core::borsh::BorshDeserialize;
use namada_core::collections::HashSet;
use namada_core::hash::Hash;
use namada_core::storage::Epoch;
use namada_core::token;
use namada_state::{
Expand Down Expand Up @@ -169,17 +170,29 @@ where
let proposal_type: Option<ProposalType> =
storage.read(&proposal_type_key)?;

let proposal = proposal_type.map(|proposal_type| StorageProposal {
let proposal_type = if let Some(proposal_type) = proposal_type {
if let ProposalType::DefaultWithWasm(_) = proposal_type {
let proposal_code_key = governance_keys::get_proposal_code_key(id);
let proposal_code: Vec<u8> =
storage.read(&proposal_code_key)?.unwrap_or_default();
let proposal_code_hash = Hash::sha256(proposal_code);
ProposalType::DefaultWithWasm(proposal_code_hash)
} else {
proposal_type
}
} else {
return Ok(None);
};

Ok(Some(StorageProposal {
id,
content: content.unwrap(),
author: author.unwrap(),
r#type: proposal_type,
voting_start_epoch: voting_start_epoch.unwrap(),
voting_end_epoch: voting_end_epoch.unwrap(),
activation_epoch: activation_epoch.unwrap(),
});

Ok(proposal)
}))
}

/// Query all the votes for a proposal_id
Expand Down
10 changes: 1 addition & 9 deletions crates/node/src/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ where
TallyResult::Passed => {
let proposal_event = match proposal_type {
ProposalType::Default => {
let proposal_code =
gov_api::get_proposal_code(&shell.state, id)?
.unwrap_or_default();
let _result = execute_default_proposal(
shell,
id,
proposal_code.clone(),
)?;
tracing::info!(
"Governance proposal #{} (default) has passed.",
id,
Expand Down Expand Up @@ -176,7 +168,7 @@ where
}
ProposalType::PGFPayment(payments) => {
let native_token = &shell.state.get_native_token()?;
let _result = execute_pgf_funding_proposal(
execute_pgf_funding_proposal(
&mut shell.state,
events,
native_token,
Expand Down

0 comments on commit f08d3f2

Please sign in to comment.