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(cli): update keypair generate command #1621

Merged
merged 12 commits into from
Dec 13, 2023
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
79 changes: 8 additions & 71 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ members = [
"core/storage",
"devtools/abi-generator",
"devtools/axon-tools",
"devtools/keypair",
"protocol",
]

Expand Down
3 changes: 3 additions & 0 deletions core/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
clap = { version = "4.4", features = ["cargo", "string", "derive"] }
semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tempfile = "3.6"
tentacle-secio = "0.6"
thiserror = "1.0"

common-config-parser = { path = "../../common/config-parser" }
common-crypto ={ path = "../../common/crypto" }
common-logger = { path = "../../common/logger" }
common-version = { path = "../../common/version" }
core-run = { path = "../../core/run" }
Expand Down
102 changes: 102 additions & 0 deletions core/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Axon CLI

Axon CLI is a command line tool for Axon framework. It is included in the Axon binary with the command of `cargo build --release`.

## Usage

### Generate Keypair

```bash
./target/release/axon generate-keypair -n 1 -p path-to-save-private-keys
```

Example Output:

```bash
$ cargo run -- -n 1 -p path-to-save-private-keys
{
"keypairs": [
{
"index": 0,
"net_private_key": "0x0000000000000000000000000000000000000000000000000000000000000000",
"public_key": "0x020044def250d1d27c0f7c0eeee6c8b964756d5ad7936fcefaf3f086245ddb9c9c",
"address": "0x83fec4b12b26a70195ccabb67ce0cd692856eaf1",
"peer_id": "QmbZEzvonMiPiioRpYeVWxngjN42FHC3EHXjeo2C7o2NDZ",
"bls_private_key": "0x1111111111111111111111111111111111111111111111111111111111111111",
"bls_public_key": "0x81ca54f01e3b433c209ae1d165e6362669e13170f89712dbc52c3572901d025ecc206a43c4b25f58388189f74587a7d"
}
]
}
```

The arguments are described in the following table:

| name | short | default value |
|--|--|--|
| number | n | 4 |
| private-key-path | p | current_path/free-space/ |

### Update Config and Spec File

First, update the `validator_list` in the [chain-spec](../../devtools/chain/specs/single_node/chain-spec.toml) file. Replace the `bls_pub_key`, `pub_key` and `address` with the value generated by the keypair generator, for example:

```toml
[[params.verifier_list]]
bls_pub_key = "0x81ca54f01e3b433c209ae1d165e6362669e13170f89712dbc52c3572901d025ecc206a43c4b25f58388189f74587a7d"
pub_key = "0x020044def250d1d27c0f7c0eeee6c8b964756d5ad7936fcefaf3f086245ddb9c9c"
address = "0x83fec4b12b26a70195ccabb67ce0cd692856eaf1"
propose_weight = 1
vote_weight = 1
```

Then, update the `bootstraps` in the [config](../../devtools/chain/config.toml) file. Fill the generated `peer_id` to the `multi_address` For example:

```toml
[[network.bootstraps]]
multi_address = "/ip4/127.0.0.1/tcp/8001/p2p/QmbZEzvonMiPiioRpYeVWxngjN42FHC3EHXjeo2C7o2NDZ"
```

Finally, set the `net_privkey_file` and `bls_privkey_file` with the generated private key file path in [config](../../devtools/chain/config.toml) file.

### Recover Public Key and Peer ID

If you forget your public key and peer id, you can recover them from the private key file.

```bash
./target/release/axon recover-keypair -n path-of-net-private-key -b path-of-bls-private-key
```

The arguments are described in the following table:

| name | short | default value |
|--|--|--|
| net-path | n | - |
| bls-path | b | - |

### Init Chain

After the config and spec file are updated, you can initialize the chain with the following command:

```bash
./target/release/axon init -c path-of-config-file -s path-of-chain-spec-file
```
The console will print the execution result of genesis block. The arguments are described in the following table:

| name | short | default value |
|--|--|--|
| config | c | - |
| chain-spec | s | - |

### Run Node

Finally, you can run the node with the following command:

```bash
./target/release/axon run -c path-of-config-file
```

The arguments are described in the following table:

| name | short | default value |
|--|--|--|
| config | c | - |
Loading
Loading