Skip to content

Commit

Permalink
working on wrapper call
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed May 23, 2024
1 parent 1039ec5 commit 602ce19
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
3 changes: 1 addition & 2 deletions crates/erc20_payment_lib/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,7 @@ pub async fn make_deposit(
"Token balance not found for account {:#x}",
from
))?;
if token_balance < amount + fee_amount
{
if token_balance < amount + fee_amount {
return Err(err_custom_create!(
"You don't have enough: {} GLM on network with chain id: {} and account {:#x}",
token_balance,
Expand Down
12 changes: 10 additions & 2 deletions crates/erc20_payment_lib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ pub async fn check_transaction(
glm_token: Address,
web3: Arc<Web3RpcPool>,
web3_tx_dao: &mut TxDbObj,
wrapper_contract_address: Option<Address>
wrapper_contract_address: Option<Address>,
) -> Result<Option<U256>, PaymentError> {
let call_request = dao_to_call_request(web3_tx_dao)?;
log::debug!("Check transaction with gas estimation: {:?}", call_request);
Expand Down Expand Up @@ -519,7 +519,15 @@ pub async fn check_transaction(
return Ok(None);
} else if e.to_string().contains("transfer amount exceeds balance") {
log::warn!("Transfer amount exceed balance (chain_id: {}, sender: {:#x}). Getting details...", web3_tx_dao.chain_id, Address::from_str(&web3_tx_dao.from_addr).map_err(err_from!())?);
match get_no_token_details(web3, conn, web3_tx_dao, glm_token, wrapper_contract_address).await {
match get_no_token_details(
web3,
conn,
web3_tx_dao,
glm_token,
wrapper_contract_address,
)
.await
{
Ok(stuck_reason) => {
log::warn!(
"Got details. needed: {} balance: {}. needed - balance: {}",
Expand Down
7 changes: 1 addition & 6 deletions crates/erc20_payment_lib_extra/src/account_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ pub async fn account_balance(
block_number: None,
chain_id: Some(chain_cfg.chain_id as u64),
};
let balance = get_balance(
web3,
args
)
.await
.unwrap();
let balance = get_balance(web3, args).await.unwrap();

let gas_balance = balance.gas_balance.map(|b| b.to_string());
let token_balance = balance.token_balance.map(|b| b.to_string());
Expand Down
23 changes: 13 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::actions::deposit::create::make_deposit_local;
use crate::actions::deposit::details::deposit_details_local;
use crate::actions::deposit::terminate::terminate_deposit_local;
use crate::stats::{export_stats, run_stats};
use erc20_payment_lib::eth::GetBalanceArgs;
use erc20_payment_lib::faucet_client::faucet_donate;
use erc20_payment_lib::misc::gen_private_keys;
use erc20_payment_lib::runtime::{
Expand All @@ -50,7 +51,6 @@ use std::sync::Arc;
use structopt::StructOpt;
use tokio::sync::{broadcast, Mutex};
use web3::types::U256;
use erc20_payment_lib::eth::GetBalanceArgs;

async fn main_internal() -> Result<(), PaymentError> {
dotenv::dotenv().ok();
Expand Down Expand Up @@ -530,18 +530,21 @@ async fn main_internal() -> Result<(), PaymentError> {
let args = GetBalanceArgs {
address: public_addr,
token_address: Some(chain_cfg.token.address),
call_with_details: chain_cfg.wrapper_contract.clone().map(|c| c.address),
call_with_details: chain_cfg
.wrapper_contract
.clone()
.map(|c| c.address),
block_number: None,
chain_id: Some(chain_cfg.chain_id as u64),
};
get_token_balance(
payment_setup.get_provider(chain_cfg.chain_id)?,
args
)
.await?.token_balance.ok_or(
err_custom_create!("No balance found for address {:#x}", public_addr)
)?
.to_string()
get_token_balance(payment_setup.get_provider(chain_cfg.chain_id)?, args)
.await?
.token_balance
.ok_or(err_custom_create!(
"No balance found for address {:#x}",
public_addr
))?
.to_string()
} else if single_transfer_options.token == "eth"
|| single_transfer_options.token == "matic"
{
Expand Down

0 comments on commit 602ce19

Please sign in to comment.