Skip to content

Commit

Permalink
fixup! sdk: use hash instead of wasm code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed May 30, 2023
1 parent 548dfa4 commit 504f4de
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 152 deletions.
119 changes: 17 additions & 102 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2112,13 +2112,7 @@ pub mod args {
sub_prefix: self.sub_prefix,
amount: self.amount,
native_token: ctx.native_token.clone(),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -2173,13 +2167,7 @@ pub mod args {
channel_id: self.channel_id,
timeout_height: self.timeout_height,
timeout_sec_offset: self.timeout_sec_offset,
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -2240,21 +2228,8 @@ pub mod args {
TxInitAccount::<SdkTypes> {
tx: self.tx.to_sdk(ctx),
source: ctx.get(&self.source),
vp_code: ctx.read_wasm(self.vp_code),
vp_code_path: self
.vp_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
vp_code_path: self.vp_code_path.to_path_buf(),
tx_code_path: self.tx_code_path.to_path_buf(),
public_key: ctx.get_cached(&self.public_key),
}
}
Expand All @@ -2267,13 +2242,11 @@ pub mod args {
let vp_code_path = CODE_PATH_OPT
.parse(matches)
.unwrap_or_else(|| PathBuf::from(VP_USER_WASM));
let vp_code = vp_code_path.clone();
let tx_code_path = PathBuf::from(TX_INIT_ACCOUNT_WASM);
let public_key = PUBLIC_KEY.parse(matches);
Self {
tx,
source,
vp_code,
vp_code_path,
public_key,
tx_code_path,
Expand Down Expand Up @@ -2310,19 +2283,9 @@ pub mod args {
max_commission_rate_change: self.max_commission_rate_change,
validator_vp_code_path: self
.validator_vp_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
.to_path_buf(),
unsafe_dont_encrypt: self.unsafe_dont_encrypt,
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -2406,20 +2369,8 @@ pub mod args {
fn to_sdk(self, ctx: &mut Context) -> TxUpdateVp<SdkTypes> {
TxUpdateVp::<SdkTypes> {
tx: self.tx.to_sdk(ctx),
vp_code_path: self
.vp_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
vp_code_path: self.vp_code_path,
tx_code_path: self.tx_code_path,
addr: ctx.get(&self.addr),
}
}
Expand Down Expand Up @@ -2461,13 +2412,7 @@ pub mod args {
amount: self.amount,
source: self.source.map(|x| ctx.get(&x)),
native_token: ctx.native_token.clone(),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -2507,13 +2452,7 @@ pub mod args {
validator: ctx.get(&self.validator),
amount: self.amount,
source: self.source.map(|x| ctx.get(&x)),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -2560,7 +2499,7 @@ pub mod args {
/// Native token address
pub native_token: C::NativeAddress,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

impl CliToSdk<InitProposal<SdkTypes>> for InitProposal<CliTypes> {
Expand All @@ -2570,13 +2509,7 @@ pub mod args {
proposal_data: self.proposal_data,
offline: self.offline,
native_token: ctx.native_token.clone(),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path,
}
}
}
Expand Down Expand Up @@ -2627,7 +2560,7 @@ pub mod args {
/// The proposal file path
pub proposal_data: Option<PathBuf>,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

impl CliToSdk<VoteProposal<SdkTypes>> for VoteProposal<CliTypes> {
Expand All @@ -2638,13 +2571,7 @@ pub mod args {
vote: self.vote,
offline: self.offline,
proposal_data: self.proposal_data,
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
proposal_pgf: self.proposal_pgf,
proposal_eth: self.proposal_eth,
}
Expand Down Expand Up @@ -2869,13 +2796,7 @@ pub mod args {
tx: self.tx.to_sdk(ctx),
validator: ctx.get(&self.validator),
source: self.source.map(|x| ctx.get(&x)),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -3107,13 +3028,7 @@ pub mod args {
tx: self.tx.to_sdk(ctx),
validator: ctx.get(&self.validator),
rate: self.rate,
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -3283,7 +3198,7 @@ pub mod args {
gas_limit: self.gas_limit,
signing_key: self.signing_key.map(|x| ctx.get_cached(&x)),
signer: self.signer.map(|x| ctx.get(&x)),
tx_reveal_code_path: ctx.read_wasm(self.tx_reveal_code_path),
tx_reveal_code_path: self.tx_reveal_code_path,
password: self.password,
expiration: self.expiration,
chain_id: self.chain_id,
Expand Down
20 changes: 13 additions & 7 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ pub async fn submit_init_validator<
.expect("DKG sessions keys should have been created")
.public();

let vp_code_path = String::from_utf8(validator_vp_code_path).unwrap();
let validator_vp_code_hash =
query_wasm_code_hash::<C>(client, vp_code_path)
.await
.unwrap();
let validator_vp_code_hash = query_wasm_code_hash::<C>(
client,
validator_vp_code_path.to_str().unwrap(),
)
.await
.unwrap();

// Validate the commission rate data
if commission_rate > Decimal::ONE || commission_rate < Decimal::ZERO {
Expand Down Expand Up @@ -824,12 +825,17 @@ pub async fn submit_vote_proposal<C: namada::ledger::queries::Client + Sync>(
.try_to_vec()
.expect("Encoding proposal data shouldn't fail");

let tx_code = args.tx_code_path;
let tx_code_hash = query_wasm_code_hash(
client,
args.tx_code_path.to_str().unwrap(),
)
.await
.unwrap();
let mut tx = Tx::new(TxType::Raw);
tx.header.chain_id = chain_id;
tx.header.expiration = expiration;
tx.set_data(Data::new(data));
tx.set_code(Code::new(tx_code));
tx.set_code(Code::from_hash(tx_code_hash));

process_tx::<C>(
client,
Expand Down
30 changes: 15 additions & 15 deletions shared/src/ledger/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Structures encapsulating SDK arguments
use std::path::PathBuf;

use namada_core::types::chain::ChainId;
use namada_core::types::time::DateTimeUtc;
use rust_decimal::Decimal;
Expand Down Expand Up @@ -98,7 +100,7 @@ pub struct TxTransfer<C: NamadaTypes = SdkTypes> {
/// Native token address
pub native_token: C::NativeAddress,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

/// IBC transfer transaction arguments
Expand All @@ -125,7 +127,7 @@ pub struct TxIbcTransfer<C: NamadaTypes = SdkTypes> {
/// Timeout timestamp offset
pub timeout_sec_offset: Option<u64>,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

/// Transaction to initialize a new account
Expand All @@ -135,12 +137,10 @@ pub struct TxInitAccount<C: NamadaTypes = SdkTypes> {
pub tx: Tx<C>,
/// Address of the source account
pub source: C::Address,
/// Wasm VP for the new account
pub vp_code: C::Data,
/// Path to the VP WASM code file for the new account
pub vp_code_path: C::Data,
pub vp_code_path: PathBuf,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
/// Public key for the new account
pub public_key: C::PublicKey,
}
Expand All @@ -165,9 +165,9 @@ pub struct TxInitValidator<C: NamadaTypes = SdkTypes> {
/// Maximum commission rate change
pub max_commission_rate_change: Decimal,
/// Path to the VP WASM code file
pub validator_vp_code_path: C::Data,
pub validator_vp_code_path: PathBuf,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
/// Don't encrypt the keypair
pub unsafe_dont_encrypt: bool,
}
Expand All @@ -178,9 +178,9 @@ pub struct TxUpdateVp<C: NamadaTypes = SdkTypes> {
/// Common tx arguments
pub tx: Tx<C>,
/// Path to the VP WASM code file
pub vp_code_path: C::Data,
pub vp_code_path: PathBuf,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
/// Address of the account whose VP is to be updated
pub addr: C::Address,
}
Expand All @@ -200,7 +200,7 @@ pub struct Bond<C: NamadaTypes = SdkTypes> {
/// Native token address
pub native_token: C::NativeAddress,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

/// Unbond arguments
Expand All @@ -216,7 +216,7 @@ pub struct Unbond<C: NamadaTypes = SdkTypes> {
/// self-bonds, the validator is also the source
pub source: Option<C::Address>,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

/// Reveal public key
Expand Down Expand Up @@ -255,7 +255,7 @@ pub struct Withdraw<C: NamadaTypes = SdkTypes> {
/// from self-bonds, the validator is also the source
pub source: Option<C::Address>,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

/// Query asset conversions
Expand Down Expand Up @@ -327,7 +327,7 @@ pub struct TxCommissionRateChange<C: NamadaTypes = SdkTypes> {
/// Value to which the tx changes the commission rate
pub rate: Decimal,
/// Path to the TX WASM code file
pub tx_code_path: C::Data,
pub tx_code_path: PathBuf,
}

/// Query PoS commission rate
Expand Down Expand Up @@ -402,7 +402,7 @@ pub struct Tx<C: NamadaTypes = SdkTypes> {
/// Sign the tx with the keypair of the public key of the given address
pub signer: Option<C::Address>,
/// Path to the TX WASM code file to reveal PK
pub tx_reveal_code_path: C::Data,
pub tx_reveal_code_path: PathBuf,
/// Password to decrypt key
pub password: Option<Zeroizing<String>>,
}
Expand Down
Loading

0 comments on commit 504f4de

Please sign in to comment.