-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathconfig.rs
More file actions
51 lines (43 loc) · 1.16 KB
/
config.rs
File metadata and controls
51 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![allow(unused)]
use serde::Deserialize;
use std::io::Read;
/// Config file
const CONFIG_FILE: &str = "config.toml";
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ChainType {
Real,
Simulator,
}
/// Contract Interact configuration
#[derive(Debug, Deserialize)]
pub struct Config {
pub gateway_uri: String,
pub chain_type: ChainType,
}
impl Config {
// Deserializes config from file
pub fn new() -> Self {
let mut file = std::fs::File::open(CONFIG_FILE).unwrap();
let mut content = String::new();
file.read_to_string(&mut content).unwrap();
toml::from_str(&content).unwrap()
}
pub fn chain_simulator_config() -> Self {
Config {
gateway_uri: "http://localhost:8085".to_owned(),
chain_type: ChainType::Simulator,
}
}
// Returns the gateway URI
pub fn gateway_uri(&self) -> &str {
&self.gateway_uri
}
// Returns if chain type is chain simulator
pub fn use_chain_simulator(&self) -> bool {
match self.chain_type {
ChainType::Real => false,
ChainType::Simulator => true,
}
}
}