Skip to content

Commit

Permalink
Added rustmt
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Oct 24, 2023
1 parent be56954 commit d0b17ad
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 47 deletions.
13 changes: 4 additions & 9 deletions crates/erc20_payment_lib/src/db/ops/token_transfer_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,10 @@ pub async fn get_transfer_count(
.fetch_one(conn)
.await?
} else if let Some(receiver) = receiver {
sqlx::query_scalar::<_, i64>(
format!(
r"SELECT COUNT(*) FROM token_transfer WHERE {transfer_filter} AND receiver_addr = $1"
)
.as_str(),
)
.bind(receiver)
.fetch_one(conn)
.await?
sqlx::query_scalar::<_, i64>(format!(r"SELECT COUNT(*) FROM token_transfer WHERE {transfer_filter} AND receiver_addr = $1").as_str())
.bind(receiver)
.fetch_one(conn)
.await?
} else {
sqlx::query_scalar::<_, i64>(
format!(r"SELECT COUNT(*) FROM token_transfer WHERE {transfer_filter}").as_str(),
Expand Down
22 changes: 11 additions & 11 deletions crates/erc20_payment_lib/src/db/ops/transfer_in_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ pub async fn insert_transfer_in(
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
",
)
.bind(&token_transfer.payment_id)
.bind(&token_transfer.from_addr)
.bind(&token_transfer.receiver_addr)
.bind(token_transfer.chain_id)
.bind(&token_transfer.token_addr)
.bind(&token_transfer.token_amount)
.bind(&token_transfer.tx_hash)
.bind(token_transfer.requested_date)
.bind(token_transfer.received_date)
.fetch_one(conn)
.await?;
.bind(&token_transfer.payment_id)
.bind(&token_transfer.from_addr)
.bind(&token_transfer.receiver_addr)
.bind(token_transfer.chain_id)
.bind(&token_transfer.token_addr)
.bind(&token_transfer.token_amount)
.bind(&token_transfer.tx_hash)
.bind(token_transfer.requested_date)
.bind(token_transfer.received_date)
.fetch_one(conn)
.await?;
Ok(res)
}

Expand Down
6 changes: 5 additions & 1 deletion crates/erc20_payment_lib/src/sender/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ pub async fn gather_transactions_batch_multi(
None,
)?
} else if let Some(multi_contract_address) = chain_setup.multi_contract_address {
log::info!("Inserting transaction stub for ERC20 multi transfer contract: {:?} for {} distinct transfers", multi_contract_address, erc20_to.len());
log::info!(
"Inserting transaction stub for ERC20 multi transfer contract: {:?} for {} distinct transfers",
multi_contract_address,
erc20_to.len()
);

create_erc20_transfer_multi(
Address::from_str(&token_transfer.from_addr).map_err(err_from!())?,
Expand Down
50 changes: 31 additions & 19 deletions crates/erc20_payment_lib/src/sender/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ pub async fn process_transaction(
}

if new_target_gas_u256 * 11 < max_fee_per_gas * 10 {
log::warn!("Eco mode activated. Sending transaction with lower base fee. Blockchain base fee: {} Gwei, Tx base fee: {} Gwei",
log::warn!(
"Eco mode activated. Sending transaction with lower base fee. Blockchain base fee: {} Gwei, Tx base fee: {} Gwei",
blockchain_gas_price.to_gwei().map_err(err_from!())?,
new_target_gas_u256.to_gwei().map_err(err_from!())?,
);
);

max_fee_per_gas = new_target_gas_u256;
}
Expand Down Expand Up @@ -531,7 +532,12 @@ pub async fn process_transaction(
db_transaction.commit().await.map_err(err_from!())?;
return Ok((current_tx.clone(), ProcessTransactionResult::Confirmed));
} else {
log::info!("Waiting for confirmations: tx: {}. Current block {}, expected at least: {}", web3_tx_dao.id, current_block_number, block_number + chain_setup.confirmation_blocks);
log::info!(
"Waiting for confirmations: tx: {}. Current block {}, expected at least: {}",
web3_tx_dao.id,
current_block_number,
block_number + chain_setup.confirmation_blocks
);
}
} else {
tx_not_found_count += 1;
Expand Down Expand Up @@ -645,7 +651,12 @@ pub async fn process_transaction(
web3_tx_dao.id
);
} else {
log::warn!("Transaction priority fee changed less than 10% more from {} to {} for tx: {}", max_tx_priority_fee_str, chain_setup.priority_fee, web3_tx_dao.id);
log::warn!(
"Transaction priority fee changed less than 10% more from {} to {} for tx: {}",
max_tx_priority_fee_str,
chain_setup.priority_fee,
web3_tx_dao.id
);
}
}

