Skip to content

Commit

Permalink
prevent floating point operations
Browse files Browse the repository at this point in the history
  • Loading branch information
trusch committed Dec 12, 2024
1 parent 6eb91ab commit 148af71
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/base_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ impl BaseClient {
.map_err(|_| Error::Parse("fail".to_string()))?;
let tx_body = cosmrs::tx::BodyBuilder::new().msg(msg).memo(memo).finish();
let signer_info = cosmrs::tx::SignerInfo::single_direct(self.pub_key, sequence);
let gas_per_ucredit = (1.0 / self.gas_price).floor() as u128;
let fee = cosmrs::tx::Fee::from_amount_and_gas(
Coin {
denom: self.denom.parse()?,
amount: (self.gas_price * gas as f64).ceil() as u128,
amount: (gas as u128) / gas_per_ucredit + 1,
},
gas,
);
Expand Down Expand Up @@ -299,11 +300,12 @@ impl BaseClient {
.await?;
log::debug!("simulate_response: {:#?}", simulate_response);
let gas_info = simulate_response.gas_info.ok_or("Failed to get gas info")?;
let gas_limit = (gas_info.gas_used as f64 * self.gas_multiplier).ceil() as u64; // Adjust gas limit based on simulation
let gas_limit = (gas_info.gas_used * ((self.gas_multiplier * 10000.0) as u64)) / 10000; // Adjust gas limit based on simulation
let gas_per_ucredit = (1.0 / self.gas_price).floor() as u128;
let fee = cosmrs::tx::Fee::from_amount_and_gas(
Coin {
denom: self.denom.parse()?,
amount: (self.gas_price * gas_limit as f64).ceil() as u128,
amount: (gas_limit as u128 / gas_per_ucredit) + 1,
},
gas_limit,
);
Expand Down

0 comments on commit 148af71

Please sign in to comment.