Skip to content

Commit 85c485e

Browse files
authored
Merge pull request #62 from fpco/no-gas-networks
Allow config to set gas price
2 parents 547a58c + ba2e0a1 commit 85c485e

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

packages/cosmos-bin/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub(crate) enum ConfigKey {
6565
ChainId,
6666
Hrp,
6767
GasCoin,
68+
LowGasPrice,
69+
HighGasPrice,
6870
}
6971

7072
impl FromStr for ConfigKey {
@@ -125,6 +127,8 @@ pub(crate) fn go(opt: crate::cli::Opt, inner: Opt) -> Result<()> {
125127
ConfigKey::ChainId => config.set_chain_id(name, value),
126128
ConfigKey::Hrp => config.set_hrp(name, value.parse()?),
127129
ConfigKey::GasCoin => config.set_gas_coin(name, value),
130+
ConfigKey::LowGasPrice => config.set_low_gas_price(name, value.parse()?),
131+
ConfigKey::HighGasPrice => config.set_high_gas_price(name, value.parse()?),
128132
}
129133
config.save()?;
130134
println!("Changes saved");

packages/cosmos/src/config.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use figment::{
99
Figment,
1010
};
1111

12-
use crate::{AddressHrp, ContractType, CosmosBuilder, CosmosNetwork};
12+
use crate::{gas_price::GasPriceMethod, AddressHrp, ContractType, CosmosBuilder, CosmosNetwork};
1313

1414
/// Configuration overrides for individual network
1515
#[derive(Debug)]
@@ -36,6 +36,8 @@ struct NetworkConfig {
3636
gas_multiplier: Option<f64>,
3737
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
3838
code_ids: BTreeMap<ContractType, u64>,
39+
low_gas_price: Option<f64>,
40+
high_gas_price: Option<f64>,
3941
}
4042

4143
impl NetworkConfig {
@@ -52,9 +54,6 @@ impl NetworkConfig {
5254
if let Some(hrp) = self.hrp {
5355
builder.set_hrp(hrp);
5456
}
55-
for (contract_type, code_id) in &self.code_ids {
56-
builder.set_code_id(*contract_type, *code_id);
57-
}
5857
}
5958
fn apply_extra_config(&self, builder: &mut CosmosBuilder) {
6059
for fallback in &self.grpc_fallbacks {
@@ -66,6 +65,18 @@ impl NetworkConfig {
6665
if let Some(gas_multiplier) = self.gas_multiplier {
6766
builder.set_gas_estimate_multiplier(gas_multiplier)
6867
}
68+
let gas_price = match (self.low_gas_price, self.high_gas_price) {
69+
(None, None) => None,
70+
(Some(x), None) => Some((x, x)),
71+
(None, Some(x)) => Some((x, x)),
72+
(Some(x), Some(y)) => Some((x, y)),
73+
};
74+
if let Some((low, high)) = gas_price {
75+
builder.set_gas_price_method(GasPriceMethod::new_static(low, high));
76+
}
77+
for (contract_type, code_id) in &self.code_ids {
78+
builder.set_code_id(*contract_type, *code_id);
79+
}
6980
}
7081
}
7182

@@ -212,6 +223,8 @@ impl CosmosConfig {
212223
grpc_fallbacks,
213224
gas_multiplier,
214225
code_ids,
226+
low_gas_price,
227+
high_gas_price,
215228
},
216229
) in networks
217230
{
@@ -235,6 +248,12 @@ impl CosmosConfig {
235248
if let Some(gas_multiplier) = gas_multiplier {
236249
println!("Gas multiplier: {gas_multiplier}");
237250
}
251+
if let Some(low) = low_gas_price {
252+
println!("Low gas price: {low}");
253+
}
254+
if let Some(high) = high_gas_price {
255+
println!("High gas price: {high}");
256+
}
238257
for (contract_type, code_id) in code_ids {
239258
println!("Code ID for {contract_type}: {code_id}");
240259
}
@@ -260,6 +279,8 @@ impl CosmosConfig {
260279
grpc_fallbacks: vec![],
261280
gas_multiplier: None,
262281
code_ids: BTreeMap::new(),
282+
low_gas_price: None,
283+
high_gas_price: None,
263284
},
264285
);
265286
}
@@ -325,6 +346,16 @@ impl CosmosConfig {
325346
.code_ids
326347
.insert(contract_type, code_id);
327348
}
349+
350+
/// Set the low gas price
351+
pub fn set_low_gas_price(&mut self, name: String, low: f64) {
352+
self.inner.network.entry(name).or_default().low_gas_price = Some(low);
353+
}
354+
355+
/// Set the high gas price
356+
pub fn set_high_gas_price(&mut self, name: String, high: f64) {
357+
self.inner.network.entry(name).or_default().high_gas_price = Some(high);
358+
}
328359
}
329360

330361
impl CosmosNetwork {

0 commit comments

Comments
 (0)