Expand Down Expand Up @@ -806,22 +817,23 @@ pub async fn process_transaction(
> tx_max_fee_per_gas_gwei
{
send_driver_event(
&event_sender,
DriverEventContent::TransactionStuck(
TransactionStuckReason::GasPriceLow(
GasLowInfo {
tx: web3_tx_dao.clone(),
tx_max_fee_per_gas_gwei,
block_date,
block_number: block.number.unwrap().as_u64(),
block_base_fee_per_gas_gwei,
assumed_min_priority_fee_gwei,
user_friendly_message:
format!("Transaction not processed after {} seconds, block base fee per gas + priority fee: {} Gwei is greater than transaction max fee per gas: {} Gwei", chain_setup.transaction_timeout, block_base_fee_per_gas_gwei + assumed_min_priority_fee_gwei, tx_max_fee_per_gas_gwei),
}
&event_sender,
DriverEventContent::TransactionStuck(TransactionStuckReason::GasPriceLow(GasLowInfo {
tx: web3_tx_dao.clone(),
tx_max_fee_per_gas_gwei,
block_date,
block_number: block.number.unwrap().as_u64(),
block_base_fee_per_gas_gwei,
assumed_min_priority_fee_gwei,
user_friendly_message: format!(
"Transaction not processed after {} seconds, block base fee per gas + priority fee: {} Gwei is greater than transaction max fee per gas: {} Gwei",
chain_setup.transaction_timeout,
block_base_fee_per_gas_gwei + assumed_min_priority_fee_gwei,
tx_max_fee_per_gas_gwei
),
))
.await;
})),
)
.await;
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/erc20_payment_lib/src/sender/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ pub async fn service_loop(
Err(e) => {
match &e.inner {
ErrorBag::NoAllowanceFound(allowance_request) => {
log::info!("No allowance found for contract {} to spend token {} for owner: {}", allowance_request.spender_addr, allowance_request.token_addr, allowance_request.owner);
log::info!(
"No allowance found for contract {} to spend token {} for owner: {}",
allowance_request.spender_addr,
allowance_request.token_addr,
allowance_request.owner
);
match process_allowance(conn, payment_setup, allowance_request, &signer)
.await
{
Expand Down
3 changes: 2 additions & 1 deletion crates/erc20_payment_lib_test/src/blockchain_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ impl GethContainer {
"GLM_CONTRACT_ADDRESS=0xfff17584d526aba263025eE7fEF517E4A31D4246".to_string(),
"FAUCET_ACCOUNT_PUBLIC_ADDRESS=0xafca53fc9628F0E7603bb2bf8E75F07Ee6442cE6".to_string(),
"MAIN_ACCOUNT_PUBLIC_ADDRESS=0x4D6947E072C1Ac37B64600B885772Bd3f27D3E91".to_string(),
"FAUCET_ACCOUNT_PRIVATE_KEY=078d8f6c16446cdb8efbee80535ce8cb32d5b69563bca33e5e6bc0f13f0666b3".to_string()];
"FAUCET_ACCOUNT_PRIVATE_KEY=078d8f6c16446cdb8efbee80535ce8cb32d5b69563bca33e5e6bc0f13f0666b3".to_string(),
];

let (web3_proxy_port, geth_rpc_port) = if let (Some(web3_proxy_port), Some(geth_rpc_port)) =
(opt.web3_proxy_port, opt.web3_port)
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 100
25 changes: 21 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,23 @@ async fn main_internal() -> Result<(), PaymentError> {
}

if scan_info.last_block > start_block {
log::info!("Start block from db is higher than start block from cli {}, using start block from db {}", start_block, scan_info.last_block);
log::info!(
"Start block from db is higher than start block from cli {}, using start block from db {}",
start_block,
scan_info.last_block
);
start_block = scan_info.last_block;
} else if scan_info.last_block != -1 {
log::error!("There is old entry in db, remove it to start new scan or give proper block range: start block: {}, last block {}", start_block, scan_info.last_block);
return Err(err_custom_create!("There is old entry in db, remove it to start new scan or give proper block range: start block: {}, last block {}", start_block, scan_info.last_block));
log::error!(
"There is old entry in db, remove it to start new scan or give proper block range: start block: {}, last block {}",
start_block,
scan_info.last_block
);
return Err(err_custom_create!(
"There is old entry in db, remove it to start new scan or give proper block range: start block: {}, last block {}",
start_block,
scan_info.last_block
));
}

let mut end_block =
Expand All @@ -369,7 +381,12 @@ async fn main_internal() -> Result<(), PaymentError> {

if let Some(blocks_behind) = scan_blockchain_options.blocks_behind {
if end_block > current_block - blocks_behind as i64 {
log::info!("End block {} is too close to current block {}, using current block - blocks_behind: {}", end_block, current_block, current_block - blocks_behind as i64);
log::info!(
"End block {} is too close to current block {}, using current block - blocks_behind: {}",
end_block,
current_block,
current_block - blocks_behind as i64
);
end_block = current_block - blocks_behind as i64;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ pub async fn export_stats(
.bind(format!("{:.6}", fee_paid_total))
.bind(1.to_string())
.bind(transaction_ids.get(&tx.id).unwrap().len().to_string())
.execute(&export_conn).await.map_err(err_from!())?;
.execute(&export_conn)
.await
.map_err(err_from!())?;
}
export_conn.close().await;

Expand Down

0 comments on commit d0b17ad

Please sign in to comment.