From d0b17adb6a2765e99bda17f9bdfd2ec0e36ce1c1 Mon Sep 17 00:00:00 2001 From: scx1332 Date: Tue, 24 Oct 2023 19:04:39 +0200 Subject: [PATCH] Added rustmt --- .../src/db/ops/token_transfer_ops.rs | 13 ++--- .../src/db/ops/transfer_in_ops.rs | 22 ++++---- .../erc20_payment_lib/src/sender/batching.rs | 6 ++- .../erc20_payment_lib/src/sender/process.rs | 50 ++++++++++++------- .../erc20_payment_lib/src/sender/service.rs | 7 ++- .../src/blockchain_setup.rs | 3 +- rustfmt.toml | 1 + src/main.rs | 25 ++++++++-- src/stats.rs | 4 +- 9 files changed, 84 insertions(+), 47 deletions(-) create mode 100644 rustfmt.toml diff --git a/crates/erc20_payment_lib/src/db/ops/token_transfer_ops.rs b/crates/erc20_payment_lib/src/db/ops/token_transfer_ops.rs index 24d4800d..a3f6b7f3 100644 --- a/crates/erc20_payment_lib/src/db/ops/token_transfer_ops.rs +++ b/crates/erc20_payment_lib/src/db/ops/token_transfer_ops.rs @@ -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(), diff --git a/crates/erc20_payment_lib/src/db/ops/transfer_in_ops.rs b/crates/erc20_payment_lib/src/db/ops/transfer_in_ops.rs index bfd5fb7c..128fe81f 100644 --- a/crates/erc20_payment_lib/src/db/ops/transfer_in_ops.rs +++ b/crates/erc20_payment_lib/src/db/ops/transfer_in_ops.rs @@ -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) } diff --git a/crates/erc20_payment_lib/src/sender/batching.rs b/crates/erc20_payment_lib/src/sender/batching.rs index 68383603..93c2de97 100644 --- a/crates/erc20_payment_lib/src/sender/batching.rs +++ b/crates/erc20_payment_lib/src/sender/batching.rs @@ -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!())?, diff --git a/crates/erc20_payment_lib/src/sender/process.rs b/crates/erc20_payment_lib/src/sender/process.rs index 9db11d87..805d9721 100644 --- a/crates/erc20_payment_lib/src/sender/process.rs +++ b/crates/erc20_payment_lib/src/sender/process.rs @@ -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; } @@ -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; @@ -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 + ); } } @@ -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; } } } diff --git a/crates/erc20_payment_lib/src/sender/service.rs b/crates/erc20_payment_lib/src/sender/service.rs index 862914a3..bd59a2a8 100644 --- a/crates/erc20_payment_lib/src/sender/service.rs +++ b/crates/erc20_payment_lib/src/sender/service.rs @@ -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 { diff --git a/crates/erc20_payment_lib_test/src/blockchain_setup.rs b/crates/erc20_payment_lib_test/src/blockchain_setup.rs index bc2e67e6..f64bd8f6 100644 --- a/crates/erc20_payment_lib_test/src/blockchain_setup.rs +++ b/crates/erc20_payment_lib_test/src/blockchain_setup.rs @@ -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) diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..d100efd0 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 100 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8c909bed..e8cdcb06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = @@ -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; } } diff --git a/src/stats.rs b/src/stats.rs index 93b69e80..86b535ef 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -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;