diff --git a/crates/erc20_payment_lib/src/runtime.rs b/crates/erc20_payment_lib/src/runtime.rs index e37af3cb..ceec4f94 100644 --- a/crates/erc20_payment_lib/src/runtime.rs +++ b/crates/erc20_payment_lib/src/runtime.rs @@ -6,7 +6,7 @@ use crate::signer::Signer; use crate::transaction::{create_token_transfer, find_receipt_extended}; use crate::{err_custom_create, err_from}; use std::collections::BTreeMap; -use std::ops::{DerefMut}; +use std::ops::DerefMut; use std::path::Path; use std::str::FromStr; @@ -582,14 +582,23 @@ impl PaymentRuntime { sender: Address, receiver: Address, amount: U256, - glm_address: Address + glm_address: Address, ) -> Result { let network_name = self.network_name(chain_id).ok_or(err_custom_create!( "Chain {} not found in config file", chain_id ))?; let prov = self.get_web3_provider(network_name).await?; - verify_transaction(&prov, chain_id, tx_hash, sender, receiver, amount, glm_address).await + verify_transaction( + &prov, + chain_id, + tx_hash, + sender, + receiver, + amount, + glm_address, + ) + .await } pub fn chains(&self) -> Vec { @@ -610,9 +619,10 @@ pub async fn verify_transaction( sender: Address, receiver: Address, amount: U256, - glm_address: Address + glm_address: Address, ) -> Result { - let (chain_tx_dao, transfers) = find_receipt_extended(web3, tx_hash, chain_id, glm_address).await?; + let (chain_tx_dao, transfers) = + find_receipt_extended(web3, tx_hash, chain_id, glm_address).await?; if chain_tx_dao.chain_status == 1 { //one transaction can contain multiple transfers. Search for ours. for transfer in transfers { diff --git a/crates/erc20_payment_lib/src/service.rs b/crates/erc20_payment_lib/src/service.rs index 19c7dcbd..f6a53145 100644 --- a/crates/erc20_payment_lib/src/service.rs +++ b/crates/erc20_payment_lib/src/service.rs @@ -1,4 +1,3 @@ - use std::str::FromStr; use std::sync::Arc; use tokio::sync::Mutex; @@ -13,12 +12,12 @@ use crate::utils::{ConversionError, U256ConvExt}; use crate::setup::{ChainSetup, PaymentSetup}; use crate::{err_custom_create, err_from}; +use crate::contracts::encode_erc20_balance_of; use crate::runtime::SharedState; use sqlx::SqlitePool; use web3::transports::Http; use web3::types::{Address, BlockNumber, CallRequest, U256}; use web3::Web3; -use crate::contracts::encode_erc20_balance_of; pub async fn add_payment_request_2( conn: &SqlitePool, @@ -82,7 +81,7 @@ pub async fn transaction_from_chain_and_into_db( conn: &SqlitePool, chain_id: i64, tx_hash: &str, - glm_address: Address + glm_address: Address, ) -> Result, PaymentError> { println!("tx_hash: {tx_hash}"); let tx_hash = web3::types::H256::from_str(tx_hash) @@ -97,7 +96,8 @@ pub async fn transaction_from_chain_and_into_db( return Ok(Some(chain_tx)); } - let (mut chain_tx_dao, transfers) = find_receipt_extended(web3, tx_hash, chain_id, glm_address).await?; + let (mut chain_tx_dao, transfers) = + find_receipt_extended(web3, tx_hash, chain_id, glm_address).await?; if chain_tx_dao.chain_status != 1 { return Ok(None); @@ -149,13 +149,17 @@ pub async fn transaction_from_chain_and_into_db( max_fee_per_gas: None, max_priority_fee_per_gas: None, }, - Some(web3::types::BlockId::Number(BlockNumber::Number(chain_tx_dao.block_number.into()))), + Some(web3::types::BlockId::Number(BlockNumber::Number( + chain_tx_dao.block_number.into(), + ))), ) - .await { + .await + { Ok(v) => { if v.0.len() == 32 { - break Some(U256::from_big_endian(&v.0)) - } } + break Some(U256::from_big_endian(&v.0)); + } + } Err(e) => { log::debug!("Error getting token balance: {}", e); } @@ -168,11 +172,13 @@ pub async fn transaction_from_chain_and_into_db( log::info!( "Token balance: {:.5} for block {}", - token_balance.map(|v| v.to_eth().unwrap()).unwrap_or_default(), + token_balance + .map(|v| v.to_eth().unwrap()) + .unwrap_or_default(), chain_tx_dao.block_number ); - chain_tx_dao.balance_eth = balance.map(|b|b.to_string()); + chain_tx_dao.balance_eth = balance.map(|b| b.to_string()); chain_tx_dao.balance_glm = token_balance.map(|v| v.to_string()); let mut db_transaction = conn.begin().await.map_err(err_from!())?; @@ -218,7 +224,6 @@ pub async fn transaction_from_chain_and_into_db( } } - db_transaction.commit().await.map_err(err_from!())?; log::info!("Transaction found and parsed successfully: {}", tx.id); Ok(Some(tx)) diff --git a/crates/erc20_payment_lib/src/transaction.rs b/crates/erc20_payment_lib/src/transaction.rs index f25fd387..019733d0 100644 --- a/crates/erc20_payment_lib/src/transaction.rs +++ b/crates/erc20_payment_lib/src/transaction.rs @@ -574,7 +574,7 @@ pub async fn find_receipt_extended( web3: &Web3, tx_hash: H256, chain_id: i64, - glm_address: Address + glm_address: Address, ) -> Result<(ChainTxDao, Vec), PaymentError> { let mut chain_tx_dao = ChainTxDao { id: -1,