Skip to content

Commit

Permalink
refactor: prepare for package open sourcing (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuttymoon authored Apr 26, 2023
2 parents 395b0e1 + 00d30fe commit 2f5bd4d
Show file tree
Hide file tree
Showing 37 changed files with 199 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Template tests config file
run: |
envsubst < crates/ash/tests/conf/quicknode.yml > ${{ runner.temp }}/ash-test-avax-conf.yml
envsubst < crates/ash_sdk/tests/conf/quicknode.yml > ${{ runner.temp }}/ash-test-avax-conf.yml
env:
ASH_QUICKNODE_FUJI_ENDPOINT: ${{ secrets.ASH_QUICKNODE_FUJI_ENDPOINT }}
ASH_QUICKNODE_FUJI_TOKEN: ${{ secrets.ASH_QUICKNODE_FUJI_TOKEN }}
Expand Down
30 changes: 15 additions & 15 deletions Cargo.lock

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

17 changes: 16 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@
# Copyright (c) 2023, E36 Knots

[workspace]
members = ["crates/cli", "crates/ash"]
members = ["crates/ash_cli", "crates/ash_sdk"]

[workspace.package]
version = "0.1.0"
edition = "2021"
authors = ["E36 Knots"]
homepage = "https://ash.center"
documentation = "https://ash.center/docs/toolkit/ash-rs/introduction"
license = "BSD-3-Clause"
repository = "https://github.com/AshAvalanche/ash-rs"
categories = [
"command-line-utilities",
"cryptography::cryptocurrencies",
"data-structures",
]
keywords = ["blockchain", "avalanche", "subnets", "sdk", "rust", "ash"]
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# ash-rs

This project provides Rust crates to interact with the Ash protocol.
This project provides Rust crates to interact with:

- Avalanche nodes, Subnets, and blockchains;
- other Ash tools.

## Crates

- [ash](crates/ash): Rust SDK to interact with the Ash protocol
- [ashcli](crates/cli): CLI to interact with the Ash protocol
- [ash_sdk](crates/ash_sdk): Ash Rust SDK
- [ash_cli](crates/ash_cli): Ash CLI

## Ash CLI Installation

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

cargo install --path crates/cli
cargo install --path crates/ash_cli

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

See [Available commands](crates/cli/README.md#available-commands).
See [Available commands](crates/ash_cli/README.md#available-commands).

## Configuration

Expand Down Expand Up @@ -94,7 +97,7 @@ ASH_INFRA_PATH=path/to/ash-infra
# Source the tests .env file
source crates/ash/tests/.env
# Generate the tests configuration file
envsubst < crates/ash/tests/conf/quicknode.yml > target/ash-test-avax-conf.yml
envsubst < crates/ash_sdk/tests/conf/quicknode.yml > target/ash-test-avax-conf.yml
# Run the tests
ASH_TEST_AVAX_CONFIG="$PWD/target/ash-test-avax-conf.yml" cargo test
```
Expand All @@ -104,7 +107,7 @@ ASH_TEST_AVAX_CONFIG="$PWD/target/ash-test-avax-conf.yml" cargo test
- [x] CLI
- [x] Get Subnets and blockchains information from the Avalanche P-Chain
- [x] Get nodes information from the Avalanche P-Chain
- [ ] Get Subnet validators information from the Avalanche P-Chain
- [ ] Ash protocol integration (abstract smart contracts interaction from the user)
- [ ] Ledger integration (to sign transactions)
- [x] Get Subnet validators information from the Avalanche P-Chain
- [ ] Subnet creation
- [ ] Blockchain creation
- [ ] WASM integration (to allow the library to be used from JavaScript)
10 changes: 0 additions & 10 deletions crates/ash/README.md

This file was deleted.

20 changes: 11 additions & 9 deletions crates/cli/Cargo.toml → crates/ash_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
# Copyright (c) 2023, E36 Knots

[package]
name = "ashcli"
name = "ash_cli"
description = "Ash CLI"
version = "0.1.0"
authors = ["E36 Knots"]
edition = "2021"
readme = "README.md"
repository = "https://github.com/AshAvalanche/ash-rs"
license = "BSD-3-Clause"
keywords = ["blockchain", "avalanche", "sdk", "rust", "ash"]
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
documentation.workspace = true
license.workspace = true
repository.workspace = true
categories.workspace = true
keywords.workspace = true

[dependencies]
ash = { path = "../ash" }
ash_sdk = { path = "../ash_sdk" }
clap = { version = "4.0.32", features = ["derive"] }
colored = "2.0.0"
exitcode = "1.1.2"
Expand Down
30 changes: 30 additions & 0 deletions crates/ash_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# `ash_cli` Crate

This crate provides the `ash` command line interface. It aims at boosting Avalanche developers productivity by providing a set of commands to interact with Avalanche. Some of the commands are:

```bash
# List available Avalanche networks
ash avalanche network list

# List the Subnets of the mainnet network
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'

# Show detailed information about a validator of the mainnet Subnet
ash avalanche validator info --network fuji --id 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

## Tutorials

See the [Tutorials](https://ash.center/docs/category/tutorials-1) section of the documentation.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod validator;
// Module that contains the avalanche subcommand parser

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

#[derive(Parser)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Module that contains the network subcommand parser

use crate::utils::{error::CliError, templating::type_colorize};
use ash::conf::AshConfig;
use ash_sdk::conf::AshConfig;
use clap::{Parser, Subcommand};

#[derive(Parser)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Module that contains the node subcommand parser

use crate::utils::{error::CliError, templating::template_avalanche_node_info};
use ash::avalanche::nodes::AvalancheNode;
use ash_sdk::avalanche::nodes::AvalancheNode;
use clap::{Parser, Subcommand};

#[derive(Parser)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::avalanche::*;
use crate::utils::{error::CliError, templating::*};
use ash::avalanche::AVAX_PRIMARY_NETWORK_ID;
use ash_sdk::avalanche::AVAX_PRIMARY_NETWORK_ID;
use clap::{Parser, Subcommand};

#[derive(Parser)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/conf.rs → crates/ash_cli/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Module that contains the conf subcommand parser

use crate::utils::error::CliError;
use ash::conf::AshConfig;
use ash_sdk::conf::AshConfig;
use clap::{Parser, Subcommand};

#[derive(Parser)]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2023, E36 Knots

use ash::avalanche::subnets::{AvalancheSubnet, AvalancheSubnetValidator};
use ash::avalanche::{blockchains::AvalancheBlockchain, nodes::AvalancheNode};
use ash_sdk::avalanche::subnets::{AvalancheSubnet, AvalancheSubnetValidator};
use ash_sdk::avalanche::{blockchains::AvalancheBlockchain, nodes::AvalancheNode};
use colored::{ColoredString, Colorize};
use indoc::formatdoc;

Expand Down
18 changes: 10 additions & 8 deletions crates/ash/Cargo.toml → crates/ash_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# Copyright (c) 2023, E36 Knots

[package]
name = "ash"
name = "ash_sdk"
description = "Ash Rust SDK"
version = "0.1.0"
authors = ["E36 Knots"]
edition = "2021"
readme = "README.md"
repository = "https://github.com/AshAvalanche/ash-rs"
license = "BSD-3-Clause"
keywords = ["blockchain", "avalanche", "sdk", "rust", "ash"]
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
documentation.workspace = true
license.workspace = true
repository.workspace = true
categories.workspace = true
keywords.workspace = true

[dependencies]
avalanche-types = "0.0"
Expand Down
96 changes: 96 additions & 0 deletions crates/ash_sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ash_sdk

`ash-rs` is a Rust SDK for [Avalanche](https://avax.network) and [Ash](https://ash.center) tools.

It provides a higher level of abstraction than [avalanche-types-rs](https://github.com/ava-labs/avalanche-types-rs) and comes with a CLI that simplifies the interaction with Avalanche networks.

## Opinionated structs layout

The library provides an opinionated layout to represent Avalanche networks, Subnets and blockchains. The layout could be represented as follows:

```
AvalancheNetwork
└── subnets
├── AvalancheSubnet 1
│ ├── blockchains
│ │ ├── AvalancheBlockchain 1
│ │ └── AvalancheBlockchain 2
│ └── validators
│ ├── AvalancheSubnetValidator 1
│ └── AvalancheSubnetValidator 2
└── AvalancheSubnet 2
├── blockchains
│ ├── AvalancheBlockchain 3
│ └── AvalancheBlockchain 4
└── validators
├── AvalancheSubnetValidator 1
└── AvalancheSubnetValidator 2
```

### Avalanche networks

An `AvalancheNetwork` is a top level struct that represents an Avalanche network. It contains the list of its `AvalancheSubnet`s. Most of the updating methods are implemented on this struct (e.g. `update_subnet`, `update_blockchains`, etc.).

### Avalanche Subnets and validators

An `AvalancheSubnet` is a struct that represents an Avalanche Subnet. It contains all the Subnet metadata, the list of its `AvalancheBlockchain`s and the list of its validators (as `AvalancheSubnetsValidator`s).

### Avalanche blockchains

An `AvalancheBlockchain` is a struct that represents an Avalanche blockchain. It contains all the blockchain metadata.

### Avalanche nodes

An `AvalancheNode` is a struct that represents an Avalanche node. An `AvalancheNode` is not directly linked to an `AvalancheNetwork` as its metadata are retrieved directly from its endpoint.

## Configuration

The library relies on YAML configuration files that contains the list of known Avalanche networks. For each network, at least the P-Chain configuration has to be provided (in the Primary Network) with its ID and RPC endpoint. All the other Subnets/blockchains will be retrieved/enriched from the P-Chain.

A default configuration is embedded in the library (see [conf/default.yaml](https://github.com/AshAvalanche/ash-rs/blob/main/crates/ash_sdk/conf/default.yml)) and contains the following networks:

- `mainnet` and `fuji` use the default Avalanche public endpoints
- `mainnet-ankr` and `fuji-ankr` use the Ankr Avalanche public endpoints
- `mainnet-blast` and `fuji-blast` use the Blast Avalanche public endpoints

Configuration example:

```yaml
# Default configuration of the mainnet network
avalancheNetworks:
- name: mainnet
subnets:
- id: 11111111111111111111111111111111LpoYY
controlKeys: []
threshold: 0
blockchains:
- id: 11111111111111111111111111111111LpoYY
name: P-Chain
vmType: PVM
rpcUrl: https://api.avax.network/ext/bc/P
- id: 2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5
name: C-Chain
vmId: mgj786NP7uDwBCcq6YwThhaN8FLyybkCa4zBWTQbNgmK6k9A6
vmType: EVM
rpcUrl: https://api.avax.network/ext/bc/C/rpc
- id: 2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM
name: X-Chain
vmId: jvYyfQTxGMJLuGWa55kdP2p2zSUYsQ5Raupu4TW34ZAUBAbtq
vmType: AVM
rpcUrl: https://api.avax.network/ext/bc/X
```
**Note:** You can generate a configuration file with the CLI using the `ash conf init` command.

## Usage

One can check out the [CLI code](https://github.com/AshAvalanche/ash-rs/tree/main/crates/ash_cli) to see examples of how to use the library.

## Modules

- `conf`: Interact with the library configuration in YAML
- `errors`: Generate errors for the library
- `avalanche`: Interact with Avalanche networks, Subnets and blockchains
- `avalanche::subnets`: Interact with Avalanche Subnets and validators
- `avalanche::blockchains`: Interact with Avalanche blockchains
- `avalanche::jsonrpc`: Interact with Avalanche VMs JSON RPC endpoints
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2023, E36 Knots

// Module that contains code to interact with Avalanche subnets and validators
// Module that contains code to interact with Avalanche Subnets and validators

use crate::avalanche::blockchains::AvalancheBlockchain;
use crate::avalanche::{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions crates/cli/README.md

This file was deleted.

0 comments on commit 2f5bd4d

Please sign in to comment.