Unverified Commit 2beb8311 authored by Michael Müller's avatar Michael Müller Committed by GitHub
Browse files

Improve readme and `decode` sub-command documentation (#572)

* Add Stack Exchange badge

* Have IntelliJ shut up about whitespace at EOL

* Make capitalization of log messages consistent

* Improve docs for `decode`

* Update changelog

* Update link to `ink-docs`

* Apply `cargo fmt`

* Remove unnecessary monospace
parent 8ea7a77d
Pipeline #194623 passed with stages
in 11 minutes and 55 seconds
...@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Updated `cargo contract new` template dependencies to ink! `3` - [#569](https://github.com/paritytech/cargo-contract/pull/569) - 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 ## [1.3.0] - 2022-05-09
...@@ -53,7 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -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 ### Interact with contracts: upload, instantiate and call commands
We added commands to upload, instantiate and call contracts! 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). [`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). For command-line examples on how to use these commands see [#79](https://github.com/paritytech/cargo-contract/pull/79).
......
...@@ -3,12 +3,14 @@ ...@@ -3,12 +3,14 @@
[![CI Status][a1]][a2] [![CI Status][a1]][a2]
[![Latest Release][d1]][d2] [![Latest Release][d1]][d2]
[![stack-exchange][s1]][s2]
[a1]: https://gitlab.parity.io/parity/mirrors/cargo-contract/badges/master/pipeline.svg [a1]: https://gitlab.parity.io/parity/mirrors/cargo-contract/badges/master/pipeline.svg
[a2]: https://gitlab.parity.io/parity/mirrors/cargo-contract/pipelines [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 [d1]: https://img.shields.io/crates/v/cargo-contract.svg
[d2]: https://crates.io/crates/cargo-contract [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
<p align="center"> <p align="center">
...@@ -17,15 +19,15 @@ ...@@ -17,15 +19,15 @@
<br/> <br/>
[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/)&nbsp;&nbsp;&nbsp;&nbsp; [Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/)&nbsp;&nbsp;&nbsp;&nbsp;
[ink! Documentation Portal](https://paritytech.github.io/ink-docs) [ink! Documentation Portal](https://ink.substrate.io)
<br/> <br/>
</div> </div>
More relevant links: 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 * [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 * [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 * [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: ...@@ -41,7 +43,7 @@ More relevant links:
* [Arch Linux](https://archlinux.org/packages/community/x86_64/binaryen/): `pacman -S binaryen` * [Arch Linux](https://archlinux.org/packages/community/x86_64/binaryen/): `pacman -S binaryen`
* Windows: [binary releases are available](https://github.com/WebAssembly/binaryen/releases) * 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). [binary release](https://github.com/WebAssembly/binaryen/releases).
* Step 3: Install `dylint` * Step 3: Install `dylint`
...@@ -87,7 +89,7 @@ e.g. `cargo contract new --help`. ...@@ -87,7 +89,7 @@ e.g. `cargo contract new --help`.
Creates an initial smart contract with some scaffolding code into a new Creates an initial smart contract with some scaffolding code into a new
folder `my_contract` . 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 contract, which is about the simplest "smart" contract you can build ‒ a `bool` which gets flipped
from `true` to `false` through the `flip()` function. 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). ...@@ -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). 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 ## License
The entire code within this repository is licensed under the [GPLv3](LICENSE). The entire code within this repository is licensed under the [GPLv3](LICENSE).
......
...@@ -29,12 +29,15 @@ use anyhow::{ ...@@ -29,12 +29,15 @@ use anyhow::{
use colored::Colorize as _; use colored::Colorize as _;
#[derive(Debug, Clone, clap::Args)] #[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 { pub struct DecodeCommand {
/// Type of data /// The type of data to encode.
#[clap(arg_enum, short, long)] #[clap(arg_enum, short, long)]
r#type: DataType, r#type: DataType,
/// The data to decode /// The data to decode; this has to be a hex value starting with `0x`.
#[clap(short, long)] #[clap(short, long)]
data: String, data: String,
} }
......
...@@ -84,7 +84,7 @@ impl CallCommand { ...@@ -84,7 +84,7 @@ impl CallCommand {
load_metadata(self.extrinsic_opts.manifest_path.as_ref())?; load_metadata(self.extrinsic_opts.manifest_path.as_ref())?;
let transcoder = ContractMessageTranscoder::new(&contract_metadata); let transcoder = ContractMessageTranscoder::new(&contract_metadata);
let call_data = transcoder.encode(&self.message, &self.args)?; 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()?); let signer = super::pair_signer(self.extrinsic_opts.signer()?);
......
...@@ -207,7 +207,7 @@ impl<'a> ContractMessageTranscoder<'a> { ...@@ -207,7 +207,7 @@ impl<'a> ContractMessageTranscoder<'a> {
variant_index variant_index
) )
})?; })?;
log::debug!("decoding contract event '{}'", event_spec.label()); log::debug!("Decoding contract event '{}'", event_spec.label());
let mut args = Vec::new(); let mut args = Vec::new();
for arg in event_spec.args() { for arg in event_spec.args() {
...@@ -234,7 +234,7 @@ impl<'a> ContractMessageTranscoder<'a> { ...@@ -234,7 +234,7 @@ impl<'a> ContractMessageTranscoder<'a> {
hex::encode(&msg_selector) 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(); let mut args = Vec::new();
for arg in msg_spec.args() { for arg in msg_spec.args() {
...@@ -261,7 +261,7 @@ impl<'a> ContractMessageTranscoder<'a> { ...@@ -261,7 +261,7 @@ impl<'a> ContractMessageTranscoder<'a> {
hex::encode(&msg_selector) 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(); let mut args = Vec::new();
for arg in msg_spec.args() { for arg in msg_spec.args() {
......
...@@ -465,7 +465,7 @@ enum Command { ...@@ -465,7 +465,7 @@ enum Command {
/// Call a contract /// Call a contract
#[clap(name = "call")] #[clap(name = "call")]
Call(CallCommand), Call(CallCommand),
/// Decode a contract input data /// Decodes a contracts input or output data (supplied in hex-encoding)
#[clap(name = "decode")] #[clap(name = "decode")]
Decode(DecodeCommand), Decode(DecodeCommand),
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment