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

refactor: Umbrella Iroha CLI #5282

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion .github/workflows/iroha2-dev-pr-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build wasm libs
run: mold --run cargo run --bin iroha_wasm_builder -- build ./wasm/libs/default_executor --optimize --out-file ${{ env.DEFAULTS_DIR }}/executor.wasm
run: mold --run cargo run --bin kagami -- wasm build ./wasm/libs/default_executor --optimize --out-file ${{ env.DEFAULTS_DIR }}/executor.wasm
- name: Upload executor to reuse in other jobs
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ It can be done by running:

```bash
# compile executor without optimizations
cargo run --bin iroha_wasm_builder -- build ./path/to/executor --out-file executor.wasm
cargo run --bin kagami -- wasm build ./path/to/executor --out-file executor.wasm
```

With profiling feature enabled Iroha exposes endpoint to scrap pprof profiles:
Expand Down
42 changes: 11 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ iroha_executor_data_model = { version = "=2.0.0-rc.1.0", path = "crates/iroha_ex
iroha_test_network = { version = "=2.0.0-rc.1.0", path = "crates/iroha_test_network" }
iroha_test_samples = { version = "=2.0.0-rc.1.0", path = "crates/iroha_test_samples" }

iroha_swarm = { version = "=2.0.0-rc.1.0", path = "crates/iroha_swarm" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about directly specifying this as a iroha_kagami dependency, not as a workspace dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It is not needed here unless used externally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inquire also would be removed from workspace dependencies


proc-macro2 = "1.0.86"
syn = { version = "2.0.72", default-features = false }
quote = "1.0.36"
Expand Down Expand Up @@ -85,6 +87,7 @@ owo-colors = "4.1.0"
supports-color = "2.1.0"
spinoff = "0.8.0"
humantime = "2.1.0"
inquire = "0.6.2"

criterion = "0.5.1"
expect-test = "1.5.0"
Expand Down
35 changes: 0 additions & 35 deletions crates/iroha_codec/Cargo.toml

This file was deleted.

16 changes: 16 additions & 0 deletions crates/iroha_kagami/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,29 @@ iroha_schema_gen.workspace = true
iroha_primitives.workspace = true
iroha_genesis.workspace = true
iroha_test_samples.workspace = true
iroha_schema.workspace = true
iroha_core.workspace = true
iroha_version.workspace = true
iroha_swarm.workspace = true
iroha_wasm_builder.workspace = true

clap = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
spinoff = { workspace = true, features = ["binary"] }
owo-colors = { workspace = true, features = ["supports-colors"] }
color-eyre.workspace = true
serde_json.workspace = true
derive_more.workspace = true
parity-scale-codec.workspace = true
inquire.workspace = true

[build-dependencies]
iroha_data_model = { workspace = true }

parity-scale-codec = { workspace = true }
serde_json = { workspace = true, features = ["std"]}
serde = { workspace = true }
color-eyre = { workspace = true }

[[bin]]
name = "kagami"
Expand Down
13 changes: 12 additions & 1 deletion crates/iroha_kagami/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ This will place `kagami` inside the `target/debug/` directory (from the root of

## Usage

As it is an internal tool with no stable API, we decided to move all the documentation into the CLI help messages and keep it up to date in a single place.
### Subcommands

| Command | Description |
|-----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| `crypto` | Generate cryptographic key pairs using the given algorithm and either private key or seed |
| `schema` | Generate the schema used for code generation in Iroha SDKs |
| [`genesis`](docs/genesis.md) | Commands related to genesis |
| [`codec`](docs/codec.md) | Commands related to codec |
| [`kura`](docs/kura.md) | Commands related to block inspection |
| [`swarm`](docs/swarm.md) | Commands related to Docker Compose configuration generation |
| [`wasm`](docs/wasm.md) | Commands related to building smartcontracts |
| `help` | Print the help message for the tool or a subcommand

Run:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{fs, path::PathBuf};

use eyre::Result;
use color_eyre::eyre::Result;
use iroha_data_model::{account::NewAccount, domain::NewDomain, prelude::*};
use parity_scale_codec::Encode;
use serde::de::DeserializeOwned;
Expand All @@ -20,7 +20,7 @@ where
T: Encode + DeserializeOwned,
{
let mut path_to = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path_to.push("samples/");
path_to.push("samples/codec");
path_to.push(filename);

let path_to_json = path_to.with_extension("json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# Parity Scale Decoder Tool
# Parity Scale Decoder

This tool helps you decode **Iroha 2** data types from binaries using [Parity Scale Codec](https://github.com/paritytech/parity-scale-codec).

## Build

To build the tool, run:

```bash
cargo build --bin iroha_codec
```

## Usage

Run Parity Scale Decoder Tool:

```bash
iroha_codec <SUBCOMMAND>
```
These commands help you decode **Iroha 2** data types from binaries using [Parity Scale Codec](https://github.com/paritytech/parity-scale-codec).

### Subcommands

Expand All @@ -33,7 +17,7 @@ iroha_codec <SUBCOMMAND>
To list all supported data types, run from the project main directory:

```bash
./target/debug/iroha_codec list-types
kagami codec list-types
```

<details> <summary> Expand to see expected output</summary>
Expand Down Expand Up @@ -66,21 +50,21 @@ These commands require `--type` argument. If data type is not known, [`scale-to-
* Decode the specified data type from a binary:

```bash
./target/debug/iroha_codec scale-to-json --input <path_to_binary> --type <type>
kagami codec scale-to-json --input <path_to_binary> --type <type>
```

### `scale-to-json` and `json-to-scale` usage examples

* Decode the `NewAccount` data type from the `samples/account.bin` binary:

```bash
./target/debug/iroha_codec scale-to-json --input iroha_codec/samples/account.bin --type NewAccount
kagami codec scale-to-json --input crates/iroha_kagami/src/codec/samples/account.bin --type NewAccount
```

* Encode the `NewAccount` data type from the `samples/account.json`:

```bash
./target/debug/iroha_codec json-to-scale --input iroha_codec/samples/account.json --output result.bin --type NewAccount
kagami codec json-to-scale --input crates/iroha_kagami/src/codec/samples/account.json --output result.bin --type NewAccount
```

## `scale-to-rust`
Expand All @@ -95,25 +79,25 @@ Decode the data type from a given binary.
* Decode the specified data type from a binary:

```bash
./target/debug/iroha_codec scale-to-rust <path_to_binary> --type <type>
kagami codec scale-to-rust <path_to_binary> --type <type>
```

* If you are not sure which data type is encoded in the binary, run the tool without the `--type` option:

```bash
./target/debug/iroha_codec scale-to-rust <path_to_binary>
kagami codec scale-to-rust <path_to_binary>
```

### `scale-to-rust` usage examples

* Decode the `NewAccount` data type from the `samples/account.bin` binary:

```bash
./target/debug/iroha_codec scale-to-rust iroha_codec/samples/account.bin --type NewAccount
kagami codec scale-to-rust crates/iroha_kagami/src/codec/samples/account.bin --type NewAccount
```

* Decode the `NewDomain` data type from the `samples/domain.bin` binary:

```bash
./target/debug/iroha_codec scale-to-rust iroha_codec/samples/domain.bin --type NewDomain
kagami codec scale-to-rust crates/iroha_kagami/src/codec/samples/domain.bin --type NewDomain
```
11 changes: 11 additions & 0 deletions crates/iroha_kagami/docs/genesis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Genesis

These commands help to organize genesis configurations

### Subcommands

| Command | Description |
|-----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| `sign` | Sign the genesis block |
| `generate` | Generate a genesis configuration and standard-output in JSON format |
| `help` | Print the help message for the tool or a subcommand |
Loading
Loading