From c9a6a61e4eb9f732deb89084b253d2e5df64629e Mon Sep 17 00:00:00 2001 From: koushiro Date: Tue, 26 Nov 2019 14:20:54 +0800 Subject: [PATCH] Simplify error handling by using anyhow Signed-off-by: koushiro --- Cargo.lock | 104 +++++++++++++++++--------------------------- Cargo.toml | 18 ++++---- build.rs | 40 +++++------------ src/cmd/build.rs | 72 ++++++++++-------------------- src/cmd/deploy.rs | 70 +++++++++++------------------ src/cmd/error.rs | 56 ------------------------ src/cmd/metadata.rs | 18 +++----- src/cmd/mod.rs | 24 +++------- src/cmd/new.rs | 45 +++++++------------ src/main.rs | 39 +++++++---------- 10 files changed, 153 insertions(+), 333 deletions(-) delete mode 100644 src/cmd/error.rs diff --git a/Cargo.lock b/Cargo.lock index 3f01123e..a064bf13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,6 +33,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "anyhow" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "arrayref" version = "0.3.5" @@ -191,14 +196,12 @@ dependencies = [ name = "cargo-contract" version = "0.2.0" dependencies = [ + "anyhow 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)", "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core-client 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -416,16 +419,6 @@ dependencies = [ "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "derive_more" -version = "0.99.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "digest" version = "0.8.1" @@ -445,11 +438,6 @@ dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "either" -version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "elastic-array" version = "0.10.2" @@ -533,7 +521,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "frame-metadata" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -544,7 +532,7 @@ dependencies = [ [[package]] name = "frame-support" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "frame-metadata 2.0.0 (git+https://github.com/paritytech/substrate/)", @@ -568,7 +556,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "frame-support-procedural-tools 2.0.0 (git+https://github.com/paritytech/substrate/)", "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -579,7 +567,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "frame-support-procedural-tools-derive 2.0.0 (git+https://github.com/paritytech/substrate/)", "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -591,7 +579,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -601,7 +589,7 @@ dependencies = [ [[package]] name = "frame-system" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "frame-support 2.0.0 (git+https://github.com/paritytech/substrate/)", "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -904,14 +892,6 @@ dependencies = [ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "itertools" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "itoa" version = "0.4.4" @@ -1032,7 +1012,7 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1289,7 +1269,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "frame-support 2.0.0 (git+https://github.com/paritytech/substrate/)", "frame-system 2.0.0 (git+https://github.com/paritytech/substrate/)", @@ -1303,7 +1283,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "frame-support 2.0.0 (git+https://github.com/paritytech/substrate/)", "frame-system 2.0.0 (git+https://github.com/paritytech/substrate/)", @@ -1322,7 +1302,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "frame-support 2.0.0 (git+https://github.com/paritytech/substrate/)", "frame-system 2.0.0 (git+https://github.com/paritytech/substrate/)", @@ -1393,7 +1373,7 @@ name = "parking_lot" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1931,7 +1911,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "sr-arithmetic" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1944,7 +1924,7 @@ dependencies = [ [[package]] name = "sr-io" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1961,7 +1941,7 @@ dependencies = [ [[package]] name = "sr-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1980,7 +1960,7 @@ dependencies = [ [[package]] name = "sr-sandbox" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0 (git+https://github.com/paritytech/substrate/)", @@ -1992,12 +1972,12 @@ dependencies = [ [[package]] name = "sr-std" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" [[package]] name = "sr-version" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "impl-serde 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2056,7 +2036,7 @@ dependencies = [ [[package]] name = "substrate-application-crypto" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2079,7 +2059,7 @@ dependencies = [ [[package]] name = "substrate-debug-derive" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2089,7 +2069,7 @@ dependencies = [ [[package]] name = "substrate-externalities" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "environmental 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2100,7 +2080,7 @@ dependencies = [ [[package]] name = "substrate-inherents" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2112,7 +2092,7 @@ dependencies = [ [[package]] name = "substrate-keyring" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0 (git+https://github.com/paritytech/substrate/)", @@ -2124,7 +2104,7 @@ dependencies = [ [[package]] name = "substrate-panic-handler" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2133,7 +2113,7 @@ dependencies = [ [[package]] name = "substrate-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2172,7 +2152,7 @@ dependencies = [ [[package]] name = "substrate-primitives-storage" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "impl-serde 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2183,7 +2163,7 @@ dependencies = [ [[package]] name = "substrate-rpc-api" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2205,7 +2185,7 @@ dependencies = [ [[package]] name = "substrate-rpc-primitives" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 2.0.0 (git+https://github.com/paritytech/substrate/)", @@ -2214,7 +2194,7 @@ dependencies = [ [[package]] name = "substrate-runtime-interface" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "environmental 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2229,7 +2209,7 @@ dependencies = [ [[package]] name = "substrate-runtime-interface-proc-macro" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2241,7 +2221,7 @@ dependencies = [ [[package]] name = "substrate-state-machine" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2287,7 +2267,7 @@ dependencies = [ [[package]] name = "substrate-transaction-graph" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2301,7 +2281,7 @@ dependencies = [ [[package]] name = "substrate-trie" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2315,7 +2295,7 @@ dependencies = [ [[package]] name = "substrate-wasm-interface" version = "2.0.0" -source = "git+https://github.com/paritytech/substrate/#c0f9a21a6d54815de0b1fe7d482a39981b4a238b" +source = "git+https://github.com/paritytech/substrate/#a9d43cc01f2b30c30f16d0a934aafa10d757acef" dependencies = [ "impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "wasmi 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2937,6 +2917,7 @@ dependencies = [ "checksum ahash 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6f33b5018f120946c1dcf279194f238a9f146725593ead1c08fa47ff22b0b5d3" "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum anyhow 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)" = "6f1072d8f55592084072d2d3cb23a4b680a8543c00f10d446118e85ad3718142" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" "checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" @@ -2982,10 +2963,8 @@ dependencies = [ "checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" "checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" "checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe" -"checksum derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2159be042979966de68315bce7034bb000c775f22e3e834e1c52ff78f041cae8" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum ed25519-dalek 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d07e8b8a8386c3b89a7a4b329fdfa4cb545de2545e9e2ebbc3dd3929253e426" -"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "073be79b6538296faf81c631872676600616073817dd9a440c477ad09b408983" "checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" "checksum environmental 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "34f8467a0284de039e6bd0e25c14519538462ba5beb548bb1f03e645097837a8" @@ -3037,7 +3016,6 @@ dependencies = [ "checksum impl-trait-for-tuples 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ef5550a42e3740a0e71f909d4c861056a284060af885ae7aa6242820f920d9d" "checksum integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ea155abb3ba6f382a75f1418988c05fe82959ed9ce727de427f9cfd425b0c903" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum jsonrpc-client-transports 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d389a085cb2184604dff060390cadb8cba1f063c7fd0ad710272c163c88b9f20" "checksum jsonrpc-core 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "34651edf3417637cc45e70ed0182ecfa9ced0b7e8131805fccf7400d989845ca" @@ -3051,7 +3029,7 @@ dependencies = [ "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum libsecp256k1 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd9a7c16c9487e710536b699c962f022266347c94201174aa0a7eb0546051aa" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" -"checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" +"checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum malloc_size_of_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e37c5d4cd9473c5f4c9c111f033f15d4df9bd378fdf615944e360a4f55a05f0b" diff --git a/Cargo.toml b/Cargo.toml index 5ffae1ae..aed55917 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,40 +7,38 @@ edition = "2018" license = "GPL-3.0" readme = "README.md" -repository = "https://github.com/paritytech/ink" +repository = "https://github.com/paritytech/cargo-contract" documentation = "https://substrate.dev/substrate-contracts-workshop/#/" homepage = "https://www.parity.io/" description = "Setup and deployment tool for developing Wasm based smart contracts via ink!" keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"] categories = ["cli", "tool"] -include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] [dependencies] env_logger = "0.7" -derive_more = { version = "0.99.2", default-features = false, features = ["from", "display"] } +anyhow = "1.0" structopt = "0.3" -itertools = "0.8" log = "0.4" heck = "0.3" -futures = "0.1.28" -jsonrpc-core-client = { version = "14.0", features = ["ws"] } zip = { version = "0.5", default-features = false } pwasm-utils = "0.12" parity-wasm = "0.41" cargo_metadata = "0.9" substrate-primitives = { git = "https://github.com/paritytech/substrate/", package = "substrate-primitives" } subxt = { git = "https://github.com/paritytech/substrate-subxt/", branch = "v0.3", package = "substrate-subxt" } -tokio = "0.1.21" +tokio = "0.1" +futures = "0.1" url = "1.7" [build-dependencies] +anyhow = "1.0" zip = { version = "0.5", default-features = false } walkdir = "2.2" [dev-dependencies] -assert_matches = "1.3.0" -tempfile = "3.1.0" -wabt = "0.9.0" +assert_matches = "1.3" +tempfile = "3.1" +wabt = "0.9" [features] default = [] diff --git a/build.rs b/build.rs index f9a44751..f5814dc1 100644 --- a/build.rs +++ b/build.rs @@ -15,27 +15,15 @@ // along with ink!. If not, see . use std::{ - error::Error, fs::File, - io::{ - prelude::*, - Write, - }, + io::{prelude::*, Write}, iter::Iterator, - path::{ - Path, - PathBuf, - }, - result::Result, + path::{Path, PathBuf}, }; +use anyhow::Result; use walkdir::WalkDir; -use zip::{ - result::ZipError, - write::FileOptions, - CompressionMethod, - ZipWriter, -}; +use zip::{result::ZipError, write::FileOptions, CompressionMethod, ZipWriter}; const DEFAULT_UNIX_PERMISSIONS: u32 = 0o755; @@ -45,24 +33,18 @@ fn main() { let dst_file = Path::new(&out_dir).join("template.zip"); match zip_dir(&src_dir, &dst_file, CompressionMethod::Stored) { - Ok(_) => { - println!( - "done: {} written to {}", - src_dir.display(), - dst_file.display() - ) - } + Ok(_) => println!( + "done: {} written to {}", + src_dir.display(), + dst_file.display() + ), Err(e) => eprintln!("Error: {:?}", e), }; } -fn zip_dir( - src_dir: &PathBuf, - dst_file: &PathBuf, - method: CompressionMethod, -) -> Result<(), Box> { +fn zip_dir(src_dir: &PathBuf, dst_file: &PathBuf, method: CompressionMethod) -> Result<()> { if !src_dir.is_dir() { - return Err(ZipError::FileNotFound.into()) + return Err(ZipError::FileNotFound.into()); } let file = File::create(dst_file)?; diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 224fa512..7687c7e6 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -16,18 +16,9 @@ use std::path::PathBuf; +use anyhow::{Context, Result}; use cargo_metadata::MetadataCommand; -use parity_wasm::elements::{ - External, - MemoryType, - Module, - Section, -}; - -use crate::cmd::{ - CommandError as Error, - Result, -}; +use parity_wasm::elements::{External, MemoryType, Module, Section}; /// This is the maximum number of pages available for a contract to allocate. const MAX_MEMORY_PAGES: u32 = 16; @@ -56,7 +47,7 @@ pub fn collect_crate_metadata(working_dir: Option<&PathBuf>) -> Result) -> Result<()> { /// /// Iterates over the import section, finds the memory import entry if any and adjusts the maximum /// limit. -fn ensure_maximum_memory_pages( - module: &mut Module, - maximum_allowed_pages: u32, -) -> Result<()> { +fn ensure_maximum_memory_pages(module: &mut Module, maximum_allowed_pages: u32) -> Result<()> { let mem_ty = module .import_section_mut() .and_then(|section| { - section.entries_mut() + section + .entries_mut() .iter_mut() - .find_map(|entry| { - match entry.external_mut() { - External::Memory(ref mut mem_ty) => Some(mem_ty), - _ => None, - } + .find_map(|entry| match entry.external_mut() { + External::Memory(ref mut mem_ty) => Some(mem_ty), + _ => None, }) }) - .ok_or_else(|| - Error::Other( - "Memory import is not found. Is --import-memory specified in the linker args".to_string() - ) - )?; + .context("Memory import is not found. Is --import-memory specified in the linker args")?; if let Some(requested_maximum) = mem_ty.limits().maximum() { // The module already has maximum, check if it is within the limit bail out. if requested_maximum > maximum_allowed_pages { - return Err( - Error::Other( - format!( - "The wasm module requires {} pages. The maximum allowed number of pages is {}", - requested_maximum, - maximum_allowed_pages, - ) - ) + anyhow::bail!( + "The wasm module requires {} pages. The maximum allowed number of pages is {}", + requested_maximum, + maximum_allowed_pages, ); } } else { @@ -154,13 +133,11 @@ fn ensure_maximum_memory_pages( /// /// Presently all custom sections are not required so they can be stripped safely. fn strip_custom_sections(module: &mut Module) { - module.sections_mut().retain(|section| { - match section { - Section::Custom(_) => false, - Section::Name(_) => false, - Section::Reloc(_) => false, - _ => true, - } + module.sections_mut().retain(|section| match section { + Section::Custom(_) => false, + Section::Name(_) => false, + Section::Reloc(_) => false, + _ => true, }); } @@ -173,7 +150,9 @@ fn post_process_wasm(crate_metadata: &CrateMetadata) -> Result<()> { // // In practice only tree-shaking is performed, i.e transitively removing all symbols that are // NOT used by the specified entrypoints. - pwasm_utils::optimize(&mut module, ["call", "deploy"].to_vec())?; + if pwasm_utils::optimize(&mut module, ["call", "deploy"].to_vec()).is_err() { + anyhow::bail!("Optimizer failed"); + } ensure_maximum_memory_pages(&mut module, MAX_MEMORY_PAGES)?; strip_custom_sections(&mut module); @@ -198,17 +177,14 @@ pub(crate) fn execute_build(working_dir: Option<&PathBuf>) -> Result { )) } +#[cfg(feature = "test-ci-only")] #[cfg(test)] mod tests { use crate::{ - cmd::{ - execute_new, - tests::with_tmp_dir, - }, + cmd::{execute_new, tests::with_tmp_dir}, AbstractionLayer, }; - #[cfg(feature = "test-ci-only")] #[test] fn build_template() { with_tmp_dir(|path| { diff --git a/src/cmd/deploy.rs b/src/cmd/deploy.rs index 2c78a299..cd9b8d85 100644 --- a/src/cmd/deploy.rs +++ b/src/cmd/deploy.rs @@ -14,43 +14,25 @@ // You should have received a copy of the GNU General Public License // along with ink!. If not, see . -use std::{ - fs, - io::Read, - path::PathBuf, -}; +use std::{fs, io::Read, path::PathBuf}; +use anyhow::{Context, Result}; use futures::future::Future; -use substrate_primitives::{ - crypto::Pair, - sr25519, - H256, -}; -use subxt::{ - contracts, - system::System, - DefaultNodeRuntime, -}; - -use crate::cmd::{ - build::{ - self, - CrateMetadata, - }, - Result, -}; +use substrate_primitives::{crypto::Pair, sr25519, H256}; +use subxt::{contracts, system::System, DefaultNodeRuntime}; + +use crate::cmd::build::{self, CrateMetadata}; /// Load the wasm blob from the specified path. /// /// Defaults to the target contract wasm in the current project, inferred via the crate metadata. fn load_contract_code(path: Option<&PathBuf>) -> Result> { - let default_wasm_path = - build::collect_crate_metadata(path).map(CrateMetadata::dest_wasm)?; + let default_wasm_path = build::collect_crate_metadata(path).map(CrateMetadata::dest_wasm)?; let contract_wasm_path = path.unwrap_or(&default_wasm_path); let mut data = Vec::new(); let mut file = fs::File::open(&contract_wasm_path) - .map_err(|e| format!("Failed to open {}: {}", contract_wasm_path.display(), e))?; + .context(format!("Failed to open {}", contract_wasm_path.display()))?; file.read_to_end(&mut data)?; Ok(data) @@ -59,13 +41,13 @@ fn load_contract_code(path: Option<&PathBuf>) -> Result> { /// Attempt to extract the code hash from the extrinsic result. /// /// Returns an Error if the `Contracts::CodeStored` is not found or cannot be decoded. -fn extract_code_hash( - extrinsic_result: subxt::ExtrinsicSuccess, -) -> Result { +fn extract_code_hash(extrinsic_result: subxt::ExtrinsicSuccess) -> Result { match extrinsic_result.find_event::("Contracts", "CodeStored") { Some(Ok(hash)) => Ok(hash), - Some(Err(err)) => Err(format!("Failed to decode code hash: {}", err).into()), - None => Err("Failed to find Contracts::CodeStored Event".into()), + Some(Err(err)) => Err(anyhow::anyhow!("Failed to decode code hash: {}", err)), + None => Err(anyhow::anyhow!( + "Failed to find Contracts::CodeStored Event" + )), } } @@ -84,7 +66,10 @@ pub(crate) fn execute_deploy( gas: u64, contract_wasm_path: Option<&PathBuf>, ) -> Result { - let signer = sr25519::Pair::from_string(suri, password)?; + let signer = match sr25519::Pair::from_string(suri, password) { + Ok(signer) => signer, + Err(_) => anyhow::bail!("Secret string error"), + }; let code = load_contract_code(contract_wasm_path)?; @@ -95,21 +80,19 @@ pub(crate) fn execute_deploy( .and_then(move |xt| xt.submit_and_watch(contracts::put_code(gas, code))); let mut rt = tokio::runtime::Runtime::new()?; - let extrinsic_success = rt.block_on(fut)?; - - log::debug!("Deploy success: {:?}", extrinsic_success); + if let Ok(extrinsic_success) = rt.block_on(fut) { + log::debug!("Deploy success: {:?}", extrinsic_success); - let code_hash = extract_code_hash(extrinsic_success)?; - Ok(format!("Code hash: {:?}", code_hash)) + let code_hash = extract_code_hash(extrinsic_success)?; + Ok(format!("Code hash: {:?}", code_hash)) + } else { + Err(anyhow::anyhow!("Deploy error")) + } } #[cfg(test)] mod tests { - use std::{ - fs, - io::Write, - path, - }; + use std::{fs, io::Write, path}; use assert_matches::assert_matches; @@ -134,8 +117,7 @@ mod tests { let _ = file.write_all(&wasm); let url = url::Url::parse("ws://localhost:9944").unwrap(); - let result = - super::execute_deploy(url, "//Alice", None, 500_000, Some(&wasm_path)); + let result = super::execute_deploy(url, "//Alice", None, 500_000, Some(&wasm_path)); assert_matches!(result, Ok(_)); } diff --git a/src/cmd/error.rs b/src/cmd/error.rs deleted file mode 100644 index 26864273..00000000 --- a/src/cmd/error.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2018-2019 Parity Technologies (UK) Ltd. -// This file is part of ink!. -// -// ink! is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ink! is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with ink!. If not, see . - -use std::{ - io::Error as IoError, - result::Result as StdResult, -}; - -use jsonrpc_core_client::RpcError; -use substrate_primitives::crypto::SecretStringError; -use subxt::Error as SubXtError; -use zip::result::ZipError; - -/// An error that can be encountered while executing commands. -#[derive(Debug, derive_more::From, derive_more::Display)] -pub enum CommandError { - Io(IoError), - #[display(fmt = "Command unimplemented")] - UnimplementedCommand, - #[display(fmt = "Abstraction layer unimplemented")] - UnimplementedAbstractionLayer, - Rpc(RpcError), - #[display(fmt = "Secret string error")] - SecretString(SecretStringError), - SubXt(SubXtError), - ZipError(ZipError), - BuildFailed, - #[display(fmt = "Error invoking `cargo metadata`")] - CargoMetadata(cargo_metadata::Error), - WasmDeserialization(parity_wasm::elements::Error), - #[display(fmt = "Optimizer failed")] - Optimizer(pwasm_utils::OptimizerError), - Other(String), -} - -impl From<&str> for CommandError { - fn from(error: &str) -> Self { - CommandError::Other(error.into()) - } -} - -/// Result type that has a `CommandError`. -pub type Result = StdResult; diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 1d47d596..44baa183 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -16,10 +16,9 @@ use std::path::PathBuf; +use anyhow::{Context, Result}; use cargo_metadata::MetadataCommand; -use crate::cmd::Result; - /// Executes build of the smart-contract which produces a wasm binary that is ready for deploying. /// /// It does so by invoking build by cargo and then post processing the final binary. @@ -38,7 +37,9 @@ pub(crate) fn execute_generate_metadata(dir: Option<&PathBuf>) -> Result dir, )?; - let cargo_metadata = MetadataCommand::new().exec()?; + let cargo_metadata = MetadataCommand::new() + .exec() + .context("Error invoking `cargo metadata`")?; let mut out_path = cargo_metadata.target_directory; out_path.push("metadata.json"); @@ -48,26 +49,21 @@ pub(crate) fn execute_generate_metadata(dir: Option<&PathBuf>) -> Result )) } +#[cfg(feature = "test-ci-only")] #[cfg(test)] mod tests { use crate::{ - cmd::{ - execute_generate_metadata, - execute_new, - tests::with_tmp_dir, - }, + cmd::{execute_generate_metadata, execute_new, tests::with_tmp_dir}, AbstractionLayer, }; - #[cfg(feature = "test-ci-only")] #[test] fn generate_metadata() { with_tmp_dir(|path| { execute_new(AbstractionLayer::Lang, "new_project", Some(path)) .expect("new project creation failed"); let working_dir = path.join("new_project"); - execute_generate_metadata(Some(&working_dir)) - .expect("generate metadata failed"); + execute_generate_metadata(Some(&working_dir)).expect("generate metadata failed"); let mut abi_file = working_dir; abi_file.push("target"); diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 00ae0680..b9fd558e 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -15,36 +15,24 @@ // along with ink!. If not, see . use std::{ - io::{ - self, - Write, - }, + io::{self, Write}, path::PathBuf, process::Command, }; +use anyhow::Result; + mod build; mod deploy; -mod error; mod metadata; mod new; pub(crate) use self::{ - build::execute_build, - deploy::execute_deploy, - error::{ - CommandError, - Result, - }, - metadata::execute_generate_metadata, + build::execute_build, deploy::execute_deploy, metadata::execute_generate_metadata, new::execute_new, }; -fn exec_cargo( - command: &str, - args: &[&'static str], - working_dir: Option<&PathBuf>, -) -> Result<()> { +fn exec_cargo(command: &str, args: &[&'static str], working_dir: Option<&PathBuf>) -> Result<()> { let mut cmd = Command::new("cargo"); let mut is_nightly_cmd = Command::new("cargo"); if let Some(dir) = working_dir { @@ -70,7 +58,7 @@ fn exec_cargo( // Dump the output streams produced by cargo into the stdout/stderr. io::stdout().write_all(&output.stdout)?; io::stderr().write_all(&output.stderr)?; - return Err(error::CommandError::BuildFailed) + anyhow::bail!("Build failed"); } Ok(()) diff --git a/src/cmd/new.rs b/src/cmd/new.rs index d9975702..e4ce869e 100644 --- a/src/cmd/new.rs +++ b/src/cmd/new.rs @@ -15,37 +15,25 @@ // along with ink!. If not, see . use std::{ - env, - fs, - io::{ - Cursor, - Read, - Seek, - SeekFrom, - Write, - }, + env, fs, + io::{Cursor, Read, Seek, SeekFrom, Write}, path::PathBuf, }; +use anyhow::Result; use heck::CamelCase as _; -use crate::{ - cmd::{ - CommandError, - Result, - }, - AbstractionLayer, -}; +use crate::AbstractionLayer; /// Initializes a project structure for the `lang` abstraction layer. fn initialize_for_lang(name: &str, target_dir: Option<&PathBuf>) -> Result { if name.contains('-') { - return Err("Contract names cannot contain hyphens".into()) + anyhow::bail!("Contract names cannot contain hyphens"); } let out_dir = target_dir.unwrap_or(&env::current_dir()?).join(name); if out_dir.join("Cargo.toml").exists() { - return Err(format!("A Cargo package already exists in {}", name).into()) + anyhow::bail!("A Cargo package already exists in {}", name); } if !out_dir.exists() { fs::create_dir(&out_dir)?; @@ -83,12 +71,12 @@ fn initialize_for_lang(name: &str, target_dir: Option<&PathBuf>) -> Result, ) -> Result { match layer { - AbstractionLayer::Core => Err(CommandError::UnimplementedAbstractionLayer), - AbstractionLayer::Model => Err(CommandError::UnimplementedAbstractionLayer), + AbstractionLayer::Core => Err(anyhow::anyhow!("Abstraction layer unimplemented")), + AbstractionLayer::Model => Err(anyhow::anyhow!("Abstraction layer unimplemented")), AbstractionLayer::Lang => initialize_for_lang(name, dir), } } @@ -125,10 +113,7 @@ pub(crate) fn execute_new( mod tests { use super::*; use crate::{ - cmd::{ - execute_new, - tests::with_tmp_dir, - }, + cmd::{execute_new, tests::with_tmp_dir}, AbstractionLayer, }; @@ -142,7 +127,7 @@ mod tests { ); assert_eq!( format!("{:?}", result), - r#"Err(Other("Contract names cannot contain hyphens"))"# + r#"Err(Contract names cannot contain hyphens)"# ) }); } @@ -155,7 +140,7 @@ mod tests { let result = execute_new(AbstractionLayer::Lang, name, Some(path)); assert_eq!( format!("{:?}", result), - r#"Err(Other("A Cargo package already exists in test_contract_cargo_project_already_exists"))"# + r#"Err(A Cargo package already exists in test_contract_cargo_project_already_exists)"# ) }); } @@ -170,7 +155,7 @@ mod tests { let result = execute_new(AbstractionLayer::Lang, name, Some(path)); assert_eq!( format!("{:?}", result), - r#"Err(Other("New contract file .gitignore already exists"))"# + r#"Err(New contract file .gitignore already exists)"# ) }); } diff --git a/src/main.rs b/src/main.rs index 0b986aca..1ada966a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,11 +16,10 @@ mod cmd; -use structopt::{ - clap, - StructOpt, -}; -use url::Url; +use std::{path::PathBuf, result::Result as StdResult}; + +use anyhow::Result; +use structopt::{clap, StructOpt}; #[derive(Debug, StructOpt)] #[structopt(bin_name = "cargo")] @@ -46,11 +45,6 @@ pub(crate) enum AbstractionLayer { Lang, } -use std::{ - path::PathBuf, - result::Result as StdResult, -}; - #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub(crate) struct InvalidAbstractionLayer; @@ -106,7 +100,7 @@ enum Command { parse(try_from_str), default_value = "ws://localhost:9944" )] - url: Url, + url: url::Url, /// Secret key URI for the account deploying the contract. #[structopt(name = "suri", long, short)] suri: String, @@ -118,7 +112,7 @@ enum Command { gas: u64, /// Path to wasm contract code, defaults to ./target/-pruned.wasm #[structopt(parse(from_os_str))] - wasm_path: Option, + wasm_path: Option, }, } @@ -132,8 +126,7 @@ fn main() { } } -fn exec(cmd: Command) -> cmd::Result { - use crate::cmd::CommandError; +fn exec(cmd: Command) -> Result { match &cmd { Command::New { layer, @@ -142,21 +135,19 @@ fn exec(cmd: Command) -> cmd::Result { } => cmd::execute_new(*layer, name, target_dir.as_ref()), Command::Build {} => cmd::execute_build(None), Command::GenerateMetadata {} => cmd::execute_generate_metadata(None), - Command::Test {} => Err(CommandError::UnimplementedCommand), + Command::Test {} => Err(anyhow::anyhow!("Command unimplemented")), Command::Deploy { url, suri, password, gas, wasm_path, - } => { - cmd::execute_deploy( - url.clone(), - suri, - password.as_ref().map(String::as_ref), - *gas, - wasm_path.as_ref(), - ) - } + } => cmd::execute_deploy( + url.clone(), + suri, + password.as_ref().map(String::as_ref), + *gas, + wasm_path.as_ref(), + ), } } -- GitLab