Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit ce9688f

Browse files
gyuhohexfusion
andcommitted
*: sync
Signed-off-by: Gyuho Lee <[email protected]> Co-authored-by: Sam Batschelet <[email protected]>
1 parent c01a519 commit ce9688f

File tree

125 files changed

+24487
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+24487
-219
lines changed

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "05:00"
8+
timezone: America/Los_Angeles
9+
open-pull-requests-limit: 10
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Test and release
2+
3+
# ref. https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
4+
on:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- "*"
10+
pull_request:
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
static_analysis:
17+
name: Static analysis (lint)
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Install Rust
23+
uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: nightly
26+
profile: minimal
27+
components: rustfmt, clippy
28+
override: true
29+
- name: Check Rust version
30+
run: rustc --version
31+
- uses: Swatinem/rust-cache@v1
32+
with:
33+
cache-on-failure: true
34+
- name: Run static analysis tests
35+
shell: bash
36+
run: scripts/tests.lint.sh
37+
38+
check_cargo_unused:
39+
name: Check Cargo unused
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v3
44+
- name: Install Rust
45+
uses: actions-rs/toolchain@v1
46+
with:
47+
toolchain: nightly
48+
profile: minimal
49+
components: rustfmt, clippy
50+
override: true
51+
- name: Check Rust version
52+
run: rustc --version
53+
- uses: Swatinem/rust-cache@v1
54+
with:
55+
cache-on-failure: true
56+
57+
# or use "abelfodil/protoc-action@v1"
58+
# ref. https://github.com/hyperium/tonic/issues/1047#issuecomment-1222508191
59+
- name: Install protoc
60+
uses: arduino/setup-protoc@v1
61+
with:
62+
version: "3.x"
63+
repo-token: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Check unused Cargo dependencies
66+
shell: bash
67+
run: scripts/tests.unused.sh
68+
69+
unit_tests:
70+
name: Unit tests
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@v3
75+
- name: Install Rust
76+
uses: actions-rs/toolchain@v1
77+
with:
78+
toolchain: stable
79+
profile: minimal
80+
override: true
81+
82+
# or use "abelfodil/protoc-action@v1"
83+
# ref. https://github.com/hyperium/tonic/issues/1047#issuecomment-1222508191
84+
- name: Install protoc
85+
uses: arduino/setup-protoc@v1
86+
with:
87+
version: "3.x"
88+
repo-token: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- name: Check Rust version
91+
run: rustc --version
92+
- uses: Swatinem/rust-cache@v1
93+
with:
94+
cache-on-failure: true
95+
- name: Run unit tests
96+
run: scripts/tests.unit.sh

Cargo.toml

+117-22
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "avalanche-types"
3-
version = "0.0.115" # https://crates.io/crates/avalanche-types
3+
version = "0.0.135" # https://crates.io/crates/avalanche-types
44
edition = "2021"
5-
rust-version = "1.64"
5+
rust-version = "1.65"
66
publish = true
7-
description = "Avalanche types"
7+
description = "Avalanche primitive types in Rust"
88
license = "BSD-3-Clause"
99
homepage = "https://avax.network"
10-
repository = "https://github.com/ava-labs/avalanche-rust/tree/main/crates/avalanche-types"
10+
repository = "https://github.com/ava-labs/avalanche-types-rs"
1111
readme = "README.md"
1212

1313
[dependencies]
@@ -17,7 +17,6 @@ bs58 = "0.4.0" # for "formatting", https://crates.io/crates/bs58
1717
bytes = "1.2.1"
1818
chrono = "0.4.22"
1919
cmp-manager = "0.0.1"
20-
futures = "0.3.25"
2120
hex = "0.4.3"
2221
lazy_static = "1.4.0"
2322
log = "0.4.17"
@@ -74,27 +73,32 @@ ethers-signers = { version = "1.0.0", optional = true }
7473
http-manager = { version = "0.0.3", optional = true }
7574
tokio = { version = "1.21.2", features = ["full"], optional = true } # https://github.com/tokio-rs/tokio/releases
7675

