Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Fix ignored config params #110

Merged
merged 4 commits into from
Nov 28, 2020
Merged
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
3 changes: 2 additions & 1 deletion src/contracts/fungible/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Opts {
)]
pub rpc_endpoint: String,

/// ZMQ socket address string for PUB/SUb API
/// ZMQ socket address string for PUB/SUB API
#[clap(
long = "pub",
default_value = FUNGIBLED_PUB_ENDPOINT,
Expand Down Expand Up @@ -152,6 +152,7 @@ impl Config {
T::Err: Display,
{
param
.replace("{id}", "default")
.replace("{network}", &self.network.to_string())
.replace("{data_dir}", self.data_dir.to_str().unwrap())
.parse()
Expand Down
15 changes: 11 additions & 4 deletions src/i9n/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
use std::collections::HashMap;

use lnpbp::bp;
use lnpbp::lnp::transport::zmqsocket::ZmqSocketAddr;

use crate::constants::*;
use crate::rgbd::ContractName;

#[derive(Clone, PartialEq, Eq, Debug, Display)]
#[display(Debug)]
pub struct Config {
pub stash_endpoint: ZmqSocketAddr,
pub contract_endpoints: HashMap<ContractName, ZmqSocketAddr>,
pub stash_rpc_endpoint: String,
pub stash_pub_endpoint: String,
pub fungible_pub_endpoint: String,
pub contract_endpoints: HashMap<ContractName, String>,
pub network: bp::Chain,
pub threaded: bool,
pub data_dir: String,
Expand All @@ -32,9 +33,15 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
stash_endpoint: STASHD_RPC_ENDPOINT
stash_rpc_endpoint: STASHD_RPC_ENDPOINT
.parse()
.expect("Error in STASHD_RPC_ENDPOINT constant value"),
stash_pub_endpoint: STASHD_PUB_ENDPOINT
.parse()
.expect("Error in STASHD_PUB_ENDPOINT constant value"),
fungible_pub_endpoint: FUNGIBLED_PUB_ENDPOINT
.parse()
.expect("Error in FUNGIBLED_PUB_ENDPOINT constant value"),
contract_endpoints: map! {
ContractName::Fungible
=> FUNGIBLED_RPC_ENDPOINT
Expand Down
15 changes: 14 additions & 1 deletion src/i9n/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

use std::str::FromStr;
use std::thread;

use lnpbp::lnp::transport::zmqsocket::ZmqType;
Expand All @@ -35,16 +36,26 @@ impl Runtime {
// Start rgbd on a separate thread
if config.threaded {
let rgbd_opts = rgbd::Opts {
verbose: 5,
bin_dir: String::new(),
data_dir: config.data_dir.clone(),
contracts: config
.contract_endpoints
.iter()
.map(|(k, _)| k.clone())
.collect(),
fungible_rpc_endpoint: config
.contract_endpoints
.get(&ContractName::Fungible)
.ok_or(BootstrapError::ArgParseError(s!(
"Fungible endpoint is unconfigured"
)))?
.clone(),
stash_rpc_endpoint: config.stash_rpc_endpoint.clone(),
stash_pub_endpoint: config.stash_pub_endpoint.clone(),
fungible_pub_endpoint: config.fungible_pub_endpoint.clone(),
network: config.network.clone(),
threaded: true,
..rgbd::Opts::default()
};

thread::spawn(move || {
Expand All @@ -60,6 +71,8 @@ impl Runtime {
config
.contract_endpoints
.get(&ContractName::Fungible)
.map(|s| transport::ZmqSocketAddr::from_str(&s).unwrap())
.as_ref()
.expect(
"Fungible engine is not connected in the configuration",
),
Expand Down
148 changes: 147 additions & 1 deletion src/rgbd/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::path::PathBuf;
use serde::Deserialize;

use crate::constants::*;
use crate::DataFormat;

#[derive(Clap)]
#[clap(
Expand All @@ -43,13 +44,95 @@ pub struct Opts {
#[clap(arg_enum, long = "contract", default_value = RGB_CONTRACTS, env = "RGB_CONTRACTS")]
pub contracts: Vec<ContractName>,

/// ZMQ socket address string for REQ/REP API of fungibled
#[clap(
long = "fungible-rpc",
default_value = FUNGIBLED_RPC_ENDPOINT,
env = "RGB_FUNGIBLED_RPC"
)]
pub fungible_rpc_endpoint: String,

/// ZMQ socket address string for PUB/SUB API of fungibled
#[clap(
long = "fungible-pub",
default_value = FUNGIBLED_PUB_ENDPOINT,
env = "RGB_FUNGIBLED_PUB"
)]
pub fungible_pub_endpoint: String,

/// ZMQ socket address string for REQ/REP API of stashd
#[clap(
long = "stash-rpc",
default_value = STASHD_RPC_ENDPOINT,
env = "RGB_STASHD_RPC"
)]
pub stash_rpc_endpoint: String,

/// ZMQ socket address string for PUB/SUB API of stashd
#[clap(
long = "stash-pub",
default_value = STASHD_PUB_ENDPOINT,
env = "RGB_STASHD_PUB"
)]
pub stash_pub_endpoint: String,

/// Connection string to fungibled cache (exact format depends on used
/// storage engine)
#[clap(
short = 'c',
long = "cache",
default_value = FUNGIBLED_CACHE,
env = "RGB_FUNGIBLED_CACHE"
)]
pub cache: String,

