From 668fb4b67bc5897a740f4082dbee1d99557da60c Mon Sep 17 00:00:00 2001 From: David Craven Date: Mon, 3 Apr 2023 17:00:29 +0200 Subject: [PATCH] Add amount param. --- chains/ethereum/server/src/lib.rs | 2 +- chains/ethereum/tx/src/lib.rs | 4 +++- chains/polkadot/tx/src/lib.rs | 1 + rosetta-client/examples/ethereum.rs | 2 +- rosetta-client/examples/voting_contract.rs | 2 +- rosetta-client/src/wallet.rs | 17 ++++++++++++----- rosetta-core/src/lib.rs | 1 + rosetta-wallet/src/main.rs | 7 ++++++- 8 files changed, 26 insertions(+), 10 deletions(-) diff --git a/chains/ethereum/server/src/lib.rs b/chains/ethereum/server/src/lib.rs index b6bb2c46..da9f4358 100644 --- a/chains/ethereum/server/src/lib.rs +++ b/chains/ethereum/server/src/lib.rs @@ -426,7 +426,7 @@ mod tests { let receipt = wallet.eth_transaction_receipt(&response.hash).await?; let contract_address = receipt.result["contractAddress"].as_str().unwrap(); let response = wallet - .eth_send_call(contract_address, "function emitEvent()", &[]) + .eth_send_call(contract_address, "function emitEvent()", &[], 0) .await?; let receipt = wallet.eth_transaction_receipt(&response.hash).await?; let logs = receipt.result["logs"].as_array().unwrap(); diff --git a/chains/ethereum/tx/src/lib.rs b/chains/ethereum/tx/src/lib.rs index 89dda043..bdfa9c92 100644 --- a/chains/ethereum/tx/src/lib.rs +++ b/chains/ethereum/tx/src/lib.rs @@ -30,8 +30,10 @@ impl TransactionBuilder for EthereumTransactionBuilder { contract: &str, method: &str, params: &[String], + amount: u128, ) -> Result { let destination: H160 = contract.parse()?; + let amount: U256 = amount.into(); let function = HumanReadableParser::parse_function(method)?; let mut tokens = Vec::with_capacity(params.len()); for (ty, arg) in function.inputs.iter().zip(params) { @@ -40,7 +42,7 @@ impl TransactionBuilder for EthereumTransactionBuilder { let bytes = function.encode_input(&tokens)?; Ok(EthereumMetadataParams { destination: destination.0.to_vec(), - amount: [0, 0, 0, 0], + amount: amount.0, data: bytes, }) } diff --git a/chains/polkadot/tx/src/lib.rs b/chains/polkadot/tx/src/lib.rs index c74d4fd0..db382fb4 100644 --- a/chains/polkadot/tx/src/lib.rs +++ b/chains/polkadot/tx/src/lib.rs @@ -103,6 +103,7 @@ impl TransactionBuilder for PolkadotTransactionBuilder { _module: &str, _method: &str, _params: &[String], + _amount: u128, ) -> Result { bail!("Not Implemented") } diff --git a/rosetta-client/examples/ethereum.rs b/rosetta-client/examples/ethereum.rs index 925f24c7..74c4ba10 100644 --- a/rosetta-client/examples/ethereum.rs +++ b/rosetta-client/examples/ethereum.rs @@ -129,7 +129,7 @@ async fn method_call(wallet: &Wallet, contract_address: &str) { println!( "{:?}", wallet - .eth_send_call(contract_address, function_signature, &[]) + .eth_send_call(contract_address, function_signature, &[], 0) .await ); println!("latest balance =================="); diff --git a/rosetta-client/examples/voting_contract.rs b/rosetta-client/examples/voting_contract.rs index 723c5a71..a1c9f3eb 100644 --- a/rosetta-client/examples/voting_contract.rs +++ b/rosetta-client/examples/voting_contract.rs @@ -78,7 +78,7 @@ async fn vote(wallet: &Wallet, data: VoteOpts) { println!( "{:?}", wallet - .eth_send_call(&data.contract_address, function_signature, &[]) + .eth_send_call(&data.contract_address, function_signature, &[], 0) .await ); diff --git a/rosetta-client/src/wallet.rs b/rosetta-client/src/wallet.rs index 087bb8d8..7700db54 100644 --- a/rosetta-client/src/wallet.rs +++ b/rosetta-client/src/wallet.rs @@ -47,10 +47,15 @@ impl GenericTransactionBuilder { contract: &str, method: &str, params: &[String], + amount: u128, ) -> Result { Ok(match self { - Self::Ethereum(tx) => serde_json::to_value(tx.method_call(contract, method, params)?)?, - Self::Polkadot(tx) => serde_json::to_value(tx.method_call(contract, method, params)?)?, + Self::Ethereum(tx) => { + serde_json::to_value(tx.method_call(contract, method, params, amount)?)? + } + Self::Polkadot(tx) => { + serde_json::to_value(tx.method_call(contract, method, params, amount)?)? + } }) } @@ -339,6 +344,7 @@ pub trait EthereumExt { contract_address: &str, method_signature: &str, params: &[String], + amount: u128, ) -> Result; /// gets storage from ethereum contract async fn eth_storage(&self, contract_address: &str, storage_slot: &str) @@ -365,10 +371,11 @@ impl EthereumExt for Wallet { contract_address: &str, method_signature: &str, params: &[String], + amount: u128, ) -> Result { - let metadata_params = self - .tx - .method_call(contract_address, method_signature, params)?; + let metadata_params = + self.tx + .method_call(contract_address, method_signature, params, amount)?; self.construct(metadata_params).await } diff --git a/rosetta-core/src/lib.rs b/rosetta-core/src/lib.rs index 97271a9c..cddff601 100644 --- a/rosetta-core/src/lib.rs +++ b/rosetta-core/src/lib.rs @@ -127,6 +127,7 @@ pub trait TransactionBuilder: Default + Sized { contract: &str, method: &str, values: &[String], + amount: u128, ) -> Result; fn deploy_contract(&self, contract_binary: Vec) -> Result; diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index 91565f0a..f67356d8 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -53,6 +53,8 @@ pub struct MethodCallOpts { pub method: String, #[clap(value_delimiter = ' ')] pub params: Vec, + #[clap(long, default_value = "0")] + pub amount: u128, } #[async_std::main] @@ -152,8 +154,11 @@ async fn main() -> Result<()> { contract, method, params, + amount, }) => { - let tx = wallet.eth_send_call(&contract, &method, ¶ms).await?; + let tx = wallet + .eth_send_call(&contract, &method, ¶ms, amount) + .await?; println!("Transaction hash: {:?}", tx.hash); } }