diff --git a/CHANGELOG.md b/CHANGELOG.md index 77622ff6f..4e1b3134c 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 @@ -53,7 +54,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 2d1426b62..990c86133 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
@@ -17,15 +19,15 @@
-[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/) •
-[ink! Documentation Portal](https://paritytech.github.io/ink-docs)
+[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/) •
+[ink! Documentation Portal](https://ink.substrate.io)
More relevant links:
-* Find answers to your questions by joining our [Stack Exchange][b2] community
-* [`ink!`](https://github.com/paritytech/ink) ‒ The main ink! repository with smart contract examples
+* 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
@@ -41,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`
@@ -87,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.
@@ -125,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 0ec7ebf7c..bff8527f3 100644
--- a/src/cmd/decode.rs
+++ b/src/cmd/decode.rs
@@ -29,12 +29,15 @@ 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/cmd/extrinsics/call.rs b/src/cmd/extrinsics/call.rs
index 279c20c24..790a2146c 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 6bb9a1b2f..4b71b0029 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() {
diff --git a/src/main.rs b/src/main.rs
index 6f526a9cf..eee566156 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),
}