Skip to content

Commit

Permalink
Revert "Merge 'origin/fraccaman/fix-sdk-tx-with-hash' (#1474)"
Browse files Browse the repository at this point in the history
This reverts commit 11a6d92, reversing
changes made to 899bb44.
  • Loading branch information
juped committed May 30, 2023
1 parent 814a643 commit 42d1c08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 112 deletions.
80 changes: 10 additions & 70 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,13 +2141,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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down Expand Up @@ -2202,13 +2196,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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down Expand Up @@ -2277,13 +2265,7 @@ pub mod args {
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: ctx.read_wasm(self.tx_code_path),
public_key: ctx.get_cached(&self.public_key),
}
}
Expand Down Expand Up @@ -2345,13 +2327,7 @@ pub mod args {
.to_string()
.into_bytes(),
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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down Expand Up @@ -2490,13 +2466,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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down Expand Up @@ -2536,13 +2506,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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down Expand Up @@ -2599,13 +2563,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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down Expand Up @@ -2667,13 +2625,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: ctx.read_wasm(self.tx_code_path),
proposal_pgf: self.proposal_pgf,
proposal_eth: self.proposal_eth,
}
Expand Down Expand Up @@ -2898,13 +2850,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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down Expand Up @@ -3136,13 +3082,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: ctx.read_wasm(self.tx_code_path),
}
}
}
Expand Down
56 changes: 14 additions & 42 deletions shared/src/ledger/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,12 @@ pub async fn submit_reveal_pk_aux<
let addr: Address = public_key.into();
println!("Submitting a tx to reveal the public key for address {addr}...");
let tx_data = public_key.try_to_vec().map_err(Error::EncodeKeyFailure)?;

let tx_code_path =
String::from_utf8(args.tx_reveal_code_path.clone()).unwrap();
let tx_code_hash =
query_wasm_code_hash(client, tx_code_path).await.unwrap();

let mut tx = Tx::new(TxType::Decrypted(DecryptedTx::Decrypted {
#[cfg(not(feature = "mainnet"))]
// To be able to dry-run testnet faucet withdrawal, pretend
// that we got a valid PoW
has_valid_pow: true,
}));
let tx_code = args.tx_reveal_code_path.clone();
let mut tx = Tx::new(TxType::Raw);
tx.header.chain_id = args.chain_id.clone().expect("value should be there");
tx.header.expiration = args.expiration;
tx.set_data(Data::new(tx_data));
tx.set_code(Code::from_hash(tx_code_hash));
tx.set_code(Code::new(tx_code));

