From 661d90f97fdf97d550bc3f4f55a9420643df0dd7 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 12 May 2020 19:57:31 +0100 Subject: [PATCH 1/3] Update installation instructions --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cb4b2caf..7dd08940 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,13 @@ A CLI tool for helping setting up and managing WebAssembly smart contracts writt ## Installation -### Prerequisites +- **Prerequisites** -- **rust-src**: `rustup component add rust-src` -- **wasm-opt**: https://github.com/WebAssembly/binaryen#tools + - **rust-src**: `rustup component add rust-src` + - **wasm-opt**: https://github.com/WebAssembly/binaryen#tools -`cargo install --git https://github.com/paritytech/cargo-contract cargo-contract --force` - -Use the --force to ensure you are updated to the most recent cargo-contract version. +- **Install latest version from [crates.io](https://crates.io/crates/cargo-contract)** + - `cargo install cargo-contract` ## Usage -- GitLab From 131f9158b962c075d2ed24f555c97c9cd2998365 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 May 2020 08:38:07 +0100 Subject: [PATCH 2/3] Upgrade to latest subxt --- Cargo.toml | 2 +- src/cmd/deploy.rs | 22 ++++++++++++---- src/cmd/extrinsics.rs | 59 ------------------------------------------ src/cmd/instantiate.rs | 27 ++++++++++++++----- src/cmd/mod.rs | 4 +-- src/main.rs | 9 ++++--- 6 files changed, 45 insertions(+), 78 deletions(-) delete mode 100644 src/cmd/extrinsics.rs diff --git a/Cargo.toml b/Cargo.toml index 603a7be4..eb58e1b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ tempfile = "3.1.0" # dependencies for optional extrinsics feature async-std = { version = "1.5.0", optional = true } sp-core = { version = "2.0.0-alpha.3", optional = true } -subxt = { version = "0.5.0", package = "substrate-subxt", optional = true } +subxt = { version = "0.7.0", package = "substrate-subxt", optional = true } futures = { version = "0.3.2", optional = true } hex = { version = "0.4.0", optional = true } url = { version = "2.1.1", optional = true } diff --git a/src/cmd/deploy.rs b/src/cmd/deploy.rs index 733a93cc..db59fc51 100644 --- a/src/cmd/deploy.rs +++ b/src/cmd/deploy.rs @@ -18,7 +18,7 @@ use std::{fs, io::Read, path::PathBuf}; use anyhow::{Context, Result}; use sp_core::H256; -use subxt::contracts; +use subxt::{contracts::*, DefaultNodeRuntime, ClientBuilder}; use crate::{cmd::build, ExtrinsicOpts}; @@ -51,10 +51,23 @@ pub(crate) fn execute_deploy( extrinsic_opts: &ExtrinsicOpts, contract_wasm_path: Option<&PathBuf>, ) -> Result { - let gas_limit = extrinsic_opts.gas_limit.clone(); let code = load_contract_code(contract_wasm_path)?; - let put_code = contracts::put_code(gas_limit, code); - super::submit_extrinsic(extrinsic_opts, put_code, "Contracts", "CodeStored") + + async_std::task::block_on(async move { + let cli = ClientBuilder::::new() + .set_url(&extrinsic_opts.url.to_string()) + .build() + .await?; + let signer = extrinsic_opts.signer()?; + let xt = cli.xt(signer, None).await?; + + let events = xt.watch().put_code(&code).await?; + let code_stored = events + .code_stored()? + .ok_or(anyhow::anyhow!("Failed to find CodeStored event"))?; + + Ok(code_stored.code_hash) + }) } #[cfg(test)] @@ -86,7 +99,6 @@ mod tests { url, suri: "//Alice".into(), password: None, - gas_limit: 500_000, }; let result = execute_deploy(&extrinsic_opts, Some(&wasm_path)); diff --git a/src/cmd/extrinsics.rs b/src/cmd/extrinsics.rs deleted file mode 100644 index ffdabda4..00000000 --- a/src/cmd/extrinsics.rs +++ /dev/null @@ -1,59 +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 anyhow::Result; -use subxt::{ClientBuilder, DefaultNodeRuntime, ExtrinsicSuccess}; - -use crate::ExtrinsicOpts; - -/// Submits an extrinsic to a substrate node, waits for it to succeed and returns an event expected -/// to have been triggered by the extrinsic. -pub(crate) fn submit_extrinsic( - extrinsic_opts: &ExtrinsicOpts, - call: subxt::Call, - event_mod: &str, - event_name: &str, -) -> Result -where - C: codec::Encode, - E: codec::Decode, -{ - let result: Result> = async_std::task::block_on(async move { - let cli = ClientBuilder::::new() - .set_url(&extrinsic_opts.url.to_string()) - .build() - .await?; - let signer = extrinsic_opts.signer()?; - let xt = cli.xt(signer, None).await?; - let success = xt.watch().submit(call).await?; - Ok(success) - }); - - match result?.find_event::(event_mod, event_name) { - Some(Ok(hash)) => Ok(hash), - Some(Err(err)) => Err(anyhow::anyhow!( - "Failed to decode event '{} {}': {}", - event_mod, - event_name, - err - )), - None => Err(anyhow::anyhow!( - "Failed to find '{} {}' Event", - event_mod, - event_name - )), - } -} diff --git a/src/cmd/instantiate.rs b/src/cmd/instantiate.rs index 29a6d1c4..62aa1eee 100644 --- a/src/cmd/instantiate.rs +++ b/src/cmd/instantiate.rs @@ -15,7 +15,7 @@ // along with ink!. If not, see . use anyhow::Result; -use subxt::{balances::Balances, contracts, system::System, DefaultNodeRuntime}; +use subxt::{balances::Balances, contracts::*, system::System, ClientBuilder, DefaultNodeRuntime}; use crate::{ExtrinsicOpts, HexData}; @@ -27,13 +27,27 @@ use crate::{ExtrinsicOpts, HexData}; pub(crate) fn execute_instantiate( extrinsic_opts: &ExtrinsicOpts, endowment: ::Balance, + gas_limit: u64, code_hash: ::Hash, data: HexData, ) -> Result<::AccountId> { - let gas_limit = extrinsic_opts.gas_limit.clone(); - let instantiate = - contracts::instantiate::(endowment, gas_limit, code_hash, data.0); - super::submit_extrinsic(extrinsic_opts, instantiate, "Contracts", "Instantiated") + async_std::task::block_on(async move { + let cli = ClientBuilder::::new() + .set_url(&extrinsic_opts.url.to_string()) + .build() + .await?; + let signer = extrinsic_opts.signer()?; + let xt = cli.xt(signer, None).await?; + + let events = xt + .watch() + .instantiate(endowment, gas_limit, &code_hash, &data.0).await?; + let instantiated = events + .instantiated()? + .ok_or(anyhow::anyhow!("Failed to find Instantiated event"))?; + + Ok(instantiated.contract) + }) } #[cfg(test)] @@ -65,14 +79,15 @@ mod tests { url, suri: "//Alice".into(), password: None, - gas_limit: 500_000, }; let code_hash = execute_deploy(&extrinsic_opts, Some(&wasm_path)).expect("Deploy should succeed"); + let gas_limit = 500_000_000; let result = super::execute_instantiate( &extrinsic_opts, 100000000000000, + gas_limit, code_hash, HexData::default(), ); diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 5b8c1b1e..48abddf5 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -18,8 +18,6 @@ mod build; #[cfg(feature = "extrinsics")] mod deploy; #[cfg(feature = "extrinsics")] -mod extrinsics; -#[cfg(feature = "extrinsics")] mod instantiate; mod metadata; mod new; @@ -29,5 +27,5 @@ pub(crate) use self::{ }; #[cfg(feature = "extrinsics")] pub(crate) use self::{ - deploy::execute_deploy, extrinsics::submit_extrinsic, instantiate::execute_instantiate, + deploy::execute_deploy, instantiate::execute_instantiate, }; diff --git a/src/main.rs b/src/main.rs index 7bd4cf92..f7808a0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,9 +76,6 @@ pub(crate) struct ExtrinsicOpts { /// Password for the secret key #[structopt(name = "password", long, short)] password: Option, - /// Maximum amount of gas to be used for this command - #[structopt(name = "gas", long, default_value = "500000")] - gas_limit: u64, } #[cfg(feature = "extrinsics")] @@ -160,6 +157,9 @@ enum Command { /// Transfers an initial balance to the instantiated contract #[structopt(name = "endowment", long, default_value = "0")] endowment: u128, + /// Maximum amount of gas to be used for this command + #[structopt(name = "gas", long, default_value = "500000000")] + gas_limit: u64, /// The hash of the smart contract code already uploaded to the chain #[structopt(long, parse(try_from_str = parse_code_hash))] code_hash: H256, @@ -217,10 +217,11 @@ fn exec(cmd: Command) -> Result { extrinsic_opts, endowment, code_hash, + gas_limit, data, } => { let contract_account = - cmd::execute_instantiate(extrinsic_opts, *endowment, *code_hash, data.clone())?; + cmd::execute_instantiate(extrinsic_opts, *endowment, *gas_limit, *code_hash, data.clone())?; Ok(format!("Contract account: {:?}", contract_account)) } } -- GitLab From 5633fede240932f6229439b5070837087fe42924 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 13 May 2020 10:26:38 +0100 Subject: [PATCH 3/3] Fmt --- Cargo.lock | 180 +++++++++++++++++++++++++++++++++++++---- src/cmd/deploy.rs | 2 +- src/cmd/instantiate.rs | 3 +- src/cmd/mod.rs | 4 +- src/main.rs | 9 ++- 5 files changed, 175 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7ab9798..0c3b3935 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,7 +126,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce6977f57fa68da77ffe5542950d47e9c23d65f5bc7cb0a9f8700996913eec7" dependencies = [ - "futures", + "futures 0.3.5", "rustls", "webpki", "webpki-roots", @@ -298,7 +298,7 @@ dependencies = [ "cargo_metadata", "colored", "env_logger", - "futures", + "futures 0.3.5", "heck", "hex", "log", @@ -312,7 +312,7 @@ dependencies = [ "substrate-subxt", "tempfile", "toml", - "url", + "url 2.1.1", "wabt", "walkdir", "which", @@ -760,6 +760,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +[[package]] +name = "futures" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" + [[package]] name = "futures" version = "0.3.5" @@ -854,6 +860,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" dependencies = [ + "futures 0.1.29", "futures-channel", "futures-core", "futures-io", @@ -1072,6 +1079,17 @@ dependencies = [ "want", ] +[[package]] +name = "idna" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.2.0" @@ -1160,6 +1178,68 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "jsonrpc-client-transports" +version = "14.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2307a7e78cf969759e390a8a2151ea12e783849a45bb00aa871b468ba58ea79e" +dependencies = [ + "failure", + "futures 0.1.29", + "jsonrpc-core", + "jsonrpc-pubsub", + "log", + "serde", + "serde_json", + "url 1.7.2", +] + +[[package]] +name = "jsonrpc-core" +version = "14.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25525f6002338fb4debb5167a89a0b47f727a5a48418417545ad3429758b7fec" +dependencies = [ + "futures 0.1.29", + "log", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "jsonrpc-core-client" +version = "14.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f9382e831a6d630c658df103aac3f971da096deb57c136ea2b760d3b4e3f9f" +dependencies = [ + "jsonrpc-client-transports", +] + +[[package]] +name = "jsonrpc-derive" +version = "14.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8609af8f63b626e8e211f52441fcdb6ec54f1a446606b10d5c89ae9bf8a20058" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "jsonrpc-pubsub" +version = "14.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4ca5e391d6c6a2261d4adca029f427fe63ea546ad6cef2957c654c08495ec16" +dependencies = [ + "jsonrpc-core", + "log", + "parking_lot 0.10.2", + "serde", +] + [[package]] name = "jsonrpsee" version = "0.1.0" @@ -1171,7 +1251,7 @@ dependencies = [ "bs58", "bytes", "fnv", - "futures", + "futures 0.3.5", "futures-timer 3.0.2", "globset", "hashbrown 0.7.2", @@ -1189,7 +1269,7 @@ dependencies = [ "thiserror", "tokio", "unicase", - "url", + "url 2.1.1", "webpki", ] @@ -1620,6 +1700,12 @@ dependencies = [ "crypto-mac", ] +[[package]] +name = "percent-encoding" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -2001,6 +2087,31 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "sc-rpc-api" +version = "0.8.0-alpha.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27aa7d70aec2be0967110b5df9a11ac3aa76fe4c8576455c266d3135d8fe63a" +dependencies = [ + "derive_more", + "futures 0.3.5", + "jsonrpc-core", + "jsonrpc-core-client", + "jsonrpc-derive", + "jsonrpc-pubsub", + "log", + "parity-scale-codec", + "parking_lot 0.10.2", + "serde", + "serde_json", + "sp-chain-spec", + "sp-core", + "sp-rpc", + "sp-runtime", + "sp-transaction-pool", + "sp-version", +] + [[package]] name = "schnorrkel" version = "0.9.1" @@ -2129,7 +2240,7 @@ checksum = "1c9dab3f95c9ebdf3a88268c19af668f637a3c5039c2c56ff2d40b1b2d64a25b" dependencies = [ "base64 0.11.0", "bytes", - "futures", + "futures 0.3.5", "http", "httparse", "log", @@ -2197,6 +2308,16 @@ dependencies = [ "sp-std", ] +[[package]] +name = "sp-chain-spec" +version = "2.0.0-alpha.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2997456fa5b605fec06c5f2267a0e7cb44708b210548b1a557ce89b07bc04211" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "sp-core" version = "2.0.0-alpha.7" @@ -2207,7 +2328,7 @@ dependencies = [ "blake2-rfc", "byteorder", "ed25519-dalek", - "futures", + "futures 0.3.5", "hash-db", "hash256-std-hasher", "hex", @@ -2281,7 +2402,7 @@ version = "2.0.0-alpha.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ede88516c08b2070ad2b49f5e4ebff896910b11c0a63184eb5c20b0b604b8655" dependencies = [ - "futures", + "futures 0.3.5", "hash-db", "libsecp256k1", "log", @@ -2434,7 +2555,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "008ceb7db9fe134ced1e67226edb36db783e5f9434ca3544efcc94d8db9e1c99" dependencies = [ "derive_more", - "futures", + "futures 0.3.5", "log", "parity-scale-codec", "serde", @@ -2464,7 +2585,7 @@ version = "2.0.0-alpha.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3aa5acc361bb7ccab3940584d9c032a587b8b4414cd949a92a7b391e6f39384" dependencies = [ - "futures", + "futures 0.3.5", "futures-core", "lazy_static", "prometheus", @@ -2572,19 +2693,20 @@ dependencies = [ [[package]] name = "substrate-subxt" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f78ce510e65aec79e5b08452c228714718298d07bb2c7f6672bbef6cb7e818fc" +checksum = "3536f9a71476d53d824008f9c546d9bdbc6eae89abdababa201f0f309d435261" dependencies = [ "frame-metadata", "frame-support", - "futures", + "futures 0.3.5", "hex", "jsonrpsee", "log", "num-traits", "pallet-indices", "parity-scale-codec", + "sc-rpc-api", "serde", "serde_json", "sp-core", @@ -2592,8 +2714,23 @@ dependencies = [ "sp-runtime", "sp-transaction-pool", "sp-version", + "substrate-subxt-proc-macro", "thiserror", - "url", + "url 2.1.1", +] + +[[package]] +name = "substrate-subxt-proc-macro" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e322605091419009a2d2cad6313d397624574690d670b7600654078b5dbf99ef" +dependencies = [ + "heck", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", + "synstructure", ] [[package]] @@ -2930,15 +3067,26 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "url" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +dependencies = [ + "idna 0.1.5", + "matches", + "percent-encoding 1.0.1", +] + [[package]] name = "url" version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" dependencies = [ - "idna", + "idna 0.2.0", "matches", - "percent-encoding", + "percent-encoding 2.1.0", ] [[package]] diff --git a/src/cmd/deploy.rs b/src/cmd/deploy.rs index db59fc51..b85ab894 100644 --- a/src/cmd/deploy.rs +++ b/src/cmd/deploy.rs @@ -18,7 +18,7 @@ use std::{fs, io::Read, path::PathBuf}; use anyhow::{Context, Result}; use sp_core::H256; -use subxt::{contracts::*, DefaultNodeRuntime, ClientBuilder}; +use subxt::{contracts::*, ClientBuilder, DefaultNodeRuntime}; use crate::{cmd::build, ExtrinsicOpts}; diff --git a/src/cmd/instantiate.rs b/src/cmd/instantiate.rs index 62aa1eee..4f1f83c3 100644 --- a/src/cmd/instantiate.rs +++ b/src/cmd/instantiate.rs @@ -41,7 +41,8 @@ pub(crate) fn execute_instantiate( let events = xt .watch() - .instantiate(endowment, gas_limit, &code_hash, &data.0).await?; + .instantiate(endowment, gas_limit, &code_hash, &data.0) + .await?; let instantiated = events .instantiated()? .ok_or(anyhow::anyhow!("Failed to find Instantiated event"))?; diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 48abddf5..c47ca2c2 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -26,6 +26,4 @@ pub(crate) use self::{ build::execute_build, metadata::execute_generate_metadata, new::execute_new, }; #[cfg(feature = "extrinsics")] -pub(crate) use self::{ - deploy::execute_deploy, instantiate::execute_instantiate, -}; +pub(crate) use self::{deploy::execute_deploy, instantiate::execute_instantiate}; diff --git a/src/main.rs b/src/main.rs index f7808a0a..870d711c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -220,8 +220,13 @@ fn exec(cmd: Command) -> Result { gas_limit, data, } => { - let contract_account = - cmd::execute_instantiate(extrinsic_opts, *endowment, *gas_limit, *code_hash, data.clone())?; + let contract_account = cmd::execute_instantiate( + extrinsic_opts, + *endowment, + *gas_limit, + *code_hash, + data.clone(), + )?; Ok(format!("Contract account: {:?}", contract_account)) } } -- GitLab