Skip to content

Commit

Permalink
Add config for Ethereum interop
Browse files Browse the repository at this point in the history
  • Loading branch information
james-chf committed Sep 2, 2022
1 parent cec849d commit c33862b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
19 changes: 19 additions & 0 deletions apps/src/lib/config/ethereum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde::{Deserialize, Serialize};

/// Default [Ethereum JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/) endpoint used by the oracle
pub const DEFAULT_ORACLE_RPC_ENDPOINT: &str = "http://127.0.0.1:8545";

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
/// The Ethereum JSON-RPC endpoint that the Ethereum event oracle will use
/// to listen for events from the Ethereum bridge smart contracts
pub oracle_rpc_endpoint: String,
}

impl Default for Config {
fn default() -> Self {
Self {
oracle_rpc_endpoint: DEFAULT_ORACLE_RPC_ENDPOINT.to_owned(),
}
}
}
13 changes: 3 additions & 10 deletions apps/src/lib/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Node and client configuration
pub mod ethereum;
pub mod genesis;
pub mod global;
pub mod utils;
Expand Down Expand Up @@ -38,8 +39,6 @@ pub const FILENAME: &str = "config.toml";
pub const TENDERMINT_DIR: &str = "tendermint";
/// Chain-specific Anoma DB. Nested in chain dirs.
pub const DB_DIR: &str = "db";
/// Websocket address for Ethereum fullnode RPC
pub const ETHEREUM_URL: &str = "http://127.0.0.1:8545";

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
Expand Down Expand Up @@ -84,6 +83,7 @@ pub struct Ledger {
pub chain_id: ChainId,
pub shell: Shell,
pub tendermint: Tendermint,
pub ethereum: ethereum::Config,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -103,8 +103,6 @@ pub struct Shell {
db_dir: PathBuf,
/// Use the [`Ledger::tendermint_dir()`] method to read the value.
tendermint_dir: PathBuf,
/// Use the [`Ledger::ethereum_url()`] method to read the value.
ethereum_url: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -176,7 +174,6 @@ impl Ledger {
tx_wasm_compilation_cache_bytes: None,
db_dir: DB_DIR.into(),
tendermint_dir: TENDERMINT_DIR.into(),
ethereum_url: ETHEREUM_URL.into(),
},
tendermint: Tendermint {
rpc_address: SocketAddr::new(
Expand All @@ -200,6 +197,7 @@ impl Ledger {
),
instrumentation_namespace: "anoman_tm".to_string(),
},
ethereum: ethereum::Config::default(),
}
}

Expand All @@ -217,11 +215,6 @@ impl Ledger {
pub fn tendermint_dir(&self) -> PathBuf {
self.shell.tendermint_dir(&self.chain_id)
}

/// Get the websocket url for the Ethereum fullnode
pub fn ethereum_url(&self) -> String {
self.shell.ethereum_url.clone()
}
}

impl Shell {
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ async fn run_aux(config: config::Ledger, wasm_dir: PathBuf) {
let (broadcaster_sender, broadcaster_receiver) =
tokio::sync::mpsc::unbounded_channel();

let ethereum_url = config.ethereum_url();
let ethereum_url = config.ethereum.oracle_rpc_endpoint.clone();
let (ethereum_node, oracle, broadcaster) = if matches!(
config.tendermint.tendermint_mode,
TendermintMode::Validator
Expand Down

0 comments on commit c33862b

Please sign in to comment.