From 79d7629582c2141b448995778acf792c8d53d3ad Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 08:35:45 +0200 Subject: [PATCH 1/8] Add Stack Exchange badge --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2d1426b6..50c1b4cf 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,14 @@ [![CI Status][a1]][a2] [![Latest Release][d1]][d2] +[![stack-exchange][s1]][s2] [a1]: https://gitlab.parity.io/parity/mirrors/cargo-contract/badges/master/pipeline.svg [a2]: https://gitlab.parity.io/parity/mirrors/cargo-contract/pipelines -[b2]: https://substrate.stackexchange.com/questions/tagged/ink?tab=Votes [d1]: https://img.shields.io/crates/v/cargo-contract.svg [d2]: https://crates.io/crates/cargo-contract +[s1]: https://img.shields.io/badge/click-white.svg?logo=StackExchange&label=ink!%20Support%20on%20StackExchange&labelColor=white&color=blue +[s2]: https://substrate.stackexchange.com/questions/tagged/ink?tab=Votes

@@ -24,7 +26,7 @@ More relevant links: -* Find answers to your questions by joining our [Stack Exchange][b2] community +* Find answers to your questions by joining our [Stack Exchange][s2] community * [`ink!`](https://github.com/paritytech/ink) ‒ The main ink! repository with smart contract examples * [Contracts UI](https://paritytech.github.io/contracts-ui/) ‒ Frontend for contract deployment and interaction * [Substrate Contracts Node](https://github.com/paritytech/substrate-contracts-node) ‒ Simple Substrate blockchain which includes smart contract functionality -- GitLab From ebaeb088be6433c406551e371b294367b0a5a8a5 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 08:46:53 +0200 Subject: [PATCH 2/8] Have IntelliJ shut up about whitespace at EOL --- CHANGELOG.md | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77622ff6..96de97eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Interact with contracts: upload, instantiate and call commands We added commands to upload, instantiate and call contracts! -This allows interacting with contracts on live chains with a compatible +This allows interacting with contracts on live chains with a compatible [`pallet-contracts`](https://github.com/paritytech/substrate/tree/master/frame/contracts). For command-line examples on how to use these commands see [#79](https://github.com/paritytech/cargo-contract/pull/79). diff --git a/README.md b/README.md index 50c1b4cf..d313462d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@
-[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/)  •   +[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/)  •   [ink! Documentation Portal](https://paritytech.github.io/ink-docs)
@@ -43,7 +43,7 @@ More relevant links: * [Arch Linux](https://archlinux.org/packages/community/x86_64/binaryen/): `pacman -S binaryen` * Windows: [binary releases are available](https://github.com/WebAssembly/binaryen/releases) - There's only an old version in your distributions package manager? Just use a + There's only an old version in your distributions package manager? Just use a [binary release](https://github.com/WebAssembly/binaryen/releases). * Step 3: Install `dylint` @@ -89,7 +89,7 @@ e.g. `cargo contract new --help`. Creates an initial smart contract with some scaffolding code into a new folder `my_contract` . -The contract contains the source code for the [`Flipper`](https://github.com/paritytech/ink/blob/master/examples/flipper/lib.rs) +The contract contains the source code for the [`Flipper`](https://github.com/paritytech/ink/blob/master/examples/flipper/lib.rs) contract, which is about the simplest "smart" contract you can build ‒ a `bool` which gets flipped from `true` to `false` through the `flip()` function. -- GitLab From c733584fe65d7ff1ca9c43657a7eb40a1e69b033 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 08:48:06 +0200 Subject: [PATCH 3/8] Make capitalization of log messages consistent --- src/cmd/extrinsics/call.rs | 2 +- src/cmd/extrinsics/transcode/mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/extrinsics/call.rs b/src/cmd/extrinsics/call.rs index 279c20c2..790a2146 100644 --- a/src/cmd/extrinsics/call.rs +++ b/src/cmd/extrinsics/call.rs @@ -84,7 +84,7 @@ impl CallCommand { load_metadata(self.extrinsic_opts.manifest_path.as_ref())?; let transcoder = ContractMessageTranscoder::new(&contract_metadata); let call_data = transcoder.encode(&self.message, &self.args)?; - log::debug!("message data: {:?}", hex::encode(&call_data)); + log::debug!("Message data: {:?}", hex::encode(&call_data)); let signer = super::pair_signer(self.extrinsic_opts.signer()?); diff --git a/src/cmd/extrinsics/transcode/mod.rs b/src/cmd/extrinsics/transcode/mod.rs index 6bb9a1b2..4b71b002 100644 --- a/src/cmd/extrinsics/transcode/mod.rs +++ b/src/cmd/extrinsics/transcode/mod.rs @@ -207,7 +207,7 @@ impl<'a> ContractMessageTranscoder<'a> { variant_index ) })?; - log::debug!("decoding contract event '{}'", event_spec.label()); + log::debug!("Decoding contract event '{}'", event_spec.label()); let mut args = Vec::new(); for arg in event_spec.args() { @@ -234,7 +234,7 @@ impl<'a> ContractMessageTranscoder<'a> { hex::encode(&msg_selector) ) })?; - log::debug!("decoding contract message '{}'", msg_spec.label()); + log::debug!("Decoding contract message '{}'", msg_spec.label()); let mut args = Vec::new(); for arg in msg_spec.args() { @@ -261,7 +261,7 @@ impl<'a> ContractMessageTranscoder<'a> { hex::encode(&msg_selector) ) })?; - log::debug!("decoding contract constructor '{}'", msg_spec.label()); + log::debug!("Decoding contract constructor '{}'", msg_spec.label()); let mut args = Vec::new(); for arg in msg_spec.args() { -- GitLab From bbe25e851c808561bd39698cd56279d7cc189df2 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 08:47:14 +0200 Subject: [PATCH 4/8] Improve docs for `decode` --- README.md | 8 ++++++++ src/cmd/decode.rs | 6 +++--- src/main.rs | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d313462d..8e5312b8 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,14 @@ Create an instance of a contract on chain. See [extrinsics](docs/extrinsics.md). Invoke a message on an existing contract on chain. See [extrinsics](docs/extrinsics.md). +##### `cargo contract decode` + +Decodes a contracts input or output data. + +This can be either an event, an invocation of a contract message, or an invocation of a contract constructor. + +The argument has to be given as hex-encoding, starting with `0x`. + ## License The entire code within this repository is licensed under the [GPLv3](LICENSE). diff --git a/src/cmd/decode.rs b/src/cmd/decode.rs index 0ec7ebf7..1b168e19 100644 --- a/src/cmd/decode.rs +++ b/src/cmd/decode.rs @@ -29,12 +29,12 @@ use anyhow::{ use colored::Colorize as _; #[derive(Debug, Clone, clap::Args)] -#[clap(name = "decode", about = "Decode input_data for a contract")] +#[clap(name = "decode", about = "Decodes the input or output data of a contract")] pub struct DecodeCommand { - /// Type of data + /// The type of data to encode. #[clap(arg_enum, short, long)] r#type: DataType, - /// The data to decode + /// The data to decode; this has to be a hex value starting with `0x`. #[clap(short, long)] data: String, } diff --git a/src/main.rs b/src/main.rs index 6f526a9c..eee56615 100644 --- a/src/main.rs +++ b/src/main.rs @@ -465,7 +465,7 @@ enum Command { /// Call a contract #[clap(name = "call")] Call(CallCommand), - /// Decode a contract input data + /// Decodes a contracts input or output data (supplied in hex-encoding) #[clap(name = "decode")] Decode(DecodeCommand), } -- GitLab From a67953749bb2396e28a122015a544d2a8bf2433b Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 09:04:02 +0200 Subject: [PATCH 5/8] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96de97eb..4e1b3134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Updated `cargo contract new` template dependencies to ink! `3` - [#569](https://github.com/paritytech/cargo-contract/pull/569) +- Improved documentation on how to invoke `cargo contract decode` - [#572](https://github.com/paritytech/cargo-contract/pull/572) ## [1.3.0] - 2022-05-09 -- GitLab From 31b91f4498614e0a9310933831c893a113d2c15b Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 09:06:42 +0200 Subject: [PATCH 6/8] Update link to `ink-docs` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e5312b8..dcdb40f2 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@
[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/)  •   -[ink! Documentation Portal](https://paritytech.github.io/ink-docs) +[ink! Documentation Portal](https://ink.substrate.io)
-- GitLab From bc221690bb221497e6c40b1b9f0451f627346d55 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 09:08:33 +0200 Subject: [PATCH 7/8] Apply `cargo fmt` --- src/cmd/decode.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/decode.rs b/src/cmd/decode.rs index 1b168e19..bff8527f 100644 --- a/src/cmd/decode.rs +++ b/src/cmd/decode.rs @@ -29,7 +29,10 @@ use anyhow::{ use colored::Colorize as _; #[derive(Debug, Clone, clap::Args)] -#[clap(name = "decode", about = "Decodes the input or output data of a contract")] +#[clap( + name = "decode", + about = "Decodes the input or output data of a contract" +)] pub struct DecodeCommand { /// The type of data to encode. #[clap(arg_enum, short, long)] -- GitLab From 2bb6482570f72916d9863e663821cf52ec3f9025 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 19 May 2022 09:10:06 +0200 Subject: [PATCH 8/8] Remove unnecessary monospace --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dcdb40f2..990c8613 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ More relevant links: * Find answers to your questions by joining our [Stack Exchange][s2] community -* [`ink!`](https://github.com/paritytech/ink) ‒ The main ink! repository with smart contract examples +* [ink!](https://github.com/paritytech/ink) ‒ The main ink! repository with smart contract examples * [Contracts UI](https://paritytech.github.io/contracts-ui/) ‒ Frontend for contract deployment and interaction * [Substrate Contracts Node](https://github.com/paritytech/substrate-contracts-node) ‒ Simple Substrate blockchain which includes smart contract functionality -- GitLab