Skip to content

Commit

Permalink
Add amount param.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Apr 3, 2023
1 parent 248f146 commit 668fb4b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion chains/ethereum/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion chains/ethereum/tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ impl TransactionBuilder for EthereumTransactionBuilder {
contract: &str,
method: &str,
params: &[String],
amount: u128,
) -> Result<Self::MetadataParams> {
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) {
Expand All @@ -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,
})
}
Expand Down
1 change: 1 addition & 0 deletions chains/polkadot/tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl TransactionBuilder for PolkadotTransactionBuilder {
_module: &str,
_method: &str,
_params: &[String],
_amount: u128,
) -> Result<Self::MetadataParams> {
bail!("Not Implemented")
}
Expand Down
2 changes: 1 addition & 1 deletion rosetta-client/examples/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==================");
Expand Down
2 changes: 1 addition & 1 deletion rosetta-client/examples/voting_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
17 changes: 12 additions & 5 deletions rosetta-client/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ impl GenericTransactionBuilder {
contract: &str,
method: &str,
params: &[String],
amount: u128,
) -> Result<serde_json::Value> {
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)?)?
}
})
}

Expand Down Expand Up @@ -339,6 +344,7 @@ pub trait EthereumExt {
contract_address: &str,
method_signature: &str,
params: &[String],
amount: u128,
) -> Result<TransactionIdentifier>;
/// gets storage from ethereum contract
async fn eth_storage(&self, contract_address: &str, storage_slot: &str)
Expand All @@ -365,10 +371,11 @@ impl EthereumExt for Wallet {
contract_address: &str,
method_signature: &str,
params: &[String],
amount: u128,
) -> Result<TransactionIdentifier> {
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
}

Expand Down
1 change: 1 addition & 0 deletions rosetta-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub trait TransactionBuilder: Default + Sized {
contract: &str,
method: &str,
values: &[String],
amount: u128,
) -> Result<Self::MetadataParams>;

fn deploy_contract(&self, contract_binary: Vec<u8>) -> Result<Self::MetadataParams>;
Expand Down
7 changes: 6 additions & 1 deletion rosetta-wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct MethodCallOpts {
pub method: String,
#[clap(value_delimiter = ' ')]
pub params: Vec<String>,
#[clap(long, default_value = "0")]
pub amount: u128,
}

#[async_std::main]
Expand Down Expand Up @@ -152,8 +154,11 @@ async fn main() -> Result<()> {
contract,
method,
params,
amount,
}) => {
let tx = wallet.eth_send_call(&contract, &method, &params).await?;
let tx = wallet
.eth_send_call(&contract, &method, &params, amount)
.await?;
println!("Transaction hash: {:?}", tx.hash);
}
}
Expand Down

0 comments on commit 668fb4b

Please sign in to comment.