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

Sync docs between book and code #269

Merged
merged 3 commits into from
Nov 2, 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
4 changes: 2 additions & 2 deletions bin/subalfred/src/command/state/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use subalfred_core::{state, system};
///
/// If the key already exists, it will be overwritten.
///
/// # Examples
/// # Example
/// ```sh
/// # Calculate the WASM code key.
/// subalfred convert ascii2hex ':code'
/// # "0x3a636f6465"
/// # Override the WASM code.
/// subalfred state insert chain_spec.json --key 0x3a636f6465 --with-file runtime.compact.compressed.wasm
/// subalfred state insert chain-spec.json --key 0x3a636f6465 --with-file runtime.compact.compressed.wasm
/// ```
#[derive(Debug, Args)]
#[command(group(
Expand Down
9 changes: 3 additions & 6 deletions doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@

# User Guide
- [Installation](user/installation.md)
- [Command Line Tool](user/cli/README.md)
- [Command](user/cli/README.md)
- [check](user/cli/check.md)
- [convert](user/cli/convert.md)
- [get](user/cli/get.md)
- [hash](user/cli/hash.md)
- [key](user/cli/key.md)
- [rpc](user/cli/rpc.md)
- [state](user/cli/state.md)
- [storage-key](user/cli/storage-key.md)
- [workspace](user/cli/workspace.md)

# Reference Guide
- [todo]()
- [todo]()
- [todo]()
- [todo]()
# Reference Guide(TODO)
56 changes: 42 additions & 14 deletions doc/src/user/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
# Command Line Tool
The `subalfred` command-line tool is used to create and build books.
After you have [installed](../installation.md) `subalfred`, you can run the `subalfred help` command in your terminal to view the available commands.

This following sections provide in-depth information on the different commands available.

* [`subalfred check`](check.md)
* [`subalfred convert`](convert.md)
* [`subalfred get`](get.md)
* [`subalfred hash`](hash.md)
* [`subalfred key`](key.md)
* [`subalfred state`](state.md)
* [`subalfred storage-key`](storage-key.md)
* [`subalfred workspace`](workspace.md)
# Command `subalfred`
```
Your Substrate Alfred.

Usage: subalfred [OPTIONS] <COMMAND>

Commands:
check
Substrate development checkers
convert
Data style converters
get
Substrate-link node getter
hash
Hash the hex with the specific hasher(hash algorithm)
key
Calculate the public key/SS58 address of the SS58 address/public key
rpc
Send a RPC request to the node's HTTP RPC endpoint
state
A set of tools to process Substrate-like chain state
storage-key
Calculate the storage key of the storage item
workspace
Workspace manager
help
Print this message or the help of the given subcommand(s)

Options:
-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)

-V, --version
Print version information
```
311 changes: 192 additions & 119 deletions doc/src/user/cli/check.md

Large diffs are not rendered by default.

144 changes: 130 additions & 14 deletions doc/src/user/cli/convert.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,98 @@
# The Convert Command
A set of really useful convertors.
# Command `convert`
```
Data style converters

Usage: subalfred convert [OPTIONS] <COMMAND>

Commands:
ascii2hex
Convert ascii to hex
bytes-style
Convert bytes between several different styles
bytes2hex
Convert bytes to hex
hex2bytes
Convert hex to bytes
help
Print this message or the help of the given subcommand(s)

Options:
-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)
```

## Command `convert ascii2hex`
```
Convert ascii to hex

Usage: subalfred convert ascii2hex [OPTIONS] <ASCII DATA>

Arguments:
<ASCII DATA>
Ascii data input

## Ascii to Hex
Convert the ascii to hex.
Options:
-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

### Examples
This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)

```

### Example
```sh
subalfred convert ascii2hex AurevoirXavier
```
```
0x41757265766f6972586176696572
```

## Bytes Style
Convert the bytes between several different styles.
## Command `convert bytes-style`
```
Convert bytes between several different styles

Usage: subalfred convert bytes-style [OPTIONS] --from <BYTES STYLE> --to <BYTES STYLE> <BYTES>

Arguments:
<BYTES>
Bytes data input

Options:
--from <BYTES STYLE>
Origin style

[possible values: byte-string-literal, vec-string]

--to <BYTES STYLE>
Target style

### Examples
[possible values: byte-string-literal, vec-string]

-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)
```