77-
# [OPTIONAL] for "rpcchainvm"
78-
avalanche-proto = { version = "0.17.0", features = ["aliasreader", "keystore", "sharedmemory", "subnetlookup", "rpcdb", "google_protobuf"], optional = true }
76+
# [OPTIONAL] for "subnet"
77+
futures = { version = "0.3.25", optional = true }
7978
http = {version = "0.2.8", optional = true}
80-
hyper = "0.14.22"
79+
hyper = "0.14.23"
8180
jsonrpc-core = {version = "18.0.0", optional = true }
8281
jsonrpc-http-server = {version = "18.0.0", optional = true }
8382
num-derive = { version = "0.3.3", optional = true }
8483
num-traits = { version = "0.2.15", optional = true }
85-
prost = { version = "0.11.0", optional = true } # prost-build requires "cmake", https://github.com/tokio-rs/prost/releases
84+
prost = { version = "0.11.2", optional = true } # prost-build requires "cmake", https://github.com/tokio-rs/prost/releases
8685
semver = { version = "1.0.14", optional = true }
8786
tokio-stream = { version = "0.1.11", features = ["net"], optional = true }
8887
tonic = { version = "0.8.2", features = ["gzip"], optional = true } # https://github.com/hyperium/tonic/tags
8988
tonic-health = { version = "0.7.1", optional = true }
9089
tonic-reflection = { version = "0.5.0", optional = true }
91-
tower-service = "0.3.2"
90+
tower-service = { version = "0.3.2", optional = true }
9291

93-
# [OPTIONAL] for "num_bigint"
92+
# [OPTIONAL] for "codec"
93+
base64 = { version = "0.13.1", optional = true }
9494
num-bigint = { version = "0.4.3", optional = true }
9595

96+
[build-dependencies]
97+
protoc-gen-prost = "0.2.0"
98+
protoc-gen-tonic = "0.2.0"
99+
96100
[dev-dependencies]
97-
env_logger = "0.9.1"
101+
env_logger = "0.9.3"
98102
id-manager = "0.0.1"
99103
random-manager = "0.0.1"
100104
tempfile = "3.3.0"
@@ -103,33 +107,115 @@ tokio-test = "0.4.2"
103107

104108
[features]
105109
default = [
106-
"cert",
107-
"client",
108-
"evm",
109110
"message_compress_gzip",
110-
"mnemonic",
111-
"rpcchainvm",
112111

113112
# optional features
114113
# "avalanchego",
114+
# "cert",
115+
# "client",
116+
# "codec_base64",
117+
# "codec_big_int",
118+
# "evm",
115119
# "kms_aws",
116120
# "libsecp256k1",
117-
# "num_bigint",
121+
# "mnemonic",
122+
# "proto",
123+
# "subnet",
118124
# "subnet_evm",
119125
]
120126

121127
avalanchego = []
122128
cert = ["rcgen", "rsa", "rustls"]
123129
client = ["http-manager", "ethers", "ethers-core", "ethers-providers", "ethers-signers", "tokio"]
130+
codec_base64 = ["base64"]
131+
codec_big_int = ["num-bigint"]
124132
evm = ["rlp", "rlp-derive"]
125133
kms_aws = ["aws-manager", "aws-sdk-kms", "aws-smithy-types"]
126134
libsecp256k1 = ["secp256k1"]
127135
message_compress_gzip = ["flate2"]
128136
mnemonic = ["bip32", "rand_core"]
129-
num_bigint = ["num-bigint"]
130-
rpcchainvm = ["avalanche-proto", "http", "jsonrpc-core", "num-derive", "num-traits", "prost", "semver", "tokio", "tokio-stream", "tonic", "tonic-health", "tonic-reflection"]
131137
subnet_evm = []
132138

