Skip to content

Commit

Permalink
feat: Subnet and blockchain creation (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuttymoon authored May 30, 2023
2 parents 7059cf2 + f6a2a8e commit 6c14b3c
Show file tree
Hide file tree
Showing 40 changed files with 1,708 additions and 259 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

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

39 changes: 9 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,19 @@ This project provides Rust crates to interact with:

## Crates

- [ash_sdk](crates/ash_sdk): Ash Rust SDK
- [ash_cli](crates/ash_cli): Ash CLI
- [ash_sdk](crates/ash_sdk): Ash Rust SDK
[<img alt="crates.io" src="https://img.shields.io/crates/v/ash_sdk.svg?style=flat&color=fc8d62&logo=rust">](https://crates.io/crates/ash_sdk)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-ash_sdk-green?style=flat&labelColor=555555&logo=docs.rs">](https://docs.rs/ash_sdk)
- [ash_cli](crates/ash_cli): Ash CLI
[<img alt="crates.io" src="https://img.shields.io/crates/v/ash_cli.svg?style=flat&color=fc8d62&logo=rust">](https://crates.io/crates/ash_cli)

## Ash CLI Installation

```sh
git clone https://github.com/AshAvalanche/ash-rs.git
cd ash-rs

cargo install --path crates/ash_cli

# The CLI is then available globally
ash --help
```

See [Available commands](crates/ash_cli/README.md#available-commands).
See the [Installation](https://ash.center/docs/toolkit/ash-cli/installation) section of the documentation.

## Configuration

A YAML configuration file can be generated using the `ash conf init` command, enriched and then reused in commands with the `--config` flag.

This allows to query custom networks with the CLI:

```yaml
avalancheNetworks:
- name: local
subnets:
- id: 11111111111111111111111111111111LpoYY
blockchains:
- id: yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp
name: C-Chain
vmType: EVM
rpcUrl: https://localhost:9650/ext/bc/C/rpc
```
See the [Custom Configuration tutorial](https://ash.center/docs/toolkit/ash-cli/tutorials/custom-configuration) section of the documentation.

## Development

Expand Down Expand Up @@ -108,6 +87,6 @@ ASH_TEST_AVAX_CONFIG="$PWD/target/ash-test-avax-conf.yml" cargo test
- [x] Get Subnets and blockchains information from the Avalanche P-Chain
- [x] Get nodes information from the Avalanche P-Chain
- [x] Get Subnet validators information from the Avalanche P-Chain
- [ ] Subnet creation
- [ ] Blockchain creation
- [x] Subnet creation
- [x] Blockchain creation
- [ ] WASM integration (to allow the library to be used from JavaScript)
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
large-error-threshold = 256
too-many-arguments-threshold = 10
too-many-arguments-threshold = 16
2 changes: 2 additions & 0 deletions crates/ash_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ serde_json = "1.0.91"
async-std = { version = "1.10.0", features = ["attributes", "tokio1"] }
enum-display-derive = "0.1.1"
rust_decimal = "1.29.1"
hex = "0.4.3"
chrono = "0.4.24"

[[bin]]
name = "ash"
Expand Down
37 changes: 30 additions & 7 deletions crates/ash_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,42 @@ ash avalanche subnet list --network mainnet

# Show detailed information about one of the mainnet Subnets
# The output can be set to JSON and piped to jq for maximum flexibility
ash avalanche subnet info --id Vn3aX6hNRstj5VHHm63TCgPNaeGnRSqCYXQqemSqDd2TQH4qJ --json | jq '.blockchains'
ash avalanche subnet info Vn3aX6hNRstj5VHHm63TCgPNaeGnRSqCYXQqemSqDd2TQH4qJ --json | jq '.blockchains'

# Show detailed information about a validator of the mainnet Subnet
ash avalanche validator info --network fuji --id NodeID-FhFWdWodxktJYq884nrJjWD8faLTk9jmp
ash avalanche validator info --network fuji NodeID-FhFWdWodxktJYq884nrJjWD8faLTk9jmp
```

## Available commands

- `ash conf`: Manipulate the Ash lib configuration
- `ash avalanche network`: Interact with Avalanche networks
- `ash avalanche node`: Interact with Avalanche nodes
- `ash avalanche subnet`: Interact with Avalanche Subnets
- `ash avalanche validator`: Interact with Avalanche validators
- `ash conf`

```bash
Interact with Ash configuration files

Usage: ash conf [OPTIONS] <COMMAND>

Commands:
init Initialize an Ash config file
```

- `ash avalanche`

```bash
Interact with Avalanche Subnets, blockchains and nodes

Usage: ash avalanche [OPTIONS] <COMMAND>

Commands:
blockchain Interact with Avalanche blockchains
network Interact with Avalanche networks
node Interact with Avalanche nodes
subnet Interact with Avalanche Subnets
validator Interact with Avalanche validators
vm Interact with Avalanche VMs
wallet Interact with Avalanche wallets
x Interact with Avalanche X-Chain
```

## Tutorials

Expand Down
12 changes: 9 additions & 3 deletions crates/ash_cli/src/avalanche.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2023, E36 Knots

mod blockchain;
mod network;
mod node;
mod subnet;
mod validator;
mod vm;
mod wallet;
mod x;

// Module that contains the avalanche subcommand parser

use crate::utils::error::CliError;
use crate::utils::{error::CliError, parsing::*};
use ash_sdk::avalanche::AvalancheNetwork;
use clap::{Parser, Subcommand};

Expand All @@ -23,12 +25,14 @@ pub(crate) struct AvalancheCommand {

#[derive(Subcommand)]
enum AvalancheSubcommands {
Blockchain(blockchain::BlockchainCommand),
Network(network::NetworkCommand),
Node(node::NodeCommand),
Subnet(subnet::SubnetCommand),
Validator(validator::ValidatorCommand),
X(x::XCommand),
Vm(vm::VmCommand),
Wallet(wallet::WalletCommand),
X(x::XCommand),
}

// Load the network configuation
Expand All @@ -55,7 +59,7 @@ fn update_subnet_validators(
subnet_id: &str,
) -> Result<(), CliError> {
network
.update_subnet_validators(subnet_id)
.update_subnet_validators(parse_id(subnet_id)?)
.map_err(|e| CliError::dataerr(format!("Error updating validators: {e}")))?;
Ok(())
}
Expand All @@ -67,10 +71,12 @@ pub(crate) fn parse(
json: bool,
) -> Result<(), CliError> {
match avalanche.command {
AvalancheSubcommands::Blockchain(blockchain) => blockchain::parse(blockchain, config, json),
AvalancheSubcommands::Network(network) => network::parse(network, config, json),
AvalancheSubcommands::Node(node) => node::parse(node, json),
AvalancheSubcommands::Subnet(subnet) => subnet::parse(subnet, config, json),
AvalancheSubcommands::Validator(validator) => validator::parse(validator, config, json),
AvalancheSubcommands::Vm(vm) => vm::parse(vm, json),
AvalancheSubcommands::X(x) => x::parse(x, config, json),
AvalancheSubcommands::Wallet(wallet) => wallet::parse(wallet, config, json),
}
Expand Down
Loading

0 comments on commit 6c14b3c

Please sign in to comment.