From 3f313ede01166610e5c724c972816c57fec3d974 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Tue, 26 May 2020 12:37:31 +0300 Subject: [PATCH] el refactor --- Cargo.lock | 1383 ++--------------- Cargo.toml | 70 +- contract.sol | 22 + crates/ethers-abi/Cargo.toml | 9 + src/abi.rs => crates/ethers-abi/src/lib.rs | 0 crates/ethers-contract/Cargo.toml | 9 + .../ethers-contract/src}/contract.rs | 0 crates/ethers-contract/src/lib.rs | 7 + .../ethers-contract/src}/mod.rs | 0 .../ethers-contract/src}/tokens.rs | 0 crates/ethers-derive/Cargo.toml | 21 + crates/ethers-derive/src/README.md | 55 + crates/ethers-derive/src/lib.rs | 503 ++++++ crates/ethers-derive/src/spanned.rs | 50 + crates/ethers-derive/src/src/contract.rs | 178 +++ .../ethers-derive/src/src/contract/common.rs | 200 +++ .../src/src/contract/deployment.rs | 167 ++ .../ethers-derive/src/src/contract/events.rs | 855 ++++++++++ .../ethers-derive/src/src/contract/methods.rs | 255 +++ .../ethers-derive/src/src/contract/types.rs | 48 + crates/ethers-derive/src/src/lib.rs | 286 ++++ crates/ethers-derive/src/src/rustfmt.rs | 36 + crates/ethers-derive/src/src/source.rs | 260 ++++ crates/ethers-derive/src/src/test/macros.rs | 10 + crates/ethers-derive/src/src/util.rs | 117 ++ crates/ethers-providers/Cargo.toml | 9 + .../ethers-providers}/http.rs | 0 .../ethers-providers}/mod.rs | 0 crates/ethers-providers/src/lib.rs | 7 + crates/ethers-signers/Cargo.toml | 9 + .../ethers-signers/src}/client.rs | 0 crates/ethers-signers/src/lib.rs | 7 + .../ethers-signers/src}/mod.rs | 0 .../ethers-signers/src}/networks.rs | 0 .../ethers-signers/src}/wallet.rs | 0 crates/ethers-types/Cargo.toml | 19 + .../ethers-types/src}/block.rs | 0 .../ethers-types/src}/block_number.rs | 0 .../ethers-types/src}/bytes.rs | 0 .../types => crates/ethers-types/src}/keys.rs | 0 .../mod.rs => crates/ethers-types/src/lib.rs | 0 {src/types => crates/ethers-types/src}/log.rs | 0 .../ethers-types/src}/signature.rs | 0 .../ethers-types/src}/transaction.rs | 0 crates/ethers-utils/Cargo.toml | 9 + crates/ethers-utils/src/lib.rs | 7 + {src => crates/ethers-utils/src}/utils.rs | 0 crates/ethers/Cargo.toml | 11 + {src => crates/ethers/src}/lib.rs | 0 49 files changed, 3363 insertions(+), 1256 deletions(-) create mode 100644 contract.sol create mode 100644 crates/ethers-abi/Cargo.toml rename src/abi.rs => crates/ethers-abi/src/lib.rs (100%) create mode 100644 crates/ethers-contract/Cargo.toml rename {src/contract => crates/ethers-contract/src}/contract.rs (100%) create mode 100644 crates/ethers-contract/src/lib.rs rename {src/contract => crates/ethers-contract/src}/mod.rs (100%) rename {src/contract => crates/ethers-contract/src}/tokens.rs (100%) create mode 100644 crates/ethers-derive/Cargo.toml create mode 100644 crates/ethers-derive/src/README.md create mode 100644 crates/ethers-derive/src/lib.rs create mode 100644 crates/ethers-derive/src/spanned.rs create mode 100644 crates/ethers-derive/src/src/contract.rs create mode 100644 crates/ethers-derive/src/src/contract/common.rs create mode 100644 crates/ethers-derive/src/src/contract/deployment.rs create mode 100644 crates/ethers-derive/src/src/contract/events.rs create mode 100644 crates/ethers-derive/src/src/contract/methods.rs create mode 100644 crates/ethers-derive/src/src/contract/types.rs create mode 100644 crates/ethers-derive/src/src/lib.rs create mode 100644 crates/ethers-derive/src/src/rustfmt.rs create mode 100644 crates/ethers-derive/src/src/source.rs create mode 100644 crates/ethers-derive/src/src/test/macros.rs create mode 100644 crates/ethers-derive/src/src/util.rs create mode 100644 crates/ethers-providers/Cargo.toml rename {src/providers => crates/ethers-providers}/http.rs (100%) rename {src/providers => crates/ethers-providers}/mod.rs (100%) create mode 100644 crates/ethers-providers/src/lib.rs create mode 100644 crates/ethers-signers/Cargo.toml rename {src/signers => crates/ethers-signers/src}/client.rs (100%) create mode 100644 crates/ethers-signers/src/lib.rs rename {src/signers => crates/ethers-signers/src}/mod.rs (100%) rename {src/signers => crates/ethers-signers/src}/networks.rs (100%) rename {src/signers => crates/ethers-signers/src}/wallet.rs (100%) create mode 100644 crates/ethers-types/Cargo.toml rename {src/types => crates/ethers-types/src}/block.rs (100%) rename {src/types => crates/ethers-types/src}/block_number.rs (100%) rename {src/types => crates/ethers-types/src}/bytes.rs (100%) rename {src/types => crates/ethers-types/src}/keys.rs (100%) rename src/types/mod.rs => crates/ethers-types/src/lib.rs (100%) rename {src/types => crates/ethers-types/src}/log.rs (100%) rename {src/types => crates/ethers-types/src}/signature.rs (100%) rename {src/types => crates/ethers-types/src}/transaction.rs (100%) create mode 100644 crates/ethers-utils/Cargo.toml create mode 100644 crates/ethers-utils/src/lib.rs rename {src => crates/ethers-utils/src}/utils.rs (100%) create mode 100644 crates/ethers/Cargo.toml rename {src => crates/ethers/src}/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index b24a1f74..d5071657 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,1579 +1,506 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "addr2line" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a49806b9dadc843c61e7c97e72490ad7f7220ae249012fbda9ad0609457c0543" -dependencies = [ - "gimli", -] - -[[package]] -name = "aho-corasick" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" -dependencies = [ - "memchr", -] - [[package]] name = "arrayvec" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" - -[[package]] -name = "async-trait" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c4f3195085c36ea8d24d32b2f828d23296a9370a28aa39d111f6f16bef9f3b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] [[package]] name = "autocfg" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - -[[package]] -name = "autocfg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" - -[[package]] -name = "backtrace" -version = "0.3.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df2f85c8a2abbe3b7d7e748052fdd9b76a0458fdeb16ad4223f5eca78c7c130" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" - -[[package]] -name = "bincode" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" -dependencies = [ - "byteorder", - "serde", -] - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "bitvec" version = "0.17.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" dependencies = [ - "either", - "radium", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "radium 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "bumpalo" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5356f1d23ee24a1f785a56d1d1a5f0fd5b0f6a0c0fb2412ce11da71649ab78f6" - [[package]] name = "byte-slice-cast" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" [[package]] name = "byteorder" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" - -[[package]] -name = "bytes" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" [[package]] name = "cc" version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff" [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - -[[package]] -name = "core-foundation" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "crunchy" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "ct-logs" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113" -dependencies = [ - "sct", -] - -[[package]] -name = "dtoa" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" [[package]] name = "either" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" - -[[package]] -name = "encoding_rs" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "error-chain" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d371106cc88ffdfb1eabd7111e432da544f16f3e2d7bf1dfe8bf575f1df045cd" -dependencies = [ - "backtrace", - "version_check", -] - -[[package]] -name = "ethabi" -version = "12.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052a565e3de82944527d6d10a465697e6bb92476b772ca7141080c901f6a63c6" -dependencies = [ - "ethereum-types", - "rustc-hex", - "serde", - "serde_json", - "tiny-keccak 1.5.0", - "uint", -] [[package]] name = "ethbloom" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71a6567e6fd35589fea0c63b94b4cf2e55573e413901bdbe60ab15cf0e25e5df" dependencies = [ - "crunchy", - "fixed-hash", - "impl-rlp", - "impl-serde", - "tiny-keccak 2.0.2", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ethereum-types" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473aecff686bd8e7b9db0165cbbb53562376b39bf35b427f0c60446a9e1634b0" dependencies = [ - "ethbloom", - "fixed-hash", - "impl-rlp", - "impl-serde", - "primitive-types", - "uint", + "ethbloom 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "ethers" +name = "ethers-types" version = "0.1.0" dependencies = [ - "arrayvec", - "async-trait", - "bincode", - "ethabi", - "ethereum-types", - "failure", - "rand 0.5.6", - "reqwest", - "rlp", - "rustc-hex", - "secp256k1", - "serde", - "serde_json", - "solc", - "thiserror", - "tiny-keccak 2.0.2", - "tokio", - "url", - "zeroize", -] - -[[package]] -name = "failure" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" -dependencies = [ - "backtrace", - "failure_derive", -] - -[[package]] -name = "failure_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", + "ethereum-types 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "secp256k1 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "fixed-hash" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" dependencies = [ - "byteorder", - "rand 0.7.3", - "rustc-hex", - "static_assertions", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] -name = "futures-channel" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" - -[[package]] -name = "futures-macro" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" - -[[package]] -name = "futures-task" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" -dependencies = [ - "once_cell", -] - -[[package]] -name = "futures-util" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" -dependencies = [ - "futures-core", - "futures-macro", - "futures-task", - "pin-project", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "getrandom" version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" - -[[package]] -name = "h2" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b7246d7e4b979c03fa093da39cfb3617a96bbeee6310af63991668d7e843ff" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "log", - "slab", - "tokio", - "tokio-util", -] - -[[package]] -name = "http" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "httparse" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" - -[[package]] -name = "hyper" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96816e1d921eca64d208a85aab4f7798455a8e34229ee5a88c935bdee1b78b14" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "itoa", - "log", - "net2", - "pin-project", - "time", - "tokio", - "tower-service", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac965ea399ec3a25ac7d13b8affd4b8f39325cca00858ddf5eb29b79e6b14b08" -dependencies = [ - "bytes", - "ct-logs", - "futures-util", - "hyper", - "log", - "rustls", - "rustls-native-certs", - "tokio", - "tokio-rustls", - "webpki", -] - -[[package]] -name = "idna" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "impl-codec" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1be51a921b067b0eaca2fad532d9400041561aa922221cc65f95a85641c6bf53" dependencies = [ - "parity-scale-codec", + "parity-scale-codec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "impl-rlp" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f7a72f11830b52333f36e3b09a288333888bf54380fd0ac0790a3c31ab0f3c5" dependencies = [ - "rlp", + "rlp 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "impl-serde" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" dependencies = [ - "serde", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "indexmap" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" -dependencies = [ - "autocfg 1.0.0", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - -[[package]] -name = "itoa" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" - -[[package]] -name = "js-sys" -version = "0.3.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" - -[[package]] -name = "memchr" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" - -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "mio" -version = "0.6.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" -dependencies = [ - "cfg-if", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "miow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - -[[package]] -name = "net2" -version = "0.2.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" -dependencies = [ - "cfg-if", - "libc", - "winapi 0.3.8", -] - -[[package]] -name = "object" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2" - -[[package]] -name = "once_cell" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" - -[[package]] -name = "openssl-probe" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "parity-scale-codec" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c8f7f4244ddb5c37c103641027a76c530e65e8e4b8240b29f81ea40508b17" dependencies = [ - "arrayvec", - "bitvec", - "byte-slice-cast", - "serde", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitvec 0.17.4 (registry+https://github.com/rust-lang/crates.io-index)", + "byte-slice-cast 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "percent-encoding" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" - -[[package]] -name = "pin-project" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc93aeee735e60ecb40cf740eb319ff23eab1c5748abfdb5c180e4ce49f7791" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e58db2081ba5b4c93bd6be09c40fd36cb9193a8336c384f3b40012e531aa7e40" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7505eeebd78492e0f6108f7171c4948dbb120ee8119d9d77d0afa5469bef67f" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "ppv-lite86" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" [[package]] name = "primitive-types" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55c21c64d0eaa4d7ed885d959ef2d62d9e488c27c0e02d9aa5ce6c877b7d5f8" dependencies = [ - "fixed-hash", - "impl-codec", - "impl-rlp", - "impl-serde", - "uint", + "fixed-hash 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-codec 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63" - -[[package]] -name = "proc-macro-nested" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694" - [[package]] name = "proc-macro2" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a50b9351bfa8d65a7d93ce712dc63d2fd15ddbf2c36990fc7cac344859c04f" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "radium" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" [[package]] name = "rand" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "winapi 0.3.8", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.8", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_chacha" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "ppv-lite86 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" dependencies = [ - "rand_core 0.4.2", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_hc" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" dependencies = [ - "rand_core 0.3.1", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_isaac" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" dependencies = [ - "rand_core 0.3.1", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_jitter" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.8", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_xorshift" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "regex" -version = "1.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", - "thread_local", -] - -[[package]] -name = "regex-syntax" -version = "0.6.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" - -[[package]] -name = "reqwest" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b81e49ddec5109a9dcfc5f2a317ff53377c915e9ae9d4f2fb50914b85614e2" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "http", - "http-body", - "hyper", - "hyper-rustls", - "js-sys", - "lazy_static", - "log", - "mime", - "mime_guess", - "percent-encoding", - "pin-project-lite", - "rustls", - "serde", - "serde_json", - "serde_urlencoded", - "time", - "tokio", - "tokio-rustls", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "webpki-roots", - "winreg", -] - -[[package]] -name = "ring" -version = "0.16.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c" -dependencies = [ - "cc", - "lazy_static", - "libc", - "spin", - "untrusted", - "web-sys", - "winapi 0.3.8", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rlp" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a7d3f9bed94764eac15b8f14af59fac420c236adaff743b7bcc88e265cb4345" dependencies = [ - "rustc-hex", + "rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rustc-demangle" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" - [[package]] name = "rustc-hex" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" - -[[package]] -name = "rustls" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0d4a31f5d68413404705d6982529b0e11a9aacd4839d1d6222ee3b8cb4015e1" -dependencies = [ - "base64", - "log", - "ring", - "sct", - "webpki", -] - -[[package]] -name = "rustls-native-certs" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75ffeb84a6bd9d014713119542ce415db3a3e4748f0bfce1e1416cd224a23a5" -dependencies = [ - "openssl-probe", - "rustls", - "schannel", - "security-framework", -] - -[[package]] -name = "ryu" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1" - -[[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi 0.3.8", -] - -[[package]] -name = "sct" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" -dependencies = [ - "ring", - "untrusted", -] [[package]] name = "secp256k1" version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2932dc07acd2066ff2e3921a4419606b220ba6cd03a9935123856cc534877056" dependencies = [ - "rand 0.6.5", - "secp256k1-sys", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "secp256k1-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "secp256k1-sys" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab2c26f0d3552a0f12e639ae8a64afc2e3db9c52fe32f5fc6c289d38519f220" dependencies = [ - "cc", -] - -[[package]] -name = "security-framework" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" -dependencies = [ - "core-foundation-sys", - "libc", + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde" version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c" dependencies = [ - "serde_derive", + "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "serde_json" -version = "1.0.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" -dependencies = [ - "dtoa", - "itoa", - "serde", - "url", -] - -[[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - -[[package]] -name = "smallvec" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" - -[[package]] -name = "solc" -version = "0.1.0" -source = "git+https://github.com/paritytech/rust_solc#3b615dd39d24d956eb22a5666999172527a382f0" -dependencies = [ - "error-chain", - "lazy_static", - "regex", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" -version = "1.0.23" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b5f192649e48a5302a13f2feb224df883b98933222369e4b3b0fe2a5447269" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "synstructure" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", + "proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "thiserror" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b13f926965ad00595dd129fa12823b04bbf866e9085ab0a5f2b05b850fbfc344" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "thiserror-impl" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "893582086c2f98cde18f906265a65b5030a074b1046c674ae898be6519a7f479" dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "time" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -dependencies = [ - "libc", - "winapi 0.3.8", -] - -[[package]] -name = "tiny-keccak" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" -dependencies = [ - "crunchy", + "proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tiny-keccak" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" dependencies = [ - "crunchy", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d099fa27b9702bed751524694adbe393e18b36b204da91eb1cbbbbb4a5ee2d58" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "iovec", - "lazy_static", - "memchr", - "mio", - "pin-project-lite", - "slab", - "tokio-macros", -] - -[[package]] -name = "tokio-macros" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-rustls" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15cb62a0d2770787abc96e99c1cd98fcf17f94959f3af63ca85bdfb203f051b4" -dependencies = [ - "futures-core", - "rustls", - "tokio", - "webpki", -] - -[[package]] -name = "tokio-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tower-service" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" - -[[package]] -name = "try-lock" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" - [[package]] name = "uint" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "173cd16430c206dc1a430af8a89a0e9c076cf15cb42b4aedb10e8cc8fee73681" dependencies = [ - "byteorder", - "crunchy", - "rustc-hex", - "static_assertions", -] - -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -dependencies = [ - "matches", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" -dependencies = [ - "smallvec", + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - -[[package]] -name = "url" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" -dependencies = [ - "idna", - "matches", - "percent-encoding", -] - -[[package]] -name = "version_check" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" - -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - -[[package]] -name = "wasm-bindgen" -version = "0.2.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551" -dependencies = [ - "cfg-if", - "serde", - "serde_json", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a369c5e1dfb7569e14d62af4da642a3cbc2f9a3652fe586e26ac22222aa4b04" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad" - -[[package]] -name = "web-sys" -version = "0.3.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4" -dependencies = [ - "webpki", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "winreg" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" -dependencies = [ - "winapi 0.3.8", -] - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] [[package]] name = "zeroize" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" + +[metadata] +"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +"checksum bitvec 0.17.4 (registry+https://github.com/rust-lang/crates.io-index)" = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" +"checksum byte-slice-cast 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" +"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +"checksum cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +"checksum ethbloom 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71a6567e6fd35589fea0c63b94b4cf2e55573e413901bdbe60ab15cf0e25e5df" +"checksum ethereum-types 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "473aecff686bd8e7b9db0165cbbb53562376b39bf35b427f0c60446a9e1634b0" +"checksum fixed-hash 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" +"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +"checksum impl-codec 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1be51a921b067b0eaca2fad532d9400041561aa922221cc65f95a85641c6bf53" +"checksum impl-rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8f7a72f11830b52333f36e3b09a288333888bf54380fd0ac0790a3c31ab0f3c5" +"checksum impl-serde 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" +"checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" +"checksum parity-scale-codec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "329c8f7f4244ddb5c37c103641027a76c530e65e8e4b8240b29f81ea40508b17" +"checksum ppv-lite86 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" +"checksum primitive-types 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c55c21c64d0eaa4d7ed885d959ef2d62d9e488c27c0e02d9aa5ce6c877b7d5f8" +"checksum proc-macro2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101" +"checksum quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea" +"checksum radium 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" +"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" +"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +"checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rlp 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7d3f9bed94764eac15b8f14af59fac420c236adaff743b7bcc88e265cb4345" +"checksum rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" +"checksum secp256k1 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2932dc07acd2066ff2e3921a4419606b220ba6cd03a9935123856cc534877056" +"checksum secp256k1-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ab2c26f0d3552a0f12e639ae8a64afc2e3db9c52fe32f5fc6c289d38519f220" +"checksum serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)" = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c" +"checksum serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)" = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984" +"checksum static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +"checksum syn 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f14a640819f79b72a710c0be059dce779f9339ae046c8bef12c361d56702146f" +"checksum thiserror 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b13f926965ad00595dd129fa12823b04bbf866e9085ab0a5f2b05b850fbfc344" +"checksum thiserror-impl 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "893582086c2f98cde18f906265a65b5030a074b1046c674ae898be6519a7f479" +"checksum tiny-keccak 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +"checksum uint 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "173cd16430c206dc1a430af8a89a0e9c076cf15cb42b4aedb10e8cc8fee73681" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" diff --git a/Cargo.toml b/Cargo.toml index 42a081da..d9918e9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,30 +1,44 @@ -[package] -name = "ethers" -version = "0.1.0" -authors = ["Georgios Konstantopoulos "] -edition = "2018" +[workspace] -[dependencies] -ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] } -url = { version = "2.1.1", default-features = false } -async-trait = { version = "0.1.31", default-features = false } -reqwest = { version = "0.10.4", default-features = false, features = ["json", "rustls-tls"] } -serde = { version = "1.0.110", default-features = false, features = ["derive"] } -serde_json = { version = "1.0.53", default-features = false } -thiserror = { version = "1.0.19", default-features = false } -rustc-hex = { version = "2.1.0", default-features = false } -rand = { version = "0.5.1", default-features = false } # this should be the same rand crate version as the one in secp -secp256k1 = { version = "0.17.2", default-features = false, features = ["std", "recovery", "rand"] } -zeroize = { version = "1.1.0", default-features = false } -tiny-keccak = { version = "2.0.2", default-features = false } +members = [ + # "./crates/ethers", + # "./crates/ethers-abi", + # "./crates/ethers-contract", + # "./crates/ethers-derive", + # "./crates/ethers-providers", + # "./crates/ethers-signers", + "./crates/ethers-types", + # "./crates/ethers-utils", +] -solc = { git = "https://github.com/paritytech/rust_solc "} -rlp = "0.4.5" -ethabi = "12.0.0" -bincode = "1.2.1" -arrayvec = "0.5.1" - -[dev-dependencies] -tokio = { version = "0.2.21", features = ["macros"] } -failure = "0.1.8" -rand = { version = "0.5.1" } +# [dependencies] +# ethers-derive = { path = "ethers-derive", optional = true } +# +# ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] } +# url = { version = "2.1.1", default-features = false } +# async-trait = { version = "0.1.31", default-features = false } +# reqwest = { version = "0.10.4", default-features = false, features = ["json", "rustls-tls"] } +# serde = { version = "1.0.110", default-features = false, features = ["derive"] } +# serde_json = { version = "1.0.53", default-features = false } +# thiserror = { version = "1.0.19", default-features = false } +# rustc-hex = { version = "2.1.0", default-features = false } +# rand = { version = "0.5.1", default-features = false } # this should be the same rand crate version as the one in secp +# secp256k1 = { version = "0.17.2", default-features = false, features = ["std", "recovery", "rand"] } +# zeroize = { version = "1.1.0", default-features = false } +# tiny-keccak = { version = "2.0.2", default-features = false } +# +# solc = { git = "https://github.com/paritytech/rust_solc", optional = true } +# rlp = "0.4.5" +# ethabi = "12.0.0" +# bincode = "1.2.1" +# arrayvec = "0.5.1" +# +# [dev-dependencies] +# tokio = { version = "0.2.21", features = ["macros"] } +# failure = "0.1.8" +# rand = { version = "0.5.1" } +# +# [features] +# default = ["derive"] +# derive = ["ethers-derive"] +# diff --git a/contract.sol b/contract.sol new file mode 100644 index 00000000..e375ba81 --- /dev/null +++ b/contract.sol @@ -0,0 +1,22 @@ +pragma solidity ^0.6.6; + +contract SimpleStorage { + + event ValueChanged(address indexed author, string oldValue, string newValue); + + string _value; + + constructor(string memory value) public { + emit ValueChanged(msg.sender, _value, value); + _value = value; + } + + function getValue() view public returns (string memory) { + return _value; + } + + function setValue(string memory value) public { + emit ValueChanged(msg.sender, _value, value); + _value = value; + } +} diff --git a/crates/ethers-abi/Cargo.toml b/crates/ethers-abi/Cargo.toml new file mode 100644 index 00000000..2536aaa0 --- /dev/null +++ b/crates/ethers-abi/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ethers-abi" +version = "0.1.0" +authors = ["Georgios Konstantopoulos "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/abi.rs b/crates/ethers-abi/src/lib.rs similarity index 100% rename from src/abi.rs rename to crates/ethers-abi/src/lib.rs diff --git a/crates/ethers-contract/Cargo.toml b/crates/ethers-contract/Cargo.toml new file mode 100644 index 00000000..18fc0aeb --- /dev/null +++ b/crates/ethers-contract/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ethers-contract" +version = "0.1.0" +authors = ["Georgios Konstantopoulos "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/contract/contract.rs b/crates/ethers-contract/src/contract.rs similarity index 100% rename from src/contract/contract.rs rename to crates/ethers-contract/src/contract.rs diff --git a/crates/ethers-contract/src/lib.rs b/crates/ethers-contract/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/crates/ethers-contract/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/contract/mod.rs b/crates/ethers-contract/src/mod.rs similarity index 100% rename from src/contract/mod.rs rename to crates/ethers-contract/src/mod.rs diff --git a/src/contract/tokens.rs b/crates/ethers-contract/src/tokens.rs similarity index 100% rename from src/contract/tokens.rs rename to crates/ethers-contract/src/tokens.rs diff --git a/crates/ethers-derive/Cargo.toml b/crates/ethers-derive/Cargo.toml new file mode 100644 index 00000000..b2e6ba9f --- /dev/null +++ b/crates/ethers-derive/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "ethers-derive" +version = "0.1.0" +authors = ["Nicholas Rodrigues Lordello ", "Georgios Konstantopoulos "] +edition = "2018" +license = "MIT OR Apache-2.0" +repository = "https://github.com/gnosis/ethcontract-rs" +homepage = "https://github.com/gnosis/ethcontract-rs" +documentation = "https://docs.rs/ethcontract" +description = "Code generation for type-safe bindings to Ethereum smart contracts" + +[dependencies] +ethers-abi = { path = "../ethers-abi" } + +anyhow = "1.0" +curl = "0.4" +Inflector = "0.11" +proc-macro2 = "1.0" +quote = "1.0" +syn = "1.0.12" +url = "2.1" diff --git a/crates/ethers-derive/src/README.md b/crates/ethers-derive/src/README.md new file mode 100644 index 00000000..371d26a3 --- /dev/null +++ b/crates/ethers-derive/src/README.md @@ -0,0 +1,55 @@ +# `ethcontract-generate` + +An alternative API for generating type-safe contract bindings from `build.rs` +scripts. Using this method instead of the procedural macro has a couple +advantages: +- Proper integration with with RLS and Racer for autocomplete support +- Ability to inspect the generated code + +The downside of using the generator API is the requirement of having a build +script instead of a macro invocation. + +## Getting Started + +Using crate requires two dependencies - one for the runtime and one for the +generator: + +```toml +[dependencies] +ethcontract = { version = "...", default-features = false } + +[build-dependencies] +ethcontract-generate = "..." +``` + +It is recommended that both versions be kept in sync or else unexpected +behaviour may occur. + +Then, in your `build.rs` include the following code: + +```rs +use ethcontract_generate::Builder; +use std::env; +use std::path::Path; + +fn main() { + let dest = env::var("OUT_DIR").unwrap(); + Builder::new("path/to/truffle/build/contract/Contract.json") + .generate() + .unwrap() + .write_to_file(Path::new(&dest).join("rust_coin.rs")) + .unwrap(); +} +``` + +## Relation to `ethcontract-derive` + +`ethcontract-derive` uses `ethcontract-generate` under the hood so their +generated bindings should be identical, they just provide different APIs to the +same functionality. + +The long term goal of this project is to maintain `ethcontract-derive`. For now +there is no extra work in having it split into two separate crates. That being +said if RLS support improves for procedural macro generated code, it is possible +that this crate be deprecated in favour of `ethcontract-derive` as long as there +is no good argument to keep it around. diff --git a/crates/ethers-derive/src/lib.rs b/crates/ethers-derive/src/lib.rs new file mode 100644 index 00000000..b0e00814 --- /dev/null +++ b/crates/ethers-derive/src/lib.rs @@ -0,0 +1,503 @@ +//! Implementation of procedural macro for generating type-safe bindings to an +//! ethereum smart contract. +#![deny(missing_docs, unsafe_code)] + +extern crate proc_macro; + +mod spanned; +use crate::spanned::{ParseInner, Spanned, parse_address, Address, Builder}; + +use ethers::abi::{Function, Param, ParamType, FunctionExt, ParamTypeExt}; + +use proc_macro::TokenStream; +use proc_macro2::{Span, TokenStream as TokenStream2}; +use quote::{quote, ToTokens as _}; +use std::collections::HashSet; +use std::error::Error; +use syn::ext::IdentExt; +use syn::parse::{Error as ParseError, Parse, ParseStream, Result as ParseResult}; +use syn::{ + braced, parenthesized, parse_macro_input, Error as SynError, Ident, LitInt, LitStr, Path, + Token, Visibility, +}; + +// TODO: Make it accept an inline ABI array +/// Proc macro to generate type-safe bindings to a contract. This macro accepts +/// an Ethereum contract ABIABI or a path. Note that this path is rooted in +/// the crate's root `CARGO_MANIFEST_DIR`. +/// +/// ```ignore +/// ethcontract::contract!("build/contracts/MyContract.json"); +/// ``` +/// +/// Alternatively, other sources may be used, for full details consult the +/// `ethcontract-generate::source` documentation. Some basic examples: +/// +/// ```ignore +/// // HTTP(S) source +/// ethcontract::contract!("https://my.domain.local/path/to/contract.json") +/// // Etherscan.io +/// ethcontract::contract!("etherscan:0x0001020304050607080910111213141516171819"); +/// ethcontract::contract!("https://etherscan.io/address/0x0001020304050607080910111213141516171819"); +/// // npmjs +/// ethcontract::contract!("npm:@org/package@1.0.0/path/to/contract.json") +/// ``` +/// +/// Note that Etherscan rate-limits requests to their API, to avoid this an +/// `ETHERSCAN_API_KEY` environment variable can be set. If it is, it will use +/// that API key when retrieving the contract ABI. +/// +/// Currently the proc macro accepts additional parameters to configure some +/// aspects of the code generation. Specifically it accepts: +/// - `crate`: The name of the `ethcontract` crate. This is useful if the crate +/// was renamed in the `Cargo.toml` for whatever reason. +/// - `contract`: Override the contract name that is used for the generated +/// type. This is required when using sources that do not provide the contract +/// name in the artifact JSON such as Etherscan. +/// - `mod`: The name of the contract module to place generated code in. Note +/// that the root contract type gets re-exported in the context where the +/// macro was invoked. This defaults to the contract name converted into snake +/// case. +/// - `methods`: A list of mappings from method signatures to method names +/// allowing methods names to be explicitely set for contract methods. This +/// also provides a workaround for generating code for contracts with multiple +/// methods with the same name. +/// - `event_derives`: A list of additional derives that should be added to +/// contract event structs and enums. +/// +/// Additionally, the ABI source can be preceeded by a visibility modifier such +/// as `pub` or `pub(crate)`. This visibility modifier is applied to both the +/// generated module and contract re-export. If no visibility modifier is +/// provided, then none is used for the generated code as well, making the +/// module and contract private to the scope where the macro was invoked. +/// +/// ```ignore +/// ethcontract::contract!( +/// pub(crate) "build/contracts/MyContract.json", +/// crate = ethcontract_rename, +/// mod = my_contract_instance, +/// contract = MyContractInstance, +/// deployments { +/// 4 => "0x000102030405060708090a0b0c0d0e0f10111213", +/// 5777 => "0x0123456789012345678901234567890123456789", +/// }, +/// methods { +/// myMethod(uint256,bool) as my_renamed_method; +/// }, +/// event_derives (serde::Deserialize, serde::Serialize), +/// ); +/// ``` +/// +/// See [`ethcontract`](ethcontract) module level documentation for additional +/// information. +#[proc_macro] +pub fn contract(input: TokenStream) -> TokenStream { + let args = parse_macro_input!(input as Spanned); + + let span = args.span(); + expand(args.into_inner()) + .unwrap_or_else(|e| SynError::new(span, format!("{:?}", e)).to_compile_error()) + .into() +} + +fn expand(args: ContractArgs) -> Result> { + Ok(args.into_builder()?.generate()?.into_tokens()) +} + +/// Contract procedural macro arguments. +#[cfg_attr(test, derive(Debug, Eq, PartialEq))] +struct ContractArgs { + visibility: Option, + artifact_path: String, + parameters: Vec, +} + +impl ContractArgs { + fn into_builder(self) -> Result> { + let mut builder = Builder::from_source_url(&self.artifact_path)? + .with_visibility_modifier(self.visibility); + + for parameter in self.parameters.into_iter() { + builder = match parameter { + Parameter::Mod(name) => builder.with_contract_mod_override(Some(name)), + Parameter::Contract(name) => builder.with_contract_name_override(Some(name)), + Parameter::Crate(name) => builder.with_runtime_crate_name(name), + Parameter::Deployments(deployments) => { + deployments.into_iter().fold(builder, |builder, d| { + builder.add_deployment(d.network_id, d.address) + }) + } + Parameter::Methods(methods) => methods.into_iter().fold(builder, |builder, m| { + builder.add_method_alias(m.signature, m.alias) + }), + Parameter::EventDerives(derives) => derives + .into_iter() + .fold(builder, |builder, derive| builder.add_event_derive(derive)), + }; + } + + Ok(builder) + } +} + +impl ParseInner for ContractArgs { + fn spanned_parse(input: ParseStream) -> ParseResult<(Span, Self)> { + let visibility = match input.parse::()? { + Visibility::Inherited => None, + token => Some(quote!(#token).to_string()), + }; + + // TODO(nlordell): Due to limitation with the proc-macro Span API, we + // can't currently get a path the the file where we were called from; + // therefore, the path will always be rooted on the cargo manifest + // directory. Eventually we can use the `Span::source_file` API to + // have a better experience. + let (span, artifact_path) = { + let literal = input.parse::()?; + (literal.span(), literal.value()) + }; + + if !input.is_empty() { + input.parse::()?; + } + let parameters = input + .parse_terminated::<_, Token![,]>(Parameter::parse)? + .into_iter() + .collect(); + + Ok(( + span, + ContractArgs { + visibility, + artifact_path, + parameters, + }, + )) + } +} + +/// A single procedural macro parameter. +#[cfg_attr(test, derive(Debug, Eq, PartialEq))] +enum Parameter { + Mod(String), + Contract(String), + Crate(String), + Deployments(Vec), + Methods(Vec), + EventDerives(Vec), +} + +impl Parse for Parameter { + fn parse(input: ParseStream) -> ParseResult { + let name = input.call(Ident::parse_any)?; + let param = match name.to_string().as_str() { + "crate" => { + input.parse::()?; + let name = input.call(Ident::parse_any)?.to_string(); + Parameter::Crate(name) + } + "mod" => { + input.parse::()?; + let name = input.parse::()?.to_string(); + Parameter::Mod(name) + } + "contract" => { + input.parse::()?; + let name = input.parse::()?.to_string(); + Parameter::Contract(name) + } + "deployments" => { + let content; + braced!(content in input); + let deployments = { + let parsed = + content.parse_terminated::<_, Token![,]>(Spanned::::parse)?; + + let mut deployments = Vec::with_capacity(parsed.len()); + let mut networks = HashSet::new(); + for deployment in parsed { + if !networks.insert(deployment.network_id) { + return Err(ParseError::new( + deployment.span(), + "duplicate network ID in `ethcontract::contract!` macro invocation", + )); + } + deployments.push(deployment.into_inner()) + } + + deployments + }; + + Parameter::Deployments(deployments) + } + "methods" => { + let content; + braced!(content in input); + let methods = { + let parsed = + content.parse_terminated::<_, Token![;]>(Spanned::::parse)?; + + let mut methods = Vec::with_capacity(parsed.len()); + let mut signatures = HashSet::new(); + let mut aliases = HashSet::new(); + for method in parsed { + if !signatures.insert(method.signature.clone()) { + return Err(ParseError::new( + method.span(), + "duplicate method signature in `ethcontract::contract!` macro invocation", + )); + } + if !aliases.insert(method.alias.clone()) { + return Err(ParseError::new( + method.span(), + "duplicate method alias in `ethcontract::contract!` macro invocation", + )); + } + methods.push(method.into_inner()) + } + + methods + }; + + Parameter::Methods(methods) + } + "event_derives" => { + let content; + parenthesized!(content in input); + let derives = content + .parse_terminated::<_, Token![,]>(Path::parse)? + .into_iter() + .map(|path| path.to_token_stream().to_string()) + .collect(); + Parameter::EventDerives(derives) + } + _ => { + return Err(ParseError::new( + name.span(), + format!("unexpected named parameter `{}`", name), + )) + } + }; + + Ok(param) + } +} + +/// A manually specified dependency. +#[cfg_attr(test, derive(Debug, Eq, PartialEq))] +struct Deployment { + network_id: u32, + address: Address, +} + +impl Parse for Deployment { + fn parse(input: ParseStream) -> ParseResult { + let network_id = input.parse::()?.base10_parse()?; + input.parse::]>()?; + let address = { + let literal = input.parse::()?; + parse_address(&literal.value()).map_err(|err| ParseError::new(literal.span(), err))? + }; + + Ok(Deployment { + network_id, + address, + }) + } +} + +/// An explicitely named contract method. +#[cfg_attr(test, derive(Debug, Eq, PartialEq))] +struct Method { + signature: String, + alias: String, +} + +impl Parse for Method { + fn parse(input: ParseStream) -> ParseResult { + let function = { + let name = input.parse::()?.to_string(); + + let content; + parenthesized!(content in input); + let inputs = content + .parse_terminated::<_, Token![,]>(Ident::parse)? + .iter() + .map(|ident| { + let kind = ParamType::from_str(&ident.to_string()) + .map_err(|err| ParseError::new(ident.span(), err))?; + Ok(Param { + name: "".into(), + kind, + }) + }) + .collect::>>()?; + + Function { + name, + inputs, + + // NOTE: The output types and const-ness of the function do not + // affect its signature. + outputs: vec![], + constant: false, + } + }; + let signature = function.abi_signature(); + input.parse::()?; + let alias = { + let ident = input.parse::()?; + ident.to_string() + }; + + Ok(Method { signature, alias }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + macro_rules! contract_args_result { + ($($arg:tt)*) => {{ + use syn::parse::Parser; + as Parse>::parse + .parse2(quote::quote! { $($arg)* }) + }}; + } + macro_rules! contract_args { + ($($arg:tt)*) => { + contract_args_result!($($arg)*) + .expect("failed to parse contract args") + .into_inner() + }; + } + macro_rules! contract_args_err { + ($($arg:tt)*) => { + contract_args_result!($($arg)*) + .expect_err("expected parse contract args to error") + }; + } + + fn deployment(network_id: u32, address: &str) -> Deployment { + Deployment { + network_id, + address: parse_address(address).expect("failed to parse deployment address"), + } + } + + fn method(signature: &str, alias: &str) -> Method { + Method { + signature: signature.into(), + alias: alias.into(), + } + } + + #[test] + fn parse_contract_args() { + let args = contract_args!("path/to/artifact.json"); + assert_eq!(args.artifact_path, "path/to/artifact.json"); + } + + #[test] + fn crate_parameter_accepts_keywords() { + let args = contract_args!("artifact.json", crate = crate); + assert_eq!(args.parameters, &[Parameter::Crate("crate".into())]); + } + + #[test] + fn parse_contract_args_with_defaults() { + let args = contract_args!("artifact.json"); + assert_eq!( + args, + ContractArgs { + visibility: None, + artifact_path: "artifact.json".into(), + parameters: vec![], + }, + ); + } + + #[test] + fn parse_contract_args_with_parameters() { + let args = contract_args!( + pub(crate) "artifact.json", + crate = foobar, + mod = contract, + contract = Contract, + deployments { + 1 => "0x000102030405060708090a0b0c0d0e0f10111213", + 4 => "0x0123456789012345678901234567890123456789", + }, + methods { + myMethod(uint256, bool) as my_renamed_method; + myOtherMethod() as my_other_renamed_method; + }, + event_derives (Asdf, a::B, a::b::c::D) + ); + assert_eq!( + args, + ContractArgs { + visibility: Some(quote!(pub(crate)).to_string()), + artifact_path: "artifact.json".into(), + parameters: vec![ + Parameter::Crate("foobar".into()), + Parameter::Mod("contract".into()), + Parameter::Contract("Contract".into()), + Parameter::Deployments(vec![ + deployment(1, "0x000102030405060708090a0b0c0d0e0f10111213"), + deployment(4, "0x0123456789012345678901234567890123456789"), + ]), + Parameter::Methods(vec![ + method("myMethod(uint256,bool)", "my_renamed_method"), + method("myOtherMethod()", "my_other_renamed_method"), + ]), + Parameter::EventDerives(vec![ + "Asdf".into(), + "a :: B".into(), + "a :: b :: c :: D".into() + ]) + ], + }, + ); + } + + #[test] + fn duplicate_network_id_error() { + contract_args_err!( + "artifact.json", + deployments { + 1 => "0x000102030405060708090a0b0c0d0e0f10111213", + 1 => "0x0123456789012345678901234567890123456789", + } + ); + } + + #[test] + fn duplicate_method_rename_error() { + contract_args_err!( + "artifact.json", + methods { + myMethod(uint256) as my_method_1; + myMethod(uint256) as my_method_2; + } + ); + contract_args_err!( + "artifact.json", + methods { + myMethod1(uint256) as my_method; + myMethod2(uint256) as my_method; + } + ); + } + + #[test] + fn method_invalid_method_parameter_type() { + contract_args_err!( + "artifact.json", + methods { + myMethod(invalid) as my_method; + } + ); + } +} diff --git a/crates/ethers-derive/src/spanned.rs b/crates/ethers-derive/src/spanned.rs new file mode 100644 index 00000000..9ace8c5a --- /dev/null +++ b/crates/ethers-derive/src/spanned.rs @@ -0,0 +1,50 @@ +//! Provides implementation for helpers used in parsing `TokenStream`s where the +//! data ultimately does not care about its `Span` information, but it is useful +//! during intermediate processing. + +use proc_macro2::Span; +use std::ops::Deref; +use syn::parse::{Parse, ParseStream, Result as ParseResult}; + +/// Trait that abstracts functionality for inner data that can be parsed and +/// wrapped with a specific `Span`. +pub trait ParseInner: Sized { + fn spanned_parse(input: ParseStream) -> ParseResult<(Span, Self)>; +} + +impl ParseInner for T { + fn spanned_parse(input: ParseStream) -> ParseResult<(Span, Self)> { + Ok((input.span(), T::parse(input)?)) + } +} + +impl Parse for Spanned { + fn parse(input: ParseStream) -> ParseResult { + let (span, value) = T::spanned_parse(input)?; + Ok(Spanned(span, value)) + } +} + +/// A struct that captures `Span` information for inner parsable data. +#[cfg_attr(test, derive(Clone, Debug))] +pub struct Spanned(Span, T); + +impl Spanned { + /// Retrieves the captured `Span` information for the parsed data. + pub fn span(&self) -> Span { + self.0 + } + + /// Retrieves the inner data. + pub fn into_inner(self) -> T { + self.1 + } +} + +impl Deref for Spanned { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.1 + } +} diff --git a/crates/ethers-derive/src/src/contract.rs b/crates/ethers-derive/src/src/contract.rs new file mode 100644 index 00000000..2c955bd5 --- /dev/null +++ b/crates/ethers-derive/src/src/contract.rs @@ -0,0 +1,178 @@ +#![deny(missing_docs)] + +//! Crate for generating type-safe bindings to Ethereum smart contracts. This +//! crate is intended to be used either indirectly with the `ethcontract` +//! crate's `contract` procedural macro or directly from a build script. + +mod common; +mod deployment; +mod events; +mod methods; +mod types; + +use crate::util; +use crate::Args; +use anyhow::{anyhow, Context as _, Result}; +use ethcontract_common::{Address, Artifact}; +use inflector::Inflector; +use proc_macro2::{Ident, Literal, TokenStream}; +use quote::quote; +use std::collections::HashMap; +use syn::{Path, Visibility}; + +/// Internal shared context for generating smart contract bindings. +pub(crate) struct Context { + /// The artifact JSON as string literal. + artifact_json: Literal, + /// The parsed artifact. + artifact: Artifact, + /// The identifier for the runtime crate. Usually this is `ethcontract` but + /// it can be different if the crate was renamed in the Cargo manifest for + /// example. + runtime_crate: Ident, + /// The visibility for the generated module and re-exported contract type. + visibility: Visibility, + /// The name of the module as an identifier in which to place the contract + /// implementation. Note that the main contract type gets re-exported in the + /// root. + contract_mod: Ident, + /// The contract name as an identifier. + contract_name: Ident, + /// Additional contract deployments. + deployments: HashMap, + /// Manually specified method aliases. + method_aliases: HashMap, + /// Derives added to event structs and enums. + event_derives: Vec, +} + +impl Context { + /// Create a context from the code generation arguments. + fn from_args(args: Args) -> Result { + let (artifact_json, artifact) = { + let artifact_json = args + .artifact_source + .artifact_json() + .context("failed to get artifact JSON")?; + + let artifact = Artifact::from_json(&artifact_json) + .with_context(|| format!("invalid artifact JSON '{}'", artifact_json)) + .with_context(|| { + format!( + "failed to parse artifact from source {:?}", + args.artifact_source, + ) + })?; + + (Literal::string(&artifact_json), artifact) + }; + + let raw_contract_name = if let Some(name) = args.contract_name_override.as_ref() { + name + } else if !artifact.contract_name.is_empty() { + &artifact.contract_name + } else { + return Err(anyhow!( + "contract artifact is missing a name, this can happen when \ + using a source that does not provide a contract name such as \ + Etherscan; in this case the contract must be manually \ + specified" + )); + }; + + let runtime_crate = util::ident(&args.runtime_crate_name); + let visibility = match args.visibility_modifier.as_ref() { + Some(vis) => syn::parse_str(vis)?, + None => Visibility::Inherited, + }; + let contract_mod = if let Some(name) = args.contract_mod_override.as_ref() { + util::ident(name) + } else { + util::ident(&raw_contract_name.to_snake_case()) + }; + let contract_name = util::ident(raw_contract_name); + + // NOTE: We only check for duplicate signatures here, since if there are + // duplicate aliases, the compiler will produce a warning because a + // method will be re-defined. + let mut method_aliases = HashMap::new(); + for (signature, alias) in args.method_aliases.into_iter() { + let alias = syn::parse_str(&alias)?; + if method_aliases.insert(signature.clone(), alias).is_some() { + return Err(anyhow!( + "duplicate method signature '{}' in method aliases", + signature, + )); + } + } + + let event_derives = args + .event_derives + .iter() + .map(|derive| syn::parse_str::(derive)) + .collect::, _>>() + .context("failed to parse event derives")?; + + Ok(Context { + artifact_json, + artifact, + runtime_crate, + visibility, + contract_mod, + contract_name, + deployments: args.deployments, + method_aliases, + event_derives, + }) + } +} + +#[cfg(test)] +impl Default for Context { + fn default() -> Self { + Context { + artifact_json: Literal::string("{}"), + artifact: Artifact::empty(), + runtime_crate: util::ident("ethcontract"), + visibility: Visibility::Inherited, + contract_mod: util::ident("contract"), + contract_name: util::ident("Contract"), + deployments: HashMap::new(), + method_aliases: HashMap::new(), + event_derives: Vec::new(), + } + } +} + +pub(crate) fn expand(args: Args) -> Result { + let cx = Context::from_args(args)?; + let contract = expand_contract(&cx).context("error expanding contract from its ABI")?; + + Ok(contract) +} + +fn expand_contract(cx: &Context) -> Result { + let runtime_crate = &cx.runtime_crate; + let vis = &cx.visibility; + let contract_mod = &cx.contract_mod; + let contract_name = &cx.contract_name; + + let common = common::expand(cx); + let deployment = deployment::expand(cx)?; + let methods = methods::expand(cx)?; + let events = events::expand(cx)?; + + Ok(quote! { + #[allow(dead_code)] + #vis mod #contract_mod { + #[rustfmt::skip] + use #runtime_crate as ethcontract; + + #common + #deployment + #methods + #events + } + #vis use self::#contract_mod::Contract as #contract_name; + }) +} diff --git a/crates/ethers-derive/src/src/contract/common.rs b/crates/ethers-derive/src/src/contract/common.rs new file mode 100644 index 00000000..d2c86b61 --- /dev/null +++ b/crates/ethers-derive/src/src/contract/common.rs @@ -0,0 +1,200 @@ +use crate::contract::Context; +use crate::util::expand_doc; +use ethcontract_common::Address; +use proc_macro2::{Literal, TokenStream}; +use quote::quote; + +pub(crate) fn expand(cx: &Context) -> TokenStream { + let artifact_json = &cx.artifact_json; + let contract_name = &cx.contract_name; + + let doc_str = cx + .artifact + .devdoc + .details + .as_deref() + .unwrap_or("Generated by `ethcontract`"); + let doc = expand_doc(doc_str); + + let deployments = cx.deployments.iter().map(|(network_id, address)| { + let network_id = Literal::string(&network_id.to_string()); + let address = expand_address(*address); + + quote! { + artifact.networks.insert( + #network_id.to_owned(), + self::ethcontract::common::truffle::Network { + address: #address, + transaction_hash: None, + }, + ); + } + }); + + quote! { + #doc + #[derive(Clone)] + pub struct Contract { + methods: Methods, + } + + impl Contract { + /// Retrieves the truffle artifact used to generate the type safe + /// API for this contract. + pub fn artifact() -> &'static self::ethcontract::Artifact { + use self::ethcontract::private::lazy_static; + use self::ethcontract::Artifact; + + lazy_static! { + pub static ref ARTIFACT: Artifact = { + #[allow(unused_mut)] + let mut artifact = Artifact::from_json(#artifact_json) + .expect("valid artifact JSON"); + #( #deployments )* + + artifact + }; + } + &ARTIFACT + } + + /// Creates a new contract instance with the specified `web3` + /// provider at the given `Address`. + /// + /// Note that this does not verify that a contract with a maching + /// `Abi` is actually deployed at the given address. + pub fn at( + web3: &self::ethcontract::web3::api::Web3, + address: self::ethcontract::Address, + ) -> Self + where + F: self::ethcontract::web3::futures::Future< + Item = self::ethcontract::json::Value, + Error = self::ethcontract::web3::Error, + > + Send + 'static, + T: self::ethcontract::web3::Transport + Send + Sync + 'static, + { + Contract::with_transaction(web3, address, None) + } + + + /// Creates a new contract instance with the specified `web3` provider with + /// the given `Abi` at the given `Address` and an optional transaction hash. + /// This hash is used to retrieve contract related information such as the + /// creation block (which is useful for fetching all historic events). + /// + /// Note that this does not verify that a contract with a matching `Abi` is + /// actually deployed at the given address nor that the transaction hash, + /// when provided, is actually for this contract deployment. + pub fn with_transaction( + web3: &self::ethcontract::web3::api::Web3, + address: self::ethcontract::Address, + transaction_hash: Option, + ) -> Self + where + F: self::ethcontract::web3::futures::Future< + Item = self::ethcontract::json::Value, + Error = self::ethcontract::web3::Error, + > + Send + 'static, + T: self::ethcontract::web3::Transport + Send + Sync + 'static, + { + use self::ethcontract::Instance; + use self::ethcontract::transport::DynTransport; + use self::ethcontract::web3::api::Web3; + + let transport = DynTransport::new(web3.transport().clone()); + let web3 = Web3::new(transport); + let abi = Self::artifact().abi.clone(); + let instance = Instance::with_transaction(web3, abi, address, transaction_hash); + + Contract::from_raw(instance) + } + + /// Creates a contract from a raw instance. + fn from_raw(instance: self::ethcontract::dyns::DynInstance) -> Self { + let methods = Methods { instance }; + Contract { methods } + } + + /// Returns the contract address being used by this instance. + pub fn address(&self) -> self::ethcontract::Address { + self.raw_instance().address() + } + + /// Returns the hash for the transaction that deployed the contract + /// if it is known, `None` otherwise. + pub fn transaction_hash(&self) -> Option { + self.raw_instance().transaction_hash() + } + + /// Returns a reference to the default method options used by this + /// contract. + pub fn defaults(&self) -> &self::ethcontract::contract::MethodDefaults { + &self.raw_instance().defaults + } + + /// Returns a mutable reference to the default method options used + /// by this contract. + pub fn defaults_mut(&mut self) -> &mut self::ethcontract::contract::MethodDefaults { + &mut self.raw_instance_mut().defaults + } + + /// Returns a reference to the raw runtime instance used by this + /// contract. + pub fn raw_instance(&self) -> &self::ethcontract::dyns::DynInstance { + &self.methods.instance + } + + /// Returns a mutable reference to the raw runtime instance used by + /// this contract. + fn raw_instance_mut(&mut self) -> &mut self::ethcontract::dyns::DynInstance { + &mut self.methods.instance + } + } + + impl std::fmt::Debug for Contract { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_tuple(stringify!(#contract_name)) + .field(&self.address()) + .finish() + } + } + } +} + +/// Expands an `Address` into a literal representation that can be used with +/// quasi-quoting for code generation. +fn expand_address(address: Address) -> TokenStream { + let bytes = address + .as_bytes() + .iter() + .copied() + .map(Literal::u8_unsuffixed); + + quote! { + self::ethcontract::H160([#( #bytes ),*]) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + #[rustfmt::skip] + fn expand_address_value() { + assert_quote!( + expand_address(Address::zero()), + { + self::ethcontract::H160([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]) + }, + ); + + assert_quote!( + expand_address("000102030405060708090a0b0c0d0e0f10111213".parse().unwrap()), + { + self::ethcontract::H160([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) + }, + ); + } +} diff --git a/crates/ethers-derive/src/src/contract/deployment.rs b/crates/ethers-derive/src/src/contract/deployment.rs new file mode 100644 index 00000000..d05faeb2 --- /dev/null +++ b/crates/ethers-derive/src/src/contract/deployment.rs @@ -0,0 +1,167 @@ +use crate::contract::{methods, Context}; +use crate::util; +use anyhow::{Context as _, Result}; +use inflector::Inflector; +use proc_macro2::{Literal, TokenStream}; +use quote::quote; + +pub(crate) fn expand(cx: &Context) -> Result { + let deployed = expand_deployed(&cx); + let deploy = + expand_deploy(&cx).context("error generating contract `deploy` associated function")?; + + Ok(quote! { + #deployed + #deploy + }) +} + +fn expand_deployed(cx: &Context) -> TokenStream { + if cx.artifact.networks.is_empty() && cx.deployments.is_empty() { + return quote! {}; + } + + quote! { + impl Contract { + /// Locates a deployed contract based on the current network ID + /// reported by the `web3` provider. + /// + /// Note that this does not verify that a contract with a maching + /// `Abi` is actually deployed at the given address. + pub async fn deployed( + web3: &self::ethcontract::web3::api::Web3, + ) -> Result + where + F: self::ethcontract::web3::futures::Future< + Item = self::ethcontract::json::Value, + Error = self::ethcontract::web3::Error + > + Send + 'static, + T: self::ethcontract::web3::Transport + Send + Sync + 'static, + { + use self::ethcontract::{Instance, Web3}; + use self::ethcontract::transport::DynTransport; + + let transport = DynTransport::new(web3.transport().clone()); + let web3 = Web3::new(transport); + let instance = Instance::deployed(web3, Contract::artifact().clone()).await?; + + Ok(Contract::from_raw(instance)) + } + } + } +} + +fn expand_deploy(cx: &Context) -> Result { + if cx.artifact.bytecode.is_empty() { + // do not generate deploy method for contracts that have empty bytecode + return Ok(quote! {}); + } + + // TODO(nlordell): not sure how contructor documentation get generated as I + // can't seem to get truffle to output it + let doc = util::expand_doc("Generated by `ethcontract`"); + + let (input, arg) = match cx.artifact.abi.constructor() { + Some(contructor) => ( + methods::expand_inputs(&contructor.inputs)?, + methods::expand_inputs_call_arg(&contructor.inputs), + ), + None => (quote! {}, quote! {()}), + }; + + let libs: Vec<_> = cx + .artifact + .bytecode + .undefined_libraries() + .map(|name| (name, util::safe_ident(&name.to_snake_case()))) + .collect(); + let (lib_struct, lib_input, link) = if !libs.is_empty() { + let lib_struct = { + let lib_struct_fields = libs.iter().map(|(name, field)| { + let doc = util::expand_doc(&format!("Address of the `{}` library.", name)); + + quote! { + #doc pub #field: self::ethcontract::Address + } + }); + + quote! { + /// Undefinied libraries in the contract bytecode that are + /// required for linking in order to deploy. + pub struct Libraries { + #( #lib_struct_fields, )* + } + } + }; + + let link = { + let link_libraries = libs.iter().map(|(name, field)| { + let name_lit = Literal::string(&name); + + quote! { + bytecode.link(#name_lit, libs.#field).expect("valid library"); + } + }); + + quote! { + let mut bytecode = bytecode; + #( #link_libraries )* + } + }; + + (lib_struct, quote! { , libs: Libraries }, link) + } else { + Default::default() + }; + + Ok(quote! { + #lib_struct + + impl Contract { + #doc + pub fn builder( + web3: &self::ethcontract::web3::api::Web3 #lib_input #input , + ) -> self::ethcontract::dyns::DynDeployBuilder + where + F: self::ethcontract::web3::futures::Future< + Item = self::ethcontract::json::Value, + Error = self::ethcontract::web3::Error, + > + Send + 'static, + T: self::ethcontract::web3::Transport + Send + Sync + 'static, + { + use self::ethcontract::dyns::DynTransport; + use self::ethcontract::contract::DeployBuilder; + use self::ethcontract::web3::api::Web3; + + let transport = DynTransport::new(web3.transport().clone()); + let web3 = Web3::new(transport); + + let bytecode = Self::artifact().bytecode.clone(); + #link + + DeployBuilder::new(web3, bytecode, #arg).expect("valid deployment args") + } + } + + impl self::ethcontract::contract::Deploy for Contract { + type Context = self::ethcontract::common::Bytecode; + + fn bytecode(cx: &Self::Context) -> &self::ethcontract::common::Bytecode { + cx + } + + fn abi(_: &Self::Context) -> &self::ethcontract::common::Abi { + &Self::artifact().abi + } + + fn from_deployment( + web3: self::ethcontract::dyns::DynWeb3, + address: self::ethcontract::Address, + transaction_hash: self::ethcontract::H256, + _: Self::Context, + ) -> Self { + Self::with_transaction(&web3, address, Some(transaction_hash)) + } + } + }) +} diff --git a/crates/ethers-derive/src/src/contract/events.rs b/crates/ethers-derive/src/src/contract/events.rs new file mode 100644 index 00000000..07a26229 --- /dev/null +++ b/crates/ethers-derive/src/src/contract/events.rs @@ -0,0 +1,855 @@ +use crate::contract::{types, Context}; +use crate::util; +use anyhow::Result; +use ethcontract_common::abi::{Event, EventParam, Hash, ParamType}; +use ethcontract_common::abiext::EventExt; +use inflector::Inflector; +use proc_macro2::{Literal, TokenStream}; +use quote::quote; +use syn::Path; + +pub(crate) fn expand(cx: &Context) -> Result { + let structs_mod = expand_structs_mod(cx)?; + let filters = expand_filters(cx)?; + let all_events = expand_all_events(cx); + + Ok(quote! { + #structs_mod + #filters + #all_events + }) +} + +/// Expands into a module containing all the event data structures from the ABI. +fn expand_structs_mod(cx: &Context) -> Result { + let data_types = cx + .artifact + .abi + .events() + .map(|event| expand_data_type(event, &cx.event_derives)) + .collect::>>()?; + if data_types.is_empty() { + return Ok(quote! {}); + } + + Ok(quote! { + /// Module containing all generated data models for this contract's + /// events. + pub mod event_data { + use super::ethcontract; + + #( #data_types )* + } + }) +} + +fn expand_derives(derives: &[Path]) -> TokenStream { + quote! {#(#derives),*} +} + +/// Expands an ABI event into a single event data type. This can expand either +/// into a structure or a tuple in the case where all event parameters (topics +/// and data) are anonymous. +fn expand_data_type(event: &Event, event_derives: &[Path]) -> Result { + let event_name = expand_struct_name(event); + + let signature = expand_hash(event.signature()); + + let abi_signature = event.abi_signature(); + let abi_signature_lit = Literal::string(&abi_signature); + let abi_signature_doc = util::expand_doc(&format!("`{}`", abi_signature)); + + let params = expand_params(event)?; + + let all_anonymous_fields = event.inputs.iter().all(|input| input.name.is_empty()); + let (data_type_definition, data_type_construction) = if all_anonymous_fields { + expand_data_tuple(&event_name, ¶ms) + } else { + expand_data_struct(&event_name, ¶ms) + }; + + let params_len = Literal::usize_unsuffixed(params.len()); + let read_param_token = params + .iter() + .map(|(name, ty)| { + quote! { + let #name = <#ty as self::ethcontract::web3::contract::tokens::Tokenizable> + ::from_token(tokens.next().unwrap())?; + } + }) + .collect::>(); + + let derives = expand_derives(event_derives); + + Ok(quote! { + #[derive(Clone, Debug, Default, Eq, PartialEq, #derives)] + pub #data_type_definition + + impl #event_name { + /// Retrieves the signature for the event this data corresponds to. + /// This signature is the Keccak-256 hash of the ABI signature of + /// this event. + pub fn signature() -> self::ethcontract::H256 { + #signature + } + + /// Retrieves the ABI signature for the event this data corresponds + /// to. For this event the value should always be: + /// + #abi_signature_doc + pub fn abi_signature() -> &'static str { + #abi_signature_lit + } + } + + impl self::ethcontract::web3::contract::tokens::Detokenize for #event_name { + fn from_tokens( + tokens: Vec, + ) -> Result { + if tokens.len() != #params_len { + return Err(self::ethcontract::web3::contract::Error::InvalidOutputType(format!( + "Expected {} tokens, got {}: {:?}", + #params_len, + tokens.len(), + tokens + ))); + } + + #[allow(unused_mut)] + let mut tokens = tokens.into_iter(); + #( #read_param_token )* + + Ok(#data_type_construction) + } + } + }) +} + +/// Expands an ABI event into an identifier for its event data type. +fn expand_struct_name(event: &Event) -> TokenStream { + let event_name = util::ident(&event.name.to_pascal_case()); + quote! { #event_name } +} + +/// Expands an ABI event into name-type pairs for each of its parameters. +fn expand_params(event: &Event) -> Result> { + event + .inputs + .iter() + .enumerate() + .map(|(i, input)| { + // NOTE: Events can contain nameless values. + let name = util::expand_input_name(i, &input.name); + let ty = expand_input_type(&input)?; + + Ok((name, ty)) + }) + .collect() +} + +/// Expands an event data structure from its name-type parameter pairs. Returns +/// a tuple with the type definition (i.e. the struct declaration) and +/// construction (i.e. code for creating an instance of the event data). +fn expand_data_struct( + name: &TokenStream, + params: &[(TokenStream, TokenStream)], +) -> (TokenStream, TokenStream) { + let fields = params + .iter() + .map(|(name, ty)| quote! { pub #name: #ty }) + .collect::>(); + + let param_names = params + .iter() + .map(|(name, _)| name) + .cloned() + .collect::>(); + + let definition = quote! { struct #name { #( #fields, )* } }; + let construction = quote! { #name { #( #param_names ),* } }; + + (definition, construction) +} + +/// Expands an event data named tuple from its name-type parameter pairs. +/// Returns a tuple with the type definition and construction. +fn expand_data_tuple( + name: &TokenStream, + params: &[(TokenStream, TokenStream)], +) -> (TokenStream, TokenStream) { + let fields = params + .iter() + .map(|(_, ty)| quote! { pub #ty }) + .collect::>(); + + let param_names = params + .iter() + .map(|(name, _)| name) + .cloned() + .collect::>(); + + let definition = quote! { struct #name( #( #fields ),* ); }; + let construction = quote! { #name( #( #param_names ),* ) }; + + (definition, construction) +} + +/// Expands into an `Events` type with method definitions for creating event +/// streams for all non-anonymous contract events in the ABI. +fn expand_filters(cx: &Context) -> Result { + let standard_events = cx + .artifact + .abi + .events() + .filter(|event| !event.anonymous) + .collect::>(); + if standard_events.is_empty() { + return Ok(quote! {}); + } + + let filters = standard_events + .iter() + .map(|event| expand_filter(event)) + .collect::>>()?; + let builders = standard_events + .iter() + .map(|event| expand_builder_type(event)) + .collect::>>()?; + + Ok(quote! { + impl Contract { + /// Retrieves a handle to a type containing for creating event + /// streams for all the contract events. + pub fn events(&self) -> Events<'_> { + Events { + instance: self.raw_instance(), + } + } + } + + pub struct Events<'a> { + instance: &'a self::ethcontract::dyns::DynInstance, + } + + impl Events<'_> { + #( #filters )* + } + + /// Module containing the generated event stream builders with type safe + /// filter methods for this contract's events. + pub mod event_builders { + use super::ethcontract; + use super::event_data; + + #( #builders )* + } + }) +} + +/// Expands into a single method for contracting an event stream. +fn expand_filter(event: &Event) -> Result { + let name = util::safe_ident(&event.name.to_snake_case()); + let builder_name = expand_builder_name(event); + let signature = expand_hash(event.signature()); + + Ok(quote! { + /// Generated by `ethcontract`. + pub fn #name(&self) -> self::event_builders::#builder_name { + self::event_builders::#builder_name( + self.instance.event(#signature) + .expect("generated event filter"), + ) + } + }) +} + +/// Expands an ABI event into a wrapped `EventBuilder` type with type-safe +/// filter methods. +fn expand_builder_type(event: &Event) -> Result { + let event_name = expand_struct_name(event); + let builder_doc = util::expand_doc(&format!( + "A builder for creating a filtered stream of `{}` events.", + event_name + )); + let builder_name = expand_builder_name(event); + let topic_filters = expand_builder_topic_filters(event)?; + + Ok(quote! { + #builder_doc + pub struct #builder_name( + /// The inner event builder. + pub self::ethcontract::dyns::DynEventBuilder, + ); + + impl #builder_name { + /// Sets the starting block from which to stream logs for. + /// + /// If left unset defaults to the latest block. + #[allow(clippy::wrong_self_convention)] + pub fn from_block(mut self, block: self::ethcontract::BlockNumber) -> Self { + self.0 = (self.0).from_block(block); + self + } + + /// Sets the last block from which to stream logs for. + /// + /// If left unset defaults to the streaming until the end of days. + #[allow(clippy::wrong_self_convention)] + pub fn to_block(mut self, block: self::ethcontract::BlockNumber) -> Self { + self.0 = (self.0).to_block(block); + self + } + + /// Limit the number of events that can be retrieved by this filter. + /// + /// Note that this parameter is non-standard. + pub fn limit(mut self, value: usize) -> Self { + self.0 = (self.0).limit(value); + self + } + + /// The polling interval. This is used as the interval between + /// consecutive `eth_getFilterChanges` calls to get filter updates. + pub fn poll_interval(mut self, value: std::time::Duration) -> Self { + self.0 = (self.0).poll_interval(value); + self + } + + #topic_filters + + /// Returns a future that resolves with a collection of all existing + /// logs matching the builder parameters. + pub async fn query(self) -> std::result::Result< + std::vec::Vec>, + self::ethcontract::errors::EventError, + > { + (self.0).query().await + } + + /// Creates an event stream from the current event builder. + pub fn stream(self) -> impl self::ethcontract::futures::stream::Stream< + Item = std::result::Result< + self::ethcontract::StreamEvent, + self::ethcontract::errors::EventError, + >, + > { + (self.0).stream() + } + } + }) +} + +/// Expands an ABI event into filter methods for its indexed parameters. +fn expand_builder_topic_filters(event: &Event) -> Result { + let topic_filters = event + .inputs + .iter() + .filter(|input| input.indexed) + .enumerate() + .map(|(topic_index, input)| expand_builder_topic_filter(topic_index, input)) + .collect::>>()?; + + Ok(quote! { + #( #topic_filters )* + }) +} + +/// Expands a event parameter into an event builder filter method for the +/// specified topic index. +fn expand_builder_topic_filter(topic_index: usize, param: &EventParam) -> Result { + let doc = util::expand_doc(&format!( + "Adds a filter for the {} event parameter.", + param.name, + )); + let topic = util::ident(&format!("topic{}", topic_index)); + let name = if param.name.is_empty() { + topic.clone() + } else { + util::safe_ident(¶m.name.to_snake_case()) + }; + let ty = expand_input_type(¶m)?; + + Ok(quote! { + #doc + pub fn #name(mut self, topic: self::ethcontract::Topic<#ty>) -> Self { + self.0 = (self.0).#topic(topic); + self + } + }) +} + +/// Expands an ABI event into an identifier for its event data type. +fn expand_builder_name(event: &Event) -> TokenStream { + let builder_name = util::ident(&format!("{}Builder", &event.name.to_pascal_case())); + quote! { #builder_name } +} + +/// Expands into the `all_events` method on the root contract type if it +/// contains events. Expands to nothing otherwise. +fn expand_all_events(cx: &Context) -> TokenStream { + if cx.artifact.abi.events.is_empty() { + return quote! {}; + } + + let event_enum = expand_event_enum(cx); + let event_parse_log = expand_event_parse_log(cx); + + quote! { + impl Contract { + /// Returns a log stream with all events. + pub fn all_events(&self) -> self::ethcontract::dyns::DynAllEventsBuilder { + self::ethcontract::dyns::DynAllEventsBuilder::new( + self.raw_instance().web3(), + self.address(), + self.transaction_hash(), + ) + } + } + + #event_enum + #event_parse_log + } +} + +/// Expands into an enum with one variant for each distinct event type, +/// including anonymous types. +fn expand_event_enum(cx: &Context) -> TokenStream { + let variants = { + let mut events = cx.artifact.abi.events().collect::>(); + + // NOTE: We sort the events by name so that the generated enum is + // consistent. This also faciliates testing as so that the same ABI + // yields consistent code. + events.sort_unstable_by_key(|event| &event.name); + + events + .into_iter() + .map(|event| { + let struct_name = expand_struct_name(&event); + quote! { + #struct_name(self::event_data::#struct_name) + } + }) + .collect::>() + }; + + let derives = expand_derives(&cx.event_derives); + + quote! { + /// A contract event. + #[derive(Clone, Debug, Eq, PartialEq, #derives)] + pub enum Event { + #( #variants, )* + } + } +} + +/// Expands the `ParseLog` implementation for the event enum. +fn expand_event_parse_log(cx: &Context) -> TokenStream { + let all_events = { + let mut all_events = cx + .artifact + .abi + .events() + .map(|event| { + let struct_name = expand_struct_name(&event); + + let name = Literal::string(&event.name); + let decode_event = quote! { + log.clone().decode( + &Contract::artifact() + .abi + .event(#name) + .expect("generated event decode") + ) + }; + + (event, struct_name, decode_event) + }) + .collect::>(); + + // NOTE: We sort the events by name so that the anonymous error decoding + // is consistent. Since the events are stored in a `HashMap`, there is + // no guaranteed order, and in the case where there is ambiguity in + // decoding anonymous events, its nice if they follow some strict and + // predictable order. + all_events.sort_unstable_by_key(|(event, _, _)| &event.name); + all_events + }; + + let standard_event_match_arms = all_events + .iter() + .filter(|(event, _, _)| !event.anonymous) + .map(|(event, struct_name, decode_event)| { + // These are all possible stardard (i.e. non-anonymous) events that + // the contract can produce, along with its signature and index in + // the contract ABI. For these, we match topic 0 to the signature + // and try to decode. + + let signature = expand_hash(event.signature()); + quote! { + #signature => Ok(Event::#struct_name(#decode_event?)), + } + }) + .collect::>(); + + let anonymous_event_try_decode = all_events + .iter() + .filter(|(event, _, _)| event.anonymous) + .map(|(_, struct_name, decode_event)| { + // For anonymous events, just try to decode one at a time and return + // the first that succeeds. + + quote! { + if let Ok(data) = #decode_event { + return Ok(Event::#struct_name(data)); + } + } + }) + .collect::>(); + + let invalid_data = expand_invalid_data(); + + quote! { + impl self::ethcontract::contract::ParseLog for Event { + fn parse_log( + log: self::ethcontract::RawLog, + ) -> Result { + let standard_event = log.topics + .get(0) + .copied() + .map(|topic| match topic { + #( #standard_event_match_arms )* + _ => #invalid_data, + }); + + if let Some(Ok(data)) = standard_event { + return Ok(data); + } + + #( #anonymous_event_try_decode )* + + #invalid_data + } + } + } +} + +/// Expands an event property type. +/// +/// Note that this is slightly different than an expanding a Solidity type as +/// complex types like arrays and strings get emited as hashes when they are +/// indexed. +fn expand_input_type(input: &EventParam) -> Result { + Ok(match (&input.kind, input.indexed) { + (ParamType::Array(..), true) + | (ParamType::Bytes, true) + | (ParamType::FixedArray(..), true) + | (ParamType::String, true) + | (ParamType::Tuple(..), true) => { + quote! { self::ethcontract::H256 } + } + (kind, _) => types::expand(kind)?, + }) +} + +/// Expands a 256-bit `Hash` into a literal representation that can be used with +/// quasi-quoting for code generation. +fn expand_hash(hash: Hash) -> TokenStream { + let bytes = hash.as_bytes().iter().copied().map(Literal::u8_unsuffixed); + + quote! { + self::ethcontract::H256([#( #bytes ),*]) + } +} + +/// Expands to a generic `InvalidData` error. +fn expand_invalid_data() -> TokenStream { + quote! { + Err(self::ethcontract::errors::ExecutionError::from( + self::ethcontract::common::abi::Error::InvalidData + )) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use ethcontract_common::abi::{EventParam, ParamType}; + + #[test] + fn expand_empty_filters() { + assert_quote!(expand_filters(&Context::default()).unwrap(), {}); + } + + #[test] + fn expand_transfer_filter() { + let event = Event { + name: "Transfer".into(), + inputs: vec![ + EventParam { + name: "from".into(), + kind: ParamType::Address, + indexed: true, + }, + EventParam { + name: "to".into(), + kind: ParamType::Address, + indexed: true, + }, + EventParam { + name: "amount".into(), + kind: ParamType::Uint(256), + indexed: false, + }, + ], + anonymous: false, + }; + let signature = expand_hash(event.signature()); + + assert_quote!(expand_filter(&event).unwrap(), { + /// Generated by `ethcontract`. + pub fn transfer(&self) -> self::event_builders::TransferBuilder { + self::event_builders::TransferBuilder( + self.instance.event(#signature) + .expect("generated event filter"), + ) + } + }); + } + + #[test] + fn expand_transfer_builder_topic_filters() { + let event = Event { + name: "Transfer".into(), + inputs: vec![ + EventParam { + name: "from".into(), + kind: ParamType::Address, + indexed: true, + }, + EventParam { + name: "to".into(), + kind: ParamType::Address, + indexed: true, + }, + EventParam { + name: "amount".into(), + kind: ParamType::Uint(256), + indexed: false, + }, + ], + anonymous: false, + }; + + #[rustfmt::skip] + assert_quote!(expand_builder_topic_filters(&event).unwrap(), { + #[doc = "Adds a filter for the from event parameter."] + pub fn from(mut self, topic: self::ethcontract::Topic) -> Self { + self.0 = (self.0).topic0(topic); + self + } + + #[doc = "Adds a filter for the to event parameter."] + pub fn to(mut self, topic: self::ethcontract::Topic) -> Self { + self.0 = (self.0).topic1(topic); + self + } + }); + } + + #[test] + fn expand_data_struct_value() { + let event = Event { + name: "Foo".into(), + inputs: vec![ + EventParam { + name: "a".into(), + kind: ParamType::Bool, + indexed: false, + }, + EventParam { + name: String::new(), + kind: ParamType::Address, + indexed: false, + }, + ], + anonymous: false, + }; + + let name = expand_struct_name(&event); + let params = expand_params(&event).unwrap(); + let (definition, construction) = expand_data_struct(&name, ¶ms); + + assert_quote!(definition, { + struct Foo { + pub a: bool, + pub p1: self::ethcontract::Address, + } + }); + assert_quote!(construction, { Foo { a, p1 } }); + } + + #[test] + fn expand_data_tuple_value() { + let event = Event { + name: "Foo".into(), + inputs: vec![ + EventParam { + name: String::new(), + kind: ParamType::Bool, + indexed: false, + }, + EventParam { + name: String::new(), + kind: ParamType::Address, + indexed: false, + }, + ], + anonymous: false, + }; + + let name = expand_struct_name(&event); + let params = expand_params(&event).unwrap(); + let (definition, construction) = expand_data_tuple(&name, ¶ms); + + assert_quote!(definition, { + struct Foo(pub bool, pub self::ethcontract::Address); + }); + assert_quote!(construction, { Foo(p0, p1) }); + } + + #[test] + fn expand_enum_for_all_events() { + let context = { + let mut context = Context::default(); + context.artifact.abi.events.insert( + "Foo".into(), + vec![Event { + name: "Foo".into(), + inputs: vec![EventParam { + name: String::new(), + kind: ParamType::Bool, + indexed: false, + }], + anonymous: false, + }], + ); + context.artifact.abi.events.insert( + "Bar".into(), + vec![Event { + name: "Bar".into(), + inputs: vec![EventParam { + name: String::new(), + kind: ParamType::Address, + indexed: false, + }], + anonymous: true, + }], + ); + context.event_derives = ["Asdf", "a::B", "a::b::c::D"] + .iter() + .map(|derive| syn::parse_str::(derive).unwrap()) + .collect(); + context + }; + + assert_quote!(expand_event_enum(&context), { + /// A contract event. + #[derive(Clone, Debug, Eq, PartialEq, Asdf, a::B, a::b::c::D)] + pub enum Event { + Bar(self::event_data::Bar), + Foo(self::event_data::Foo), + } + }); + } + + #[test] + fn expand_parse_log_impl_for_all_events() { + let context = { + let mut context = Context::default(); + context.artifact.abi.events.insert( + "Foo".into(), + vec![Event { + name: "Foo".into(), + inputs: vec![EventParam { + name: String::new(), + kind: ParamType::Bool, + indexed: false, + }], + anonymous: false, + }], + ); + context.artifact.abi.events.insert( + "Bar".into(), + vec![Event { + name: "Bar".into(), + inputs: vec![EventParam { + name: String::new(), + kind: ParamType::Address, + indexed: false, + }], + anonymous: true, + }], + ); + context + }; + + let foo_signature = expand_hash(context.artifact.abi.event("Foo").unwrap().signature()); + let invalid_data = expand_invalid_data(); + + assert_quote!(expand_event_parse_log(&context), { + impl self::ethcontract::contract::ParseLog for Event { + fn parse_log( + log: self::ethcontract::RawLog, + ) -> Result { + let standard_event = log.topics + .get(0) + .copied() + .map(|topic| match topic { + #foo_signature => Ok(Event::Foo( + log.clone().decode( + &Contract::artifact() + .abi + .event("Foo") + .expect("generated event decode") + )? + )), + _ => #invalid_data, + }); + + if let Some(Ok(data)) = standard_event { + return Ok(data); + } + + if let Ok(data) = log.clone().decode( + &Contract::artifact() + .abi + .event("Bar") + .expect("generated event decode") + ) { + return Ok(Event::Bar(data)); + } + + #invalid_data + } + } + }); + } + + #[test] + #[rustfmt::skip] + fn expand_hash_value() { + assert_quote!( + expand_hash( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f".parse().unwrap() + ), + { + self::ethcontract::H256([ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 + ]) + }, + ); + } +} diff --git a/crates/ethers-derive/src/src/contract/methods.rs b/crates/ethers-derive/src/src/contract/methods.rs new file mode 100644 index 00000000..d1a037c6 --- /dev/null +++ b/crates/ethers-derive/src/src/contract/methods.rs @@ -0,0 +1,255 @@ +use crate::contract::{types, Context}; +use crate::util; +use anyhow::{anyhow, Context as _, Result}; +use ethcontract_common::abi::{Function, Param}; +use ethcontract_common::abiext::FunctionExt; +use ethcontract_common::hash::H32; +use inflector::Inflector; +use proc_macro2::{Literal, TokenStream}; +use quote::quote; +use syn::Ident; + +pub(crate) fn expand(cx: &Context) -> Result { + let functions = expand_functions(cx)?; + let fallback = expand_fallback(cx); + + Ok(quote! { + #functions + #fallback + }) +} + +/// Expands a context into a method struct containing all the generated bindings +/// to the Solidity contract methods. +fn expand_functions(cx: &Context) -> Result { + let mut aliases = cx.method_aliases.clone(); + let functions = cx + .artifact + .abi + .functions() + .map(|function| { + let signature = function.abi_signature(); + expand_function(&cx, function, aliases.remove(&signature)) + .with_context(|| format!("error expanding function '{}'", signature)) + }) + .collect::>>()?; + if let Some(unused) = aliases.keys().next() { + return Err(anyhow!( + "a manual method alias for '{}' was specified but this method does not exist", + unused, + )); + } + + let methods_attrs = quote! { #[derive(Clone)] }; + let methods_struct = quote! { + struct Methods { + instance: self::ethcontract::dyns::DynInstance, + } + }; + + if functions.is_empty() { + // NOTE: The methods struct is still needed when there are no functions + // as it contains the the runtime instance. The code is setup this way + // so that the contract can implement `Deref` targetting the methods + // struct and, therefore, call the methods directly. + return Ok(quote! { + #methods_attrs + #methods_struct + }); + } + + Ok(quote! { + impl Contract { + /// Retrives a reference to type containing all the generated + /// contract methods. This can be used for methods where the name + /// would collide with a common method (like `at` or `deployed`). + pub fn methods(&self) -> &Methods { + &self.methods + } + } + + /// Type containing all contract methods for generated contract type. + #methods_attrs + pub #methods_struct + + #[allow(clippy::too_many_arguments, clippy::type_complexity)] + impl Methods { + #( #functions )* + } + + impl std::ops::Deref for Contract { + type Target = Methods; + fn deref(&self) -> &Self::Target { + &self.methods + } + } + }) +} + +fn expand_function(cx: &Context, function: &Function, alias: Option) -> Result { + let name = alias.unwrap_or_else(|| util::safe_ident(&function.name.to_snake_case())); + let signature = function.abi_signature(); + let selector = expand_selector(function.selector()); + + let doc_str = cx + .artifact + .devdoc + .methods + .get(&signature) + .or_else(|| cx.artifact.userdoc.methods.get(&signature)) + .and_then(|entry| entry.details.as_ref()) + .map(String::as_str) + .unwrap_or("Generated by `ethcontract`"); + let doc = util::expand_doc(doc_str); + + let input = expand_inputs(&function.inputs)?; + let outputs = expand_fn_outputs(&function.outputs)?; + let (method, result_type_name) = if function.constant { + (quote! { view_method }, quote! { DynViewMethodBuilder }) + } else { + (quote! { method }, quote! { DynMethodBuilder }) + }; + let result = quote! { self::ethcontract::dyns::#result_type_name<#outputs> }; + let arg = expand_inputs_call_arg(&function.inputs); + + Ok(quote! { + #doc + pub fn #name(&self #input) -> #result { + self.instance.#method(#selector, #arg) + .expect("generated call") + } + }) +} + +pub(crate) fn expand_inputs(inputs: &[Param]) -> Result { + let params = inputs + .iter() + .enumerate() + .map(|(i, param)| { + let name = util::expand_input_name(i, ¶m.name); + let kind = types::expand(¶m.kind)?; + Ok(quote! { #name: #kind }) + }) + .collect::>>()?; + Ok(quote! { #( , #params )* }) +} + +pub(crate) fn expand_inputs_call_arg(inputs: &[Param]) -> TokenStream { + let names = inputs + .iter() + .enumerate() + .map(|(i, param)| util::expand_input_name(i, ¶m.name)); + quote! { ( #( #names ,)* ) } +} + +fn expand_fn_outputs(outputs: &[Param]) -> Result { + match outputs.len() { + 0 => Ok(quote! { self::ethcontract::Void }), + 1 => types::expand(&outputs[0].kind), + _ => { + let types = outputs + .iter() + .map(|param| types::expand(¶m.kind)) + .collect::>>()?; + Ok(quote! { (#( #types ),*) }) + } + } +} + +fn expand_selector(selector: H32) -> TokenStream { + let bytes = selector.iter().copied().map(Literal::u8_unsuffixed); + quote! { [#( #bytes ),*] } +} + +/// Expands a context into fallback method when the contract implements one, +/// and an empty token stream otherwise. +fn expand_fallback(cx: &Context) -> TokenStream { + if cx.artifact.abi.fallback { + quote! { + impl Contract { + /// Returns a method builder to setup a call to a smart + /// contract's fallback function. + pub fn fallback(&self, data: D) -> self::ethcontract::dyns::DynMethodBuilder< + self::ethcontract::Void, + > + where + D: Into>, + { + self.raw_instance().fallback(data) + .expect("generated fallback method") + } + } + } + } else { + quote! {} + } +} + +#[cfg(test)] +mod tests { + use super::*; + use ethcontract_common::abi::ParamType; + + #[test] + fn expand_inputs_empty() { + assert_quote!(expand_inputs(&[]).unwrap().to_string(), {},); + } + + #[test] + fn expand_inputs_() { + assert_quote!( + expand_inputs( + + &[ + Param { + name: "a".to_string(), + kind: ParamType::Bool, + }, + Param { + name: "b".to_string(), + kind: ParamType::Address, + }, + ], + ) + .unwrap(), + { , a: bool, b: self::ethcontract::Address }, + ); + } + + #[test] + fn expand_fn_outputs_empty() { + assert_quote!(expand_fn_outputs(&[],).unwrap(), { + self::ethcontract::Void + }); + } + + #[test] + fn expand_fn_outputs_single() { + assert_quote!( + expand_fn_outputs(&[Param { + name: "a".to_string(), + kind: ParamType::Bool, + }]) + .unwrap(), + { bool }, + ); + } + + #[test] + fn expand_fn_outputs_muliple() { + assert_quote!( + expand_fn_outputs(&[ + Param { + name: "a".to_string(), + kind: ParamType::Bool, + }, + Param { + name: "b".to_string(), + kind: ParamType::Address, + }, + ],) + .unwrap(), + { (bool, self::ethcontract::Address) }, + ); + } +} diff --git a/crates/ethers-derive/src/src/contract/types.rs b/crates/ethers-derive/src/src/contract/types.rs new file mode 100644 index 00000000..176e3970 --- /dev/null +++ b/crates/ethers-derive/src/src/contract/types.rs @@ -0,0 +1,48 @@ +use anyhow::{anyhow, Result}; +use ethcontract_common::abi::ParamType; +use proc_macro2::{Literal, TokenStream}; +use quote::quote; + +pub(crate) fn expand(kind: &ParamType) -> Result { + match kind { + ParamType::Address => Ok(quote! { self::ethcontract::Address }), + ParamType::Bytes => Ok(quote! { Vec }), + ParamType::Int(n) => match n / 8 { + 1 => Ok(quote! { i8 }), + 2 => Ok(quote! { i16 }), + 3..=4 => Ok(quote! { i32 }), + 5..=8 => Ok(quote! { i64 }), + 9..=16 => Ok(quote! { i128 }), + 17..=32 => Ok(quote! { self::ethcontract::I256 }), + _ => Err(anyhow!("unsupported solidity type int{}", n)), + }, + ParamType::Uint(n) => match n / 8 { + 1 => Ok(quote! { u8 }), + 2 => Ok(quote! { u16 }), + 3..=4 => Ok(quote! { u32 }), + 5..=8 => Ok(quote! { u64 }), + 9..=16 => Ok(quote! { u128 }), + 17..=32 => Ok(quote! { self::ethcontract::U256 }), + _ => Err(anyhow!("unsupported solidity type uint{}", n)), + }, + ParamType::Bool => Ok(quote! { bool }), + ParamType::String => Ok(quote! { String }), + ParamType::Array(t) => { + let inner = expand(t)?; + Ok(quote! { Vec<#inner> }) + } + ParamType::FixedBytes(n) => { + // TODO(nlordell): what is the performance impact of returning large + // `FixedBytes` and `FixedArray`s with `web3`? + let size = Literal::usize_unsuffixed(*n); + Ok(quote! { [u8; #size] }) + } + ParamType::FixedArray(t, n) => { + // TODO(nlordell): see above + let inner = expand(t)?; + let size = Literal::usize_unsuffixed(*n); + Ok(quote! { [#inner; #size] }) + } + ParamType::Tuple(_) => Err(anyhow!("ABIEncoderV2 is currently not supported")), + } +} diff --git a/crates/ethers-derive/src/src/lib.rs b/crates/ethers-derive/src/src/lib.rs new file mode 100644 index 00000000..8a83289c --- /dev/null +++ b/crates/ethers-derive/src/src/lib.rs @@ -0,0 +1,286 @@ +#![deny(missing_docs, unsafe_code)] + +//! Crate for generating type-safe bindings to Ethereum smart contracts. This +//! crate is intended to be used either indirectly with the `ethcontract` +//! crate's `contract` procedural macro or directly from a build script. + +#[cfg(test)] +#[allow(missing_docs)] +#[macro_use] +#[path = "test/macros.rs"] +mod test_macros; + +mod contract; +mod rustfmt; +mod source; +mod util; + +pub use crate::source::Source; +pub use crate::util::parse_address; +use anyhow::Result; +pub use ethcontract_common::Address; +use proc_macro2::TokenStream; +use std::collections::HashMap; +use std::fs::File; +use std::io::Write; +use std::path::Path; + +/// Internal global arguments passed to the generators for each individual +/// component that control expansion. +pub(crate) struct Args { + /// The source of the truffle artifact JSON for the contract whose bindings + /// are being generated. + artifact_source: Source, + /// The runtime crate name to use. + runtime_crate_name: String, + /// The visibility modifier to use for the generated module and contract + /// re-export. + visibility_modifier: Option, + /// Override the contract module name that contains the generated code. + contract_mod_override: Option, + /// Override the contract name to use for the generated type. + contract_name_override: Option, + /// Manually specified deployed contract addresses. + deployments: HashMap, + /// Manually specified contract method aliases. + method_aliases: HashMap, + /// Derives added to event structs and enums. + event_derives: Vec, +} + +impl Args { + /// Creates a new builder given the path to a contract's truffle artifact + /// JSON file. + pub fn new(source: Source) -> Self { + Args { + artifact_source: source, + runtime_crate_name: "ethcontract".to_owned(), + visibility_modifier: None, + contract_mod_override: None, + contract_name_override: None, + deployments: HashMap::new(), + method_aliases: HashMap::new(), + event_derives: Vec::new(), + } + } +} + +/// Internal output options for controlling how the generated code gets +/// serialized to file. +struct SerializationOptions { + /// Format the code using a locally installed copy of `rustfmt`. + rustfmt: bool, +} + +impl Default for SerializationOptions { + fn default() -> Self { + SerializationOptions { rustfmt: true } + } +} + +/// Builder for generating contract code. Note that no code is generated until +/// the builder is finalized with `generate` or `output`. +pub struct Builder { + /// The contract binding generation args. + args: Args, + /// The serialization options. + options: SerializationOptions, +} + +impl Builder { + /// Creates a new builder given the path to a contract's truffle artifact + /// JSON file. + pub fn new

(artifact_path: P) -> Self + where + P: AsRef, + { + Builder::with_source(Source::local(artifact_path)) + } + + /// Creates a new builder from a source URL. + pub fn from_source_url(source_url: S) -> Result + where + S: AsRef, + { + let source = Source::parse(source_url)?; + Ok(Builder::with_source(source)) + } + + /// Creates a new builder with the given artifact JSON source. + pub fn with_source(source: Source) -> Self { + Builder { + args: Args::new(source), + options: SerializationOptions::default(), + } + } + + /// Sets the crate name for the runtime crate. This setting is usually only + /// needed if the crate was renamed in the Cargo manifest. + pub fn with_runtime_crate_name(mut self, name: S) -> Self + where + S: Into, + { + self.args.runtime_crate_name = name.into(); + self + } + + /// Sets an optional visibility modifier for the generated module and + /// contract re-export. + pub fn with_visibility_modifier(mut self, vis: Option) -> Self + where + S: Into, + { + self.args.visibility_modifier = vis.map(S::into); + self + } + + /// Sets the optional contract module name override. + pub fn with_contract_mod_override(mut self, name: Option) -> Self + where + S: Into, + { + self.args.contract_mod_override = name.map(S::into); + self + } + + /// Sets the optional contract name override. This setting is needed when + /// using a artifact JSON source that does not provide a contract name such + /// as Etherscan. + pub fn with_contract_name_override(mut self, name: Option) -> Self + where + S: Into, + { + self.args.contract_name_override = name.map(S::into); + self + } + + /// Manually adds specifies the deployed address of a contract for a given + /// network. Note that manually specified deployments take precedence over + /// deployments in the Truffle artifact (in the `networks` property of the + /// artifact). + /// + /// This is useful for integration test scenarios where the address of a + /// contract on the test node is deterministic (for example using + /// `ganache-cli -d`) but the contract address is not part of the Truffle + /// artifact; or to override a deployment included in a Truffle artifact. + pub fn add_deployment(mut self, network_id: u32, address: Address) -> Self { + self.args.deployments.insert(network_id, address); + self + } + + /// Manually adds specifies the deployed address as a string of a contract + /// for a given network. See `Builder::add_deployment` for more information. + /// + /// # Panics + /// + /// This method panics if the specified address string is invalid. See + /// `parse_address` for more information on the address string format. + pub fn add_deployment_str(self, network_id: u32, address: S) -> Self + where + S: AsRef, + { + self.add_deployment( + network_id, + parse_address(address).expect("failed to parse address"), + ) + } + + /// Manually adds a solidity method alias to specify what the method name + /// will be in Rust. For solidity methods without an alias, the snake cased + /// method name will be used. + pub fn add_method_alias(mut self, signature: S1, alias: S2) -> Self + where + S1: Into, + S2: Into, + { + self.args + .method_aliases + .insert(signature.into(), alias.into()); + self + } + + /// Specify whether or not to format the code using a locally installed copy + /// of `rustfmt`. + /// + /// Note that in case `rustfmt` does not exist or produces an error, the + /// unformatted code will be used. + pub fn with_rustfmt(mut self, rustfmt: bool) -> Self { + self.options.rustfmt = rustfmt; + self + } + + /// Add a custom derive to the derives for event structs and enums. + /// + /// This makes it possible to for example derive serde::Serialize and + /// serde::Deserialize for events. + /// + /// # Examples + /// + /// ``` + /// use ethcontract_generate::Builder; + /// let builder = Builder::new("path") + /// .add_event_derive("serde::Serialize") + /// .add_event_derive("serde::Deserialize"); + /// ``` + pub fn add_event_derive(mut self, derive: S) -> Self + where + S: Into, + { + self.args.event_derives.push(derive.into()); + self + } + + /// Generates the contract bindings. + pub fn generate(self) -> Result { + let tokens = contract::expand(self.args)?; + Ok(ContractBindings { + tokens, + options: self.options, + }) + } +} + +/// Type-safe contract bindings generated by a `Builder`. This type can be +/// either written to file or into a token stream for use in a procedural macro. +pub struct ContractBindings { + /// The TokenStream representing the contract bindings. + tokens: TokenStream, + /// The output options used for serialization. + options: SerializationOptions, +} + +impl ContractBindings { + /// Writes the bindings to a given `Write`. + pub fn write(&self, mut w: W) -> Result<()> + where + W: Write, + { + let source = { + let raw = self.tokens.to_string(); + + if self.options.rustfmt { + rustfmt::format(&raw).unwrap_or(raw) + } else { + raw + } + }; + + w.write_all(source.as_bytes())?; + Ok(()) + } + + /// Writes the bindings to the specified file. + pub fn write_to_file

(&self, path: P) -> Result<()> + where + P: AsRef, + { + let file = File::create(path)?; + self.write(file) + } + + /// Converts the bindings into its underlying token stream. This allows it + /// to be used within a procedural macro. + pub fn into_tokens(self) -> TokenStream { + self.tokens + } +} diff --git a/crates/ethers-derive/src/src/rustfmt.rs b/crates/ethers-derive/src/src/rustfmt.rs new file mode 100644 index 00000000..390f20ae --- /dev/null +++ b/crates/ethers-derive/src/src/rustfmt.rs @@ -0,0 +1,36 @@ +//! This module implements basic `rustfmt` code formatting. + +use anyhow::{anyhow, Result}; +use std::io::Write; +use std::process::{Command, Stdio}; + +/// Format the raw input source string and return formatted output. +pub fn format(source: S) -> Result +where + S: AsRef, +{ + let mut rustfmt = Command::new("rustfmt") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn()?; + + { + let stdin = rustfmt + .stdin + .as_mut() + .ok_or_else(|| anyhow!("stdin was not created for `rustfmt` child process"))?; + stdin.write_all(source.as_ref().as_bytes())?; + } + + let output = rustfmt.wait_with_output()?; + if !output.status.success() { + return Err(anyhow!( + "`rustfmt` exited with code {}:\n{}", + output.status, + String::from_utf8_lossy(&output.stderr), + )); + } + + let stdout = String::from_utf8(output.stdout)?; + Ok(stdout) +} diff --git a/crates/ethers-derive/src/src/source.rs b/crates/ethers-derive/src/src/source.rs new file mode 100644 index 00000000..335288f2 --- /dev/null +++ b/crates/ethers-derive/src/src/source.rs @@ -0,0 +1,260 @@ +//! Module implements reading of contract artifacts from various sources. + +use crate::util; +use anyhow::{anyhow, Context, Error, Result}; +use ethcontract_common::Address; +use std::borrow::Cow; +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use url::Url; + +/// A source of a Truffle artifact JSON. +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum Source { + /// A Truffle artifact or ABI located on the local file system. + Local(PathBuf), + /// A truffle artifact or ABI to be retrieved over HTTP(S). + Http(Url), + /// An address of a mainnet contract that has been verified on Etherscan.io. + Etherscan(Address), + /// The package identifier of an npm package with a path to a Truffle + /// artifact or ABI to be retrieved from `unpkg.io`. + Npm(String), +} + +impl Source { + /// Parses an artifact source from a string. + /// + /// Contract artifacts can be retrieved from the local filesystem or online + /// from `etherscan.io`, this method parses artifact source URLs and accepts + /// the following: + /// - `relative/path/to/Contract.json`: a relative path to a truffle + /// artifact JSON file. This relative path is rooted in the current + /// working directory. To specify the root for relative paths, use + /// `Source::with_root`. + /// - `/absolute/path/to/Contract.json` or + /// `file:///absolute/path/to/Contract.json`: an absolute path or file URL + /// to a truffle artifact JSON file. + /// - `http(s)://...` an HTTP url to a contract ABI or Truffle artifact. + /// - `etherscan:0xXX..XX` or `https://etherscan.io/address/0xXX..XX`: a + /// address or URL of a verified contract on Etherscan. + /// - `npm:@org/package@1.0.0/path/to/contract.json` an npmjs package with + /// an optional version and path (defaulting to the latest version and + /// `index.js`). The contract artifact or ABI will be retrieved through + /// `unpkg.io`. + pub fn parse(source: S) -> Result + where + S: AsRef, + { + let root = env::current_dir()?.canonicalize()?; + Source::with_root(root, source) + } + + /// Parses an artifact source from a string and a specified root directory + /// for resolving relative paths. See `Source::with_root` for more details + /// on supported source strings. + pub fn with_root(root: P, source: S) -> Result + where + P: AsRef, + S: AsRef, + { + let base = Url::from_directory_path(root) + .map_err(|_| anyhow!("root path '{}' is not absolute"))?; + let url = base.join(source.as_ref())?; + + match url.scheme() { + "file" => Ok(Source::local(url.path())), + "http" | "https" => match url.host_str() { + Some("etherscan.io") => Source::etherscan( + url.path() + .rsplit('/') + .next() + .ok_or_else(|| anyhow!("HTTP URL does not have a path"))?, + ), + _ => Ok(Source::Http(url)), + }, + "etherscan" => Source::etherscan(url.path()), + "npm" => Ok(Source::npm(url.path())), + _ => Err(anyhow!("unsupported URL '{}'", url)), + } + } + + /// Creates a local filesystem source from a path string. + pub fn local

(path: P) -> Self + where + P: AsRef, + { + Source::Local(path.as_ref().into()) + } + + /// Creates an HTTP source from a URL. + pub fn http(url: S) -> Result + where + S: AsRef, + { + Ok(Source::Http(Url::parse(url.as_ref())?)) + } + + /// Creates an Etherscan source from an address string. + pub fn etherscan(address: S) -> Result + where + S: AsRef, + { + let address = + util::parse_address(address).context("failed to parse address for Etherscan source")?; + Ok(Source::Etherscan(address)) + } + + /// Creates an Etherscan source from an address string. + pub fn npm(package_path: S) -> Self + where + S: Into, + { + Source::Npm(package_path.into()) + } + + /// Retrieves the source JSON of the artifact this will either read the JSON + /// from the file system or retrieve a contract ABI from the network + /// dependending on the source type. + pub fn artifact_json(&self) -> Result { + match self { + Source::Local(path) => get_local_contract(path), + Source::Http(url) => get_http_contract(url), + Source::Etherscan(address) => get_etherscan_contract(*address), + Source::Npm(package) => get_npm_contract(package), + } + } +} + +impl FromStr for Source { + type Err = Error; + + fn from_str(s: &str) -> Result { + Source::parse(s) + } +} + +/// Reads a Truffle artifact JSON file from the local filesystem. +fn get_local_contract(path: &Path) -> Result { + let path = if path.is_relative() { + let absolute_path = path.canonicalize().with_context(|| { + format!( + "unable to canonicalize file from working dir {} with path {}", + env::current_dir() + .map(|cwd| cwd.display().to_string()) + .unwrap_or_else(|err| format!("??? ({})", err)), + path.display(), + ) + })?; + Cow::Owned(absolute_path) + } else { + Cow::Borrowed(path) + }; + + let json = fs::read_to_string(path).context("failed to read artifact JSON file")?; + Ok(abi_or_artifact(json)) +} + +/// Retrieves a Truffle artifact or ABI from an HTTP URL. +fn get_http_contract(url: &Url) -> Result { + let json = util::http_get(url.as_str()) + .with_context(|| format!("failed to retrieve JSON from {}", url))?; + Ok(abi_or_artifact(json)) +} + +/// Retrieves a contract ABI from the Etherscan HTTP API and wraps it in an +/// artifact JSON for compatibility with the code generation facilities. +fn get_etherscan_contract(address: Address) -> Result { + // NOTE: We do not retrieve the bytecode since deploying contracts with the + // same bytecode is unreliable as the libraries have already linked and + // probably don't reference anything when deploying on other networks. + + let api_key = env::var("ETHERSCAN_API_KEY") + .map(|key| format!("&apikey={}", key)) + .unwrap_or_default(); + + let abi_url = format!( + "http://api.etherscan.io/api\ + ?module=contract&action=getabi&address={:?}&format=raw{}", + address, api_key, + ); + let abi = util::http_get(&abi_url).context("failed to retrieve ABI from Etherscan.io")?; + + // NOTE: Wrap the retrieved ABI in an empty contract, this is because + // currently, the code generation infrastructure depends on having an + // `Artifact` instance. + let json = format!( + r#"{{"abi":{},"networks":{{"1":{{"address":"{:?}"}}}}}}"#, + abi, address, + ); + + Ok(json) +} + +/// Retrieves a Truffle artifact or ABI from an npm package through `unpkg.io`. +fn get_npm_contract(package: &str) -> Result { + let unpkg_url = format!("https://unpkg.io/{}", package); + let json = util::http_get(&unpkg_url) + .with_context(|| format!("failed to retrieve JSON from for npm package {}", package))?; + + Ok(abi_or_artifact(json)) +} + +/// A best-effort coersion of an ABI or Truffle artifact JSON document into a +/// Truffle artifact JSON document. +/// +/// This method uses the fact that ABIs are arrays and Truffle artifacts are +/// objects to guess at what type of document this is. Note that no parsing or +/// validation is done at this point as the document gets parsed and validated +/// at generation time. +/// +/// This needs to be done as currently the contract generation infrastructure +/// depends on having a Truffle artifact. +fn abi_or_artifact(json: String) -> String { + if json.trim().starts_with('[') { + format!(r#"{{"abi":{}}}"#, json.trim()) + } else { + json + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_source() { + let root = "/rooted"; + for (url, expected) in &[ + ( + "relative/Contract.json", + Source::local("/rooted/relative/Contract.json"), + ), + ( + "/absolute/Contract.json", + Source::local("/absolute/Contract.json"), + ), + ( + "https://my.domain.eth/path/to/Contract.json", + Source::http("https://my.domain.eth/path/to/Contract.json").unwrap(), + ), + ( + "etherscan:0x0001020304050607080910111213141516171819", + Source::etherscan("0x0001020304050607080910111213141516171819").unwrap(), + ), + ( + "https://etherscan.io/address/0x0001020304050607080910111213141516171819", + Source::etherscan("0x0001020304050607080910111213141516171819").unwrap(), + ), + ( + "npm:@openzeppelin/contracts@2.5.0/build/contracts/IERC20.json", + Source::npm("@openzeppelin/contracts@2.5.0/build/contracts/IERC20.json"), + ), + ] { + let source = Source::with_root(root, url).unwrap(); + assert_eq!(source, *expected); + } + } +} diff --git a/crates/ethers-derive/src/src/test/macros.rs b/crates/ethers-derive/src/src/test/macros.rs new file mode 100644 index 00000000..467f89e9 --- /dev/null +++ b/crates/ethers-derive/src/src/test/macros.rs @@ -0,0 +1,10 @@ +/// Asserts the result of an expansion matches source output. +/// +/// # Panics +/// +/// If the expanded source does not match the quoted source. +macro_rules! assert_quote { + ($ex:expr, { $($t:tt)* } $(,)?) => { + assert_eq!($ex.to_string(), quote::quote! { $($t)* }.to_string()) + }; +} diff --git a/crates/ethers-derive/src/src/util.rs b/crates/ethers-derive/src/src/util.rs new file mode 100644 index 00000000..d3632cbe --- /dev/null +++ b/crates/ethers-derive/src/src/util.rs @@ -0,0 +1,117 @@ +use anyhow::{anyhow, Result}; +use curl::easy::Easy; +use ethcontract_common::Address; +use inflector::Inflector; +use proc_macro2::{Ident, Literal, Span, TokenStream}; +use quote::quote; +use syn::Ident as SynIdent; + +/// Expands a identifier string into an token. +pub fn ident(name: &str) -> Ident { + Ident::new(name, Span::call_site()) +} + +/// Expands an identifier string into a token and appending `_` if the +/// identifier is for a reserved keyword. +/// +/// Parsing keywords like `self` can fail, in this case we add an underscore. +pub fn safe_ident(name: &str) -> Ident { + syn::parse_str::(name).unwrap_or_else(|_| ident(&format!("{}_", name))) +} + +/// Expands a positional identifier string that may be empty. +/// +/// Note that this expands the parameter name with `safe_ident`, meaning that +/// identifiers that are reserved keywords get `_` appended to them. +pub fn expand_input_name(index: usize, name: &str) -> TokenStream { + let name_str = match name { + "" => format!("p{}", index), + n => n.to_snake_case(), + }; + let name = safe_ident(&name_str); + + quote! { #name } +} + +/// Expands a doc string into an attribute token stream. +pub fn expand_doc(s: &str) -> TokenStream { + let doc = Literal::string(s); + quote! { + #[doc = #doc] + } +} + +/// Parses the given address string +pub fn parse_address(address_str: S) -> Result

+where + S: AsRef, +{ + let address_str = address_str.as_ref(); + if !address_str.starts_with("0x") { + return Err(anyhow!("address must start with '0x'")); + } + Ok(address_str[2..].parse()?) +} + +/// Perform an HTTP GET request and return the contents of the response. +pub fn http_get(url: &str) -> Result { + let mut buffer = Vec::new(); + let mut handle = Easy::new(); + handle.url(url)?; + { + let mut transfer = handle.transfer(); + transfer.write_function(|data| { + buffer.extend_from_slice(data); + Ok(data.len()) + })?; + transfer.perform()?; + } + + let buffer = String::from_utf8(buffer)?; + Ok(buffer) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn input_name_to_ident_empty() { + assert_quote!(expand_input_name(0, ""), { p0 }); + } + + #[test] + fn input_name_to_ident_keyword() { + assert_quote!(expand_input_name(0, "self"), { self_ }); + } + + #[test] + fn input_name_to_ident_snake_case() { + assert_quote!(expand_input_name(0, "CamelCase1"), { camel_case_1 }); + } + + #[test] + fn parse_address_missing_prefix() { + if parse_address("0000000000000000000000000000000000000000").is_ok() { + panic!("parsing address not starting with 0x should fail"); + } + } + + #[test] + fn parse_address_address_too_short() { + if parse_address("0x00000000000000").is_ok() { + panic!("parsing address not starting with 0x should fail"); + } + } + + #[test] + fn parse_address_ok() { + let expected = Address::from([ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + ]); + assert_eq!( + parse_address("0x000102030405060708090a0b0c0d0e0f10111213").unwrap(), + expected + ); + } +} diff --git a/crates/ethers-providers/Cargo.toml b/crates/ethers-providers/Cargo.toml new file mode 100644 index 00000000..d1c25786 --- /dev/null +++ b/crates/ethers-providers/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ethers-providers" +version = "0.1.0" +authors = ["Georgios Konstantopoulos "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/providers/http.rs b/crates/ethers-providers/http.rs similarity index 100% rename from src/providers/http.rs rename to crates/ethers-providers/http.rs diff --git a/src/providers/mod.rs b/crates/ethers-providers/mod.rs similarity index 100% rename from src/providers/mod.rs rename to crates/ethers-providers/mod.rs diff --git a/crates/ethers-providers/src/lib.rs b/crates/ethers-providers/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/crates/ethers-providers/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/crates/ethers-signers/Cargo.toml b/crates/ethers-signers/Cargo.toml new file mode 100644 index 00000000..f63a327b --- /dev/null +++ b/crates/ethers-signers/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ethers-signers" +version = "0.1.0" +authors = ["Georgios Konstantopoulos "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/signers/client.rs b/crates/ethers-signers/src/client.rs similarity index 100% rename from src/signers/client.rs rename to crates/ethers-signers/src/client.rs diff --git a/crates/ethers-signers/src/lib.rs b/crates/ethers-signers/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/crates/ethers-signers/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/signers/mod.rs b/crates/ethers-signers/src/mod.rs similarity index 100% rename from src/signers/mod.rs rename to crates/ethers-signers/src/mod.rs diff --git a/src/signers/networks.rs b/crates/ethers-signers/src/networks.rs similarity index 100% rename from src/signers/networks.rs rename to crates/ethers-signers/src/networks.rs diff --git a/src/signers/wallet.rs b/crates/ethers-signers/src/wallet.rs similarity index 100% rename from src/signers/wallet.rs rename to crates/ethers-signers/src/wallet.rs diff --git a/crates/ethers-types/Cargo.toml b/crates/ethers-types/Cargo.toml new file mode 100644 index 00000000..4ee313f8 --- /dev/null +++ b/crates/ethers-types/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "ethers-types" +version = "0.1.0" +authors = ["Georgios Konstantopoulos "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ethereum-types = { version = "0.9.2", default-features = false, features = ["serialize"] } +serde = { version = "1.0.110", default-features = false, features = ["derive"] } +rlp = { version = "0.4.5", default-features = false } +rustc-hex = { version = "2.1.0", default-features = false } +thiserror = { version = "1.0.19", default-features = false } + +# crypto +secp256k1 = { version = "0.17.2", default-features = false, features = ["std", "recovery", "rand"] } +rand = { version = "0.5.1", default-features = false } # this should be the same rand crate version as the one in secp +zeroize = { version = "1.1.0", default-features = false } diff --git a/src/types/block.rs b/crates/ethers-types/src/block.rs similarity index 100% rename from src/types/block.rs rename to crates/ethers-types/src/block.rs diff --git a/src/types/block_number.rs b/crates/ethers-types/src/block_number.rs similarity index 100% rename from src/types/block_number.rs rename to crates/ethers-types/src/block_number.rs diff --git a/src/types/bytes.rs b/crates/ethers-types/src/bytes.rs similarity index 100% rename from src/types/bytes.rs rename to crates/ethers-types/src/bytes.rs diff --git a/src/types/keys.rs b/crates/ethers-types/src/keys.rs similarity index 100% rename from src/types/keys.rs rename to crates/ethers-types/src/keys.rs diff --git a/src/types/mod.rs b/crates/ethers-types/src/lib.rs similarity index 100% rename from src/types/mod.rs rename to crates/ethers-types/src/lib.rs diff --git a/src/types/log.rs b/crates/ethers-types/src/log.rs similarity index 100% rename from src/types/log.rs rename to crates/ethers-types/src/log.rs diff --git a/src/types/signature.rs b/crates/ethers-types/src/signature.rs similarity index 100% rename from src/types/signature.rs rename to crates/ethers-types/src/signature.rs diff --git a/src/types/transaction.rs b/crates/ethers-types/src/transaction.rs similarity index 100% rename from src/types/transaction.rs rename to crates/ethers-types/src/transaction.rs diff --git a/crates/ethers-utils/Cargo.toml b/crates/ethers-utils/Cargo.toml new file mode 100644 index 00000000..11e6b42a --- /dev/null +++ b/crates/ethers-utils/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ethers-utils" +version = "0.1.0" +authors = ["Georgios Konstantopoulos "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/crates/ethers-utils/src/lib.rs b/crates/ethers-utils/src/lib.rs new file mode 100644 index 00000000..31e1bb20 --- /dev/null +++ b/crates/ethers-utils/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/utils.rs b/crates/ethers-utils/src/utils.rs similarity index 100% rename from src/utils.rs rename to crates/ethers-utils/src/utils.rs diff --git a/crates/ethers/Cargo.toml b/crates/ethers/Cargo.toml new file mode 100644 index 00000000..5ca63397 --- /dev/null +++ b/crates/ethers/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "ethers" +version = "0.1.0" +authors = ["Georgios Konstantopoulos "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +# TODO: Make this have features for each available module diff --git a/src/lib.rs b/crates/ethers/src/lib.rs similarity index 100% rename from src/lib.rs rename to crates/ethers/src/lib.rs