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

Added substrate network #236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion configuration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nomad-xyz-configuration"
version = "1.0.0-rc.1"
version = "1.0.0-rc.2"
edition = "2021"
authors = ["James Prestwich <[email protected]>", "The Nomad Developers <[email protected]>"]
description = "Nomad project configuration file utilities"
Expand Down
12 changes: 6 additions & 6 deletions configuration/configs/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"networks": {
"ethereum": {
"name": "ethereum",
"domain": 6648936,
"rpcStyle": "ethereum",
"domain": 6648936,
"connections": ["moonbeam", "evmos"],
"specs": {
"chainId": 1,
Expand All @@ -41,7 +42,8 @@
},
"moonbeam": {
"name": "moonbeam",
"domain": 1650811245,
"rpcStyle": "ethereum",
"domain": 1650811245,
"connections": ["ethereum", "evmos"],
"specs": {
"chainId": 1284,
Expand Down Expand Up @@ -71,7 +73,8 @@
},
"evmos": {
"name": "evmos",
"domain": 1702260083,
"rpcStyle": "ethereum",
"domain": 1702260083,
"connections": ["ethereum", "moonbeam"],
"configuration": {
"optimisticSeconds": 1800,
Expand Down Expand Up @@ -272,7 +275,6 @@
},
"agent": {
"ethereum": {
"rpcStyle": "ethereum",
"db": "db",
"metrics": 9090,
"logging": {
Expand Down Expand Up @@ -301,7 +303,6 @@
}
},
"moonbeam": {
"rpcStyle": "ethereum",
"db": "db",
"metrics": 9090,
"logging": {
Expand Down Expand Up @@ -330,7 +331,6 @@
}
},
"evmos": {
"rpcStyle": "ethereum",
"db": "db",
"metrics": 9090,
"logging": {
Expand Down
15 changes: 8 additions & 7 deletions configuration/configs/testMultiVm.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"networks": {
"ethereum": {
"name": "ethereum",
"domain": 6648936,
"rpcStyle": "ethereum",
"domain": 6648936,
"connections": ["moonbeam", "evmos"],
"specs": {
"chainId": 1,
Expand All @@ -42,7 +43,8 @@
},
"moonbeam": {
"name": "moonbeam",
"domain": 1650811245,
"rpcStyle": "ethereum",
"domain": 1650811245,
"connections": ["ethereum", "evmos"],
"specs": {
"chainId": 1284,
Expand Down Expand Up @@ -72,7 +74,8 @@
},
"evmos": {
"name": "evmos",
"domain": 1702260083,
"rpcStyle": "ethereum",
"domain": 1702260083,
"connections": ["ethereum", "moonbeam"],
"configuration": {
"optimisticSeconds": 1800,
Expand Down Expand Up @@ -109,7 +112,8 @@
},
"avail": {
"name": "avail",
"domain": 1702260083,
"rpcStyle": "substrate",
"domain": 1702260083,
"connections": ["ethereum"],
"configuration": {
"optimisticSeconds": 1800,
Expand Down Expand Up @@ -311,7 +315,6 @@
},
"agent": {
"ethereum": {
"rpcStyle": "ethereum",
"db": "db",
"metrics": 9090,
"logging": {
Expand Down Expand Up @@ -340,7 +343,6 @@
}
},
"moonbeam": {
"rpcStyle": "ethereum",
"db": "db",
"metrics": 9090,
"logging": {
Expand Down Expand Up @@ -369,7 +371,6 @@
}
},
"evmos": {
"rpcStyle": "ethereum",
"db": "db",
"metrics": 9090,
"logging": {
Expand Down
2 changes: 1 addition & 1 deletion configuration/data/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export type ProcessorConfig = BaseAgentConfig & {
};

export interface AgentConfig {
rpcStyle: string;
db: string;
metrics: number;
logging: LogConfig;
Expand Down Expand Up @@ -130,6 +129,7 @@ export interface BridgeConfiguration {
export interface Domain {
name: string;
domain: number;
rpcStyle: string;
connections: Array<string>;
configuration: ContractConfig;
specs: NetworkSpecs;
Expand Down
31 changes: 2 additions & 29 deletions configuration/src/agent/logging.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
//! Agent configuration types

/// Rpc Styles
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum RpcStyles {
/// Ethereum
Ethereum,
/// Substrate
Substrate,
}

impl std::fmt::Display for RpcStyles {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let style = match self {
RpcStyles::Ethereum => "ethereum",
RpcStyles::Substrate => "substrate",
};

write!(f, "{}", style)
}
}

impl Default for RpcStyles {
fn default() -> Self {
RpcStyles::Ethereum
}
}

/// Basic tracing configuration
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -96,11 +69,11 @@ impl Default for LogConfig {
mod test {
use serde_json::json;

use super::RpcStyles;
use crate::RpcStyle;

#[test]
fn it_deserializes_rpc_styles() {
let serialized = serde_json::to_value(&RpcStyles::Ethereum).unwrap();
let serialized = serde_json::to_value(&RpcStyle::Ethereum).unwrap();

let val = json! { "ethereum" };
assert_eq!(val, serialized);
Expand Down
2 changes: 0 additions & 2 deletions configuration/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ use self::{
#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgentConfig {
/// RPC specifier
pub rpc_style: RpcStyles,
/// Path to the DB
pub db: PathBuf,
/// Metrics port
Expand Down
16 changes: 15 additions & 1 deletion configuration/src/chains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ pub mod substrate;

use std::str::FromStr;

use serde::{Deserialize, Serialize};
use serde_json::json;

/// Rpc style of chain
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Default, Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq)]
#[serde(rename_all = "camelCase")]
pub enum RpcStyle {
#[default]
/// Ethereum
Ethereum,
/// Substrate
Expand All @@ -29,6 +32,17 @@ impl FromStr for RpcStyle {
}
}

impl std::fmt::Display for RpcStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let style = match self {
RpcStyle::Ethereum => "ethereum",
RpcStyle::Substrate => "substrate",
};

write!(f, "{}", style)
}
}

/// Chain connection configuration
#[derive(Debug, Clone, PartialEq)]
pub enum Connection {
Expand Down
4 changes: 3 additions & 1 deletion configuration/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Core deploy information

use crate::bridge::BridgeConfiguration;
use crate::{bridge::BridgeConfiguration, RpcStyle};
use nomad_types::{
deser_nomad_u32, deser_nomad_u64, deser_nomad_u8, NameOrDomain, NomadIdentifier, NomadLocator,
};
Expand Down Expand Up @@ -83,6 +83,8 @@ pub struct Domain {
/// Network domain identifier
#[serde(deserialize_with = "deser_nomad_u32")]
pub domain: u32,
/// dwfgkewopgk
pub rpc_style: RpcStyle,
/// List of connections to other networks
pub connections: HashSet<String>,
/// Nomad protocol configuration options
Expand Down
2 changes: 1 addition & 1 deletion configuration/src/wasm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export type ProcessorConfig = BaseAgentConfig & {
};

export interface AgentConfig {
rpcStyle: string;
db: string;
metrics: number;
logging: LogConfig;
Expand Down Expand Up @@ -136,6 +135,7 @@ export interface BridgeConfiguration {
export interface Domain {
name: string;
domain: number;
rpcStyle: string;
connections: Array<string>;
configuration: ContractConfig;
specs: NetworkSpecs;
Expand Down
8 changes: 4 additions & 4 deletions fixtures/external_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"networks": {
"ethereum": {
"name": "ethereum",
"domain": 6648936,
"rpcStyle": "ethereum",
"domain": 6648936,
"connections": ["polygon"],
"specs": {
"chainId": 1,
Expand Down Expand Up @@ -45,7 +46,8 @@
},
"polygon": {
"name": "polygon",
"domain": 1650811245,
"rpcStyle": "ethereum",
"domain": 1650811245,
"connections": ["ethereum"],
"specs": {
"chainId": 1284,
Expand Down Expand Up @@ -170,7 +172,6 @@
},
"agent": {
"ethereum": {
"rpcStyle": "ethereum",
"db": "/usr/share/nomad",
"metrics": 9090,
"logging": {
Expand All @@ -195,7 +196,6 @@
}
},
"polygon": {
"rpcStyle": "ethereum",
"db": "/usr/share/nomad",
"metrics": 9090,
"logging": {
Expand Down
8 changes: 7 additions & 1 deletion nomad-base/src/bin/secrets_template.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use nomad_types::NameOrDomain;
use serde_json::json;
use std::{fs::OpenOptions, io::Write};

Expand All @@ -16,7 +17,12 @@ fn main() {
});

for network in config.networks.iter() {
let rpc_style = config.agent().get(network).expect("!agent").rpc_style;
let networks = config.protocol();
let rpc_style = networks
.networks
.get(network.as_str())
.expect("!no domain")
.rpc_style;
template["rpcs"].as_object_mut().unwrap().insert(
network.to_owned(),
json!({
Expand Down