Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve readme and decode sub-command documentation #572

Merged
merged 8 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<p align="center">

Expand All @@ -17,15 +19,15 @@

<br/>

[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)
[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1/)&nbsp;&nbsp;•&nbsp;&nbsp;
[ink! Documentation Portal](https://ink.substrate.io)

<br/>
</div>

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

Expand All @@ -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`
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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).
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/extrinsics/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?);

Expand Down
6 changes: 3 additions & 3 deletions src/cmd/extrinsics/transcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down