Skip to content

Commit b2dc053

Browse files
committed
fix(c-bridge): properly read testnet environment config from envars
1 parent f58517e commit b2dc053

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

bridges/centralized-ethereum/src/config.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,19 @@ pub fn from_file<S: AsRef<Path>>(file: S) -> Result<Config, Box<dyn std::error::
126126
/// Load configuration from environment variables
127127
pub fn from_env() -> Result<Config, envy::Error> {
128128
USING_ENVY.with(|x| x.set(true));
129-
let res = envy::prefixed("WITNET_CENTRALIZED_ETHEREUM_BRIDGE_").from_env();
129+
let res: Result<Config, envy::Error> = envy::prefixed("WITNET_CENTRALIZED_ETHEREUM_BRIDGE_").from_env();
130130
USING_ENVY.with(|x| x.set(false));
131-
132-
res
131+
if let Ok(config) = res {
132+
witnet_data_structures::set_environment(if config.witnet_testnet {
133+
Environment::Testnet
134+
} else {
135+
Environment::Mainnet
136+
});
137+
Ok(config)
138+
139+
} else {
140+
res
141+
}
133142
}
134143

135144
thread_local! {

bridges/centralized-ethereum/src/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Witnet <> Ethereum bridge
22
33
use actix::{Actor, System, SystemRegistry};
4+
use witnet_data_structures::chain::Environment;
45
use std::{path::PathBuf, process::exit, sync::Arc};
56
use structopt::StructOpt;
67

@@ -59,9 +60,10 @@ fn main() {
5960
fn run(callback: fn()) -> Result<(), String> {
6061
let app = App::from_args();
6162
let config = if app.env {
62-
config::from_env()
63+
let config = config::from_env()
6364
.map(Arc::new)
64-
.map_err(|e| format!("Error reading configuration from environment: {}", e))?
65+
.map_err(|e| format!("Error reading configuration from environment: {}", e))?;
66+
config
6567
} else {
6668
config::from_file(
6769
app.config

0 commit comments

Comments
 (0)