Skip to content
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
4 changes: 4 additions & 0 deletions packages/cosmos-bin/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub(crate) enum ConfigKey {
ChainId,
Hrp,
GasCoin,
LowGasPrice,
HighGasPrice,
}

impl FromStr for ConfigKey {
Expand Down Expand Up @@ -125,6 +127,8 @@ pub(crate) fn go(opt: crate::cli::Opt, inner: Opt) -> Result<()> {
ConfigKey::ChainId => config.set_chain_id(name, value),
ConfigKey::Hrp => config.set_hrp(name, value.parse()?),
ConfigKey::GasCoin => config.set_gas_coin(name, value),
ConfigKey::LowGasPrice => config.set_low_gas_price(name, value.parse()?),
ConfigKey::HighGasPrice => config.set_high_gas_price(name, value.parse()?),
}
config.save()?;
println!("Changes saved");
Expand Down
39 changes: 35 additions & 4 deletions packages/cosmos/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use figment::{
Figment,
};

use crate::{AddressHrp, ContractType, CosmosBuilder, CosmosNetwork};
use crate::{gas_price::GasPriceMethod, AddressHrp, ContractType, CosmosBuilder, CosmosNetwork};

/// Configuration overrides for individual network
#[derive(Debug)]
Expand All @@ -36,6 +36,8 @@ struct NetworkConfig {
gas_multiplier: Option<f64>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
code_ids: BTreeMap<ContractType, u64>,
low_gas_price: Option<f64>,
high_gas_price: Option<f64>,
}

impl NetworkConfig {
Expand All @@ -52,9 +54,6 @@ impl NetworkConfig {
if let Some(hrp) = self.hrp {
builder.set_hrp(hrp);
}
for (contract_type, code_id) in &self.code_ids {
builder.set_code_id(*contract_type, *code_id);
}
}
fn apply_extra_config(&self, builder: &mut CosmosBuilder) {
for fallback in &self.grpc_fallbacks {
Expand All @@ -66,6 +65,18 @@ impl NetworkConfig {
if let Some(gas_multiplier) = self.gas_multiplier {
builder.set_gas_estimate_multiplier(gas_multiplier)
}
let gas_price = match (self.low_gas_price, self.high_gas_price) {
(None, None) => None,
(Some(x), None) => Some((x, x)),
(None, Some(x)) => Some((x, x)),
(Some(x), Some(y)) => Some((x, y)),
};
if let Some((low, high)) = gas_price {
builder.set_gas_price_method(GasPriceMethod::new_static(low, high));
}
for (contract_type, code_id) in &self.code_ids {
builder.set_code_id(*contract_type, *code_id);
}
}
}

Expand Down Expand Up @@ -212,6 +223,8 @@ impl CosmosConfig {
grpc_fallbacks,
gas_multiplier,
code_ids,
low_gas_price,
high_gas_price,
},
) in networks
{
Expand All @@ -235,6 +248,12 @@ impl CosmosConfig {
if let Some(gas_multiplier) = gas_multiplier {
println!("Gas multiplier: {gas_multiplier}");
}
if let Some(low) = low_gas_price {
println!("Low gas price: {low}");
}
if let Some(high) = high_gas_price {
println!("High gas price: {high}");
}
for (contract_type, code_id) in code_ids {
println!("Code ID for {contract_type}: {code_id}");
}
Expand All @@ -260,6 +279,8 @@ impl CosmosConfig {
grpc_fallbacks: vec![],
gas_multiplier: None,
code_ids: BTreeMap::new(),
low_gas_price: None,
high_gas_price: None,
},
);
}
Expand Down Expand Up @@ -325,6 +346,16 @@ impl CosmosConfig {
.code_ids
.insert(contract_type, code_id);
}

/// Set the low gas price
pub fn set_low_gas_price(&mut self, name: String, low: f64) {
self.inner.network.entry(name).or_default().low_gas_price = Some(low);
}

/// Set the high gas price
pub fn set_high_gas_price(&mut self, name: String, high: f64) {
self.inner.network.entry(name).or_default().high_gas_price = Some(high);
}
}

impl CosmosNetwork {
Expand Down
Loading