diff --git a/.changelog/unreleased/bug-fixes/1611-move-init-proposal-content.md b/.changelog/unreleased/bug-fixes/1611-move-init-proposal-content.md new file mode 100644 index 0000000000..fa84739c3a --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1611-move-init-proposal-content.md @@ -0,0 +1,3 @@ +- Move the content and code of init proposal transactions + into separare section to reduce tx size for hardware wallets + ([\#1611](https://github.com/anoma/namada/pull/1611)) \ No newline at end of file diff --git a/apps/src/bin/namada-client/cli.rs b/apps/src/bin/namada-client/cli.rs index bf9921a527..69ca15a89d 100644 --- a/apps/src/bin/namada-client/cli.rs +++ b/apps/src/bin/namada-client/cli.rs @@ -148,6 +148,17 @@ pub async fn main() -> Result<()> { tx::submit_withdraw::(&client, ctx, args) .await?; } + Sub::TxCommissionRateChange(TxCommissionRateChange(args)) => { + wait_until_node_is_synched(&args.tx.ledger_address).await; + let client = + HttpClient::new(args.tx.ledger_address.clone()) + .unwrap(); + let args = args.to_sdk(&mut ctx); + tx::submit_validator_commission_change::( + &client, ctx, args, + ) + .await?; + } // Ledger queries Sub::QueryEpoch(QueryEpoch(args)) => { wait_until_node_is_synched(&args.ledger_address).await; diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 0a88306f18..0f5644a159 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -164,6 +164,7 @@ pub mod cmds { .subcommand(Bond::def().display_order(2)) .subcommand(Unbond::def().display_order(2)) .subcommand(Withdraw::def().display_order(2)) + .subcommand(TxCommissionRateChange::def().display_order(2)) // Queries .subcommand(QueryEpoch::def().display_order(3)) .subcommand(QueryTransfers::def().display_order(3)) @@ -198,6 +199,8 @@ pub mod cmds { Self::parse_with_ctx(matches, TxInitProposal); let tx_vote_proposal = Self::parse_with_ctx(matches, TxVoteProposal); + let tx_commission_rate_change = + Self::parse_with_ctx(matches, TxCommissionRateChange); let bond = Self::parse_with_ctx(matches, Bond); let unbond = Self::parse_with_ctx(matches, Unbond); let withdraw = Self::parse_with_ctx(matches, Withdraw); @@ -232,6 +235,7 @@ pub mod cmds { .or(tx_init_proposal) .or(tx_vote_proposal) .or(tx_init_validator) + .or(tx_commission_rate_change) .or(bond) .or(unbond) .or(withdraw) @@ -294,6 +298,7 @@ pub mod cmds { TxUpdateVp(TxUpdateVp), TxInitAccount(TxInitAccount), TxInitValidator(TxInitValidator), + TxCommissionRateChange(TxCommissionRateChange), TxInitProposal(TxInitProposal), TxVoteProposal(TxVoteProposal), TxRevealPk(TxRevealPk), @@ -1534,6 +1539,32 @@ pub mod cmds { } } + #[derive(Clone, Debug)] + pub struct TxCommissionRateChange( + pub args::CommissionRateChange, + ); + + impl SubCmd for TxCommissionRateChange { + const CMD: &'static str = "change-commission-rate"; + + fn parse(matches: &ArgMatches) -> Option + where + Self: Sized, + { + matches.subcommand_matches(Self::CMD).map(|matches| { + TxCommissionRateChange(args::CommissionRateChange::parse( + matches, + )) + }) + } + + fn def() -> App { + App::new(Self::CMD) + .about("Change commission raate.") + .add_args::>() + } + } + #[derive(Clone, Debug)] pub struct TxVoteProposal(pub args::VoteProposal); @@ -3101,11 +3132,11 @@ pub mod args { } } - impl CliToSdk> - for TxCommissionRateChange + impl CliToSdk> + for CommissionRateChange { - fn to_sdk(self, ctx: &mut Context) -> TxCommissionRateChange { - TxCommissionRateChange:: { + fn to_sdk(self, ctx: &mut Context) -> CommissionRateChange { + CommissionRateChange:: { tx: self.tx.to_sdk(ctx), validator: ctx.get(&self.validator), rate: self.rate, @@ -3114,7 +3145,7 @@ pub mod args { } } - impl Args for TxCommissionRateChange { + impl Args for CommissionRateChange { fn parse(matches: &ArgMatches) -> Self { let tx = Tx::parse(matches); let validator = VALIDATOR.parse(matches); diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index be8936f6ee..644b3029e3 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -27,9 +27,7 @@ use namada::types::hash::Hash; use namada::types::key::*; use namada::types::storage::{Epoch, Key}; use namada::types::token; -use namada::types::transaction::governance::{ - InitProposalData, ProposalType, VoteProposalData, -}; +use namada::types::transaction::governance::{ProposalType, VoteProposalData}; use namada::types::transaction::{InitValidator, TxType}; use sha2::{Digest as Sha2Digest, Sha256}; @@ -566,13 +564,14 @@ pub async fn submit_init_proposal( Ok(()) } else { let signer = ctx.get(&signer); - let tx_data: Result = proposal.clone().try_into(); - let init_proposal_data = if let Ok(data) = tx_data { - data - } else { - eprintln!("Invalid data for init proposal transaction."); - safe_exit(1) - }; + let tx_data = proposal.clone().try_into(); + let (mut init_proposal_data, init_proposal_content, init_proposal_code) = + if let Ok(data) = tx_data { + data + } else { + eprintln!("Invalid data for init proposal transaction."); + safe_exit(1) + }; let balance = rpc::get_token_balance(client, &ctx.native_token, &proposal.author) @@ -592,7 +591,7 @@ pub async fn submit_init_proposal( safe_exit(1); } - if init_proposal_data.content.len() + if init_proposal_content.len() > governance_parameters.max_proposal_content_size as usize { eprintln!("Proposal content size too big.",); @@ -600,14 +599,33 @@ pub async fn submit_init_proposal( } let mut tx = Tx::new(TxType::Raw); - let data = init_proposal_data - .try_to_vec() - .expect("Encoding proposal data shouldn't fail"); let tx_code_hash = query_wasm_code_hash(client, args::TX_INIT_PROPOSAL) .await .unwrap(); tx.header.chain_id = ctx.config.ledger.chain_id.clone(); tx.header.expiration = args.tx.expiration; + // Put the content of this proposal into an extra section + { + let content_sec = tx.add_section(Section::ExtraData(Code::new( + init_proposal_content, + ))); + let content_sec_hash = Hash( + content_sec.hash(&mut Sha256::new()).finalize_reset().into(), + ); + init_proposal_data.content = content_sec_hash; + } + // Put any proposal code into an extra section + if let Some(init_proposal_code) = init_proposal_code { + let code_sec = tx + .add_section(Section::ExtraData(Code::new(init_proposal_code))); + let code_sec_hash = + Hash(code_sec.hash(&mut Sha256::new()).finalize_reset().into()); + init_proposal_data.r#type = + ProposalType::Default(Some(code_sec_hash)); + } + let data = init_proposal_data + .try_to_vec() + .expect("Encoding proposal data shouldn't fail"); tx.set_data(Data::new(data)); tx.set_code(Code::from_hash(tx_code_hash)); @@ -1036,7 +1054,7 @@ pub async fn submit_validator_commission_change< >( client: &C, mut ctx: Context, - mut args: args::TxCommissionRateChange, + mut args: args::CommissionRateChange, ) -> Result<(), tx::Error> { args.tx.chain_id = args .tx diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 2c2db986c6..f9423dcfdf 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -927,6 +927,7 @@ mod test_finalize_block { use namada::proto::{Code, Data, Section, Signature}; use namada::types::dec::POS_DECIMAL_PRECISION; use namada::types::governance::ProposalVote; + use namada::types::hash::Hash; use namada::types::key::tm_consensus_key_raw_hash; use namada::types::storage::Epoch; use namada::types::time::DurationSecs; @@ -1316,7 +1317,7 @@ mod test_finalize_block { let proposal = InitProposalData { id: Some(proposal_id), - content: vec![], + content: Hash::default(), author: validator.clone(), voting_start_epoch: Epoch::default(), voting_end_epoch: Epoch::default().next(), @@ -1327,6 +1328,8 @@ mod test_finalize_block { storage_api::governance::init_proposal( &mut shell.wl_storage, proposal, + vec![], + None, ) .unwrap(); diff --git a/core/src/ledger/storage_api/governance.rs b/core/src/ledger/storage_api/governance.rs index b71f4a6e40..c2316bffa7 100644 --- a/core/src/ledger/storage_api/governance.rs +++ b/core/src/ledger/storage_api/governance.rs @@ -11,6 +11,8 @@ use crate::types::transaction::governance::{ pub fn init_proposal( storage: &mut S, data: InitProposalData, + content: Vec, + code: Option>, ) -> storage_api::Result<()> where S: StorageRead + StorageWrite, @@ -23,18 +25,21 @@ where }; let content_key = storage::get_content_key(proposal_id); - storage.write_bytes(&content_key, data.content)?; + storage.write_bytes(&content_key, content)?; let author_key = storage::get_author_key(proposal_id); storage.write(&author_key, data.author.clone())?; let proposal_type_key = storage::get_proposal_type_key(proposal_id); match data.r#type { - ProposalType::Default(Some(ref code)) => { + ProposalType::Default(Some(_)) => { // Remove wasm code and write it under a different subkey storage.write(&proposal_type_key, ProposalType::Default(None))?; let proposal_code_key = storage::get_proposal_code_key(proposal_id); - storage.write_bytes(&proposal_code_key, code)? + let proposal_code = code.clone().ok_or( + storage_api::Error::new_const("Missing proposal code"), + )?; + storage.write_bytes(&proposal_code_key, proposal_code)? } _ => storage.write(&proposal_type_key, data.r#type.clone())?, } @@ -49,8 +54,10 @@ where let grace_epoch_key = storage::get_grace_epoch_key(proposal_id); storage.write(&grace_epoch_key, data.grace_epoch)?; - if let ProposalType::Default(Some(proposal_code)) = data.r#type { + if let ProposalType::Default(Some(_)) = data.r#type { let proposal_code_key = storage::get_proposal_code_key(proposal_id); + let proposal_code = + code.ok_or(storage_api::Error::new_const("Missing proposal code"))?; storage.write_bytes(&proposal_code_key, proposal_code)?; } diff --git a/core/src/types/transaction/governance.rs b/core/src/types/transaction/governance.rs index 3b1f183eaa..bfc17eeaef 100644 --- a/core/src/types/transaction/governance.rs +++ b/core/src/types/transaction/governance.rs @@ -7,6 +7,7 @@ use crate::types::address::Address; use crate::types::governance::{ self, Proposal, ProposalError, ProposalVote, VoteType, }; +use crate::types::hash::Hash; use crate::types::storage::Epoch; /// The type of a Proposal @@ -21,7 +22,7 @@ use crate::types::storage::Epoch; )] pub enum ProposalType { /// Default governance proposal with the optional wasm code - Default(Option>), + Default(Option), /// PGF council proposal PGFCouncil, /// ETH proposal @@ -54,7 +55,7 @@ impl PartialEq for ProposalType { } } -impl TryFrom for ProposalType { +impl TryFrom for (ProposalType, Option>) { type Error = ProposalError; fn try_from(value: governance::ProposalType) -> Result { @@ -62,15 +63,22 @@ impl TryFrom for ProposalType { governance::ProposalType::Default(path) => { if let Some(p) = path { match std::fs::read(p) { - Ok(code) => Ok(Self::Default(Some(code))), + Ok(code) => Ok(( + ProposalType::Default(Some(Hash::default())), + Some(code), + )), Err(_) => Err(Self::Error::InvalidProposalData), } } else { - Ok(Self::Default(None)) + Ok((ProposalType::Default(None), None)) } } - governance::ProposalType::PGFCouncil => Ok(Self::PGFCouncil), - governance::ProposalType::ETHBridge => Ok(Self::ETHBridge), + governance::ProposalType::PGFCouncil => { + Ok((ProposalType::PGFCouncil, None)) + } + governance::ProposalType::ETHBridge => { + Ok((ProposalType::ETHBridge, None)) + } } } } @@ -89,7 +97,7 @@ pub struct InitProposalData { /// The proposal id pub id: Option, /// The proposal content - pub content: Vec, + pub content: Hash, /// The proposal author address pub author: Address, /// The proposal type @@ -123,18 +131,23 @@ pub struct VoteProposalData { pub delegations: Vec
, } -impl TryFrom for InitProposalData { +impl TryFrom for (InitProposalData, Vec, Option>) { type Error = ProposalError; fn try_from(proposal: Proposal) -> Result { - Ok(InitProposalData { - id: proposal.id, - content: proposal.content.try_to_vec().unwrap(), - author: proposal.author, - r#type: proposal.r#type.try_into()?, - voting_start_epoch: proposal.voting_start_epoch, - voting_end_epoch: proposal.voting_end_epoch, - grace_epoch: proposal.grace_epoch, - }) + let (r#type, code) = proposal.r#type.try_into()?; + Ok(( + InitProposalData { + id: proposal.id, + content: Hash::default(), + author: proposal.author, + r#type, + voting_start_epoch: proposal.voting_start_epoch, + voting_end_epoch: proposal.voting_end_epoch, + grace_epoch: proposal.grace_epoch, + }, + proposal.content.try_to_vec().unwrap(), + code, + )) } } diff --git a/scripts/generator.sh b/scripts/generator.sh index 9c8a2de352..16ced33298 100755 --- a/scripts/generator.sh +++ b/scripts/generator.sh @@ -12,26 +12,6 @@ NAMADA_DIR="$(pwd)" export NAMADA_LEDGER_LOG_PATH="$(pwd)/vectors.json" export NAMADA_TX_LOG_PATH="$(pwd)/debugs.txt" -echo '{ - "content": { - "title": "TheTitle", - "authors": "test@test.com", - "discussions-to": "www.github.com/anoma/aip/1", - "created": "2022-03-10T08:54:37Z", - "license": "MIT", - "abstract": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", - "motivation": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", - "details": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", - "requires": "2" - }, - "author": "atest1v4ehgw36xvcyyvejgvenxs34g3zygv3jxqunjd6rxyeyys3sxy6rwvfkx4qnj33hg9qnvse4lsfctw", - "voting_start_epoch": 12, - "voting_end_epoch": 24, - "grace_epoch": 30, - "type": { "Default": "'"$NAMADA_DIR"'/wasm_for_tests/tx_no_op.wasm" } -} -' > valid_proposal.json - if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" elif [ "$1" = "server" ]; then @@ -56,11 +36,240 @@ elif [ "$1" = "client" ]; then echo > $NAMADA_TX_LOG_PATH echo $'[' > $NAMADA_LEDGER_LOG_PATH + + ALBERT_ADDRESS=$(cargo run --bin namadaw -- address find --alias albert | sed 's/^Found address Established: //') + + echo '{ + "author":"'$ALBERT_ADDRESS'", + "content":{ + "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors":"test@test.com", + "created":"2022-03-10T08:54:37Z", + "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to":"www.github.com/anoma/aip/1", + "license":"MIT", + "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires":"2", + "title":"TheTitle" + }, + "grace_epoch":30, + "type":{ + "Default":"'$NAMADA_DIR'/wasm_for_tests/tx_proposal_code.wasm" + }, + "voting_end_epoch":24, + "voting_start_epoch":12 +} +' > proposal_submission_valid_proposal.json + + echo '{ + "content": { + "abstract": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors": "test@test.com", + "created": "2022-03-10T08:54:37Z", + "details": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to": "www.github.com/anoma/aip/1", + "license": "MIT", + "motivation": "Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires": "2", + "title": "TheTitle" + }, + "author": "'$ALBERT_ADDRESS'", + "tally_epoch": 18, + "signature": { + "Ed25519": { + "R_bytes": [ + 113, + 196, + 231, + 134, + 101, + 191, + 75, + 17, + 245, + 19, + 50, + 231, + 183, + 80, + 162, + 38, + 108, + 72, + 72, + 2, + 116, + 112, + 121, + 33, + 197, + 67, + 64, + 116, + 21, + 250, + 196, + 121 + ], + "s_bytes": [ + 87, + 163, + 134, + 87, + 42, + 156, + 121, + 211, + 189, + 19, + 255, + 5, + 23, + 178, + 143, + 39, + 118, + 249, + 37, + 53, + 121, + 136, + 59, + 103, + 190, + 91, + 121, + 95, + 46, + 54, + 168, + 9 + ] + } + }, + "address": "'$ALBERT_ADDRESS'" +} +' > proposal_offline_proposal + + echo '{ + "author":"'$ALBERT_ADDRESS'", + "content":{ + "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors":"test@test.com", + "created":"2022-03-10T08:54:37Z", + "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to":"www.github.com/anoma/aip/1", + "license":"MIT", + "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires":"2", + "title":"TheTitle" + }, + "grace_epoch":18, + "type":{ + "Default":null + }, + "voting_end_epoch":9, + "voting_start_epoch":3 +}' > proposal_offline_valid_proposal.json + + echo '{ + "author":"'$ALBERT_ADDRESS'", + "content":{ + "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors":"test@test.com", + "created":"2022-03-10T08:54:37Z", + "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to":"www.github.com/anoma/aip/1", + "license":"MIT", + "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires":"2", + "title":"TheTitle" + }, + "grace_epoch":30, + "type":"ETHBridge", + "voting_end_epoch":24, + "voting_start_epoch":12 +}' > eth_governance_proposal_valid_proposal.json + + echo '{ + "author":"'$ALBERT_ADDRESS'", + "content":{ + "abstract":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros. Nullam sed ex justo. Ut at placerat ipsum, sit amet rhoncus libero. Sed blandit non purus non suscipit. Phasellus sed quam nec augue bibendum bibendum ut vitae urna. Sed odio diam, ornare nec sapien eget, congue viverra enim.", + "authors":"test@test.com", + "created":"2022-03-10T08:54:37Z", + "details":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices. Quisque viverra varius cursus. Praesent sed mauris gravida, pharetra turpis non, gravida eros.", + "discussions-to":"www.github.com/anoma/aip/1", + "license":"MIT", + "motivation":"Ut convallis eleifend orci vel venenatis. Duis vulputate metus in lacus sollicitudin vestibulum. Suspendisse vel velit ac est consectetur feugiat nec ac urna. Ut faucibus ex nec dictum fermentum. Morbi aliquet purus at sollicitudin ultrices.", + "requires":"2", + "title":"TheTitle" + }, + "grace_epoch":30, + "type":"PGFCouncil", + "voting_end_epoch":24, + "voting_start_epoch":12 +}' > pgf_governance_proposal_valid_proposal.json + + # proposal_submission + + cargo run --bin namadac --features std -- --mode full bond --validator validator-0 --source Bertha --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --node 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full change-commission-rate --validator Bertha --commission-rate 0.02 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + + PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- --mode full init-proposal --force --data-path proposal_submission_valid_proposal.json --node 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + + cargo run --bin namadac --features std -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada --mode validator vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --signer validator-0 --node 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote nay --signer Bertha --node 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --signer Albert --node 127.0.0.1:27657 + + # proposal_offline + + cargo run --bin namadac --features std -- --mode full bond --validator validator-0 --source Albert --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --node 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full change-commission-rate --validator Albert --commission-rate 0.05 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full init-proposal --force --data-path proposal_offline_valid_proposal.json --offline --node 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full vote-proposal --data-path proposal_offline_proposal --vote yay --signer Albert --offline --node 127.0.0.1:27657 + + # eth_governance_proposal + + cargo run --bin namadac --features std -- --mode full bond --validator validator-0 --source Bertha --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full change-commission-rate --validator Bertha --commission-rate 0.07 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + + PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- --mode full init-proposal --force --data-path eth_governance_proposal_valid_proposal.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + + cargo run --bin namadac --features std -- --mode full vote-proposal --force --proposal-id 0 --vote yay --eth '011586062748ba53bc53155e817ec1ea708de75878dcb9a5713bf6986d87fe14e7 fd34672ab5' --signer Bertha --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada --mode validator vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --eth '011586062748ba53bc53155e817ec1ea708de75878dcb9a5713bf6986d87fe14e7 fd34672ab5' --signer validator-0 --ledger-address 127.0.0.1:27657 + + # pgf_governance_proposal + + cargo run --bin namadac --features std -- --mode full bond --validator validator-0 --source Bertha --amount 900 --gas-amount 0 --gas-limit 0 --gas-token NAM --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full change-commission-rate --validator Bertha --commission-rate 0.09 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + + PROPOSAL_ID_0=$(cargo run --bin namadac --features std -- --mode full init-proposal --force --data-path pgf_governance_proposal_valid_proposal.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + + PROPOSAL_ID_1=$(cargo run --bin namadac --features std -- --mode full init-proposal --force --data-path pgf_governance_proposal_valid_proposal.json --ledger-address 127.0.0.1:27657 | grep -o -P '(?<=/proposal/).*(?=/author)') + + cargo run --bin namadac --features std -- --base-dir $NAMADA_BASE_DIR/setup/validator-0/.namada --mode validator vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --pgf "$ALBERT_ADDRESS 1000" --signer validator-0 --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full vote-proposal --force --proposal-id $PROPOSAL_ID_0 --vote yay --pgf "$ALBERT_ADDRESS 900" --signer Bertha --ledger-address 127.0.0.1:27657 + + cargo run --bin namadac --features std -- --mode full vote-proposal --force --proposal-id $PROPOSAL_ID_1 --vote yay --pgf "$ALBERT_ADDRESS 900" --signer Bertha --ledger-address 127.0.0.1:27657 + + # non-proposal tests cargo run --bin namadac --features std -- transfer --source bertha --target christel --token btc --amount 23 --force --signing-key bertha-key --ledger-address 127.0.0.1:27657 cargo run --bin namadac --features std -- bond --validator bertha --amount 25 --signing-key bertha-key --force --ledger-address 127.0.0.1:27657 + cargo run --bin namadac --features std -- --mode full change-commission-rate --validator Bertha --commission-rate 0.11 --gas-amount 0 --gas-limit 0 --gas-token NAM --force --node 127.0.0.1:27657 + cargo run --bin namadac --features std -- reveal-pk --public-key albert-key --force --ledger-address 127.0.0.1:27657 cargo run --bin namadac --features std -- update --code-path vp_user.wasm --address bertha --signing-key bertha-key --force --ledger-address 127.0.0.1:27657 @@ -77,8 +286,6 @@ elif [ "$1" = "client" ]; then cargo run --bin namadac --features std -- ibc-transfer --source bertha --receiver christel --token btc --amount 24 --channel-id channel-141 --signing-key bertha-key --force --ledger-address 127.0.0.1:27657 - #cargo run --bin namadac -- init-proposal --data-path valid_proposal.json --epoch 2 --force --signing-key bertha-key --ledger-address 127.0.0.1:27657 - cargo run --bin namadaw -- masp add --alias a_spending_key --value xsktest1qqqqqqqqqqqqqq9v0sls5r5de7njx8ehu49pqgmqr9ygelg87l5x8y4s9r0pjlvu69au6gn3su5ewneas486hdccyayx32hxvt64p3d0hfuprpgcgv2q9gdx3jvxrn02f0nnp3jtdd6f5vwscfuyum083cvfv4jun75ak5sdgrm2pthzj3sflxc0jx0edrakx3vdcngrfjmru8ywkguru8mxss2uuqxdlglaz6undx5h8w7g70t2es850g48xzdkqay5qs0yw06rtxcvedhsv --unsafe-dont-encrypt cargo run --bin namadaw -- masp add --alias b_spending_key --value xsktest1qqqqqqqqqqqqqqpagte43rsza46v55dlz8cffahv0fnr6eqacvnrkyuf9lmndgal7c2k4r7f7zu2yr5rjwr374unjjeuzrh6mquzy6grfdcnnu5clzaq2llqhr70a8yyx0p62aajqvrqjxrht3myuyypsvm725uyt5vm0fqzrzuuedtf6fala4r4nnazm9y9hq5yu6pq24arjskmpv4mdgfn3spffxxv8ugvym36kmnj45jcvvmm227vqjm5fq8882yhjsq97p7xrwqqd82s0 --unsafe-dont-encrypt @@ -101,9 +308,17 @@ elif [ "$1" = "client" ]; then cargo run --bin namadac --features std -- --mode full transfer --source b_spending_key --target bb_payment_address --token btc --amount 6 --force --ledger-address 127.0.0.1:27657 + rm proposal_submission_valid_proposal.json + + rm proposal_offline_proposal + + rm proposal_offline_valid_proposal.json + + rm eth_governance_proposal_valid_proposal.json + + rm pgf_governance_proposal_valid_proposal.json + perl -0777 -i.original -pe 's/,\s*$//igs' $NAMADA_LEDGER_LOG_PATH echo $'\n]' >> $NAMADA_LEDGER_LOG_PATH fi - -rm valid_proposal.json diff --git a/shared/src/ledger/args.rs b/shared/src/ledger/args.rs index 0ad90faf0a..e05e216db4 100644 --- a/shared/src/ledger/args.rs +++ b/shared/src/ledger/args.rs @@ -332,7 +332,7 @@ pub struct QueryBondedStake { #[derive(Clone, Debug)] /// Commission rate change args -pub struct TxCommissionRateChange { +pub struct CommissionRateChange { /// Common tx arguments pub tx: Tx, /// Validator address (should be self) diff --git a/shared/src/ledger/signing.rs b/shared/src/ledger/signing.rs index 30bdb12d34..a3d7037257 100644 --- a/shared/src/ledger/signing.rs +++ b/shared/src/ledger/signing.rs @@ -1,5 +1,5 @@ //! Functions to sign transactions -use std::collections::{BTreeMap, HashMap}; +use std::collections::HashMap; #[cfg(feature = "std")] use std::env; #[cfg(feature = "std")] @@ -43,7 +43,7 @@ use crate::ledger::tx::{ pub use crate::ledger::wallet::store::AddressVpType; use crate::ledger::wallet::{Wallet, WalletUtils}; use crate::ledger::{args, rpc}; -use crate::proto::{Section, Signature, Tx}; +use crate::proto::{MaspBuilder, Section, Signature, Tx}; use crate::types::key::*; use crate::types::masp::{ExtendedViewingKey, PaymentAddress}; use crate::types::storage::Epoch; @@ -532,6 +532,86 @@ fn format_outputs(output: &mut Vec) { } } +/// Adds a Ledger output for the sender and destination for transparent and MASP +/// transactions +pub async fn make_ledger_masp_endpoints< + C: crate::ledger::queries::Client + Sync, +>( + client: &C, + tokens: &HashMap, + output: &mut Vec, + transfer: &Transfer, + builder: Option<&MaspBuilder>, + assets: &HashMap, MaspDenom, Epoch)>, +) { + if transfer.source != masp() { + output.push(format!("Sender : {}", transfer.source)); + if transfer.target == masp() { + make_ledger_amount_addr( + tokens, + output, + transfer.amount, + &transfer.token, + &transfer.sub_prefix, + "Sending ", + ); + } + } else if let Some(builder) = builder { + for sapling_input in builder.builder.sapling_inputs() { + let vk = ExtendedViewingKey::from(*sapling_input.key()); + output.push(format!("Sender : {}", vk)); + make_ledger_amount_asset( + client, + tokens, + output, + sapling_input.value(), + &sapling_input.asset_type(), + assets, + "Sending ", + ) + .await; + } + } + if transfer.target != masp() { + output.push(format!("Destination : {}", transfer.target)); + if transfer.source == masp() { + make_ledger_amount_addr( + tokens, + output, + transfer.amount, + &transfer.token, + &transfer.sub_prefix, + "Receiving ", + ); + } + } else if let Some(builder) = builder { + for sapling_output in builder.builder.sapling_outputs() { + let pa = PaymentAddress::from(sapling_output.address()); + output.push(format!("Destination : {}", pa)); + make_ledger_amount_asset( + client, + tokens, + output, + sapling_output.value(), + &sapling_output.asset_type(), + assets, + "Receiving ", + ) + .await; + } + } + if transfer.source != masp() && transfer.target != masp() { + make_ledger_amount_addr( + tokens, + output, + transfer.amount, + &transfer.token, + &transfer.sub_prefix, + "", + ); + } +} + /// Converts the given transaction to the form that is displayed on the Ledger /// device pub async fn to_ledger_vector< @@ -711,15 +791,8 @@ pub async fn to_ledger_vector< ), format!("Grace epoch : {}", init_proposal_data.grace_epoch), ]); - let content: BTreeMap = - BorshDeserialize::try_from_slice(&init_proposal_data.content)?; - if !content.is_empty() { - for (key, value) in &content { - tv.output.push(format!("Content {} : {}", key, value)); - } - } else { - tv.output.push("Content : (none)".to_string()); - } + tv.output + .push(format!("Content: {}", init_proposal_data.content)); tv.output_expert.extend(vec![ format!("ID : {}", init_proposal_data_id), @@ -734,14 +807,8 @@ pub async fn to_ledger_vector< ), format!("Grace epoch : {}", init_proposal_data.grace_epoch), ]); - if !content.is_empty() { - for (key, value) in content { - tv.output_expert - .push(format!("Content {} : {}", key, value)); - } - } else { - tv.output_expert.push("Content : none".to_string()); - } + tv.output + .push(format!("Content: {}", init_proposal_data.content)); } else if code_hash == vote_proposal_hash { let vote_proposal = VoteProposalData::try_from_slice(&tx.data().ok_or_else(|| { @@ -849,79 +916,24 @@ pub async fn to_ledger_vector< tv.name = "Transfer 0".to_string(); tv.output.push("Type : Transfer".to_string()); - if transfer.source != masp() { - tv.output.push(format!("Sender : {}", transfer.source)); - if transfer.target == masp() { - make_ledger_amount_addr( - &tokens, - &mut tv.output, - transfer.amount, - &transfer.token, - &transfer.sub_prefix, - "Sending ", - ); - } - } else if let Some(builder) = builder { - for input in builder.builder.sapling_inputs() { - let vk = ExtendedViewingKey::from(*input.key()); - tv.output.push(format!("Sender : {}", vk)); - make_ledger_amount_asset( - client, - &tokens, - &mut tv.output, - input.value(), - &input.asset_type(), - &asset_types, - "Sending ", - ) - .await; - } - } - if transfer.target != masp() { - tv.output.push(format!("Destination : {}", transfer.target)); - if transfer.source == masp() { - make_ledger_amount_addr( - &tokens, - &mut tv.output, - transfer.amount, - &transfer.token, - &transfer.sub_prefix, - "Receiving ", - ); - } - } else if let Some(builder) = builder { - for output in builder.builder.sapling_outputs() { - let pa = PaymentAddress::from(output.address()); - tv.output.push(format!("Destination : {}", pa)); - make_ledger_amount_asset( - client, - &tokens, - &mut tv.output, - output.value(), - &output.asset_type(), - &asset_types, - "Receiving ", - ) - .await; - } - } - if transfer.source != masp() && transfer.target != masp() { - make_ledger_amount_addr( - &tokens, - &mut tv.output, - transfer.amount, - &transfer.token, - &transfer.sub_prefix, - "", - ); - } - - tv.output_expert.extend(vec![ - format!("Source : {}", transfer.source), - format!("Target : {}", transfer.target), - format!("Token : {}", transfer.token), - format!("Amount : {}", transfer.amount), - ]); + make_ledger_masp_endpoints( + client, + &tokens, + &mut tv.output, + &transfer, + builder, + &asset_types, + ) + .await; + make_ledger_masp_endpoints( + client, + &tokens, + &mut tv.output_expert, + &transfer, + builder, + &asset_types, + ) + .await; } else if code_hash == ibc_hash { let msg = Any::decode( tx.data() diff --git a/shared/src/ledger/tx.rs b/shared/src/ledger/tx.rs index 27245ecaed..339c7ac5c9 100644 --- a/shared/src/ledger/tx.rs +++ b/shared/src/ledger/tx.rs @@ -599,7 +599,7 @@ pub async fn submit_validator_commission_change< >( client: &C, wallet: &mut Wallet, - args: args::TxCommissionRateChange, + args: args::CommissionRateChange, ) -> Result<(), Error> { let epoch = rpc::query_epoch(client).await; diff --git a/wasm/checksums.json b/wasm/checksums.json index 4dc880d270..f0bcae2c21 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,21 +1,21 @@ { - "tx_bond.wasm": "tx_bond.22ae29557b12fcd402add2041b0616b02ec517b255f57fe2a2b42f8e8b122d6a.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.bc2221a98b0a7434ee10fc60e90c6da75722d18233bb20b878959ca739dde3a3.wasm", - "tx_ibc.wasm": "tx_ibc.6a67b61b4b749498f5f11d667d41bad841781089bf104f53843675569cbead06.wasm", - "tx_init_account.wasm": "tx_init_account.8d0853e9b8c2c453ebf18d32ba7268150318d64efd93d93bcfbb1f1e21789dfd.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.6fb695273206ac9a0666e6d25ed002cd335673b6f444e01df9fcc8b4a0bf5967.wasm", - "tx_init_validator.wasm": "tx_init_validator.d57519588d95903437d987157d293e25f2e919fa4da4b9e998b95f4b6c8e098b.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.24a641072eb7aba949f0d4f927dc156f8096d3e4da6fad046363a3fc1cf0cb01.wasm", - "tx_transfer.wasm": "tx_transfer.60a7dbe38bad2a86f52f6cd109cd30002b46de4cd7ee82045fd3302da6deb424.wasm", - "tx_unbond.wasm": "tx_unbond.64ce8a1181e993c8cea75ec52c8a103d98d946e633ccd1c134041ba5473ffbce.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.fdb92288ddf746c8e94fdd3d1cef8eb0498a576da6d080bce9a0c6ed32dde909.wasm", - "tx_update_vp.wasm": "tx_update_vp.5ede9d5a56d8ebe7075f9a9bb8a988fcd629e5ca1f800ca738a10d8b31d56ae7.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.2f7176863cec7379cbf2c27e17dc6475e2a4b5a772e4142bb3cefa5783cb710f.wasm", - "tx_withdraw.wasm": "tx_withdraw.f30cc0a7d015cdc141cb3d68865006486f0cdb40140ddafec11528fd3e9ceb3c.wasm", - "vp_implicit.wasm": "vp_implicit.ee1caec6e233c899dd6c0f7106ae493304394a7a0774db0cd0714afdee8d26bd.wasm", - "vp_masp.wasm": "vp_masp.8f2e84eeacf76c17892d7cd4e327a071ce399ab4cdd48fb709bb66324e82bea1.wasm", - "vp_testnet_faucet.wasm": "vp_testnet_faucet.9cd90e26b1d2660ad1add04e65c302325de7210fca5cce2f520a08ad83f9cba7.wasm", - "vp_token.wasm": "vp_token.94be4a19c2b3e4b78f61d213ea5d070e81f6a79348bc6b05ff6cc36291a2dbcb.wasm", - "vp_user.wasm": "vp_user.595d69f43189d651c7fddbb9106683522ae5128194b382ff4193952930faa142.wasm", - "vp_validator.wasm": "vp_validator.285dc9030008de641312269bb4e707a2882ff7daeb18ddfc70a238eddf00af57.wasm" + "tx_bond.wasm": "tx_bond.7b553643c34d31118b7b684bc9330ca8383c91b1a6027ac0e883fb0192db8e67.wasm", + "tx_change_validator_commission.wasm": "tx_change_validator_commission.9e4325398d9f15e0f752b4cfadcda361b9a5db5bb50d0c1eba1ae0103b244521.wasm", + "tx_ibc.wasm": "tx_ibc.4078f6701fce3201fc7cada8ddcd717e641f65571adc9ffaae7815b1d044cba3.wasm", + "tx_init_account.wasm": "tx_init_account.e6eee9e84876ca74534fc88c11ff391dad77c0d36c8e5112ba29e4f32fecd7fd.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.43d5cf697fabf34a92cdbafdcf1b31e117010abe20a72c64ee867f14832f9d1b.wasm", + "tx_init_validator.wasm": "tx_init_validator.1095233a6bb97c4a10ab795b1b476636692bce586024eedb3874c9fc0f17d572.wasm", + "tx_reveal_pk.wasm": "tx_reveal_pk.323961f7ddcd7914a695a8c3ba830aa74196cf98ced3a221a8d089919e106715.wasm", + "tx_transfer.wasm": "tx_transfer.98b5567748d4b1454148e2d6ce88844e18060987bfc7491a201a6e2c5fd55389.wasm", + "tx_unbond.wasm": "tx_unbond.09f6b1b7ce576556158a90f83423894e2cc59f30406eca714b9a181c60979b4a.wasm", + "tx_unjail_validator.wasm": "tx_unjail_validator.8d10144875bffa6f37e748971e11220bd4ab2df3dacc87d6e46936eeef1d5357.wasm", + "tx_update_vp.wasm": "tx_update_vp.0767f6914484d03194fb5d61b88f6cf3b41e0cbd87e2fb697551f8c4ed143853.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.63bee839b6267901a5838f8bde7ad2afbcf0f7c8d45c8bf6d94ac26fe4811874.wasm", + "tx_withdraw.wasm": "tx_withdraw.4e8ceb3a6345ad0392a18103cb09dc4e618f7fd43674629e50459929768f8c01.wasm", + "vp_implicit.wasm": "vp_implicit.cef440d43efa3abc2b724139a8cda1551bfb9c27676845723c83b10dabf2a3d9.wasm", + "vp_masp.wasm": "vp_masp.eccc2714c5c509e23150a42324c5fa99813a6365962ce055480a82a006c452d2.wasm", + "vp_testnet_faucet.wasm": "vp_testnet_faucet.3e68597d9bab83ff06a1c38b345c31ae02868bbb7b029f004a07f3b06c50c27e.wasm", + "vp_token.wasm": "vp_token.d16fc4702135bcd161ddf54586dbc61d7ffac820ae6b83542f110a57bc3b54e6.wasm", + "vp_user.wasm": "vp_user.ab46199cd33fc17375f23a7da44b48152c634083979c1d70bb1974acae0c043f.wasm", + "vp_validator.wasm": "vp_validator.351db7b15aca23948dad97e7a5264571f7759be5da9accbddd10a9c2e533b9de.wasm" } \ No newline at end of file diff --git a/wasm/wasm_source/src/tx_init_proposal.rs b/wasm/wasm_source/src/tx_init_proposal.rs index 2507a18d21..c0da1d9316 100644 --- a/wasm/wasm_source/src/tx_init_proposal.rs +++ b/wasm/wasm_source/src/tx_init_proposal.rs @@ -3,13 +3,28 @@ use namada_tx_prelude::*; #[transaction] -fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { - let signed = tx_data; - let data = signed.data().ok_or_err_msg("Missing data")?; +fn apply_tx(ctx: &mut Ctx, tx: Tx) -> TxResult { + let data = tx.data().ok_or_err_msg("Missing data")?; let tx_data = transaction::governance::InitProposalData::try_from_slice(&data[..]) .wrap_err("failed to decode InitProposalData")?; + // Get the content from the referred to section + let content = tx + .get_section(&tx_data.content) + .ok_or_err_msg("Missing proposal content")? + .extra_data() + .ok_or_err_msg("Missing full proposal content")?; + // Get the code from the referred to section + let code = match tx_data.r#type { + transaction::governance::ProposalType::Default(Some(hash)) => Some( + tx.get_section(&hash) + .ok_or_err_msg("Missing proposal code")? + .extra_data() + .ok_or_err_msg("Missing full proposal code")?, + ), + _ => None, + }; log_string("apply_tx called to create a new governance proposal"); - governance::init_proposal(ctx, tx_data) + governance::init_proposal(ctx, tx_data, content, code) } diff --git a/wasm_for_tests/tx_memory_limit.wasm b/wasm_for_tests/tx_memory_limit.wasm index a347676c78..caba19deec 100755 Binary files a/wasm_for_tests/tx_memory_limit.wasm and b/wasm_for_tests/tx_memory_limit.wasm differ diff --git a/wasm_for_tests/tx_mint_tokens.wasm b/wasm_for_tests/tx_mint_tokens.wasm index 55619c33f5..2b9a77652e 100755 Binary files a/wasm_for_tests/tx_mint_tokens.wasm and b/wasm_for_tests/tx_mint_tokens.wasm differ diff --git a/wasm_for_tests/tx_no_op.wasm b/wasm_for_tests/tx_no_op.wasm index 7cfb49d910..0a5b81ff03 100755 Binary files a/wasm_for_tests/tx_no_op.wasm and b/wasm_for_tests/tx_no_op.wasm differ diff --git a/wasm_for_tests/tx_proposal_code.wasm b/wasm_for_tests/tx_proposal_code.wasm index b2d35b39c8..ef4e11b935 100755 Binary files a/wasm_for_tests/tx_proposal_code.wasm and b/wasm_for_tests/tx_proposal_code.wasm differ diff --git a/wasm_for_tests/tx_read_storage_key.wasm b/wasm_for_tests/tx_read_storage_key.wasm index e79ae72cb9..9afdf98b7a 100755 Binary files a/wasm_for_tests/tx_read_storage_key.wasm and b/wasm_for_tests/tx_read_storage_key.wasm differ diff --git a/wasm_for_tests/tx_write.wasm b/wasm_for_tests/tx_write.wasm index 2d0ce34be7..ac3075deeb 100755 Binary files a/wasm_for_tests/tx_write.wasm and b/wasm_for_tests/tx_write.wasm differ diff --git a/wasm_for_tests/vp_always_false.wasm b/wasm_for_tests/vp_always_false.wasm index 389acc29b1..6b8b88b7f8 100755 Binary files a/wasm_for_tests/vp_always_false.wasm and b/wasm_for_tests/vp_always_false.wasm differ diff --git a/wasm_for_tests/vp_always_true.wasm b/wasm_for_tests/vp_always_true.wasm index 47460e2f57..87d2b85338 100755 Binary files a/wasm_for_tests/vp_always_true.wasm and b/wasm_for_tests/vp_always_true.wasm differ diff --git a/wasm_for_tests/vp_eval.wasm b/wasm_for_tests/vp_eval.wasm index 218a125101..6f9652534c 100755 Binary files a/wasm_for_tests/vp_eval.wasm and b/wasm_for_tests/vp_eval.wasm differ diff --git a/wasm_for_tests/vp_memory_limit.wasm b/wasm_for_tests/vp_memory_limit.wasm index cfe4d441cc..793e1e44d1 100755 Binary files a/wasm_for_tests/vp_memory_limit.wasm and b/wasm_for_tests/vp_memory_limit.wasm differ diff --git a/wasm_for_tests/vp_read_storage_key.wasm b/wasm_for_tests/vp_read_storage_key.wasm index 7c7ebc8c81..a67d42f920 100755 Binary files a/wasm_for_tests/vp_read_storage_key.wasm and b/wasm_for_tests/vp_read_storage_key.wasm differ