139+
proto = [
140+
"prost",
141+
"tonic",
142+
143+
# TODO: remove all proto specific features
144+
"aliasreader",
145+
"appsender",
146+
"google_protobuf",
147+
"helloworld",
148+
"http_proto", # TODO: remove feature for buf
149+
"http_responsewriter",
150+
"io_prometheus_client",
151+
"io_reader",
152+
"io_writer",
153+
"keystore",
154+
"messenger",
155+
"net_conn",
156+
"p2p",
157+
"plugin",
158+
"rpcdb",
159+
"sharedmemory",
160+
"subnetlookup",
161+
"validatorstate",
162+
"vm",
163+
]
164+
subnet = [
165+
"futures",
166+
"http",
167+
"jsonrpc-core",
168+
"num-derive",
169+
"num-traits",
170+
"prost",
171+
"semver",
172+
"tokio",
173+
"tokio-stream",
174+
"tonic",
175+
"tonic-health",
176+
"tonic-reflection",
177+
"tower-service",
178+
179+
"proto",
180+
]
181+
182+
# TODO: remove all proto specific features
183+
aliasreader = []
184+
appsender = ["google_protobuf"]
185+
google_protobuf = []
186+
helloworld = []
187+
http_proto = []
188+
http_responsewriter = ["google_protobuf"]
189+
io_prometheus_client = []
190+
io_reader = []
191+
io_writer = []
192+
keystore = []
193+
messenger = []
194+
net_conn = ["google_protobuf"]
195+
p2p = []
196+
plugin = ["google_protobuf"]
197+
rpcdb = ["google_protobuf"]
198+
sharedmemory = []
199+
subnetlookup = []
200+
validatorstate = ["google_protobuf"]
201+
vm = ["io_prometheus_client", "google_protobuf"]
202+
203+
[[example]]
204+
name = "client_c"
205+
required-features = ["client", "evm"]
206+
207+
[[example]]
208+
name = "client_info"
209+
required-features = ["client"]
210+
211+
[[example]]
212+
name = "client_p"
213+
required-features = ["client"]
214+
215+
[[example]]
216+
name = "client_x"
217+
required-features = ["client"]
218+
133219
[[example]]
134220
name = "key_cert"
135221
required-features = ["cert"]
@@ -142,11 +228,20 @@ required-features = ["kms_aws"]
142228
name = "key_secp256k1_mnemonic_derive_load"
143229
required-features = ["mnemonic"]
144230

231+
[[example]]
232+
name = "proto_client"
233+
required-features = ["proto", "subnet"]
234+
235+
[[example]]
236+
name = "proto_server"
237+
required-features = ["proto", "subnet"]
238+
145239
[[test]]
146240
name = "integration"
147241
path = "tests/integration_tests.rs"
148-
required-features = ["rpcchainvm"]
242+
required-features = ["subnet"]
149243

150244
[package.metadata.cargo-udeps.ignore]
245+
build = ["protoc-gen-prost", "protoc-gen-tonic"]
246+
development = ["id-manager", "tokio-test", "tonic-reflection"]
151247
normal = ["rsa"]
152-
development = ["id-manager", "tokio-test"]

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11

2-
(still in active development, please contact https://github.com/gyuho or https://github.com/hexfusion for bug reports and questions)
3-
4-
![Crates.io](https://img.shields.io/crates/v/avalanche-types?logo=rust&style=for-the-badge)
5-
6-
https://crates.io/crates/avalanche-types
2+
[<img alt="crates.io" src="https://img.shields.io/crates/v/avalanche-types.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/avalanche-types)
3+
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-avalanche_types-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/avalanche-types)
4+
![Github Actions](https://github.com/ava-labs/avalanche-types-rs/actions/workflows/test-and-release.yml/badge.svg)
75

86
`avalanche-types` crate implements Avalanche primitive types in Rust:
97
- Ids (e.g., [`src/ids`](./src/ids))
108
- Transaction types/serialization (e.g., [`src/platformvm/txs`](./src/platformvm/txs))
119
- Certificates (e.g., [`src/key/cert`](./src/key/cert))
1210
- Keys and addresses (e.g., [`src/key/secp256k1`](./src/key/secp256k1))
1311
- Peer-to-peer messages (e.g., [`src/message`](./src/message))
14-
- RPC chain VM (e.g., [`src/rpcchainvm`](./src/rpcchainvm))
12+
- RPC chain VM (e.g., [`src/subnet/rpc`](./src/subnet/rpc))
1513
- Genesis generate helper (e.g., [`src/subnet_evm`](./src/subnet_evm))
1614

1715
The basic types available in this crate are used in other Avalanche Rust projects (e.g., distributed load tester [`blizzard`](https://talks.gyuho.dev/distributed-load-generator-avalanche-2022.html), [`avalanche-ops`](https://github.com/ava-labs/avalanche-ops)).

examples/proto_client.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use avalanche_types::proto::pb::helloworld::{greeter_client::GreeterClient, HelloRequest};
2+
3+
#[tokio::main]
4+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
5+
let mut client = GreeterClient::connect("http://[::1]:50051").await?;
6+
let request = tonic::Request::new(HelloRequest {
7+
name: "Avalanche Rustaceans!".into(),
8+
});
9+
let resp = client.say_hello(request).await?;
10+
11+
println!("SUCCESSFUL response: {:?}", resp);
12+
13+
Ok(())
14+
}

0 commit comments

Comments
 (0)