/// Data format for fungibled cache storage (valid only if file storage is
/// used)
#[clap(short, long, default_value = "yaml", env = "RGB_FUNGIBLED_FORMAT")]
pub format: DataFormat,

/// Connection string to stashd stash (exact format depends on used storage
/// engine)
#[clap(
short,
long,
default_value = STASHD_STASH,
env = "RGB_STASHD_STASH"
)]
pub stash: String,

/// Connection string to indexing service
#[clap(
short,
long,
default_value = STASHD_INDEX,
env = "RGB_STASHD_INDEX"
)]
pub index: String,

/// LNP socket address string for P2P API of stashd
#[clap(
long = "bind",
default_value = STASHD_P2P_ENDPOINT,
env = "RGB_STASHD_BIND"
)]
pub p2p_endpoint: String,

/// Run services as threads instead of daemons
#[clap(short, long)]
pub threaded: bool,

/// Bitcoin network to use
#[clap(short, long, default_value = RGB_NETWORK, env = "RGB_NETWORK")]
pub network: bp::Chain,

/// Electrum server to use to fecth Bitcoin transactions
#[clap(
long = "electrum",
default_value = DEFAULT_ELECTRUM_ENDPOINT,
env = "RGB_ELECTRUM_SERVER"
)]
pub electrum_server: String,
}

#[derive(Clap, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display)]
Expand Down Expand Up @@ -86,6 +169,16 @@ pub struct Config {
pub contracts: Vec<ContractName>,
pub network: bp::Chain,
pub verbose: u8,
pub fungible_rpc_endpoint: String,
pub fungible_pub_endpoint: String,
pub stash_rpc_endpoint: String,
pub stash_pub_endpoint: String,
pub cache: String,
pub format: DataFormat,
pub stash: String,
pub index: String,
pub p2p_endpoint: String,
pub electrum_server: String,
}

impl From<Opts> for Config {
Expand All @@ -96,8 +189,17 @@ impl From<Opts> for Config {
threaded: opts.threaded,
network: opts.network,
contracts: opts.contracts,
fungible_rpc_endpoint: opts.fungible_rpc_endpoint,
fungible_pub_endpoint: opts.fungible_pub_endpoint,
stash_rpc_endpoint: opts.stash_rpc_endpoint,
stash_pub_endpoint: opts.stash_pub_endpoint,
cache: opts.cache,
format: opts.format,
stash: opts.stash,
index: opts.index,
p2p_endpoint: opts.p2p_endpoint,
verbose: opts.verbose,
..Config::default()
electrum_server: opts.electrum_server,
}
}
}
Expand All @@ -114,10 +216,54 @@ impl Default for Config {
threaded: false,
contracts: vec![ContractName::from_str(RGB_CONTRACTS, false)
.expect("Error in RGB_CONTRACTS constant value")],
fungible_rpc_endpoint: FUNGIBLED_RPC_ENDPOINT.to_string(),
fungible_pub_endpoint: FUNGIBLED_PUB_ENDPOINT.to_string(),
stash_rpc_endpoint: STASHD_RPC_ENDPOINT.to_string(),
stash_pub_endpoint: STASHD_PUB_ENDPOINT.to_string(),
cache: FUNGIBLED_CACHE.to_string(),
format: DataFormat::Yaml,
stash: STASHD_STASH.to_string(),
index: STASHD_INDEX.to_string(),
p2p_endpoint: STASHD_P2P_ENDPOINT.to_string(),
network: RGB_NETWORK
.parse()
.expect("Error in RGB_NETWORK constant value"),
verbose: 0,
electrum_server: DEFAULT_ELECTRUM_ENDPOINT
.parse()
.expect("Error in DEFAULT_ELECTRUM_ENDPOINT constant value"),
}
}
}

