network-defaults: make defaults a bit more dynamic

By attaching network defaults to the selector enum, we can get them
either from DEFAULT_NETWORK or a selector passed as a dependency.
Hopefully this opens up some venues for being able to toggle between
networks at runtime.
This commit is contained in:
Jon Häggblad
2022-03-01 12:15:53 +01:00
parent b9ef848523
commit acb1aa8df0
18 changed files with 164 additions and 147 deletions
Generated
+1
View File
@@ -3735,6 +3735,7 @@ version = "0.1.0"
dependencies = [
"cfg-if 1.0.0",
"hex-literal",
"once_cell",
"serde",
"thiserror",
"url",
@@ -4,6 +4,7 @@
use crate::{validator_api, ValidatorClientError};
use coconut_interface::{BlindSignRequestBody, BlindedSignatureResponse, VerificationKeyResponse};
use mixnet_contract_common::{GatewayBond, IdentityKeyRef, MixNodeBond};
use network_defaults::DEFAULT_NETWORK;
use url::Url;
use validator_api_requests::models::{
CoreNodeStatusResponse, MixnodeStatusResponse, RewardEstimationResponse,
@@ -29,6 +30,7 @@ use std::str::FromStr;
#[cfg(feature = "nymd-client")]
#[must_use]
#[derive(Debug)]
pub struct Config {
network: network_defaults::all::Network,
api_url: Url,
@@ -159,12 +161,10 @@ impl Client<QueryNymdClient> {
let nymd_client = NymdClient::connect(
config.nymd_url.as_str(),
Some(config.mixnet_contract_address.clone().unwrap_or_else(|| {
cosmrs::AccountId::from_str(network_defaults::DEFAULT_MIXNET_CONTRACT_ADDRESS)
.unwrap()
cosmrs::AccountId::from_str(DEFAULT_NETWORK.mixnet_contract_address()).unwrap()
})),
Some(config.vesting_contract_address.clone().unwrap_or_else(|| {
cosmrs::AccountId::from_str(network_defaults::DEFAULT_VESTING_CONTRACT_ADDRESS)
.unwrap()
cosmrs::AccountId::from_str(DEFAULT_NETWORK.vesting_contract_address()).unwrap()
})),
Some(
config
@@ -172,7 +172,7 @@ impl Client<QueryNymdClient> {
.clone()
.unwrap_or_else(|| {
cosmrs::AccountId::from_str(
network_defaults::DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
DEFAULT_NETWORK.bandwidth_claim_contract_address(),
)
.unwrap()
}),
@@ -72,7 +72,7 @@ impl FromStr for GasPrice {
}
impl GasPrice {
pub fn new_with_default_price(denom: String) -> Result<Self, NymdError> {
pub fn new_with_default_price(denom: &str) -> Result<Self, NymdError> {
format!("{}{}", defaults::GAS_PRICE_AMOUNT, denom).parse()
}
}
@@ -83,8 +83,8 @@ mod tests {
#[test]
fn default_gas_price_is_valid() {
let denom = "unym".parse().unwrap();
let _ = GasPrice::new_with_default_price(denom);
let denom = "unym";
GasPrice::new_with_default_price(denom).unwrap();
}
#[test]
@@ -57,16 +57,16 @@ pub struct DirectSecp256k1HdWallet {
}
impl DirectSecp256k1HdWallet {
pub fn builder(prefix: String) -> DirectSecp256k1HdWalletBuilder {
pub fn builder(prefix: &str) -> DirectSecp256k1HdWalletBuilder {
DirectSecp256k1HdWalletBuilder::new(prefix)
}
/// Restores a wallet from the given BIP39 mnemonic using default options.
pub fn from_mnemonic(prefix: String, mnemonic: bip39::Mnemonic) -> Result<Self, NymdError> {
pub fn from_mnemonic(prefix: &str, mnemonic: bip39::Mnemonic) -> Result<Self, NymdError> {
DirectSecp256k1HdWalletBuilder::new(prefix).build(mnemonic)
}
pub fn generate(prefix: String, word_count: usize) -> Result<Self, NymdError> {
pub fn generate(prefix: &str, word_count: usize) -> Result<Self, NymdError> {
let mneomonic = bip39::Mnemonic::generate(word_count)?;
Self::from_mnemonic(prefix, mneomonic)
}
@@ -146,11 +146,11 @@ pub struct DirectSecp256k1HdWalletBuilder {
}
impl DirectSecp256k1HdWalletBuilder {
pub fn new(prefix: String) -> Self {
pub fn new(prefix: &str) -> Self {
DirectSecp256k1HdWalletBuilder {
bip39_password: String::new(),
hd_paths: vec![defaults::COSMOS_DERIVATION_PATH.parse().unwrap()],
prefix,
prefix: prefix.into(),
}
}
@@ -197,11 +197,11 @@ impl DirectSecp256k1HdWalletBuilder {
#[cfg(test)]
mod tests {
use super::*;
use network_defaults::{default_network, BECH32_PREFIX};
use network_defaults::DEFAULT_NETWORK;
#[test]
fn generating_account_addresses() {
let (addr1, addr2, addr3) = match BECH32_PREFIX {
let (addr1, addr2, addr3) = match DEFAULT_NETWORK.bech32_prefix() {
"punk" => (
"punk1jw6mp7d5xqc7w6xm79lha27glmd0vdt32a3fj2",
"punk1h5hgn94nsq4kh99rjj794hr5h5q6yfm22mcqqn",
@@ -222,7 +222,7 @@ mod tests {
];
for (mnemonic, address) in mnemonic_address.into_iter() {
let prefix = default_network().bech32_prefix();
let prefix = DEFAULT_NETWORK.bech32_prefix();
let wallet =
DirectSecp256k1HdWallet::from_mnemonic(prefix, mnemonic.parse().unwrap()).unwrap();
assert_eq!(
@@ -1,4 +1,4 @@
use config::defaults;
use config::defaults::DEFAULT_NETWORK;
use subtle_encoding::bech32;
#[derive(Debug, Clone, PartialEq)]
@@ -18,12 +18,12 @@ pub fn try_bech32_decode(address: &str) -> Result<String, Bech32Error> {
pub fn validate_bech32_prefix(address: &str) -> Result<(), Bech32Error> {
let prefix = try_bech32_decode(address)?;
if prefix == defaults::BECH32_PREFIX {
if prefix == DEFAULT_NETWORK.bech32_prefix() {
Ok(())
} else {
Err(Bech32Error::WrongPrefix(format!(
"your bech32 address prefix should be {}, not {}",
defaults::BECH32_PREFIX,
DEFAULT_NETWORK.bech32_prefix(),
prefix
)))
}
+1
View File
@@ -9,6 +9,7 @@ edition = "2021"
[dependencies]
cfg-if = "1.0.0"
hex-literal = "0.3.3"
once_cell = "1.7.2"
serde = {version = "1.0", features = ["derive"]}
thiserror = "1.0"
url = "2.2"
+55 -59
View File
@@ -2,9 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt, str::FromStr};
use std::{collections::HashMap, fmt, ops::Deref, str::FromStr};
use crate::{mainnet, qa, sandbox, ValidatorDetails};
use crate::{
DefaultNetworkDetails, ValidatorDetails, MAINNET_DEFAULTS, QA_DEFAULTS, SANDBOX_DEFAULTS,
};
use thiserror::Error;
@@ -22,20 +24,40 @@ pub enum Network {
}
impl Network {
pub fn bech32_prefix(&self) -> String {
fn details(&self) -> &DefaultNetworkDetails<'_> {
match self {
Self::QA => String::from(qa::BECH32_PREFIX),
Self::SANDBOX => String::from(sandbox::BECH32_PREFIX),
Self::MAINNET => String::from(mainnet::BECH32_PREFIX),
Self::QA => &QA_DEFAULTS,
Self::SANDBOX => &SANDBOX_DEFAULTS,
Self::MAINNET => &MAINNET_DEFAULTS,
}
}
pub fn denom(&self) -> String {
match self {
Self::QA => String::from(qa::DENOM),
Self::SANDBOX => String::from(sandbox::DENOM),
Self::MAINNET => String::from(mainnet::DENOM),
}
pub fn bech32_prefix(&self) -> &str {
self.details().bech32_prefix
}
pub fn denom(&self) -> &str {
self.details().denom
}
pub fn mixnet_contract_address(&self) -> &str {
self.details().mixnet_contract_address
}
pub fn vesting_contract_address(&self) -> &str {
self.details().vesting_contract_address
}
pub fn bandwidth_claim_contract_address(&self) -> &str {
self.details().bandwidth_claim_contract_address
}
pub fn rewarding_validator_address(&self) -> &str {
self.details().rewarding_validator_address
}
pub fn validators(&self) -> impl Iterator<Item = &ValidatorDetails> {
self.details().validators.iter()
}
}
@@ -75,6 +97,20 @@ pub struct NetworkDetails {
validators: Vec<ValidatorDetails>,
}
impl From<&DefaultNetworkDetails<'_>> for NetworkDetails {
fn from(details: &DefaultNetworkDetails) -> Self {
NetworkDetails {
bech32_prefix: details.bech32_prefix.into(),
denom: details.denom.into(),
mixnet_contract_address: details.mixnet_contract_address.into(),
vesting_contract_address: details.vesting_contract_address.into(),
bandwidth_claim_contract_address: details.bandwidth_claim_contract_address.into(),
rewarding_validator_address: details.rewarding_validator_address.into(),
validators: details.validators.clone(),
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SupportedNetworks {
networks: HashMap<Network, NetworkDetails>,
@@ -86,53 +122,13 @@ impl SupportedNetworks {
for network in support {
match network {
Network::MAINNET => networks.insert(
Network::MAINNET,
NetworkDetails {
bech32_prefix: String::from(mainnet::BECH32_PREFIX),
denom: String::from(mainnet::DENOM),
mixnet_contract_address: String::from(mainnet::MIXNET_CONTRACT_ADDRESS),
vesting_contract_address: String::from(mainnet::VESTING_CONTRACT_ADDRESS),
bandwidth_claim_contract_address: String::from(
mainnet::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
),
rewarding_validator_address: String::from(
mainnet::REWARDING_VALIDATOR_ADDRESS,
),
validators: mainnet::validators(),
},
),
Network::SANDBOX => networks.insert(
Network::SANDBOX,
NetworkDetails {
bech32_prefix: String::from(sandbox::BECH32_PREFIX),
denom: String::from(sandbox::DENOM),
mixnet_contract_address: String::from(sandbox::MIXNET_CONTRACT_ADDRESS),
vesting_contract_address: String::from(sandbox::VESTING_CONTRACT_ADDRESS),
bandwidth_claim_contract_address: String::from(
sandbox::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
),
rewarding_validator_address: String::from(
sandbox::REWARDING_VALIDATOR_ADDRESS,
),
validators: sandbox::validators(),
},
),
Network::QA => networks.insert(
Network::QA,
NetworkDetails {
bech32_prefix: String::from(qa::BECH32_PREFIX),
denom: String::from(qa::DENOM),
mixnet_contract_address: String::from(qa::MIXNET_CONTRACT_ADDRESS),
vesting_contract_address: String::from(qa::VESTING_CONTRACT_ADDRESS),
bandwidth_claim_contract_address: String::from(
qa::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
),
rewarding_validator_address: String::from(qa::REWARDING_VALIDATOR_ADDRESS),
validators: qa::validators(),
},
),
Network::MAINNET => {
networks.insert(Network::MAINNET, MAINNET_DEFAULTS.deref().into())
}
Network::SANDBOX => {
networks.insert(Network::SANDBOX, SANDBOX_DEFAULTS.deref().into())
}
Network::QA => networks.insert(Network::QA, QA_DEFAULTS.deref().into()),
};
}
SupportedNetworks { networks }
+58 -41
View File
@@ -1,5 +1,7 @@
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use url::Url;
@@ -9,64 +11,79 @@ pub mod mainnet;
pub mod qa;
pub mod sandbox;
// The set of defaults that are decided at compile time. Ideally we want to reduce these to a
// minimum.
// Keep DENOM around mostly for use in contracts. (TODO: consider moving it there, or renaming?)
cfg_if::cfg_if! {
if #[cfg(network = "mainnet")] {
pub const BECH32_PREFIX: &str = mainnet::BECH32_PREFIX;
pub const DEFAULT_NETWORK: all::Network = all::Network::MAINNET;
pub const DENOM: &str = mainnet::DENOM;
pub const DEFAULT_MIXNET_CONTRACT_ADDRESS: &str = mainnet::MIXNET_CONTRACT_ADDRESS;
pub const DEFAULT_VESTING_CONTRACT_ADDRESS: &str = mainnet::VESTING_CONTRACT_ADDRESS;
pub const DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS: &str = mainnet::BANDWIDTH_CLAIM_CONTRACT_ADDRESS;
pub const ETH_CONTRACT_ADDRESS: [u8; 20] = mainnet::_ETH_CONTRACT_ADDRESS;
pub const ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] = mainnet::_ETH_ERC20_CONTRACT_ADDRESS;
pub const DEFAULT_REWARDING_VALIDATOR_ADDRESS: &str = mainnet::REWARDING_VALIDATOR_ADDRESS;
pub fn default_validators() -> Vec<ValidatorDetails> {
mainnet::validators()
}
pub fn default_network() -> all::Network {
all::Network::MAINNET
}
} else if #[cfg(network = "qa")] {
pub const BECH32_PREFIX: &str = qa::BECH32_PREFIX;
pub const DEFAULT_NETWORK: all::Network = all::Network::QA;
pub const DENOM: &str = qa::DENOM;
pub const DEFAULT_MIXNET_CONTRACT_ADDRESS: &str = qa::MIXNET_CONTRACT_ADDRESS;
pub const DEFAULT_VESTING_CONTRACT_ADDRESS: &str = qa::VESTING_CONTRACT_ADDRESS;
pub const DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS: &str = qa::BANDWIDTH_CLAIM_CONTRACT_ADDRESS;
pub const ETH_CONTRACT_ADDRESS: [u8; 20] = qa::_ETH_CONTRACT_ADDRESS;
pub const ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] = qa::_ETH_ERC20_CONTRACT_ADDRESS;
pub const DEFAULT_REWARDING_VALIDATOR: &str = qa::REWARDING_VALIDATOR_ADDRESS;
pub fn default_validators() -> Vec<ValidatorDetails> {
qa::validators()
}
pub fn default_network() -> all::Network {
all::Network::QA
}
} else if #[cfg(network = "sandbox")] {
pub const BECH32_PREFIX: &str = sandbox::BECH32_PREFIX;
pub const DEFAULT_NETWORK: all::Network = all::Network::SANDBOX;
pub const DENOM: &str = sandbox::DENOM;
pub const DEFAULT_MIXNET_CONTRACT_ADDRESS: &str = sandbox::MIXNET_CONTRACT_ADDRESS;
pub const DEFAULT_VESTING_CONTRACT_ADDRESS: &str = sandbox::VESTING_CONTRACT_ADDRESS;
pub const DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS: &str = sandbox::BANDWIDTH_CLAIM_CONTRACT_ADDRESS;
pub const ETH_CONTRACT_ADDRESS: [u8; 20] = sandbox::_ETH_CONTRACT_ADDRESS;
pub const ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] = sandbox::_ETH_ERC20_CONTRACT_ADDRESS;
pub const DEFAULT_REWARDING_VALIDATOR: &str = sandbox::REWARDING_VALIDATOR_ADDRESS;
pub fn default_validators() -> Vec<ValidatorDetails> {
sandbox::validators()
}
pub fn default_network() -> all::Network {
all::Network::SANDBOX
}
}
}
// Since these are lazily constructed, we can afford to switch some of them to stronger types in the
// future. If we do this, and also get rid of the references we could potentially unify with
// `NetworkDetails`.
#[derive(Debug)]
pub struct DefaultNetworkDetails<'a> {
bech32_prefix: &'a str,
denom: &'a str,
mixnet_contract_address: &'a str,
vesting_contract_address: &'a str,
bandwidth_claim_contract_address: &'a str,
rewarding_validator_address: &'a str,
validators: Vec<ValidatorDetails>,
}
static MAINNET_DEFAULTS: Lazy<DefaultNetworkDetails<'static>> =
Lazy::new(|| DefaultNetworkDetails {
bech32_prefix: mainnet::BECH32_PREFIX,
denom: mainnet::DENOM,
mixnet_contract_address: mainnet::MIXNET_CONTRACT_ADDRESS,
vesting_contract_address: mainnet::VESTING_CONTRACT_ADDRESS,
bandwidth_claim_contract_address: mainnet::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
rewarding_validator_address: mainnet::REWARDING_VALIDATOR_ADDRESS,
validators: mainnet::validators(),
});
static SANDBOX_DEFAULTS: Lazy<DefaultNetworkDetails<'static>> =
Lazy::new(|| DefaultNetworkDetails {
bech32_prefix: sandbox::BECH32_PREFIX,
denom: sandbox::DENOM,
mixnet_contract_address: sandbox::MIXNET_CONTRACT_ADDRESS,
vesting_contract_address: sandbox::VESTING_CONTRACT_ADDRESS,
bandwidth_claim_contract_address: sandbox::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
rewarding_validator_address: sandbox::REWARDING_VALIDATOR_ADDRESS,
validators: sandbox::validators(),
});
static QA_DEFAULTS: Lazy<DefaultNetworkDetails<'static>> = Lazy::new(|| DefaultNetworkDetails {
bech32_prefix: qa::BECH32_PREFIX,
denom: qa::DENOM,
mixnet_contract_address: qa::MIXNET_CONTRACT_ADDRESS,
vesting_contract_address: qa::VESTING_CONTRACT_ADDRESS,
bandwidth_claim_contract_address: qa::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
rewarding_validator_address: qa::REWARDING_VALIDATOR_ADDRESS,
validators: qa::validators(),
});
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ValidatorDetails {
// it is assumed those values are always valid since they're being provided in our defaults file
@@ -99,15 +116,15 @@ impl ValidatorDetails {
}
pub fn default_nymd_endpoints() -> Vec<Url> {
default_validators()
.iter()
DEFAULT_NETWORK
.validators()
.map(|validator| validator.nymd_url())
.collect()
}
pub fn default_api_endpoints() -> Vec<Url> {
default_validators()
.iter()
DEFAULT_NETWORK
.validators()
.filter_map(|validator| validator.api_url())
.collect()
}
+1
View File
@@ -846,6 +846,7 @@ version = "0.1.0"
dependencies = [
"cfg-if",
"hex-literal",
"once_cell",
"serde",
"thiserror",
"url",
+2 -2
View File
@@ -335,7 +335,7 @@ pub fn migrate(_deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> Result<Respon
pub mod tests {
use super::*;
use crate::support::tests;
use config::defaults::DENOM;
use config::defaults::{DEFAULT_NETWORK, DENOM};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coins, from_binary};
use mixnet_contract_common::PagedMixnodeResponse;
@@ -345,7 +345,7 @@ pub mod tests {
let mut deps = mock_dependencies();
let env = mock_env();
let msg = InstantiateMsg {
rewarding_validator_address: config::defaults::DEFAULT_REWARDING_VALIDATOR.to_string(),
rewarding_validator_address: DEFAULT_NETWORK.rewarding_validator_address().to_string(),
};
let info = mock_info("creator", &[]);
+2 -2
View File
@@ -17,7 +17,7 @@ pub mod test_helpers {
use crate::mixnodes::storage as mixnodes_storage;
use crate::mixnodes::transactions::try_add_mixnode;
use crate::support::tests;
use config::defaults::DENOM;
use config::defaults::{DEFAULT_NETWORK, DENOM};
use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::testing::mock_env;
use cosmwasm_std::testing::mock_info;
@@ -83,7 +83,7 @@ pub mod test_helpers {
pub fn init_contract() -> OwnedDeps<MemoryStorage, MockApi, MockQuerier<Empty>> {
let mut deps = mock_dependencies();
let msg = InstantiateMsg {
rewarding_validator_address: config::defaults::DEFAULT_REWARDING_VALIDATOR.to_string(),
rewarding_validator_address: DEFAULT_NETWORK.rewarding_validator_address().to_string(),
};
let env = mock_env();
let info = mock_info("creator", &[]);
+3 -5
View File
@@ -1,11 +1,9 @@
use network_defaults::{
default_api_endpoints, default_network, default_nymd_endpoints, DEFAULT_MIXNET_CONTRACT_ADDRESS,
};
use network_defaults::{default_api_endpoints, default_nymd_endpoints, DEFAULT_NETWORK};
use validator_client::nymd::QueryNymdClient;
pub(crate) fn new_nymd_client() -> validator_client::Client<QueryNymdClient> {
let network = default_network();
let mixnet_contract = DEFAULT_MIXNET_CONTRACT_ADDRESS.to_string();
let network = DEFAULT_NETWORK;
let mixnet_contract = network.mixnet_contract_address().to_string();
let nymd_url = default_nymd_endpoints()[0].clone();
let api_url = default_api_endpoints()[0].clone();
@@ -3,6 +3,7 @@
use bip39::core::str::FromStr;
use bip39::Mnemonic;
use config::defaults::DEFAULT_NETWORK;
use rand::seq::SliceRandom;
use rand::thread_rng;
use url::Url;
@@ -19,10 +20,7 @@ use bandwidth_claim_contract::payment::LinkPaymentData;
use credentials::token::bandwidth::TokenCredential;
use crypto::asymmetric::identity::{PublicKey, Signature, SIGNATURE_LENGTH};
use gateway_client::bandwidth::eth_contract;
use network_defaults::{
DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS, DEFAULT_MIXNET_CONTRACT_ADDRESS, ETH_EVENT_NAME,
ETH_MIN_BLOCK_DEPTH,
};
use network_defaults::{ETH_EVENT_NAME, ETH_MIN_BLOCK_DEPTH};
use validator_client::nymd::{AccountId, NymdClient, SigningNymdClient};
pub(crate) struct ERC20Bridge {
@@ -42,11 +40,11 @@ impl ERC20Bridge {
let mnemonic =
Mnemonic::from_str(&cosmos_mnemonic).expect("Invalid Cosmos mnemonic provided");
let nymd_client = NymdClient::connect_with_mnemonic(
config::defaults::default_network(),
DEFAULT_NETWORK,
nymd_url.as_ref(),
AccountId::from_str(DEFAULT_MIXNET_CONTRACT_ADDRESS).ok(),
AccountId::from_str(DEFAULT_NETWORK.mixnet_contract_address()).ok(),
None,
AccountId::from_str(DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS).ok(),
AccountId::from_str(DEFAULT_NETWORK.bandwidth_claim_contract_address()).ok(),
mnemonic,
None,
)
+1
View File
@@ -2781,6 +2781,7 @@ version = "0.1.0"
dependencies = [
"cfg-if 1.0.0",
"hex-literal",
"once_cell",
"serde",
"thiserror",
"url",
@@ -129,7 +129,7 @@ async fn _connect_with_mnemonic(
mnemonic: Mnemonic,
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<Account, BackendError> {
let default_network = Network::try_from(config::defaults::default_network())?;
let default_network = Network::try_from(config::defaults::DEFAULT_NETWORK)?;
let mut default_account = None;
for network in Network::iter() {
let client = {
@@ -162,6 +162,7 @@ async fn _connect_with_mnemonic(
w_state.add_client(network, client);
}
default_account
.ok_or_else(|| BackendError::NetworkNotSupported(config::defaults::default_network()))
default_account.ok_or(BackendError::NetworkNotSupported(
config::defaults::DEFAULT_NETWORK,
))
}
+2 -2
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::config::template::config_template;
use config::defaults::{default_api_endpoints, DEFAULT_MIXNET_CONTRACT_ADDRESS};
use config::defaults::{default_api_endpoints, DEFAULT_NETWORK};
use config::NymConfig;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
@@ -97,7 +97,7 @@ impl Default for Base {
local_validator: DEFAULT_LOCAL_VALIDATOR
.parse()
.expect("default local validator is malformed!"),
mixnet_contract_address: DEFAULT_MIXNET_CONTRACT_ADDRESS.to_string(),
mixnet_contract_address: DEFAULT_NETWORK.mixnet_contract_address().to_string(),
#[cfg(feature = "coconut")]
keypair_bs58: String::default(),
}
+3 -3
View File
@@ -3,7 +3,7 @@
use crate::config::Config;
use crate::rewarding::{error::RewardingError, IntervalRewardParams, MixnodeToReward};
use config::defaults::{default_network, DEFAULT_VALIDATOR_API_PORT};
use config::defaults::{DEFAULT_NETWORK, DEFAULT_VALIDATOR_API_PORT};
use mixnet_contract_common::{
ContractStateParams, Delegation, ExecuteMsg, GatewayBond, IdentityKey, Interval, MixNodeBond,
MixnodeRewardingStatusResponse, RewardedSetNodeStatus, RewardedSetUpdateDetails,
@@ -37,7 +37,7 @@ impl Client<QueryNymdClient> {
.parse()
.unwrap();
let nymd_url = config.get_nymd_validator_url();
let network = default_network();
let network = DEFAULT_NETWORK;
let mixnet_contract = config
.get_mixnet_contract_address()
@@ -67,7 +67,7 @@ impl Client<SigningNymdClient> {
.parse()
.unwrap();
let nymd_url = config.get_nymd_validator_url();
let network = default_network();
let network = DEFAULT_NETWORK;
let mixnet_contract = config
.get_mixnet_contract_address()
+7 -4
View File
@@ -9,7 +9,7 @@ use crate::storage::models::{
FailedMixnodeRewardChunk, PossiblyUnrewardedMixnode, RewardingReport,
};
use crate::storage::ValidatorApiStorage;
use config::defaults::DENOM;
use config::defaults::DEFAULT_NETWORK;
use log::{error, info};
use mixnet_contract_common::mixnode::NodeRewardParams;
use mixnet_contract_common::{
@@ -201,15 +201,18 @@ impl Rewarder {
info!("Rewarding pool stats");
info!(
"-- Reward pool: {} {}",
interval_reward_params.reward_pool, DENOM
interval_reward_params.reward_pool,
DEFAULT_NETWORK.denom()
);
info!(
"---- Interval reward pool: {} {}",
interval_reward_params.period_reward_pool, DENOM
interval_reward_params.period_reward_pool,
DEFAULT_NETWORK.denom()
);
info!(
"-- Circulating supply: {} {}",
interval_reward_params.circulating_supply, DENOM
interval_reward_params.circulating_supply,
DEFAULT_NETWORK.denom()
);
// 1. get list of all currently bonded nodes