Skip to content

Commit

Permalink
fix gas needed calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Oct 30, 2023
1 parent 179fd4a commit 6161574
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions crates/erc20_payment_lib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,23 +509,24 @@ pub async fn send_transaction(
match e {
web3::Error::Rpc(e) => {
log::error!("Error sending transaction: {:#?}", e);
let event =
if e.message.contains("insufficient funds") {
Some(DriverEventContent::TransactionStuck(
TransactionStuckReason::NoGas(NoGasDetails {
tx: web3_tx_dao.clone(),
gas_balance: web3
.eth()
.balance(
Address::from_str(&web3_tx_dao.from_addr)
.map_err(err_from!())?,
None,
)
.await
.map_err(err_from!())?
.to_eth()
.map_err(err_from!())?,
gas_needed: (web3_tx_dao
let event = if e.message.contains("insufficient funds") {
Some(DriverEventContent::TransactionStuck(
TransactionStuckReason::NoGas(NoGasDetails {
tx: web3_tx_dao.clone(),
gas_balance: web3
.eth()
.balance(
Address::from_str(&web3_tx_dao.from_addr)
.map_err(err_from!())?,
None,
)
.await
.map_err(err_from!())?
.to_eth()
.map_err(err_from!())?,
gas_needed: (U256::from_dec_str(&web3_tx_dao.val)
.map_err(err_from!())?
+ web3_tx_dao
.max_fee_per_gas
.clone()
.ok_or(err_custom_create!("Expected max fee per gas here"))?
Expand All @@ -534,40 +535,40 @@ pub async fn send_transaction(
* U256::from(web3_tx_dao.gas_limit.ok_or(
err_custom_create!("Expected gas limit here"),
)?))
.to_eth()
.to_eth()
.map_err(err_from!())?,
}),
))
} else if e.message.contains("transfer amount exceeds balance") {
Some(DriverEventContent::TransactionStuck(
TransactionStuckReason::NoToken(NoTokenDetails {
tx: web3_tx_dao.clone(),
sender: Address::from_str(&web3_tx_dao.from_addr)
.map_err(err_from!())?,
}),
))
} else if e.message.contains("transfer amount exceeds balance") {
Some(DriverEventContent::TransactionStuck(
TransactionStuckReason::NoToken(NoTokenDetails {
tx: web3_tx_dao.clone(),
sender: Address::from_str(&web3_tx_dao.from_addr)
token_balance: get_token_balance(
web3,
glm_token,
Address::from_str(&web3_tx_dao.from_addr)
.map_err(err_from!())?,
token_balance: get_token_balance(
web3,
glm_token,
Address::from_str(&web3_tx_dao.from_addr)
.map_err(err_from!())?,
)
.await?
.to_eth()
.map_err(err_from!())?,
token_needed: get_unpaid_token_amount(
conn,
web3_tx_dao.chain_id,
glm_token,
Address::from_str(&web3_tx_dao.from_addr)
.map_err(err_from!())?,
)
.await?
.to_eth()
.map_err(err_from!())?,
}),
))
} else {
None
};
)
.await?
.to_eth()
.map_err(err_from!())?,
token_needed: get_unpaid_token_amount(
conn,
web3_tx_dao.chain_id,
glm_token,
Address::from_str(&web3_tx_dao.from_addr)
.map_err(err_from!())?,
)
.await?
.to_eth()
.map_err(err_from!())?,
}),
))
} else {
None
};

if let Some(event) = event {
send_driver_event(&event_sender, event).await;
Expand Down

0 comments on commit 6161574

Please sign in to comment.