### Example
#### From Vec String to Byte String Literal
```sh
subalfred convert bytes-style --from vec-string --to byte-string-literal "[65, 117, 114, 101, 118, 111, 105, 114, 88, 97, 118, 105, 101, 114]"
Expand Down Expand Up @@ -45,23 +121,63 @@ subalfred convert bytes-style --from byte-string-literal --to vec-string "\x01\x
[1, 1, 1, 1]
```

## Command `convert bytes2hex`
```
Convert bytes to hex

Usage: subalfred convert bytes2hex [OPTIONS] <BYTES>

Arguments:
<BYTES>
Bytes data input.

Example: `[0, 0, 0, 0]`.

Options:
-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

## Bytes to Hex
Convert the bytes to hex.
[default: info]

### Examples
-h, --help
Print help information (use `-h` for a summary)
```

### Example
```sh
subalfred convert bytes2hex "[65, 117, 114, 101, 118, 111, 105, 114, 88, 97, 118, 105, 101, 114]"
```
```
0x41757265766f6972586176696572
```

## Hex to Bytes
Convert the hex to bytes.
## Command `convert hex2bytes`
```
Convert hex to bytes

Usage: subalfred convert hex2bytes [OPTIONS] <HEX>

Arguments:
<HEX>
Hex input.

Example: `0x00000000`.

Options:
-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)
```

### Examples
### Example
```sh
subalfred convert hex2bytes 0x41757265766f6972586176696572
```
Expand Down
59 changes: 54 additions & 5 deletions doc/src/user/cli/get.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
# The Get Command
Currently, there's only one subcommand available.
# Command `get`
```
Substrate-link node getter

Usage: subalfred get [OPTIONS] <COMMAND>

Commands:
runtime-upgrade-block
Get the runtime upgrade block
help
Print this message or the help of the given subcommand(s)

Options:
-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)
```

## Command `get runtime-upgrade-block`
```
Get the runtime upgrade block.

Using the dichotomy algorithm to find it out. This operation will fail if the runtime version does not existed.

## Runtime Upgrade Block
Usage: subalfred get runtime-upgrade-block [OPTIONS] --uri <URI> <VERSION>

Arguments:
<VERSION>
At this runtime version

Options:
--uri <URI>
Node's WS RPC endpoint

[default: ws://localhost:9944]

-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)
```

### Episode 1
The original question was from [stackexchange](https://substrate.stackexchange.com/questions/3861/how-do-you-tell-which-block-number-the-last-runtime-upgrade-happened-on-a-chain).

Yep, I think that is an interesting question.
So, I implemented this method.

It uses dichotomy algorithm, the whole process takes:

$$\log_{2} BlockHeight\times Requests$$

### Examples
### Example
```sh
subalfred get runtime-upgrade-block 9100 --uri wss://rpc.polkadot.io -lsubalfred_core::node
```
Expand Down
46 changes: 28 additions & 18 deletions doc/src/user/cli/hash.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
# The Hash Command
Hash the data with the specify algorithm.

Available algorithms:
- blake2-128
- blake2-128-concat (default)
- blake2-256
- blake2-512
- twox64
- twox64-concat
- twox128
- twox256
- keccak256
- keccak512
- sha2-256

## Examples
# Command `hash`
```
Hash the hex with the specific hasher(hash algorithm)

Usage: subalfred hash [OPTIONS] <HEX>

Arguments:
<HEX>
Hex data input

Options:
--hasher <HASHER>
Hash algorithm

[default: blake2-128-concat]
[possible values: blake2-128, blake2-128-concat, blake2-256, blake2-512, twox64, twox64-concat, twox128, twox256, keccak256, keccak512, sha2-256]

-l, --log <TARGET=LEVEL,*>
Set a custom log filter.

This flag is also working with the `RUST_LOG` environment variable. If you use `RUST_LOG` simultaneously, this will append `RUST_LOG`'s value after the log.

[default: info]

-h, --help
Print help information (use `-h` for a summary)
```

## Example
### blake2-128-concat (Default)
```sh
subalfred hash 0xb4f7f03bebc56ebe96bc52ea5ed3159d45a0ce3a8d7f082983c33ef133274747
Expand Down Expand Up @@ -103,4 +114,3 @@ subalfred hash --hasher sha2-256 0xb4f7f03bebc56ebe96bc52ea5ed3159d45a0ce3a8d7f0
```
0x5d0ae9ab625ce7c50e5ced079f414f28161b1b645df49679ebd794fc43c239bc
```

Loading