From 71ee2a6e35f8ef77969c9503b66d9c2433ff5836 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 18:18:44 +0500 Subject: [PATCH 1/9] adding cli options for deploy contract --- Cargo.lock | 120 ++++++++++++++++++++++++++----------- rosetta-wallet/Cargo.toml | 2 + rosetta-wallet/src/main.rs | 40 +++++++++++++ 3 files changed, 126 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd6153f9..ecb3ec22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -515,7 +515,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" dependencies = [ - "futures", + "futures 0.3.28", "pharos", "rustc_version 0.4.0", ] @@ -526,7 +526,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4057f2c32adbb2fc158e22fb38433c8e9bbf76b75a4732c7c0cbaf695fb65568" dependencies = [ - "bytes", + "bytes 1.4.0", "futures-sink", "futures-util", "memchr", @@ -896,6 +896,16 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" +dependencies = [ + "byteorder", + "iovec", +] + [[package]] name = "bytes" version = "1.4.0" @@ -1705,7 +1715,7 @@ dependencies = [ "asynchronous-codec", "base64 0.13.1", "byteorder", - "bytes", + "bytes 1.4.0", "chrono", "containers-api", "docker-api-stubs", @@ -1874,7 +1884,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf56acd72bb22d2824e66ae8e9e5ada4d0de17a69c7fd35569dde2ada8ec9116" dependencies = [ "base64 0.13.1", - "bytes", + "bytes 1.4.0", "hex 0.4.3", "k256", "log", @@ -2105,7 +2115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ca2514feb98918a0a31de7e1983c29f2267ebf61b2dc5d4294f91e5b866623" dependencies = [ "arrayvec 0.7.4", - "bytes", + "bytes 1.4.0", "cargo_metadata", "chrono", "elliptic-curve", @@ -2179,7 +2189,7 @@ dependencies = [ "async-trait", "auto_impl", "base64 0.21.2", - "bytes", + "bytes 1.4.0", "enr", "ethers-core", "futures-core", @@ -2443,6 +2453,17 @@ dependencies = [ "serde", ] +[[package]] +name = "fs" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94befb4c82414e638647f3f6fe8f908c39a7f2f40d556d318adb803ef263154" +dependencies = [ + "bytes 0.4.12", + "futures 0.1.31", + "futures-cpupool", +] + [[package]] name = "fs2" version = "0.4.3" @@ -2459,6 +2480,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" + [[package]] name = "futures" version = "0.3.28" @@ -2490,6 +2517,16 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +[[package]] +name = "futures-cpupool" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" +dependencies = [ + "futures 0.1.31", + "num_cpus", +] + [[package]] name = "futures-executor" version = "0.3.28" @@ -2703,7 +2740,7 @@ version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" dependencies = [ - "bytes", + "bytes 1.4.0", "fnv", "futures-core", "futures-sink", @@ -2866,7 +2903,7 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ - "bytes", + "bytes 1.4.0", "fnv", "itoa", ] @@ -2877,7 +2914,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ - "bytes", + "bytes 1.4.0", "http", "pin-project-lite 0.2.12", ] @@ -2895,7 +2932,7 @@ dependencies = [ "cfg-if", "dashmap", "deadpool", - "futures", + "futures 0.3.28", "http-types", "log", "rustls 0.18.1", @@ -2947,7 +2984,7 @@ version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ - "bytes", + "bytes 1.4.0", "futures-channel", "futures-core", "futures-util", @@ -3168,6 +3205,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + [[package]] name = "ipnet" version = "2.8.0" @@ -3980,7 +4026,7 @@ checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" dependencies = [ "arrayvec 0.7.4", "auto_impl", - "bytes", + "bytes 1.4.0", "ethereum-types", "open-fastrlp-derive", ] @@ -3991,7 +4037,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" dependencies = [ - "bytes", + "bytes 1.4.0", "proc-macro2", "quote", "syn 1.0.109", @@ -4078,7 +4124,7 @@ dependencies = [ "arrayvec 0.7.4", "bitvec 1.0.1", "byte-slice-cast", - "bytes", + "bytes 1.4.0", "impl-trait-for-tuples", "parity-scale-codec-derive", "serde", @@ -4210,7 +4256,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" dependencies = [ - "futures", + "futures 0.3.28", "rustc_version 0.4.0", ] @@ -4692,7 +4738,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" dependencies = [ "base64 0.21.2", - "bytes", + "bytes 1.4.0", "encoding_rs", "futures-core", "futures-util", @@ -4764,7 +4810,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" dependencies = [ - "bytes", + "bytes 1.4.0", "rlp-derive", "rustc-hex", ] @@ -4800,7 +4846,7 @@ dependencies = [ "clap", "dirs-next", "fraction", - "futures", + "futures 0.3.28", "getrandom 0.2.10", "hex 0.4.3", "js-sys", @@ -4905,7 +4951,7 @@ dependencies = [ "anyhow", "docker-api", "env_logger", - "futures", + "futures 0.3.28", "getrandom 0.2.10", "log", "rosetta-client", @@ -4923,7 +4969,7 @@ dependencies = [ "async-trait", "clap", "femme", - "futures", + "futures 0.3.28", "hex 0.4.3", "jsonrpsee 0.19.0", "log", @@ -4949,7 +4995,7 @@ dependencies = [ "async-trait", "ethers", "ethers-solc", - "futures", + "futures 0.3.28", "hex 0.4.3", "log", "parity-scale-codec", @@ -5063,7 +5109,9 @@ dependencies = [ "anyhow", "async-std", "clap", - "futures", + "fs", + "futures 0.3.28", + "hex 0.4.3", "rosetta-client", "surf", "tracing-subscriber 0.3.17", @@ -6029,8 +6077,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" dependencies = [ "base64 0.13.1", - "bytes", - "futures", + "bytes 1.4.0", + "futures 0.3.28", "httparse", "log", "rand 0.8.5", @@ -6093,7 +6141,7 @@ dependencies = [ "bs58 0.4.0", "dyn-clonable", "ed25519-zebra", - "futures", + "futures 0.3.28", "hash-db", "hash256-std-hasher", "impl-serde", @@ -6169,10 +6217,10 @@ version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d597e35a9628fe7454b08965b2442e3ec0f264b0a90d41328e87422cec02e99" dependencies = [ - "bytes", + "bytes 1.4.0", "ed25519", "ed25519-dalek", - "futures", + "futures 0.3.28", "libsecp256k1", "log", "parity-scale-codec", @@ -6208,7 +6256,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be3cdd67cc1d9c1db17c5cbc4ec4924054a8437009d167f21f6590797e4aa45" dependencies = [ - "futures", + "futures 0.3.28", "parity-scale-codec", "parking_lot", "sp-core", @@ -6256,7 +6304,7 @@ version = "17.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e676128182f90015e916f806cba635c8141e341e7abbc45d25525472e1bbce8" dependencies = [ - "bytes", + "bytes 1.4.0", "impl-trait-for-tuples", "parity-scale-codec", "primitive-types", @@ -6596,7 +6644,7 @@ dependencies = [ "derivative", "either", "frame-metadata 16.0.0", - "futures", + "futures 0.3.28", "hex 0.4.3", "impl-serde", "jsonrpsee 0.16.2", @@ -6645,7 +6693,7 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6aa72c1cb7e06772efa1476949c3f0e83718c79c1b2615eb510c076b012e9c84" dependencies = [ - "futures", + "futures 0.3.28", "futures-util", "serde", "serde_json", @@ -7070,7 +7118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40de3a2ba249dcb097e01be5e67a5ff53cf250397715a071a81543e8a832a920" dependencies = [ "backtrace", - "bytes", + "bytes 1.4.0", "libc", "mio", "num_cpus", @@ -7184,7 +7232,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" dependencies = [ - "bytes", + "bytes 1.4.0", "futures-core", "futures-io", "futures-sink", @@ -7368,7 +7416,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15fba1a6d6bb030745759a9a2a588bfe8490fc8b4751a277db3a0be1c9ebbf67" dependencies = [ "byteorder", - "bytes", + "bytes 1.4.0", "data-encoding", "http", "httparse", @@ -7389,7 +7437,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e862a1c4128df0112ab625f55cd5c934bcb4312ba80b39ae4b4835a3fd58e649" dependencies = [ "byteorder", - "bytes", + "bytes 1.4.0", "data-encoding", "http", "httparse", @@ -8141,7 +8189,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" dependencies = [ "async_io_stream", - "futures", + "futures 0.3.28", "js-sys", "log", "pharos", diff --git a/rosetta-wallet/Cargo.toml b/rosetta-wallet/Cargo.toml index d7e18c54..b661ba67 100644 --- a/rosetta-wallet/Cargo.toml +++ b/rosetta-wallet/Cargo.toml @@ -14,3 +14,5 @@ futures = "0.3.26" rosetta-client = { version = "0.4.0", path = "../rosetta-client" } surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls"] } tracing-subscriber = "0.3.16" +hex = "0.4.3" +fs = "0.0.5" diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index f67356d8..7dca2483 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -3,6 +3,7 @@ use clap::Parser; use futures::stream::StreamExt; use rosetta_client::types::{AccountIdentifier, BlockTransaction, TransactionIdentifier}; use rosetta_client::EthereumExt; +use std::fs::read_to_string; use std::path::PathBuf; #[derive(Parser)] @@ -24,6 +25,8 @@ pub enum Command { Pubkey, Account, Balance, + DeployContract(DeployContractOpts), + EthTransactionReceipt(EthTransactionReceiptOpts), Faucet(FaucetOpts), Transfer(TransferOpts), Transaction(TransactionOpts), @@ -57,6 +60,16 @@ pub struct MethodCallOpts { pub amount: u128, } +#[derive(Parser)] +pub struct EthTransactionReceiptOpts { + pub tx_hash: String, +} + +#[derive(Parser)] +pub struct DeployContractOpts { + pub bin_path: String, +} + #[async_std::main] async fn main() -> Result<()> { tracing_subscriber::fmt::init(); @@ -79,6 +92,33 @@ async fn main() -> Result<()> { let balance = wallet.balance().await?; println!("{}", rosetta_client::amount_to_string(&balance)?); } + Command::DeployContract(DeployContractOpts { bin_path }) => { + match wallet.config().blockchain { + "bitcoin" => { + anyhow::bail!("Not implemented"); + } + _ => { + let compiled_contract_str = read_to_string(format!("{}", bin_path))?; + let compiled_contract_bin = compiled_contract_str + .strip_suffix('\n') + .unwrap_or(&compiled_contract_str); + let bytes = hex::decode(compiled_contract_bin).unwrap(); + let response = wallet.eth_deploy_contract(bytes.to_vec()).await?; + println!("Deploy contract response {:?}", response); + } + } + } + Command::EthTransactionReceipt(EthTransactionReceiptOpts { tx_hash }) => { + match wallet.config().blockchain { + "bitcoin" => { + anyhow::bail!("Not implemented"); + } + _ => { + let receipt = wallet.eth_transaction_receipt(&tx_hash).await?; + println!("Receipt: {:?}", receipt); + } + } + } Command::Transfer(TransferOpts { account, amount }) => { let amount = rosetta_client::string_to_amount(&amount, wallet.config().currency_decimals)?; From e7eab4f65a06fe55b0ceb365d922ef3ab16a1f73 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 18:26:12 +0500 Subject: [PATCH 2/9] clippy fix --- rosetta-wallet/Cargo.toml | 5 +++-- rosetta-wallet/src/main.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rosetta-wallet/Cargo.toml b/rosetta-wallet/Cargo.toml index b661ba67..c5c1c70b 100644 --- a/rosetta-wallet/Cargo.toml +++ b/rosetta-wallet/Cargo.toml @@ -10,9 +10,10 @@ description = "Command line wallet implemented using the rosetta client." anyhow = "1.0.69" async-std = { version = "1.12.0", features = ["attributes"] } clap = { version = "4.1.8", features = ["derive"] } +fs = "0.0.5" futures = "0.3.26" +hex = "0.4.3" rosetta-client = { version = "0.4.0", path = "../rosetta-client" } surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls"] } tracing-subscriber = "0.3.16" -hex = "0.4.3" -fs = "0.0.5" + diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index 7dca2483..66a75117 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -98,7 +98,7 @@ async fn main() -> Result<()> { anyhow::bail!("Not implemented"); } _ => { - let compiled_contract_str = read_to_string(format!("{}", bin_path))?; + let compiled_contract_str = read_to_string(bin_path.to_string())?; let compiled_contract_bin = compiled_contract_str .strip_suffix('\n') .unwrap_or(&compiled_contract_str); From bd9c9147cb5d02adf78b4bef66a393f80bebebb9 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 18:30:00 +0500 Subject: [PATCH 3/9] fmt fix --- rosetta-wallet/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/rosetta-wallet/Cargo.toml b/rosetta-wallet/Cargo.toml index c5c1c70b..f1609757 100644 --- a/rosetta-wallet/Cargo.toml +++ b/rosetta-wallet/Cargo.toml @@ -16,4 +16,3 @@ hex = "0.4.3" rosetta-client = { version = "0.4.0", path = "../rosetta-client" } surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls"] } tracing-subscriber = "0.3.16" - From 6c12526ae67c680a4130f7cf5df1b17356af1f30 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 18:46:49 +0500 Subject: [PATCH 4/9] clippy --- rosetta-wallet/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index 66a75117..9eb72e0e 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -94,11 +94,8 @@ async fn main() -> Result<()> { } Command::DeployContract(DeployContractOpts { bin_path }) => { match wallet.config().blockchain { - "bitcoin" => { - anyhow::bail!("Not implemented"); - } - _ => { - let compiled_contract_str = read_to_string(bin_path.to_string())?; + "astar" | "ethereum" => { + let compiled_contract_str = read_to_string(&bin_path)?; let compiled_contract_bin = compiled_contract_str .strip_suffix('\n') .unwrap_or(&compiled_contract_str); @@ -106,6 +103,9 @@ async fn main() -> Result<()> { let response = wallet.eth_deploy_contract(bytes.to_vec()).await?; println!("Deploy contract response {:?}", response); } + _ => { + anyhow::bail!("Not implemented"); + } } } Command::EthTransactionReceipt(EthTransactionReceiptOpts { tx_hash }) => { From c492cd66bd55f51d8acd6fdc1d45528267bd715a Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 21:02:39 +0500 Subject: [PATCH 5/9] reviews --- Cargo.lock | 121 ++++++++++++------------------------- rosetta-wallet/Cargo.toml | 3 +- rosetta-wallet/src/main.rs | 65 +++++++++++--------- 3 files changed, 75 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecb3ec22..15707b84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -515,7 +515,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" dependencies = [ - "futures 0.3.28", + "futures", "pharos", "rustc_version 0.4.0", ] @@ -526,7 +526,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4057f2c32adbb2fc158e22fb38433c8e9bbf76b75a4732c7c0cbaf695fb65568" dependencies = [ - "bytes 1.4.0", + "bytes", "futures-sink", "futures-util", "memchr", @@ -896,16 +896,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -dependencies = [ - "byteorder", - "iovec", -] - [[package]] name = "bytes" version = "1.4.0" @@ -1715,7 +1705,7 @@ dependencies = [ "asynchronous-codec", "base64 0.13.1", "byteorder", - "bytes 1.4.0", + "bytes", "chrono", "containers-api", "docker-api-stubs", @@ -1884,7 +1874,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf56acd72bb22d2824e66ae8e9e5ada4d0de17a69c7fd35569dde2ada8ec9116" dependencies = [ "base64 0.13.1", - "bytes 1.4.0", + "bytes", "hex 0.4.3", "k256", "log", @@ -2115,7 +2105,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ca2514feb98918a0a31de7e1983c29f2267ebf61b2dc5d4294f91e5b866623" dependencies = [ "arrayvec 0.7.4", - "bytes 1.4.0", + "bytes", "cargo_metadata", "chrono", "elliptic-curve", @@ -2189,7 +2179,7 @@ dependencies = [ "async-trait", "auto_impl", "base64 0.21.2", - "bytes 1.4.0", + "bytes", "enr", "ethers-core", "futures-core", @@ -2453,17 +2443,6 @@ dependencies = [ "serde", ] -[[package]] -name = "fs" -version = "0.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94befb4c82414e638647f3f6fe8f908c39a7f2f40d556d318adb803ef263154" -dependencies = [ - "bytes 0.4.12", - "futures 0.1.31", - "futures-cpupool", -] - [[package]] name = "fs2" version = "0.4.3" @@ -2480,12 +2459,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" -[[package]] -name = "futures" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" - [[package]] name = "futures" version = "0.3.28" @@ -2517,16 +2490,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" -[[package]] -name = "futures-cpupool" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" -dependencies = [ - "futures 0.1.31", - "num_cpus", -] - [[package]] name = "futures-executor" version = "0.3.28" @@ -2740,7 +2703,7 @@ version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" dependencies = [ - "bytes 1.4.0", + "bytes", "fnv", "futures-core", "futures-sink", @@ -2903,7 +2866,7 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ - "bytes 1.4.0", + "bytes", "fnv", "itoa", ] @@ -2914,7 +2877,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ - "bytes 1.4.0", + "bytes", "http", "pin-project-lite 0.2.12", ] @@ -2932,7 +2895,7 @@ dependencies = [ "cfg-if", "dashmap", "deadpool", - "futures 0.3.28", + "futures", "http-types", "log", "rustls 0.18.1", @@ -2984,7 +2947,7 @@ version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ - "bytes 1.4.0", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -3205,15 +3168,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "ipnet" version = "2.8.0" @@ -4026,7 +3980,7 @@ checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" dependencies = [ "arrayvec 0.7.4", "auto_impl", - "bytes 1.4.0", + "bytes", "ethereum-types", "open-fastrlp-derive", ] @@ -4037,7 +3991,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" dependencies = [ - "bytes 1.4.0", + "bytes", "proc-macro2", "quote", "syn 1.0.109", @@ -4124,7 +4078,7 @@ dependencies = [ "arrayvec 0.7.4", "bitvec 1.0.1", "byte-slice-cast", - "bytes 1.4.0", + "bytes", "impl-trait-for-tuples", "parity-scale-codec-derive", "serde", @@ -4256,7 +4210,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" dependencies = [ - "futures 0.3.28", + "futures", "rustc_version 0.4.0", ] @@ -4738,7 +4692,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" dependencies = [ "base64 0.21.2", - "bytes 1.4.0", + "bytes", "encoding_rs", "futures-core", "futures-util", @@ -4810,7 +4764,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" dependencies = [ - "bytes 1.4.0", + "bytes", "rlp-derive", "rustc-hex", ] @@ -4846,7 +4800,7 @@ dependencies = [ "clap", "dirs-next", "fraction", - "futures 0.3.28", + "futures", "getrandom 0.2.10", "hex 0.4.3", "js-sys", @@ -4951,7 +4905,7 @@ dependencies = [ "anyhow", "docker-api", "env_logger", - "futures 0.3.28", + "futures", "getrandom 0.2.10", "log", "rosetta-client", @@ -4969,7 +4923,7 @@ dependencies = [ "async-trait", "clap", "femme", - "futures 0.3.28", + "futures", "hex 0.4.3", "jsonrpsee 0.19.0", "log", @@ -4995,7 +4949,7 @@ dependencies = [ "async-trait", "ethers", "ethers-solc", - "futures 0.3.28", + "futures", "hex 0.4.3", "log", "parity-scale-codec", @@ -5109,9 +5063,8 @@ dependencies = [ "anyhow", "async-std", "clap", - "fs", - "futures 0.3.28", - "hex 0.4.3", + "ethers-solc", + "futures", "rosetta-client", "surf", "tracing-subscriber 0.3.17", @@ -6077,8 +6030,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" dependencies = [ "base64 0.13.1", - "bytes 1.4.0", - "futures 0.3.28", + "bytes", + "futures", "httparse", "log", "rand 0.8.5", @@ -6141,7 +6094,7 @@ dependencies = [ "bs58 0.4.0", "dyn-clonable", "ed25519-zebra", - "futures 0.3.28", + "futures", "hash-db", "hash256-std-hasher", "impl-serde", @@ -6217,10 +6170,10 @@ version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d597e35a9628fe7454b08965b2442e3ec0f264b0a90d41328e87422cec02e99" dependencies = [ - "bytes 1.4.0", + "bytes", "ed25519", "ed25519-dalek", - "futures 0.3.28", + "futures", "libsecp256k1", "log", "parity-scale-codec", @@ -6256,7 +6209,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be3cdd67cc1d9c1db17c5cbc4ec4924054a8437009d167f21f6590797e4aa45" dependencies = [ - "futures 0.3.28", + "futures", "parity-scale-codec", "parking_lot", "sp-core", @@ -6304,7 +6257,7 @@ version = "17.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e676128182f90015e916f806cba635c8141e341e7abbc45d25525472e1bbce8" dependencies = [ - "bytes 1.4.0", + "bytes", "impl-trait-for-tuples", "parity-scale-codec", "primitive-types", @@ -6644,7 +6597,7 @@ dependencies = [ "derivative", "either", "frame-metadata 16.0.0", - "futures 0.3.28", + "futures", "hex 0.4.3", "impl-serde", "jsonrpsee 0.16.2", @@ -6693,7 +6646,7 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6aa72c1cb7e06772efa1476949c3f0e83718c79c1b2615eb510c076b012e9c84" dependencies = [ - "futures 0.3.28", + "futures", "futures-util", "serde", "serde_json", @@ -7118,7 +7071,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40de3a2ba249dcb097e01be5e67a5ff53cf250397715a071a81543e8a832a920" dependencies = [ "backtrace", - "bytes 1.4.0", + "bytes", "libc", "mio", "num_cpus", @@ -7232,7 +7185,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" dependencies = [ - "bytes 1.4.0", + "bytes", "futures-core", "futures-io", "futures-sink", @@ -7416,7 +7369,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15fba1a6d6bb030745759a9a2a588bfe8490fc8b4751a277db3a0be1c9ebbf67" dependencies = [ "byteorder", - "bytes 1.4.0", + "bytes", "data-encoding", "http", "httparse", @@ -7437,7 +7390,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e862a1c4128df0112ab625f55cd5c934bcb4312ba80b39ae4b4835a3fd58e649" dependencies = [ "byteorder", - "bytes 1.4.0", + "bytes", "data-encoding", "http", "httparse", @@ -8189,7 +8142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" dependencies = [ "async_io_stream", - "futures 0.3.28", + "futures", "js-sys", "log", "pharos", diff --git a/rosetta-wallet/Cargo.toml b/rosetta-wallet/Cargo.toml index f1609757..d8edd9b0 100644 --- a/rosetta-wallet/Cargo.toml +++ b/rosetta-wallet/Cargo.toml @@ -10,9 +10,8 @@ description = "Command line wallet implemented using the rosetta client." anyhow = "1.0.69" async-std = { version = "1.12.0", features = ["attributes"] } clap = { version = "4.1.8", features = ["derive"] } -fs = "0.0.5" +ethers-solc = "2.0.1" futures = "0.3.26" -hex = "0.4.3" rosetta-client = { version = "0.4.0", path = "../rosetta-client" } surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls"] } tracing-subscriber = "0.3.16" diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index 9eb72e0e..2202e8d4 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -1,10 +1,11 @@ use anyhow::Result; use clap::Parser; +use ethers_solc::{CompilerInput, artifacts::Source, Solc}; use futures::stream::StreamExt; use rosetta_client::types::{AccountIdentifier, BlockTransaction, TransactionIdentifier}; use rosetta_client::EthereumExt; -use std::fs::read_to_string; -use std::path::PathBuf; +use std::collections::BTreeMap; +use std::path::{PathBuf, Path}; #[derive(Parser)] pub struct Opts { @@ -26,7 +27,6 @@ pub enum Command { Account, Balance, DeployContract(DeployContractOpts), - EthTransactionReceipt(EthTransactionReceiptOpts), Faucet(FaucetOpts), Transfer(TransferOpts), Transaction(TransactionOpts), @@ -60,14 +60,9 @@ pub struct MethodCallOpts { pub amount: u128, } -#[derive(Parser)] -pub struct EthTransactionReceiptOpts { - pub tx_hash: String, -} - #[derive(Parser)] pub struct DeployContractOpts { - pub bin_path: String, + pub contract_path: String, } #[async_std::main] @@ -92,33 +87,24 @@ async fn main() -> Result<()> { let balance = wallet.balance().await?; println!("{}", rosetta_client::amount_to_string(&balance)?); } - Command::DeployContract(DeployContractOpts { bin_path }) => { + Command::DeployContract(DeployContractOpts { contract_path }) => { match wallet.config().blockchain { "astar" | "ethereum" => { - let compiled_contract_str = read_to_string(&bin_path)?; - let compiled_contract_bin = compiled_contract_str - .strip_suffix('\n') - .unwrap_or(&compiled_contract_str); - let bytes = hex::decode(compiled_contract_bin).unwrap(); - let response = wallet.eth_deploy_contract(bytes.to_vec()).await?; - println!("Deploy contract response {:?}", response); + let bytes = compile_file(&contract_path)?; + let response = wallet.eth_deploy_contract(bytes).await?; + let tx_receipt = wallet + .eth_transaction_receipt(&response.hash) + .await?; + let contract_address = tx_receipt.result["contractAddress"] + .as_str() + .ok_or(anyhow::anyhow!("Unable to get contract address"))?; + println!("Deploy contract address {:?}", contract_address); } _ => { anyhow::bail!("Not implemented"); } } } - Command::EthTransactionReceipt(EthTransactionReceiptOpts { tx_hash }) => { - match wallet.config().blockchain { - "bitcoin" => { - anyhow::bail!("Not implemented"); - } - _ => { - let receipt = wallet.eth_transaction_receipt(&tx_hash).await?; - println!("Receipt: {:?}", receipt); - } - } - } Command::Transfer(TransferOpts { account, amount }) => { let amount = rosetta_client::string_to_amount(&amount, wallet.config().currency_decimals)?; @@ -234,3 +220,26 @@ fn print_transaction(tx: &BlockTransaction) -> Result<()> { } Ok(()) } + +fn compile_file(path: &str) -> Result> { + let solc = Solc::default(); + let mut sources = BTreeMap::new(); + sources.insert(Path::new(path).into(), Source::read(path).unwrap()); + let input = &CompilerInput::with_sources(sources)[0]; + let output = solc.compile_exact(input)?; + let file = output.contracts.get(path).unwrap(); + let (key, _) = file.first_key_value().unwrap(); + let contract = file.get(key).unwrap(); + let bytecode = contract + .evm + .as_ref() + .unwrap() + .bytecode + .as_ref() + .unwrap() + .object + .as_bytes() + .unwrap() + .to_vec(); + Ok(bytecode) +} From 3a7759a3fb080a6ccd6dfe83ea748cb2b3cf4704 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 21:06:18 +0500 Subject: [PATCH 6/9] fmt fix --- rosetta-wallet/src/main.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index 2202e8d4..03fd1553 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -1,11 +1,11 @@ use anyhow::Result; use clap::Parser; -use ethers_solc::{CompilerInput, artifacts::Source, Solc}; +use ethers_solc::{artifacts::Source, CompilerInput, Solc}; use futures::stream::StreamExt; use rosetta_client::types::{AccountIdentifier, BlockTransaction, TransactionIdentifier}; use rosetta_client::EthereumExt; use std::collections::BTreeMap; -use std::path::{PathBuf, Path}; +use std::path::{Path, PathBuf}; #[derive(Parser)] pub struct Opts { @@ -92,9 +92,7 @@ async fn main() -> Result<()> { "astar" | "ethereum" => { let bytes = compile_file(&contract_path)?; let response = wallet.eth_deploy_contract(bytes).await?; - let tx_receipt = wallet - .eth_transaction_receipt(&response.hash) - .await?; + let tx_receipt = wallet.eth_transaction_receipt(&response.hash).await?; let contract_address = tx_receipt.result["contractAddress"] .as_str() .ok_or(anyhow::anyhow!("Unable to get contract address"))?; From f160000deea9e4ac2e1dbfeb8f90740ccaf7d8a1 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 21:31:06 +0500 Subject: [PATCH 7/9] improving errors --- rosetta-wallet/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index 03fd1553..fb4e69da 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -231,13 +231,13 @@ fn compile_file(path: &str) -> Result> { let bytecode = contract .evm .as_ref() - .unwrap() + .ok_or(anyhow::anyhow!("Evm not found"))? .bytecode .as_ref() - .unwrap() + .ok_or(anyhow::anyhow!("Bytecode not founds"))? .object .as_bytes() - .unwrap() + .ok_or(anyhow::anyhow!("Could not convert to bytes"))? .to_vec(); Ok(bytecode) } From f6d75fb5ba0302a2bd0c09d2618b2fe604c8223a Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 21:37:08 +0500 Subject: [PATCH 8/9] using context --- rosetta-wallet/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index fb4e69da..10df0fb0 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -6,6 +6,7 @@ use rosetta_client::types::{AccountIdentifier, BlockTransaction, TransactionIden use rosetta_client::EthereumExt; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; +use anyhow::Context; #[derive(Parser)] pub struct Opts { @@ -231,13 +232,13 @@ fn compile_file(path: &str) -> Result> { let bytecode = contract .evm .as_ref() - .ok_or(anyhow::anyhow!("Evm not found"))? + .context("evm not found")? .bytecode .as_ref() - .ok_or(anyhow::anyhow!("Bytecode not founds"))? + .context("bytecode not found")? .object .as_bytes() - .ok_or(anyhow::anyhow!("Could not convert to bytes"))? + .context("could not convert to bytes")? .to_vec(); Ok(bytecode) } From b7146c95898fa3685860e2c0abf51352fc45e0a7 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Mon, 21 Aug 2023 21:37:51 +0500 Subject: [PATCH 9/9] fmt fix --- rosetta-wallet/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosetta-wallet/src/main.rs b/rosetta-wallet/src/main.rs index 10df0fb0..4a7baf03 100644 --- a/rosetta-wallet/src/main.rs +++ b/rosetta-wallet/src/main.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use anyhow::Result; use clap::Parser; use ethers_solc::{artifacts::Source, CompilerInput, Solc}; @@ -6,7 +7,6 @@ use rosetta_client::types::{AccountIdentifier, BlockTransaction, TransactionIden use rosetta_client::EthereumExt; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; -use anyhow::Context; #[derive(Parser)] pub struct Opts {