Skip to content

Commit

Permalink
Merge pull request #258 from PeggyJV/collin/proto-build-improvements
Browse files Browse the repository at this point in the history
feat:Proto crate and build improvements
  • Loading branch information
cbrit authored Feb 26, 2024
2 parents d373270 + f4e7920 commit 444dec4
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 207 deletions.
485 changes: 291 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 28 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
[package]
name = "steward"
authors = []
[workspace]
members = [
".",
"crates/steward-proto",
]
default-members = [
".",
]
resolver = "2"

[workspace.package]
version = "4.2.0"
edition = "2021"

[workspace.dependencies]
prost = "0.7"
serde = { version = "1.0", features = ["serde_derive"] }
tonic = { version = "0.4.3", features = ["codegen", "tls", "tower", "transport"] }

[package]
name = "steward"
authors = ["Collin Brittain", "Eric Bolten", "Ukpai Ugochi", "Zaki Manian"]
version.workspace = true
edition.workspace = true

[dependencies]
abscissa_tokio = "0.6.0"
bip32 = "0.2"
Expand All @@ -22,22 +41,23 @@ num-bigint = "0.4"
num-rational = "0.4"
num-traits = "0.2"
pkcs8 = { version = "0.7", features = ["pem"] }
prost = "0.7"
prost.workspace = true
prost-types = "0.7"
rand_core = { version = "0.6", features = ["std"] }
rand = "0.8.0"
regex = "1.5.4"
rpassword = "5"
serde = { version = "1.0", features = ["serde_derive"] }
serde.workspace = true
serde_json = "1.0.64"
sha2 = "0.9"
sha3 = "0.10.6"
signatory = "0.23.0-pre"
somm_proto = { git = "https://github.com/PeggyJV/sommelier", rev = "34bf4246db57270338479c80ba12c50949ca805b" }
steward-proto = { path = "crates/steward-proto" }
thiserror = "1"
tokio ={ version = "1", features = ["macros", "fs"] }
toml = { version = "0.5" }
tonic = { version = "0.4.3", features = ["codegen", "tls", "tower", "transport"] }
tonic.workspace = true
tonic-reflection = "0.1.0"
tower = { version = "0.4", features = ["buffer", "util"] }
url = "2.2.2"
Expand Down Expand Up @@ -76,6 +96,8 @@ tempdir = "0.3"

[build-dependencies]
ethers = { git = "https://github.com/iqlusioninc/ethers-rs.git", branch="zaki/error_abi_support", features = ["abigen"] }
hex = "0.4"
merkle_hash = "3.6"
prost-build = "0.7"
tonic = { version = "0.4.3", features = ["codegen", "tls", "transport"] }
tonic-build = "0.4"
Expand Down
39 changes: 36 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,49 @@ use std::{
fs::{self, create_dir_all, remove_dir_all},
path::PathBuf,
};

use merkle_hash::{Algorithm, MerkleTree};
use walkdir::WalkDir;

/// A temporary directory for proto building
const TMP_PATH: &str = "/tmp/steward/";
/// the output directory
const OUT_PATH: &str = "src/gen/proto/";
const OUT_PATH: &str = "crates/steward-proto/src/gen/";
const HASH_ABI_FILE: &str = "hash_abi";
const HASH_PROTO_FILE: &str = "hash_proto";

fn main() {
generate_contract_abis();
generate_rust_protos();
// only generate bindings if changes have occurred
let previous_abi_hash = fs::read_to_string(HASH_ABI_FILE).unwrap_or_default();
let previous_proto_hash = fs::read_to_string(HASH_PROTO_FILE).unwrap_or_default();
let current_abi_hash = MerkleTree::builder("abi")
.algorithm(Algorithm::Blake3)
.hash_names(false)
.build()
.expect("abi dir merkle tree build failed")
.root
.item
.hash;
let current_proto_hash = MerkleTree::builder("proto")
.algorithm(Algorithm::Blake3)
.hash_names(false)
.build()
.expect("proto dir merkle tree build failed")
.root
.item
.hash;
let current_abi_hash = hex::encode(current_abi_hash);
let current_proto_hash = hex::encode(current_proto_hash);

if current_abi_hash != previous_abi_hash {
generate_contract_abis();
fs::write(HASH_ABI_FILE, current_abi_hash).expect("failed to write abi hash");
}

if current_proto_hash != previous_proto_hash {
generate_rust_protos();
fs::write(HASH_PROTO_FILE, current_proto_hash).expect("failed to write proto hash");
}
}

fn generate_contract_abis() {
Expand Down
16 changes: 16 additions & 0 deletions crates/steward-proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "steward-proto"
description = "Protobuf bindings for Steward, the Sommelier blockchain sidecar"
authors = ["Collin Brittain"]
version.workspace = true
edition.workspace = true
keywords = ["steward", "sommelier"]
repository = "https://github.com/PeggyJV/steward"
readme = "README.md"
categories = ["blockchain", "sommelier"]

[dependencies]
prost.workspace = true
serde.workspace = true
tonic.workspace = true

4 changes: 4 additions & 0 deletions crates/steward-proto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Steward Protos

This crate contains bindings for Steward's protobuf API definitions. It can be used to build tooling for Sommelier strategists in Rust.

File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions crates/steward-proto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Proto bindings for [Steward](https://github.com/peggyjv/steward), the sidecar application which hosts the Strategist API and
//! handles many other key processes for the Sommelier blockchain.
//!
//! The proto definitions can be found [here](https://github.com/PeggyJV/steward/tree/main/proto/steward/v4)
/// Generated proto definitions
pub mod proto {
include!("gen/steward.v4.rs");
}
1 change: 1 addition & 0 deletions hash_abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
85098a751b81941b3a36d28fd24d26189b3a20ec4cf8fcb5184e3eb778a8be32
1 change: 1 addition & 0 deletions hash_proto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42ce538b083bd8e0909e5be03277d74f5b19aad9dae9c5fc956831579c2a61e6
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,4 @@ pub mod abi {
}

#[allow(clippy::all)]
pub mod proto {
include!("gen/proto/steward.v4.rs");
}
pub use steward_proto::proto;
3 changes: 2 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use tonic::{
use x509_parser::prelude::{FromDer, KeyIdentifier, ParsedExtension, X509Certificate};

// for gRPC reflection
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("gen/proto/descriptor.bin");
pub const FILE_DESCRIPTOR_SET: &[u8] =
include_bytes!("../crates/steward-proto/src/gen/descriptor.bin");

pub struct ServerConfig {
pub tls_config: Option<ServerTlsConfig>,
Expand Down

0 comments on commit 444dec4

Please sign in to comment.