// submit_tx without signing the inner tx
let keypair = if let Some(signing_key) = &args.signing_key {
Expand Down Expand Up @@ -592,9 +582,7 @@ pub async fn submit_validator_commission_change<
) -> Result<(), Error> {
let epoch = rpc::query_epoch(client).await;

let tx_code_path = String::from_utf8(args.tx_code_path).unwrap();
let tx_code_hash =
query_wasm_code_hash(client, tx_code_path).await.unwrap();
let tx_code = args.tx_code_path;

// TODO: put following two let statements in its own function
let params_key = crate::ledger::pos::params_key();
Expand Down Expand Up @@ -661,7 +649,7 @@ pub async fn submit_validator_commission_change<
tx.header.chain_id = args.tx.chain_id.clone().unwrap();
tx.header.expiration = args.tx.expiration;
tx.set_data(Data::new(data));
tx.set_code(Code::from_hash(tx_code_hash));
tx.set_code(Code::new(tx_code));

let default_signer = args.validator.clone();
process_tx::<C, U>(
Expand Down Expand Up @@ -739,10 +727,7 @@ pub async fn submit_withdraw<
.await?;

let source = args.source.clone();

let tx_code_path = String::from_utf8(args.tx_code_path).unwrap();
let tx_code_hash =
query_wasm_code_hash(client, tx_code_path).await.unwrap();
let tx_code = args.tx_code_path;

// Check the source's current unbond amount
let bond_source = source.clone().unwrap_or_else(|| validator.clone());
Expand Down Expand Up @@ -775,7 +760,7 @@ pub async fn submit_withdraw<
tx.header.chain_id = args.tx.chain_id.clone().unwrap();
tx.header.expiration = args.tx.expiration;
tx.set_data(Data::new(data));
tx.set_code(Code::from_hash(tx_code_hash));
tx.set_code(Code::new(tx_code));

let default_signer = args.source.unwrap_or(args.validator);
process_tx::<C, U>(
Expand Down Expand Up @@ -803,11 +788,7 @@ pub async fn submit_unbond<
let source = args.source.clone();
// Check the source's current bond amount
let bond_source = source.clone().unwrap_or_else(|| args.validator.clone());

let tx_code_path = String::from_utf8(args.tx_code_path).unwrap();
let tx_code_hash =
query_wasm_code_hash(client, tx_code_path).await.unwrap();

let tx_code = args.tx_code_path;
if !args.tx.force {
known_validator_or_err(args.validator.clone(), args.tx.force, client)
.await?;
Expand Down Expand Up @@ -855,7 +836,7 @@ pub async fn submit_unbond<
tx.header.chain_id = args.tx.chain_id.clone().unwrap();
tx.header.expiration = args.tx.expiration;
tx.set_data(Data::new(data));
tx.set_code(Code::from_hash(tx_code_hash));
tx.set_code(Code::new(tx_code));

let default_signer = args.source.unwrap_or_else(|| args.validator.clone());
process_tx::<C, U>(
Expand Down Expand Up @@ -956,10 +937,7 @@ pub async fn submit_bond<
)
.await?;

let tx_code_path = String::from_utf8(args.tx_code_path).unwrap();
let tx_code_hash =
query_wasm_code_hash(client, tx_code_path).await.unwrap();

let tx_code = args.tx_code_path;
let bond = pos::Bond {
validator,
amount: args.amount,
Expand All @@ -971,7 +949,7 @@ pub async fn submit_bond<
tx.header.chain_id = args.tx.chain_id.clone().unwrap();
tx.header.expiration = args.tx.expiration;
tx.set_data(Data::new(data));
tx.set_code(Code::from_hash(tx_code_hash));
tx.set_code(Code::new(tx_code));

let default_signer = args.source.unwrap_or(args.validator);
process_tx::<C, U>(
Expand Down Expand Up @@ -1057,9 +1035,7 @@ pub async fn submit_ibc_transfer<
)
.await?;

let tx_code_path = String::from_utf8(args.tx_code_path).unwrap();
let tx_code_hash =
query_wasm_code_hash(client, tx_code_path).await.unwrap();
let tx_code = args.tx_code_path;

let denom = match sub_prefix {
// To parse IbcToken address, remove the address prefix
Expand Down Expand Up @@ -1109,7 +1085,7 @@ pub async fn submit_ibc_transfer<
tx.header.chain_id = args.tx.chain_id.clone().unwrap();
tx.header.expiration = args.tx.expiration;
tx.set_data(Data::new(data));
tx.set_code(Code::from_hash(tx_code_hash));
tx.set_code(Code::new(tx_code));

process_tx::<C, U>(
client,
Expand Down Expand Up @@ -1416,10 +1392,6 @@ pub async fn submit_init_account<
let vp_code_hash =
query_wasm_code_hash(client, vp_code_path).await.unwrap();

let tx_code_path = String::from_utf8(args.tx_code_path).unwrap();
let tx_code_hash =
query_wasm_code_hash(client, tx_code_path).await.unwrap();

let mut tx = Tx::new(TxType::Raw);
tx.header.chain_id = args.tx.chain_id.clone().unwrap();
tx.header.expiration = args.tx.expiration;
Expand All @@ -1433,7 +1405,7 @@ pub async fn submit_init_account<
};
let data = data.try_to_vec().map_err(Error::EncodeTxFailure)?;
tx.set_data(Data::new(data));
tx.set_code(Code::from_hash(tx_code_hash));
tx.set_code(Code::new(args.tx_code_path));

// TODO Move unwrap to an either
let initialized_accounts = process_tx::<C, U>(
Expand Down

0 comments on commit 42d1c08

Please sign in to comment.