impl Default for Opts {
fn default() -> Self {
Self {
data_dir: RGB_DATA_DIR
.parse()
.expect("Error in RGB_DATA_DIR constant value"),
bin_dir: RGB_BIN_DIR
.parse()
.expect("Error in RGB_BIN_DIR constant value"),
threaded: false,
contracts: vec![ContractName::from_str(RGB_CONTRACTS, false)
.expect("Error in RGB_CONTRACTS constant value")],
fungible_rpc_endpoint: FUNGIBLED_RPC_ENDPOINT.to_string(),
fungible_pub_endpoint: FUNGIBLED_PUB_ENDPOINT.to_string(),
stash_rpc_endpoint: STASHD_RPC_ENDPOINT.to_string(),
stash_pub_endpoint: STASHD_PUB_ENDPOINT.to_string(),
cache: FUNGIBLED_CACHE.to_string(),
format: DataFormat::Yaml,
stash: STASHD_STASH.to_string(),
index: STASHD_INDEX.to_string(),
p2p_endpoint: STASHD_P2P_ENDPOINT.to_string(),
network: RGB_NETWORK
.parse()
.expect("Error in RGB_NETWORK constant value"),
verbose: 0,
electrum_server: DEFAULT_ELECTRUM_ENDPOINT
.parse()
.expect("Error in DEFAULT_ELECTRUM_ENDPOINT constant value"),
}
}
}
57 changes: 52 additions & 5 deletions src/rgbd/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Runtime {
#[cfg(any(feature = "node"))]
fn get_task_for(
name: &str,
args: &[&str],
args: &[String],
) -> Result<task::JoinHandle<Result<(), DaemonError>>, DaemonError> {
match name {
"stashd" => {
Expand All @@ -59,14 +59,61 @@ impl Runtime {

#[cfg(any(feature = "node"))]
fn daemon(&self, bin: &str) -> Result<DaemonHandle, DaemonError> {
let args = [
"-vvvv",
"--data-dir",
let common_args: Vec<String> = vec![
s!("-v"), // required flag but doesn't change verbosity
s!("--data-dir"),
self.config
.data_dir
.to_str()
.expect("Datadir path is wrong"),
.expect("Datadir path is wrong")
.to_string(),
s!("--network"),
self.config.network.to_string(),
];
let mut fungibled_args: Vec<String> = common_args.clone();
let mut stashd_args: Vec<String> = common_args.clone();
fungibled_args.extend(
vec![
s!("--rpc"),
self.config.fungible_rpc_endpoint.to_string(),
s!("--pub"),
self.config.fungible_pub_endpoint.to_string(),
s!("--stash-rpc"),
self.config.stash_rpc_endpoint.to_string(),
s!("--stash-sub"),
self.config.stash_pub_endpoint.to_string(),
s!("--stash"),
self.config.stash.to_string(),
s!("--format"),
self.config.format.to_string(),
]
.iter()
.cloned(),
);
stashd_args.extend(vec![
s!("--rpc"),
self.config.stash_rpc_endpoint.to_string(),
s!("--pub"),
self.config.stash_pub_endpoint.to_string(),
s!("--stash"),
self.config.stash.to_string(),
s!("--index"),
self.config.index.to_string(),
s!("--bind"),
self.config.p2p_endpoint.to_string(),
s!("--electrum"),
self.config.electrum_server.to_string(),
]);
let args;
match bin {
"stashd" => {
args = stashd_args;
}
"fungibled" => {
args = fungibled_args;
}
_ => args = [].to_vec(),
}

if self.config.threaded {
Ok(DaemonHandle::Task(Self::get_task_for(bin, &args)?))
Expand Down
Loading