diff --git a/Cargo.toml b/Cargo.toml index 4e0dc73b70f71..ff78fdcc52012 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,29 +1,14 @@ -[package] -name = "dapptools" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -structopt = "0.3.22" -# ethers = "0.5.2" -ethers = { git = "https://github.com/gakonst/ethers-rs", branch = "chore/update-ethabi" } - -eyre = "0.6.5" -tokio = { version = "1.10.1", features = ["macros"] } -rustc-hex = "2.1.0" -serde_json = "1.0.67" -rpassword = "5.0.1" -evm = { version = "0.30.1" } -ansi_term = "0.12.1" -serde = "1.0.130" -hex = "0.4.3" -regex = { version = "1.5.4", default-features = false } - -svm = { package = "svm-rs", git = "https://github.com/roynalnaruto/svm-rs" } -glob = "0.3.0" -semver = "1.0.4" - -[patch.'crates-io'] -evm = { git = "https://github.com/gakonst/evm" } +[workspace] +members = [ + "utils", + "seth", + "dapp", + "dapptools", +] + +# Binary size optimizations +[profile.release] +opt-level = "z" +lto = true +codegen-units = 1 +panic = "abort" diff --git a/dapp/Cargo.toml b/dapp/Cargo.toml new file mode 100644 index 0000000000000..876f226d6036d --- /dev/null +++ b/dapp/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "dapp" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dapp-utils = { path = "./../utils" } + +# evm = { version = "0.30.1" } +evm = { git = "https://github.com/gakonst/evm" } +# ethers = { version = "0.5.2" } +ethers = { git = "https://github.com/gakonst/ethers-rs", branch = "master" } +svm = { package = "svm-rs", git = "https://github.com/roynalnaruto/svm-rs" } + +eyre = "0.6.5" +semver = "1.0.4" +serde_json = "1.0.67" +serde = "1.0.130" +regex = { version = "1.5.4", default-features = false } +hex = "0.4.3" +glob = "0.3.0" +# TODO: Trim +tokio = { version = "1.10.1" } diff --git a/GreetTest.sol b/dapp/GreetTest.sol similarity index 100% rename from GreetTest.sol rename to dapp/GreetTest.sol diff --git a/src/dapp.rs b/dapp/src/lib.rs similarity index 99% rename from src/dapp.rs rename to dapp/src/lib.rs index 5190f2164204e..03b8cd7be0d3f 100644 --- a/src/dapp.rs +++ b/dapp/src/lib.rs @@ -14,10 +14,13 @@ use std::{ path::{Path, PathBuf}, }; +/// Re-export of the Rust EVM for convenience +pub use evm; + use eyre::Result; use regex::Regex; -use crate::utils::get_func; +use dapp_utils::get_func; // TODO: Check if we can implement this as the base layer of an ethers-provider // Middleware stack instead of doing RPC calls. diff --git a/dapptools/Cargo.toml b/dapptools/Cargo.toml new file mode 100644 index 0000000000000..17f9bc579d75d --- /dev/null +++ b/dapptools/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "dapptools" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +structopt = "0.3.23" +dapp-utils = { path = "../utils" } +dapp = { path = "../dapp" } +seth = { path = "../seth" } + +# ethers = "0.5" +ethers = { git = "https://github.com/gakonst/ethers-rs", branch = "master" } +eyre = "0.6.5" +rustc-hex = "2.1.0" +serde_json = "1.0.67" +tokio = { version = "1.11.0", features = ["macros"] } +regex = { version = "1.5.4", default-features = false } +ansi_term = "0.12.1" +rpassword = "5.0.1" + +[[bin]] +name = "seth" +path = "src/seth.rs" + +[[bin]] +name = "dapp" +path = "src/dapp.rs" diff --git a/src/bin/dapp.rs b/dapptools/src/dapp.rs similarity index 99% rename from src/bin/dapp.rs rename to dapptools/src/dapp.rs index e6bed8d8b42b7..b87737466a6aa 100644 --- a/src/bin/dapp.rs +++ b/dapptools/src/dapp.rs @@ -1,7 +1,9 @@ use structopt::StructOpt; -use dapptools::dapp::MultiContractRunner; -use evm::{backend::MemoryVicinity, Config}; +use dapp::{ + evm::{backend::MemoryVicinity, Config}, + MultiContractRunner, +}; use ansi_term::Colour; use std::{ diff --git a/src/opts.rs b/dapptools/src/opts.rs similarity index 56% rename from src/opts.rs rename to dapptools/src/opts.rs index e60d72ec55da9..5d5c6963b0e51 100644 --- a/src/opts.rs +++ b/dapptools/src/opts.rs @@ -1,76 +1,13 @@ -use ethers::types::Address; -use ethers::{prelude::*, signers::coins_bip39::English}; +use ethers::{ + providers::{Http, Provider}, + signers::{coins_bip39::English, LocalWallet, MnemonicBuilder}, + types::Address, +}; use eyre::Result; use std::convert::TryFrom; use std::str::FromStr; use structopt::StructOpt; -#[derive(Debug, StructOpt)] -#[structopt(about = "Perform Ethereum RPC calls from the comfort of your command line.")] -pub enum Subcommands { - #[structopt(name = "--from-ascii")] - #[structopt(about = "convert text data into hexdata")] - FromAscii { text: String }, - #[structopt(name = "--to-checksum-address")] - #[structopt(about = "convert an address to a checksummed format (EIP-55)")] - ToCheckSumAddress { address: Address }, - #[structopt(name = "--to-bytes32")] - #[structopt(about = "left-pads a hex bytes string to 32 bytes)")] - ToBytes32 { bytes: String }, - #[structopt(name = "block")] - #[structopt( - about = "Prints information about . If is given, print only the value of that field" - )] - Block { - #[structopt(help = "the block you want to query, can also be earliest/latest/pending", parse(try_from_str = parse_block_id))] - block: BlockId, - #[structopt(long, env = "SETH_FULL_BLOCK")] - full: bool, - field: Option, - #[structopt(long = "--json", short = "-j")] - to_json: bool, - #[structopt(long, env = "ETH_RPC_URL")] - rpc_url: String, - }, - #[structopt(name = "call")] - #[structopt(about = "Perform a local call to without publishing a transaction.")] - Call { - #[structopt(help = "the address you want to query")] - address: Address, - sig: String, - args: Vec, - #[structopt(long, env = "ETH_RPC_URL")] - rpc_url: String, - }, - #[structopt(name = "send")] - #[structopt(about = "Publish a transaction signed by to call with ")] - SendTx { - #[structopt(help = "the address you want to transact with")] - to: Address, - #[structopt(help = "the function signature you want to call")] - sig: String, - #[structopt(help = "the list of arguments you want to call the function with")] - args: Vec, - #[structopt(flatten)] - eth: EthereumOpts, - }, -} - -fn parse_block_id(s: &str) -> eyre::Result { - Ok(match s { - "earliest" => BlockId::Number(BlockNumber::Earliest), - "latest" => BlockId::Number(BlockNumber::Latest), - s if s.starts_with("0x") => BlockId::Hash(H256::from_str(s)?), - s => BlockId::Number(BlockNumber::Number(U64::from_str(s)?)), - }) -} - -#[derive(Debug, StructOpt)] -pub struct Opts { - #[structopt(subcommand)] - pub sub: Subcommands, -} - #[derive(StructOpt, Debug, Clone)] pub struct EthereumOpts { #[structopt( @@ -94,6 +31,7 @@ pub struct EthereumOpts { // TODO: Improve these so that we return a middleware trait object use std::sync::Arc; impl EthereumOpts { + #[allow(unused)] pub fn provider(&self) -> eyre::Result>> { Ok(Arc::new(Provider::try_from(self.rpc_url.as_str())?)) } diff --git a/src/bin/seth.rs b/dapptools/src/seth.rs similarity index 50% rename from src/bin/seth.rs rename to dapptools/src/seth.rs index a0bc6b6823f83..007b8405280eb 100644 --- a/src/bin/seth.rs +++ b/dapptools/src/seth.rs @@ -1,15 +1,82 @@ -use std::convert::TryFrom; +mod opts; +use opts::EthereumOpts; + +use seth::{Seth, SimpleSeth}; use ethers::{ - prelude::SignerMiddleware, + middleware::SignerMiddleware, providers::{Middleware, Provider}, signers::Signer, - types::Address, + types::{Address, BlockId, BlockNumber, H256, U64}, }; +use std::{convert::TryFrom, str::FromStr}; use structopt::StructOpt; -use dapptools::opts::{Opts, Subcommands}; -use dapptools::{Seth, SimpleSeth}; +#[derive(Debug, StructOpt)] +#[structopt(about = "Perform Ethereum RPC calls from the comfort of your command line.")] +pub enum Subcommands { + #[structopt(name = "--from-ascii")] + #[structopt(about = "convert text data into hexdata")] + FromAscii { text: String }, + #[structopt(name = "--to-checksum-address")] + #[structopt(about = "convert an address to a checksummed format (EIP-55)")] + ToCheckSumAddress { address: Address }, + #[structopt(name = "--to-bytes32")] + #[structopt(about = "left-pads a hex bytes string to 32 bytes)")] + ToBytes32 { bytes: String }, + #[structopt(name = "block")] + #[structopt( + about = "Prints information about . If is given, print only the value of that field" + )] + Block { + #[structopt(help = "the block you want to query, can also be earliest/latest/pending", parse(try_from_str = parse_block_id))] + block: BlockId, + #[structopt(long, env = "SETH_FULL_BLOCK")] + full: bool, + field: Option, + #[structopt(long = "--json", short = "-j")] + to_json: bool, + #[structopt(long, env = "ETH_RPC_URL")] + rpc_url: String, + }, + #[structopt(name = "call")] + #[structopt(about = "Perform a local call to without publishing a transaction.")] + Call { + #[structopt(help = "the address you want to query")] + address: Address, + sig: String, + args: Vec, + #[structopt(long, env = "ETH_RPC_URL")] + rpc_url: String, + }, + #[structopt(name = "send")] + #[structopt(about = "Publish a transaction signed by to call with ")] + SendTx { + #[structopt(help = "the address you want to transact with")] + to: Address, + #[structopt(help = "the function signature you want to call")] + sig: String, + #[structopt(help = "the list of arguments you want to call the function with")] + args: Vec, + #[structopt(flatten)] + eth: EthereumOpts, + }, +} + +fn parse_block_id(s: &str) -> eyre::Result { + Ok(match s { + "earliest" => BlockId::Number(BlockNumber::Earliest), + "latest" => BlockId::Number(BlockNumber::Latest), + s if s.starts_with("0x") => BlockId::Hash(H256::from_str(s)?), + s => BlockId::Number(BlockNumber::Number(U64::from_str(s)?)), + }) +} + +#[derive(Debug, StructOpt)] +pub struct Opts { + #[structopt(subcommand)] + pub sub: Subcommands, +} #[tokio::main] async fn main() -> eyre::Result<()> { diff --git a/seth/Cargo.toml b/seth/Cargo.toml new file mode 100644 index 0000000000000..0deebe06b83bc --- /dev/null +++ b/seth/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "seth" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dapp-utils = { path = "../utils" } +# ethers = "0.5" +ethers-core = { git = "https://github.com/gakonst/ethers-rs", branch = "master", default-features = false } +ethers-providers = { git = "https://github.com/gakonst/ethers-rs", branch = "master", default-features = false } +eyre = "0.6.5" +rustc-hex = "2.1.0" +serde_json = "1.0.67" diff --git a/src/seth.rs b/seth/src/lib.rs similarity index 92% rename from src/seth.rs rename to seth/src/lib.rs index 4ff4ed5d6240e..c4e3b2c68ba8e 100644 --- a/src/seth.rs +++ b/seth/src/lib.rs @@ -1,18 +1,13 @@ //! Seth //! //! TODO -use ethers::{ - providers::{Middleware, PendingTransaction}, - types::*, - utils, -}; +use ethers_providers::{Middleware, PendingTransaction}; +use ethers_core::{types::*, utils}; use eyre::Result; use rustc_hex::ToHex; use std::str::FromStr; -use crate::utils::get_func; - -use super::utils::{encode_args, to_table}; +use dapp_utils::{encode_args, get_func, to_table}; // TODO: SethContract with common contract initializers? Same for SethProviders? @@ -27,7 +22,7 @@ where /// Converts ASCII text input to hex /// /// ``` - /// use dapptools::Seth; + /// use seth::Seth; /// use ethers::providers::{Provider, Http}; /// use std::convert::TryFrom; /// @@ -45,8 +40,8 @@ where /// /// ```no_run /// - /// use dapptools::Seth; - /// use dapptools::ethers::types::Address; + /// use seth::Seth; + /// use ethers::types::Address; /// use ethers::providers::{Provider, Http}; /// use std::{str::FromStr, convert::TryFrom}; /// @@ -85,8 +80,8 @@ where /// Sends a transaction to the specified address /// /// ```no_run - /// use dapptools::Seth; - /// use dapptools::ethers::types::Address; + /// use seth::Seth; + /// use ethers::types::Address; /// use ethers::providers::{Provider, Http}; /// use std::{str::FromStr, convert::TryFrom}; /// @@ -122,7 +117,7 @@ where } /// ```no_run - /// use dapptools::Seth; + /// use seth::Seth; /// use ethers::providers::{Provider, Http}; /// use std::convert::TryFrom; /// @@ -189,7 +184,7 @@ impl SimpleSeth { /// Converts ASCII text input to hex /// /// ``` - /// use dapptools::SimpleSeth as Seth; + /// use seth::SimpleSeth as Seth; /// /// let bin = Seth::from_ascii("yo"); /// assert_eq!(bin, "0x796f") @@ -203,8 +198,8 @@ impl SimpleSeth { /// according to [EIP-55](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md) /// /// ``` - /// use dapptools::SimpleSeth as Seth; - /// use dapptools::ethers::types::Address; + /// use seth::SimpleSeth as Seth; + /// use ethers::types::Address; /// use std::str::FromStr; /// /// # fn main() -> eyre::Result<()> { @@ -221,7 +216,7 @@ impl SimpleSeth { /// Converts hexdata into bytes32 value /// ``` - /// use dapptools::SimpleSeth as Seth; + /// use seth::SimpleSeth as Seth; /// /// # fn main() -> eyre::Result<()> { /// let bytes = Seth::to_bytes32("1234")?; diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 3db70b8b46f49..0000000000000 --- a/src/lib.rs +++ /dev/null @@ -1,19 +0,0 @@ -pub mod opts; - -mod utils; - -pub mod dapp; - -mod seth; -pub use seth::*; - -// Re-export Ethers for convenience. -pub use ethers; - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/utils/Cargo.toml b/utils/Cargo.toml new file mode 100644 index 0000000000000..1cfb13bd404b3 --- /dev/null +++ b/utils/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "dapp-utils" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# ethers = "0.5" +ethers-core = { git = "https://github.com/gakonst/ethers-rs", branch = "master" } + +eyre = { version = "0.6.5", default-features = false } +rustc-hex = { version = "2.1.0", default-features = false } +serde_json = { version = "1.0.67", default-features = false } + diff --git a/src/utils.rs b/utils/src/lib.rs similarity index 97% rename from src/utils.rs rename to utils/src/lib.rs index 583c96dd3d3c1..704c4115c3980 100644 --- a/src/utils.rs +++ b/utils/src/lib.rs @@ -1,7 +1,6 @@ -use ethers::{ - abi::{Function, ParamType, Token, Tokenizable}, - core::abi::parse_abi, +use ethers_core::{ types::*, + abi::{Function, ParamType, Token, Tokenizable, parse_abi}, }; use eyre::Result; use rustc_hex::FromHex;