diff --git a/src/components/abciapp/src/abci/server/callback/mod.rs b/src/components/abciapp/src/abci/server/callback/mod.rs index fec71386e..dd5244bdf 100644 --- a/src/components/abciapp/src/abci/server/callback/mod.rs +++ b/src/components/abciapp/src/abci/server/callback/mod.rs @@ -278,11 +278,11 @@ pub fn deliver_tx( if let Err(err) = s.account_base_app.write().deliver_findora_tx(&txn, &hash.0) { - tracing::error!(target: "abciapp", "deliver convert account tx failed: {:?}", err); + tracing::error!(target: "abciapp", "deliver convert account tx failed: {err:?}", ); resp.code = 1; resp.log = - format!("deliver convert account tx failed: {:?}", err); + format!("deliver convert account tx failed: {err:?}",); return resp; } diff --git a/src/components/abciapp/src/abci/server/tx_sender.rs b/src/components/abciapp/src/abci/server/tx_sender.rs index 13dbb354a..0382234e6 100644 --- a/src/components/abciapp/src/abci/server/tx_sender.rs +++ b/src/components/abciapp/src/abci/server/tx_sender.rs @@ -50,7 +50,7 @@ pub fn forward_txn_with_mode( ) }; - let tendermint_reply = format!("http://{}", url); + let tendermint_reply = format!("http://{url}",); if 2000 > TX_PENDING_CNT.fetch_add(1, Ordering::Relaxed) { POOL.spawn_ok(async move { ruc::info_omit!(attohttpc::post(&tendermint_reply) diff --git a/src/components/abciapp/src/api/query_server/query_api/mod.rs b/src/components/abciapp/src/api/query_server/query_api/mod.rs index e799d2cb9..617f4d247 100644 --- a/src/components/abciapp/src/api/query_server/query_api/mod.rs +++ b/src/components/abciapp/src/api/query_server/query_api/mod.rs @@ -803,7 +803,7 @@ impl QueryApi { }); for (host, port) in addrs.iter() { - hdr = hdr.bind(&format!("{}:{}", host, port)).c(d!())? + hdr = hdr.bind(&format!("{host}:{port}")).c(d!())? } hdr.run(); diff --git a/src/components/abciapp/src/api/submission_server/submission_api.rs b/src/components/abciapp/src/api/submission_server/submission_api.rs index bc8b690f2..4c67684b3 100644 --- a/src/components/abciapp/src/api/submission_server/submission_api.rs +++ b/src/components/abciapp/src/api/submission_server/submission_api.rs @@ -130,7 +130,7 @@ impl SubmissionApi { web::get().to(txn_status::), ) }) - .bind(&format!("{}:{}", host, port)) + .bind(&format!("{host}:{port}",)) .c(d!())? .run(); diff --git a/src/components/abciapp/src/bins/findorad.rs b/src/components/abciapp/src/bins/findorad.rs index a9eaee0ab..cf450af88 100644 --- a/src/components/abciapp/src/bins/findorad.rs +++ b/src/components/abciapp/src/bins/findorad.rs @@ -123,10 +123,10 @@ fn node_command() -> Result<()> { ctrlc::set_handler(move || { //info_omit!(kill(Pid::from_raw(0), Signal::SIGINT)); pnk!(abcid_child.kill().c(d!())); - pnk!(abcid_child.wait().c(d!()).map(|s| println!("{}", s))); + pnk!(abcid_child.wait().c(d!()).map(|s| println!("{s}",))); pnk!(tendermint_child.kill()); - pnk!(tendermint_child.wait().c(d!()).map(|s| println!("{}", s))); + pnk!(tendermint_child.wait().c(d!()).map(|s| println!("{s}",))); pnk!(send.send(())); }) @@ -163,7 +163,7 @@ fn init_command() -> Result<()> { fn pack() -> Result<()> { let bin_path_orig = get_bin_path().c(d!())?; let bin_name = bin_path_orig.file_name().c(d!())?.to_str().c(d!())?; - let bin_path = format!("/tmp/{}", bin_name); + let bin_path = format!("/tmp/{bin_name}",); fs::copy(bin_path_orig, &bin_path).c(d!())?; let mut f = OpenOptions::new().append(true).open(bin_path).c(d!())?; diff --git a/src/components/config/src/abci/mod.rs b/src/components/config/src/abci/mod.rs index 669233601..e4a94faee 100644 --- a/src/components/config/src/abci/mod.rs +++ b/src/components/config/src/abci/mod.rs @@ -161,11 +161,11 @@ impl CheckPointConfig { return Some(config); } Err(error) => { - panic!("failed to create file: {:?}", error) + panic!("failed to create file: {error:?}",) } }; } else { - panic!("failed to open file: {:?}", error) + panic!("failed to open file: {error:?}",) } } }; @@ -451,7 +451,7 @@ pub mod global_cfg { .value_of("checkpoint-file") .map(|v| v.to_owned()) .unwrap_or_else(|| String::from("./checkpoint.toml")); - println!("{}", checkpoint_path); + println!("{checkpoint_path}",); let res = Config { abci_host: ah, @@ -558,7 +558,7 @@ pub mod global_cfg { .into_iter() .rev() .for_each(|h| { - println!(" {}", h); + println!(" {h}",); }); exit(0); } @@ -576,7 +576,7 @@ pub mod global_cfg { || m.is_present("snapshot-rollback-to") || m.is_present("snapshot-rollback-to-exact") { - println!("\x1b[31;01m\n{}\x1b[00m", HINTS); + println!("\x1b[31;01m\n{HINTS}\x1b[00m",); let (h, strict) = m .value_of("snapshot-rollback-to-exact") diff --git a/src/components/contracts/baseapp/src/app.rs b/src/components/contracts/baseapp/src/app.rs index 2211728ce..5928bddbe 100644 --- a/src/components/contracts/baseapp/src/app.rs +++ b/src/components/contracts/baseapp/src/app.rs @@ -50,7 +50,7 @@ impl crate::BaseApp { let ctx = self.create_query_context(Some(req.height as u64), req.prove); if let Err(e) = ctx { - return err_resp(format!("Cannot create query context with err: {}!", e)); + return err_resp(format!("Cannot create query context with err: {e}!",)); } match path.remove(0) { @@ -144,14 +144,14 @@ impl crate::BaseApp { } resp.code = ar.code; if ar.code != 0 { - info!(target: "baseapp", "Transaction check error, action result {:?}", ar); + info!(target: "baseapp", "Transaction check error, action result {ar:?}", ); resp.log = ar.log; } } Err(e) => { - info!(target: "baseapp", "Transaction check error: {}", e); + info!(target: "baseapp", "Transaction check error: {e}", ); resp.code = 1; - resp.log = format!("Transaction check error: {}", e); + resp.log = format!("Transaction check error: {e}",); } } }; @@ -294,9 +294,9 @@ impl crate::BaseApp { resp } Err(e) => { - error!(target: "baseapp", "Ethereum transaction deliver error: {}", e); + error!(target: "baseapp", "Ethereum transaction deliver error: {e}", ); resp.code = 1; - resp.log = format!("Ethereum transaction deliver error: {}", e); + resp.log = format!("Ethereum transaction deliver error: {e}",); resp } } @@ -334,8 +334,8 @@ impl crate::BaseApp { .write() .commit(block_height) .unwrap_or_else(|e| { - println!("{:?}", e); - panic!("Failed to commit chain state at height: {}", block_height) + println!("{e:?}",); + panic!("Failed to commit chain state at height: {block_height}",) }); // Commit module data based on root_hash @@ -347,7 +347,7 @@ impl crate::BaseApp { .write() .commit(block_height) .unwrap_or_else(|_| { - panic!("Failed to commit chain db at height: {}", block_height) + panic!("Failed to commit chain db at height: {block_height}",) }); // Reset the deliver state, but keep the ethereum cache diff --git a/src/components/contracts/baseapp/src/lib.rs b/src/components/contracts/baseapp/src/lib.rs index 05d003679..3a899fe32 100644 --- a/src/components/contracts/baseapp/src/lib.rs +++ b/src/components/contracts/baseapp/src/lib.rs @@ -310,7 +310,7 @@ impl BaseApp { } fn validate_height(&self, height: i64) -> Result<()> { - ensure!(height >= 1, format!("invalid height: {}", height)); + ensure!(height >= 1, format!("invalid height: {height}",)); let mut expected_height = self.chain_state.read().height().unwrap_or_default() as i64; if expected_height == 0 { @@ -320,7 +320,7 @@ impl BaseApp { } ensure!( height == expected_height, - format!("invalid height: {}; expected: {}", height, expected_height) + format!("invalid height: {height}; expected: {expected_height}") ); Ok(()) } @@ -356,7 +356,7 @@ impl BaseProvider for BaseApp { fn account_of(&self, who: &Address, height: Option) -> Result { let ctx = self.create_query_context(height, false)?; module_account::App::::account_of(&ctx, who, height) - .ok_or(eg!(format!("account does not exist: {}", who))) + .ok_or(eg!(format!("account does not exist: {who}",))) } fn current_block(&self, id: Option) -> Option { diff --git a/src/components/contracts/baseapp/src/modules.rs b/src/components/contracts/baseapp/src/modules.rs index f4982471c..42d2d6346 100644 --- a/src/components/contracts/baseapp/src/modules.rs +++ b/src/components/contracts/baseapp/src/modules.rs @@ -63,7 +63,7 @@ impl ModuleManager { self.template_module.query_route(ctx, path, req) } else { resp.code = 1; - resp.log = format!("Invalid query module route: {}!", module_name); + resp.log = format!("Invalid query module route: {module_name}!",); resp } } diff --git a/src/components/contracts/modules/account/src/impls.rs b/src/components/contracts/modules/account/src/impls.rs index c0ff983cf..c4c64eb13 100644 --- a/src/components/contracts/modules/account/src/impls.rs +++ b/src/components/contracts/modules/account/src/impls.rs @@ -138,7 +138,7 @@ impl AccountAsset
for App { } let mut target_account = Self::account_of(ctx, target, None) - .c(d!(format!("account: {} does not exist", target)))?; + .c(d!(format!("account: {target} does not exist",)))?; target_account.balance = target_account .balance .checked_sub(balance) diff --git a/src/components/contracts/modules/account/src/tests.rs b/src/components/contracts/modules/account/src/tests.rs index 7d20c8733..36c8c3322 100644 --- a/src/components/contracts/modules/account/src/tests.rs +++ b/src/components/contracts/modules/account/src/tests.rs @@ -19,7 +19,7 @@ fn setup() -> Context { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let fdb = FinDB::open(path).unwrap(); let chain_state = Arc::new(RwLock::new(ChainState::new( @@ -29,7 +29,7 @@ fn setup() -> Context { ))); let mut rocks_path = temp_dir(); - rocks_path.push(format!("temp-rocks-db–{}", time)); + rocks_path.push(format!("temp-rocks-db–{time}",)); let rdb = RocksDB::open(rocks_path).unwrap(); let chain_db = Arc::new(RwLock::new(ChainState::new( diff --git a/src/components/contracts/modules/ethereum/src/impls.rs b/src/components/contracts/modules/ethereum/src/impls.rs index 61654416b..639098b04 100644 --- a/src/components/contracts/modules/ethereum/src/impls.rs +++ b/src/components/contracts/modules/ethereum/src/impls.rs @@ -268,7 +268,7 @@ impl App { return Ok(ActionResult { code: 1, data: vec![], - log: format!("{}", e), + log: format!("{e}",), gas_wanted: gas_limit.low_u64(), gas_used: 0, events, @@ -343,7 +343,7 @@ impl App { let message_len = data[36..68].iter().sum::(); let body: &[u8] = &data[68..68 + message_len as usize]; if let Ok(reason) = std::str::from_utf8(body) { - message = format!("{} {}", message, reason); + message = format!("{message} {reason}"); } } (3, message) diff --git a/src/components/contracts/modules/ethereum/src/lib.rs b/src/components/contracts/modules/ethereum/src/lib.rs index 07c180354..f32905238 100644 --- a/src/components/contracts/modules/ethereum/src/lib.rs +++ b/src/components/contracts/modules/ethereum/src/lib.rs @@ -228,8 +228,7 @@ impl ValidateUnsigned for App { let total_payment = transaction.value.saturating_add(fee); if balance < total_payment { return Err(eg!(format!( - "InsufficientBalance, origin: {:?}, actual balance {}, but expected payment {}", - origin, balance, total_payment + "InsufficientBalance, origin: {origin:?}, actual balance {balance}, but expected payment {total_payment}", ))); } diff --git a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs index 1551e9a2f..039159e9a 100644 --- a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs +++ b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs @@ -18,7 +18,7 @@ fn setup() -> Context { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let fdb = FinDB::open(path).unwrap(); let chain_state = Arc::new(RwLock::new(ChainState::new( @@ -28,7 +28,7 @@ fn setup() -> Context { ))); let mut rocks_path = temp_dir(); - rocks_path.push(format!("temp-rocks-db–{}", time)); + rocks_path.push(format!("temp-rocks-db–{time}",)); let rdb = RocksDB::open(rocks_path).unwrap(); let chain_db = Arc::new(RwLock::new(ChainState::new( diff --git a/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs b/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs index 2332c04e7..2fbc24384 100644 --- a/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs +++ b/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs @@ -114,7 +114,7 @@ fn test_abci_deliver_tx() { resp.code, resp.log ); - println!("transfer resp: {:?}", resp); + println!("transfer resp: {resp:?}",); // initial balance = 100_0000_0000_0000_0000_u64, gas limit = 21000, transfer balance = 10 assert_eq!( diff --git a/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs b/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs index 21a6fa2e3..2b083636e 100644 --- a/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs @@ -304,7 +304,7 @@ impl FRC20 { ); C::AccountAsset::approve(state, &caller, &spender_id, amount) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, @@ -349,7 +349,7 @@ impl FRC20 { ); C::AccountAsset::transfer(state, &caller, &recipient_id, amount) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, @@ -405,7 +405,7 @@ impl FRC20 { ); C::AccountAsset::transfer(state, &from_id, &recipient_id, amount) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; C::AccountAsset::approve( state, @@ -413,7 +413,7 @@ impl FRC20 { &caller, allowance.saturating_sub(amount), ) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, diff --git a/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs b/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs index 55d5e5493..8718f50d1 100644 --- a/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs @@ -89,7 +89,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } @@ -110,7 +110,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } @@ -131,7 +131,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } @@ -154,7 +154,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } diff --git a/src/components/contracts/modules/evm/precompile/utils/src/tests.rs b/src/components/contracts/modules/evm/precompile/utils/src/tests.rs index f00e0e2c7..6ac27929f 100644 --- a/src/components/contracts/modules/evm/precompile/utils/src/tests.rs +++ b/src/components/contracts/modules/evm/precompile/utils/src/tests.rs @@ -379,7 +379,7 @@ fn write_address_nested_array() { writer_output .chunks_exact(32) .map(H256::from_slice) - .for_each(|hash| println!("{:?}", hash)); + .for_each(|hash| println!("{hash:?}",)); // We can read this "manualy" using simpler functions since arrays are 32-byte aligned. let mut reader = EvmDataReader::new(&writer_output); diff --git a/src/components/contracts/modules/evm/src/precompile.rs b/src/components/contracts/modules/evm/src/precompile.rs index 828a067be..54e8b8229 100644 --- a/src/components/contracts/modules/evm/src/precompile.rs +++ b/src/components/contracts/modules/evm/src/precompile.rs @@ -17,12 +17,12 @@ pub trait PrecompileSet { /// Otherwise, calculate the amount of gas needed with given `input` and /// `target_gas`. Return `Some(Ok(status, output, gas_used))` if the execution /// is successful. Otherwise return `Some(Err(_))`. - fn execute<'context, 'vicinity, 'config, T>( + fn execute( address: H160, input: &[u8], target_gas: Option, context: &Context, - state: &mut FindoraStackState<'context, 'vicinity, 'config, T>, + state: &mut FindoraStackState<'_, '_, '_, T>, is_static: bool, ) -> Option; } @@ -53,12 +53,12 @@ pub trait PrecompileId { impl PrecompileSet for Tuple { for_tuples!( where #( Tuple: Precompile + PrecompileId )* ); - fn execute<'context, 'vicinity, 'config, T>( + fn execute( address: H160, input: &[u8], target_gas: Option, context: &Context, - state: &mut FindoraStackState<'context, 'vicinity, 'config, T>, + state: &mut FindoraStackState<'_, '_, '_, T>, _is_static: bool, ) -> Option { for_tuples!( #( diff --git a/src/components/contracts/modules/evm/tests/evm_integration.rs b/src/components/contracts/modules/evm/tests/evm_integration.rs index 7f6163ce2..24e4fc188 100644 --- a/src/components/contracts/modules/evm/tests/evm_integration.rs +++ b/src/components/contracts/modules/evm/tests/evm_integration.rs @@ -131,7 +131,7 @@ fn test_deploy_deliver_tx() -> (H160, ethabi::Contract) { resp.code, resp.log ); - println!("deploy erc20 result: {:?}\n", resp); + println!("deploy erc20 result: {resp:?}\n",); let info = serde_json::from_slice::(&resp.data).unwrap(); if let CallOrCreateInfo::Create(info) = info { @@ -144,7 +144,7 @@ fn test_deploy_deliver_tx() -> (H160, ethabi::Contract) { println!("erc20 contract address: {:?}\n", info.value); (info.value, contract_abi) } else { - panic!("not expected result: {:?}", info) + panic!("not expected result: {info:?}",) } } @@ -197,7 +197,7 @@ fn test_mint_deliver_tx(contract: ERC20) { resp.code, resp.log ); - println!("call erc20 mint result: {:?}\n", resp); + println!("call erc20 mint result: {resp:?}\n",); } fn test_transfer_check_tx(contract: ERC20) { @@ -239,7 +239,7 @@ fn test_transfer_deliver_tx(contract: ERC20) { resp.code, resp.log ); - println!("call erc20 transfer result: {:?}\n", resp); + println!("call erc20 transfer result: {resp:?}\n",); } fn test_balance_of_deliver_tx(contract: ERC20, who: H160) -> U256 { @@ -255,7 +255,7 @@ fn test_balance_of_deliver_tx(contract: ERC20, who: H160) -> U256 { resp.code, resp.log ); - println!("call erc20 balanceOf result: {:?}\n", resp); + println!("call erc20 balanceOf result: {resp:?}\n",); let info = serde_json::from_slice::(&resp.data).unwrap(); if let CallOrCreateInfo::Call(info) = info { @@ -267,7 +267,7 @@ fn test_balance_of_deliver_tx(contract: ERC20, who: H160) -> U256 { U256::from_big_endian(info.value.as_ref()) } else { - panic!("not expected result: {:?}", info) + panic!("not expected result: {info:?}",) } } @@ -297,7 +297,7 @@ fn test_balance_of_with_eth_call(contract: ERC20, who: H160) -> U256 { ) .unwrap(); - println!("eth call erc20 balanceOf result: {:?}\n", info); + println!("eth call erc20 balanceOf result: {info:?}\n",); U256::from_big_endian(info.value.as_ref()) } diff --git a/src/components/contracts/modules/evm/tests/utils/solidity.rs b/src/components/contracts/modules/evm/tests/utils/solidity.rs index 6fda0f06f..64728b4ca 100644 --- a/src/components/contracts/modules/evm/tests/utils/solidity.rs +++ b/src/components/contracts/modules/evm/tests/utils/solidity.rs @@ -28,8 +28,8 @@ impl ContractConstructor { P2: AsRef, P3: AsRef, { - let bin_file = format!("{}.bin", contract_name); - let abi_file = format!("{}.abi", contract_name); + let bin_file = format!("{contract_name}.bin",); + let abi_file = format!("{contract_name}.abi",); let hex_path = artifacts_base_path.as_ref().join(bin_file); let hex_rep = match std::fs::read_to_string(&hex_path) { Ok(hex) => hex, diff --git a/src/components/contracts/primitives/evm/src/lib.rs b/src/components/contracts/primitives/evm/src/lib.rs index 2b972ea60..172c098a7 100644 --- a/src/components/contracts/primitives/evm/src/lib.rs +++ b/src/components/contracts/primitives/evm/src/lib.rs @@ -79,6 +79,6 @@ impl BlockId { impl core::fmt::Display for BlockId { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - write!(f, "{:?}", self) + write!(f, "{self:?}",) } } diff --git a/src/components/contracts/primitives/mocks/src/lib.rs b/src/components/contracts/primitives/mocks/src/lib.rs index f88cac008..e34b7fdd1 100644 --- a/src/components/contracts/primitives/mocks/src/lib.rs +++ b/src/components/contracts/primitives/mocks/src/lib.rs @@ -79,7 +79,7 @@ pub fn create_temp_db_path() -> PathBuf { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); path } diff --git a/src/components/contracts/primitives/rpc-core/src/types/block_number.rs b/src/components/contracts/primitives/rpc-core/src/types/block_number.rs index c94fc31a8..9a2523bb1 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/block_number.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/block_number.rs @@ -76,10 +76,9 @@ impl Serialize for BlockNumber { hash, require_canonical, } => serializer.serialize_str(&format!( - "{{ 'hash': '{}', 'requireCanonical': '{}' }}", - hash, require_canonical + "{{ 'hash': '{hash}', 'requireCanonical': '{require_canonical}' }}", )), - BlockNumber::Num(ref x) => serializer.serialize_str(&format!("0x{:x}", x)), + BlockNumber::Num(ref x) => serializer.serialize_str(&format!("0x{x:x}",)), BlockNumber::Latest => serializer.serialize_str("latest"), BlockNumber::Earliest => serializer.serialize_str("earliest"), BlockNumber::Pending => serializer.serialize_str("pending"), @@ -116,7 +115,7 @@ impl<'a> Visitor<'a> for BlockNumberVisitor { "pending" => Ok(BlockNumber::Pending), _ if value.starts_with("0x") => u64::from_str_radix(&value[2..], 16) .map(BlockNumber::Num) - .map_err(|e| Error::custom(format!("Invalid block number: {}", e))), + .map_err(|e| Error::custom(format!("Invalid block number: {e}",))), _ => value.parse::().map(BlockNumber::Num).map_err(|_| { Error::custom( "Invalid block number: non-decimal or missing 0x prefix".to_string(), @@ -148,7 +147,7 @@ impl<'a> Visitor<'a> for BlockNumberVisitor { let value: String = visitor.next_value()?; if let Some(v) = value.strip_prefix("0x") { let number = u64::from_str_radix(v, 16).map_err(|e| { - Error::custom(format!("Invalid block number: {}", e)) + Error::custom(format!("Invalid block number: {e}",)) })?; block_number = Some(number); @@ -165,7 +164,7 @@ impl<'a> Visitor<'a> for BlockNumberVisitor { "requireCanonical" => { require_canonical = visitor.next_value()?; } - key => return Err(Error::custom(format!("Unknown key: {}", key))), + key => return Err(Error::custom(format!("Unknown key: {key}",))), }, None => break, }; diff --git a/src/components/contracts/primitives/rpc-core/src/types/bytes.rs b/src/components/contracts/primitives/rpc-core/src/types/bytes.rs index 4aae0b7c3..d330ee5f5 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/bytes.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/bytes.rs @@ -85,7 +85,7 @@ impl<'a> Visitor<'a> for BytesVisitor { { if value.len() >= 2 && value.starts_with("0x") && value.len() & 1 == 0 { Ok(Bytes::new(FromHex::from_hex(&value[2..]).map_err(|e| { - Error::custom(format!("Invalid hex: {}", e)) + Error::custom(format!("Invalid hex: {e}",)) })?)) } else { Err(Error::custom( diff --git a/src/components/contracts/primitives/rpc-core/src/types/filter.rs b/src/components/contracts/primitives/rpc-core/src/types/filter.rs index c3d3b2221..2b800e540 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/filter.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/filter.rs @@ -59,7 +59,7 @@ where .map(VariadicValue::Single) .or_else(|_| from_value(v).map(VariadicValue::Multiple)) .map_err(|err| { - D::Error::custom(format!("Invalid variadic value type: {}", err)) + D::Error::custom(format!("Invalid variadic value type: {err}",)) }) } } diff --git a/src/components/contracts/primitives/rpc-core/src/types/index.rs b/src/components/contracts/primitives/rpc-core/src/types/index.rs index 30fcf63cb..a3cd28552 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/index.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/index.rs @@ -56,11 +56,11 @@ impl<'a> Visitor<'a> for IndexVisitor { match value { _ if value.starts_with("0x") => usize::from_str_radix(&value[2..], 16) .map(Index) - .map_err(|e| Error::custom(format!("Invalid index: {}", e))), + .map_err(|e| Error::custom(format!("Invalid index: {e}",))), _ => value .parse::() .map(Index) - .map_err(|e| Error::custom(format!("Invalid index: {}", e))), + .map_err(|e| Error::custom(format!("Invalid index: {e}",))), } } diff --git a/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs b/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs index c9c7b5c1e..2b28359d3 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs @@ -105,7 +105,7 @@ impl<'a> Deserialize<'a> for Params { from_value(v) .map(Params::Logs) - .map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {}", e))) + .map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {e}",))) } } diff --git a/src/components/contracts/primitives/storage/src/tests.rs b/src/components/contracts/primitives/storage/src/tests.rs index b67602afa..b8e031abe 100644 --- a/src/components/contracts/primitives/storage/src/tests.rs +++ b/src/components/contracts/primitives/storage/src/tests.rs @@ -12,7 +12,7 @@ fn setup_temp_db() -> Arc>> { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let fdb = TempFinDB::open(path).unwrap(); let chain_state = Arc::new(RwLock::new(ChainState::new( fdb, diff --git a/src/components/contracts/primitives/utils/src/ecdsa.rs b/src/components/contracts/primitives/utils/src/ecdsa.rs index 4e71af624..6bbf4fecd 100644 --- a/src/components/contracts/primitives/utils/src/ecdsa.rs +++ b/src/components/contracts/primitives/utils/src/ecdsa.rs @@ -73,9 +73,8 @@ impl<'de> Deserialize<'de> for Public { { let pk = base64::decode_config(String::deserialize(deserializer)?, base64::URL_SAFE) - .map_err(|e| de::Error::custom(format!("{:?}", e)))?; - Public::try_from(pk.as_slice()) - .map_err(|e| de::Error::custom(format!("{:?}", e))) + .map_err(|e| de::Error::custom(format!("{e:?}",)))?; + Public::try_from(pk.as_slice()).map_err(|e| de::Error::custom(format!("{e:?}",))) } } @@ -174,9 +173,9 @@ impl<'de> Deserialize<'de> for Signature { D: Deserializer<'de>, { let signature_hex = hex::decode(String::deserialize(deserializer)?) - .map_err(|e| de::Error::custom(format!("{:?}", e)))?; + .map_err(|e| de::Error::custom(format!("{e:?}",)))?; Signature::try_from(signature_hex.as_ref()) - .map_err(|e| de::Error::custom(format!("{:?}", e))) + .map_err(|e| de::Error::custom(format!("{e:?}",))) } } @@ -444,7 +443,7 @@ mod test { "2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000200d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000" ); let signature = pair.sign(&message[..]); - println!("Correct signature: {:?}", signature); + println!("Correct signature: {signature:?}",); assert!(SecpPair::verify(&signature, &message[..], &public)); assert!(!SecpPair::verify(&signature, "Other message", &public)); } diff --git a/src/components/contracts/primitives/wasm/src/wasm.rs b/src/components/contracts/primitives/wasm/src/wasm.rs index f587e244c..08b31bdbe 100644 --- a/src/components/contracts/primitives/wasm/src/wasm.rs +++ b/src/components/contracts/primitives/wasm/src/wasm.rs @@ -47,7 +47,7 @@ pub fn recover_tx_signer(raw_tx: String) -> Result { .map_err(error_to_jsvalue)?; if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let signer = recover_signer(&tx).c(d!()).map_err(error_to_jsvalue)?; - Ok(format!("{:?}", signer)) + Ok(format!("{signer:?}",)) } else { Err(error_to_jsvalue("invalid raw tx")) } @@ -67,7 +67,7 @@ pub fn evm_tx_hash(raw_tx: String) -> Result { .map_err(error_to_jsvalue)?; if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&tx)).as_slice()); - Ok(format!("{:?}", hash)) + Ok(format!("{hash:?}",)) } else { Err(error_to_jsvalue("invalid raw tx")) } @@ -89,7 +89,7 @@ mod test { if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let signer = recover_signer(&tx).unwrap(); assert_eq!( - format!("{:?}", signer), + format!("{signer:?}",), "0xa5225cbee5052100ec2d2d94aa6d258558073757" ); } else { @@ -106,7 +106,7 @@ mod test { if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&tx)).as_slice()); assert_eq!( - format!("{:?}", hash), + format!("{hash:?}",), "0x0eeb0ff455b1b57b821634cf853e7247e584a675610f13097cc49c2022505df3" ); } else { diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index 5f572cb1b..b1e7b8331 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -103,8 +103,7 @@ impl EthApiImpl { Some(block) => Some(block.header.number.as_u64()), None => { return Err(internal_err(format!( - "block number not found, hash: {:?}", - hash + "block number not found, hash: {hash:?}", ))) } }, @@ -113,8 +112,7 @@ impl EthApiImpl { Some(num) } else { return Err(internal_err(format!( - "block number: {} exceeds version range: {:?}", - num, range + "block number: {num} exceeds version range: {range:?}", ))); } } @@ -379,7 +377,7 @@ impl EthApi for EthApiImpl { .read() .create_query_context(None, false) .map_err(|err| { - internal_err(format!("create query context error: {:?}", err)) + internal_err(format!("create query context error: {err:?}",)) })?; if let Some(block) = block { ctx.header @@ -406,9 +404,9 @@ impl EthApi for EthApiImpl { &ctx, call, &config, ) .map_err(|err| { - internal_err(format!("evm runner call error: {:?}", err)) + internal_err(format!("evm runner call error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); + debug!(target: "eth_rpc", "evm runner call result: {info:?}", ); error_on_execution_failure(&info.exit_reason, &info.value)?; @@ -428,9 +426,9 @@ impl EthApi for EthApiImpl { &ctx, create, &config, ) .map_err(|err| { - internal_err(format!("evm runner create error: {:?}", err)) + internal_err(format!("evm runner create error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + debug!(target: "eth_rpc", "evm runner create result: {info:?}", ); error_on_execution_failure(&info.exit_reason, &[])?; @@ -774,8 +772,7 @@ impl EthApi for EthApiImpl { (Some(BlockId::Number(U256::from(num))), false) } else { return Err(internal_err(format!( - "block number: {} exceeds version range: {:?}", - num, range + "block number: {num} exceeds version range: {range:?}", ))); } } @@ -854,7 +851,7 @@ impl EthApi for EthApiImpl { .read() .create_query_context(if pending { None } else { Some(0) }, false) .map_err(|err| { - internal_err(format!("create query context error: {:?}", err)) + internal_err(format!("create query context error: {err:?}",)) })?; let CallRequest { @@ -891,9 +888,9 @@ impl EthApi for EthApiImpl { &ctx, call, &config, ) .map_err(|err| { - internal_err(format!("evm runner call error: {:?}", err)) + internal_err(format!("evm runner call error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); + debug!(target: "eth_rpc", "evm runner call result: {info:?}", ); Ok(ExecuteResult { data: info.value, @@ -915,9 +912,9 @@ impl EthApi for EthApiImpl { &ctx, create, &config, ) .map_err(|err| { - internal_err(format!("evm runner create error: {:?}", err)) + internal_err(format!("evm runner create error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + debug!(target: "eth_rpc", "evm runner create result: {info:?}", ); Ok(ExecuteResult { data: vec![], @@ -986,7 +983,7 @@ impl EthApi for EthApiImpl { id = Some(BlockId::Number(number)); index = idx as usize } - println!("{:?}, {:?}", id, index); + println!("{id:?}, {index:?}"); let block = account_base_app.read().current_block(id.clone()); let statuses = account_base_app diff --git a/src/components/contracts/rpc/src/eth_filter.rs b/src/components/contracts/rpc/src/eth_filter.rs index 18c71814d..eb82a4228 100644 --- a/src/components/contracts/rpc/src/eth_filter.rs +++ b/src/components/contracts/rpc/src/eth_filter.rs @@ -154,8 +154,7 @@ impl EthFilterApiImpl { // Check for restrictions if ret.len() as u32 > max_past_logs { return Err(internal_err(format!( - "query returned more than {} results", - max_past_logs + "query returned more than {max_past_logs} results", ))); } if begin_request.elapsed() > max_duration { @@ -302,7 +301,7 @@ impl EthFilterApi for EthFilterApiImpl { _ => Err(internal_err("Method not available.")), } } else { - Err(internal_err(format!("Filter id {:?} does not exist.", key))) + Err(internal_err(format!("Filter id {key:?} does not exist.",))) } } else { Err(internal_err("Filter pool is not available.")) @@ -346,12 +345,11 @@ impl EthFilterApi for EthFilterApiImpl { Ok(ret) } _ => Err(internal_err(format!( - "Filter id {:?} is not a Log filter.", - key + "Filter id {key:?} is not a Log filter.", ))), } } else { - Err(internal_err(format!("Filter id {:?} does not exist.", key))) + Err(internal_err(format!("Filter id {key:?} does not exist.",))) } } else { Err(internal_err("Filter pool is not available.")) @@ -367,7 +365,7 @@ impl EthFilterApi for EthFilterApiImpl { if locked.remove(&key).is_some() { Ok(true) } else { - Err(internal_err(format!("Filter id {:?} does not exist.", key))) + Err(internal_err(format!("Filter id {key:?} does not exist.",))) } } else { Err(internal_err("Filter pool is not available.")) diff --git a/src/components/contracts/rpc/src/lib.rs b/src/components/contracts/rpc/src/lib.rs index d989d77bf..51c482bb7 100644 --- a/src/components/contracts/rpc/src/lib.rs +++ b/src/components/contracts/rpc/src/lib.rs @@ -161,7 +161,7 @@ pub fn error_on_execution_failure( } Err(Error { code: ErrorCode::InternalError, - message: format!("evm error: {:?}", e), + message: format!("evm error: {e:?}",), data: Some(Value::String("0x".to_string())), }) } @@ -174,7 +174,7 @@ pub fn error_on_execution_failure( let message_len = data[36..68].iter().sum::(); let body: &[u8] = &data[68..68 + message_len as usize]; if let Ok(reason) = std::str::from_utf8(body) { - message = format!("{} {}", message, reason); + message = format!("{message} {reason}"); } } Err(Error { @@ -185,7 +185,7 @@ pub fn error_on_execution_failure( } ExitReason::Fatal(e) => Err(Error { code: ErrorCode::InternalError, - message: format!("evm fatal: {:?}", e), + message: format!("evm fatal: {e:?}"), data: Some(Value::String("0x".to_string())), }), } diff --git a/src/components/contracts/rpc/src/utils.rs b/src/components/contracts/rpc/src/utils.rs index 51745ebdb..865f0021e 100644 --- a/src/components/contracts/rpc/src/utils.rs +++ b/src/components/contracts/rpc/src/utils.rs @@ -6,7 +6,7 @@ use tokio::task::JoinError; pub fn convert_join_error_to_rpc_error(e: JoinError) -> Error { Error { code: ErrorCode::InternalError, - message: format!("{:?}", e), + message: format!("{e:?}",), data: None, } } @@ -14,7 +14,7 @@ pub fn convert_join_error_to_rpc_error(e: JoinError) -> Error { pub fn convert_error_to_rpc_error(e: impl Debug) -> Error { Error { code: ErrorCode::InternalError, - message: format!("{:?}", e), + message: format!("{e:?}",), data: None, } } diff --git a/src/components/finutils/src/bins/cfg_generator.rs b/src/components/finutils/src/bins/cfg_generator.rs index d41b09914..66bb1a0b5 100644 --- a/src/components/finutils/src/bins/cfg_generator.rs +++ b/src/components/finutils/src/bins/cfg_generator.rs @@ -76,8 +76,7 @@ fn gen() -> Result<()> { .and_then(|m| fs::write(&secret_info_path, m).c(d!())) .map(|_| { println!( - "\x1b[01mSecret info has been writed to \x1b[31m{}\x1b[00m", - secret_info_path + "\x1b[01mSecret info has been writed to \x1b[31m{secret_info_path}\x1b[00m", ); }) } diff --git a/src/components/finutils/src/bins/fn.rs b/src/components/finutils/src/bins/fn.rs index f8823e74b..75240bbe3 100644 --- a/src/components/finutils/src/bins/fn.rs +++ b/src/components/finutils/src/bins/fn.rs @@ -209,7 +209,7 @@ fn run() -> Result<()> { .c(d!())?; } else { let help = "fn asset [--create | --issue | --show]"; - println!("{}", help); + println!("{help}",); } } else if let Some(m) = matches.subcommand_matches("staker-update") { let vm = if let Some(memo) = m.value_of("validator-memo") { @@ -431,7 +431,7 @@ fn run() -> Result<()> { } if address.is_some() { let (account, info) = contract_account_info(address, is_address_fra)?; - println!("AccountId: {}\n{:#?}\n", account, info); + println!("AccountId: {account}\n{info:#?}\n",); } } else if let Some(m) = matches.subcommand_matches("contract-deposit") { let amount = m.value_of("amount").c(d!())?; @@ -542,7 +542,7 @@ fn run() -> Result<()> { if let Some(path) = m.value_of("file-path") { serde_json::to_writer_pretty(&File::create(path).c(d!())?, &keys).c(d!())?; - println!("Keys saved to file: {}", path); + println!("Keys saved to file: {path}",); } // print keys to terminal @@ -603,7 +603,7 @@ fn run() -> Result<()> { ); // Print UTXO table - println!("Owned utxos for {:?}", pk); + println!("Owned utxos for {pk:?}",); println!("{:-^1$}", "", 100); println!( "{0: <8} | {1: <18} | {2: <45} ", @@ -1132,7 +1132,7 @@ fn tip_fail(e: impl fmt::Display) { eprintln!( "\x1b[35;01mTips\x1b[01m:\n\tPlease send your error messages to us,\n\tif you can't understand their meanings ~^!^~\x1b[00m" ); - eprintln!("\n{}", e); + eprintln!("\n{e}",); } fn tip_success() { diff --git a/src/components/finutils/src/bins/stt/init/i_testing.rs b/src/components/finutils/src/bins/stt/init/i_testing.rs index 909fdc10a..271e655e3 100644 --- a/src/components/finutils/src/bins/stt/init/i_testing.rs +++ b/src/components/finutils/src/bins/stt/init/i_testing.rs @@ -394,7 +394,7 @@ struct TmValidator { } fn get_26657_validators(sa: &str) -> Result { - let url = format!("{}:26657/validators", sa); + let url = format!("{sa}:26657/validators",); attohttpc::get(url) .send() .c(d!())? diff --git a/src/components/finutils/src/bins/stt/init/mod.rs b/src/components/finutils/src/bins/stt/init/mod.rs index 7de620bce..d0721d999 100644 --- a/src/components/finutils/src/bins/stt/init/mod.rs +++ b/src/components/finutils/src/bins/stt/init/mod.rs @@ -40,7 +40,7 @@ pub fn init( } else { let root_kp = wallet::restore_keypair_from_mnemonic_default(ROOT_MNEMONIC).c(d!())?; - println!(">>> Block interval: {} seconds", interval); + println!(">>> Block interval: {interval} seconds",); println!(">>> Define and issue FRA ..."); common::utils::send_tx(&fra_gen_initial_tx(&root_kp)).c(d!())?; diff --git a/src/components/finutils/src/bins/stt/stt.rs b/src/components/finutils/src/bins/stt/stt.rs index 7f416affe..d757d8084 100644 --- a/src/components/finutils/src/bins/stt/stt.rs +++ b/src/components/finutils/src/bins/stt/stt.rs @@ -406,20 +406,20 @@ fn print_info( if show_user_list { let user_list = serde_json::to_string_pretty(&*USER_LIST).c(d!())?; - println!("\x1b[31;01mUSER LIST:\x1b[00m\n{}\n", user_list); + println!("\x1b[31;01mUSER LIST:\x1b[00m\n{user_list}\n",); } if show_validator_list { let validator_list = serde_json::to_string_pretty(&*VALIDATOR_LIST).c(d!())?; - println!("\x1b[31;01mVALIDATOR LIST:\x1b[00m\n{}\n", validator_list); + println!("\x1b[31;01mVALIDATOR LIST:\x1b[00m\n{validator_list}\n",); } if let Some(u) = user { let balance = get_balance(u).c(d!())?; - println!("\x1b[31;01mUSER BALANCE:\x1b[00m\n{} FRA units\n", balance); + println!("\x1b[31;01mUSER BALANCE:\x1b[00m\n{balance} FRA units\n",); let user_info = get_delegation_info(u).c(d!())?; - println!("\x1b[31;01mUSER DELEGATION:\x1b[00m\n{}\n", user_info); + println!("\x1b[31;01mUSER DELEGATION:\x1b[00m\n{user_info}\n",); } Ok(()) diff --git a/src/components/finutils/src/common/ddev/init.rs b/src/components/finutils/src/common/ddev/init.rs index 29419fd70..93c7f631e 100644 --- a/src/components/finutils/src/common/ddev/init.rs +++ b/src/components/finutils/src/common/ddev/init.rs @@ -48,7 +48,7 @@ pub(super) fn init(env: &mut Env) -> Result<()> { let port = ports[IDX_TM_RPC]; let page_size = env.custom_data.initial_validator_num; let tmrpc_endpoint = - format!("http://{}:{}/validators?per_page={}", addr, port, page_size); + format!("http://{addr}:{port}/validators?per_page={page_size}",); let tm_validators = attohttpc::get(&tmrpc_endpoint) .send() @@ -173,7 +173,7 @@ fn setup_initial_validators(env: &Env) -> Result<()> { fn send_tx(env: &Env, tx: &Transaction) -> Result<()> { let (addr, ports) = env.get_addrports_any_node(); let port = ports[IDX_APP_8669]; - let rpc_endpoint = format!("http://{}:{}/submit_transaction", addr, port); + let rpc_endpoint = format!("http://{addr}:{port}/submit_transaction"); attohttpc::post(&rpc_endpoint) .header(attohttpc::header::CONTENT_TYPE, "application/json") .bytes(&serde_json::to_vec(tx).c(d!())?) @@ -244,7 +244,7 @@ fn new_tx_builder(env: &Env) -> Result { fn gen_8668_endpoint(env: &Env) -> String { let (addr, ports) = env.get_addrports_any_node(); let port = ports[IDX_APP_8668]; - format!("http://{}:{}", addr, port) + format!("http://{addr}:{port}",) } #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/src/components/finutils/src/common/ddev/mod.rs b/src/components/finutils/src/common/ddev/mod.rs index 26a8421e5..a71e67b8e 100644 --- a/src/components/finutils/src/common/ddev/mod.rs +++ b/src/components/finutils/src/common/ddev/mod.rs @@ -304,7 +304,7 @@ impl NodeOptsGenerator, EnvMeta>> for OptsGe ); if let Some(cp) = m.custom_data.checkpoint_file.as_ref() { - write!(opts, " --checkpoint-file {}", cp).unwrap(); + write!(opts, " --checkpoint-file {cp}",).unwrap(); } write!(opts, " {}", &m.app_extra_opts).unwrap(); diff --git a/src/components/finutils/src/common/dev/mod.rs b/src/components/finutils/src/common/dev/mod.rs index 926d0aaf7..0692e7b2e 100644 --- a/src/components/finutils/src/common/dev/mod.rs +++ b/src/components/finutils/src/common/dev/mod.rs @@ -182,7 +182,7 @@ impl NodeOptsGenerator, EnvMeta>> for OptsGe ); if let Some(cp) = m.custom_data.checkpoint_file.as_ref() { - write!(opts, " --checkpoint-file {}", cp).unwrap(); + write!(opts, " --checkpoint-file {cp}",).unwrap(); } write!(opts, " {}", &m.app_extra_opts).unwrap(); diff --git a/src/components/finutils/src/common/mod.rs b/src/components/finutils/src/common/mod.rs index 1f9e848fa..7486d02f2 100644 --- a/src/components/finutils/src/common/mod.rs +++ b/src/components/finutils/src/common/mod.rs @@ -155,8 +155,7 @@ pub fn stake( || diff!(network_height, local_height) > 3 { println!( - "The difference in block height of your node and the remote network is too big: \n remote / local: {} / {}", - network_height, local_height + "The difference in block height of your node and the remote network is too big: \n remote / local: {network_height} / {local_height}", ); if !force { println!("Append option --force to ignore this warning."); @@ -329,7 +328,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { let kp = get_keypair(is_address_fra).c(d!())?; let serv_addr = ruc::info!(get_serv_addr()).map(|i| { - println!("\x1b[31;01mServer URL:\x1b[00m\n{}\n", i); + println!("\x1b[31;01mServer URL:\x1b[00m\n{i}\n",); }); let xfr_account = ruc::info!(get_keypair(is_address_fra)).map(|i| { @@ -348,7 +347,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { }); let self_balance = ruc::info!(utils::get_balance(&kp)).map(|i| { - println!("\x1b[31;01mNode Balance:\x1b[00m\n{} FRA units\n", i); + println!("\x1b[31;01mNode Balance:\x1b[00m\n{i} FRA units\n",); }); if basic { @@ -357,7 +356,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { let td_info = ruc::info!(get_td_pubkey()).map(|i| { let addr = td_pubkey_to_td_addr(&i); - println!("\x1b[31;01mValidator Node Addr:\x1b[00m\n{}\n", addr); + println!("\x1b[31;01mValidator Node Addr:\x1b[00m\n{addr}\n",); (i, addr) }); @@ -371,7 +370,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { serde_json::to_string_pretty(&di).c(d!("server returned invalid data")) }); let delegation_info = ruc::info!(delegation_info).map(|i| { - println!("\x1b[31;01mYour Delegation:\x1b[00m\n{}\n", i); + println!("\x1b[31;01mYour Delegation:\x1b[00m\n{i}\n",); }); if let Ok((tpk, addr)) = td_info.as_ref() { @@ -385,7 +384,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { .c(d!("server returned invalid data")) }) .map(|i| { - println!("\x1b[31;01mYour Staking:\x1b[00m\n{}\n", i); + println!("\x1b[31;01mYour Staking:\x1b[00m\n{i}\n",); }); ruc::info_omit!(res); } @@ -639,8 +638,7 @@ pub fn gen_key(is_fra_address: bool) -> (String, String, String, XfrKeyPair) { pub fn gen_key_and_print(is_fra_address: bool) { let (wallet_addr, mnemonic, key, _) = gen_key(is_fra_address); println!( - "\n\x1b[31;01mWallet Address:\x1b[00m {}\n\x1b[31;01mMnemonic:\x1b[00m {}\n\x1b[31;01mKey:\x1b[00m {}\n", - wallet_addr, mnemonic, key + "\n\x1b[31;01mWallet Address:\x1b[00m {wallet_addr}\n\x1b[31;01mMnemonic:\x1b[00m {mnemonic}\n\x1b[31;01mKey:\x1b[00m {key}\n", ); } @@ -649,7 +647,7 @@ fn restore_keypair_from_str_with_default( is_fra_address: bool, ) -> Result { if let Some(sk) = sk_str { - serde_json::from_str::(&format!("\"{}\"", sk)) + serde_json::from_str::(&format!("\"{sk}\"",)) .map(|sk| sk.into_keypair()) .c(d!("Invalid secret key")) } else { @@ -905,7 +903,7 @@ pub fn show_asset(addr: &str) -> Result<()> { for asset in assets { let base64 = asset.body.asset.code.to_base64(); let h = hex::encode(asset.body.asset.code.val.0); - println!("Base64: {}, Hex: {}", base64, h); + println!("Base64: {base64}, Hex: {h}",); } Ok(()) @@ -924,12 +922,11 @@ pub fn convert_bar2abar( ) -> Result { // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\"",))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_fra).c(d!())?, }; // parse receiver AxfrPubKey @@ -1397,7 +1394,7 @@ pub fn get_owned_abars( axfr_secret_key: AXfrKeyPair, commitments_list: &str, ) -> Result<()> { - println!("Abar data for commitments: {}", commitments_list); + println!("Abar data for commitments: {commitments_list}",); println!(); println!( "{0: <8} | {1: <18} | {2: <45} | {3: <9} | {4: <45}", diff --git a/src/components/finutils/src/common/utils.rs b/src/components/finutils/src/common/utils.rs index ef89aae62..d6f346350 100644 --- a/src/components/finutils/src/common/utils.rs +++ b/src/components/finutils/src/common/utils.rs @@ -482,7 +482,7 @@ struct TmStatus { // retrieve tendermint status and node info #[inline(always)] fn get_network_status(addr: &str) -> Result { - let url = format!("{}:26657/status", addr); + let url = format!("{addr}:26657/status",); attohttpc::get(url) .send() diff --git a/src/components/finutils/src/txn_builder/mod.rs b/src/components/finutils/src/txn_builder/mod.rs index 102cba254..ad40f086e 100644 --- a/src/components/finutils/src/txn_builder/mod.rs +++ b/src/components/finutils/src/txn_builder/mod.rs @@ -799,7 +799,7 @@ impl TransactionBuilder { return Err(eg!("insufficient FRA to pay fees!")); } if fra_remainder > 0 { - println!("Transaction FRA Remainder Amount: {:?}", fra_remainder); + println!("Transaction FRA Remainder Amount: {fra_remainder:?}",); let oabar_money_back = OpenAnonAssetRecordBuilder::new() .amount(fra_remainder as u64) .asset_type(ASSET_TYPE_FRA) @@ -1353,7 +1353,7 @@ impl TransferOperationBuilder { .iter() .fold(0, |acc, ar| acc + ar.open_asset_record.amount); if input_total != output_total { - return Err(eg!(format!("{} != {}", input_total, output_total))); + return Err(eg!(format!("{input_total} != {output_total}",))); } Ok(()) @@ -1421,8 +1421,7 @@ impl TransferOperationBuilder { .fold(0, |acc, ar| acc + ar.open_asset_record.amount); if spend_total != output_total { return Err(eg!(format!( - "Spend total != output, {} != {}", - spend_total, output_total + "Spend total != output, {spend_total} != {output_total}", ))); } self.output_records.append(&mut partially_consumed_inputs); diff --git a/src/ledger/src/data_model/mod.rs b/src/ledger/src/data_model/mod.rs index a929225d5..0fe831488 100644 --- a/src/ledger/src/data_model/mod.rs +++ b/src/ledger/src/data_model/mod.rs @@ -254,10 +254,7 @@ impl AssetTypeCode { val: NoahAssetType(buf), }) } - Err(e) => Err(eg!((format!( - "Failed to deserialize base64 '{}': {}", - b64, e - )))), + Err(e) => Err(eg!((format!("Failed to deserialize base64 '{b64}': {e}",)))), } } @@ -1037,7 +1034,7 @@ impl AssetTypePrefix { AssetTypePrefix::NFT => "02", }; - hex::decode(format!("{:0>64}", code)).unwrap() + hex::decode(format!("{code:0>64}",)).unwrap() } } diff --git a/src/ledger/src/data_model/test.rs b/src/ledger/src/data_model/test.rs index 145fdadd1..8b0e1918d 100755 --- a/src/ledger/src/data_model/test.rs +++ b/src/ledger/src/data_model/test.rs @@ -46,7 +46,7 @@ fn test_gen_random_with_rng() { let uniform_stddev = 1.0 / (12.0f64).sqrt(); let average = sum as f64 / sample_size as f64; let stddev = (uniform_stddev * 255.0) / (sample_size as f64).sqrt(); - println!("Average {}, stddev {}", average, stddev); + println!("Average {average}, stddev {stddev}"); assert!(average > 127.5 - 5.0 * stddev); assert!(average < 127.5 + 5.0 * stddev); } diff --git a/src/ledger/src/staking/cosig.rs b/src/ledger/src/staking/cosig.rs index e88333307..041631f71 100644 --- a/src/ledger/src/staking/cosig.rs +++ b/src/ledger/src/staking/cosig.rs @@ -207,7 +207,7 @@ impl fmt::Display for CoSigErr { CoSigErr::WeightInsufficient => "total weight is lower than the threshold", CoSigErr::SigInvalid => "invalid signature", }; - write!(f, "{}", msg) + write!(f, "{msg}",) } } diff --git a/src/ledger/src/staking/mod.rs b/src/ledger/src/staking/mod.rs index 6d0545835..fca45ab10 100644 --- a/src/ledger/src/staking/mod.rs +++ b/src/ledger/src/staking/mod.rs @@ -1461,7 +1461,7 @@ impl Staking { vd.addr_td_to_app .get(addr) .copied() - .c(d!(format!("Failed to get pk {}", addr))) + .c(d!(format!("Failed to get pk {addr}",))) }) } @@ -2452,8 +2452,7 @@ pub fn check_delegation_amount(am: Amount, is_append: bool) -> Result<()> { Ok(()) } else { let msg = format!( - "Invalid delegation amount: {} (min: {}, max: {})", - am, lowb, MAX_DELEGATION_AMOUNT + "Invalid delegation amount: {am} (min: {lowb}, max: {MAX_DELEGATION_AMOUNT})", ); Err(eg!(msg)) } diff --git a/src/ledger/src/store/api_cache.rs b/src/ledger/src/store/api_cache.rs index a08f3c277..38bb290bc 100644 --- a/src/ledger/src/store/api_cache.rs +++ b/src/ledger/src/store/api_cache.rs @@ -92,55 +92,45 @@ impl ApiCache { ApiCache { prefix: prefix.to_owned(), related_transactions: new_mapx!(format!( - "api_cache/{}related_transactions", - prefix + "api_cache/{prefix}related_transactions", )), - related_transfers: new_mapx!(format!( - "api_cache/{}related_transfers", - prefix - )), - claim_hist_txns: new_mapx!(format!("api_cache/{}claim_hist_txns", prefix)), + related_transfers: new_mapx!( + format!("api_cache/{prefix}related_transfers",) + ), + claim_hist_txns: new_mapx!(format!("api_cache/{prefix}claim_hist_txns",)), coinbase_oper_hist: new_mapx!(format!( - "api_cache/{}coinbase_oper_hist", - prefix + "api_cache/{prefix}coinbase_oper_hist", )), - created_assets: new_mapx!(format!("api_cache/{}created_assets", prefix)), - issuances: new_mapx!(format!("api_cache/{}issuances", prefix)), + created_assets: new_mapx!(format!("api_cache/{prefix}created_assets",)), + issuances: new_mapx!(format!("api_cache/{prefix}issuances",)), token_code_issuances: new_mapx!(format!( - "api_cache/{}token_code_issuances", - prefix + "api_cache/{prefix}token_code_issuances", )), - owner_memos: new_mapxnk!(format!("api_cache/{}owner_memos", prefix)), - abar_memos: new_mapx!(format!("api_cache/{}abar_memos", prefix)), + owner_memos: new_mapxnk!(format!("api_cache/{prefix}owner_memos",)), + abar_memos: new_mapx!(format!("api_cache/{prefix}abar_memos",)), utxos_to_map_index: new_mapxnk!(format!( - "api_cache/{}utxos_to_map_index", - prefix + "api_cache/{prefix}utxos_to_map_index", )), - txo_to_txnid: new_mapxnk!(format!("api_cache/{}txo_to_txnid", prefix)), - atxo_to_txnid: new_mapx!(format!("api_cache/{}atxo_to_txnid", prefix)), - txn_sid_to_hash: new_mapxnk!(format!("api_cache/{}txn_sid_to_hash", prefix)), - txn_hash_to_sid: new_mapx!(format!("api_cache/{}txn_hash_to_sid", prefix)), + txo_to_txnid: new_mapxnk!(format!("api_cache/{prefix}txo_to_txnid",)), + atxo_to_txnid: new_mapx!(format!("api_cache/{prefix}atxo_to_txnid",)), + txn_sid_to_hash: new_mapxnk!(format!("api_cache/{prefix}txn_sid_to_hash",)), + txn_hash_to_sid: new_mapx!(format!("api_cache/{prefix}txn_hash_to_sid",)), staking_global_rate_hist: new_mapxnk!(format!( - "api_cache/{}staking_global_rate_hist", - prefix + "api_cache/{prefix}staking_global_rate_hist", )), height_to_max_atxo: new_mapxnk!(format!( - "api_cache/{}height_to_max_atxo", - prefix + "api_cache/{prefix}height_to_max_atxo", )), staking_self_delegation_hist: new_mapx!(format!( - "api_cache/{}staking_self_delegation_hist", - prefix + "api_cache/{prefix}staking_self_delegation_hist", )), staking_delegation_amount_hist: new_mapx!(format!( - "api_cache/{}staking_delegation_amount_hist", - prefix + "api_cache/{prefix}staking_delegation_amount_hist", )), staking_delegation_rwd_hist: new_mapx!(format!( - "api_cache/{}staking_delegation_rwd_hist", - prefix + "api_cache/{prefix}staking_delegation_rwd_hist", )), - last_sid: new_mapx!(format!("api_cache/{}last_sid", prefix)), + last_sid: new_mapx!(format!("api_cache/{prefix}last_sid",)), state_commitment_version: None, } } diff --git a/src/ledger/src/store/helpers.rs b/src/ledger/src/store/helpers.rs index 5acbc8097..b74d65475 100644 --- a/src/ledger/src/store/helpers.rs +++ b/src/ledger/src/store/helpers.rs @@ -103,7 +103,7 @@ pub fn apply_transaction( } Err(e) => { fn unwrap_failed(msg: &str, error: impl Debug) -> ! { - panic!("{}: {:?}", msg, error) + panic!("{msg}: {error:?}",) } unwrap_failed("apply_transaction: error in compute_effect", e) } diff --git a/src/ledger/src/store/mod.rs b/src/ledger/src/store/mod.rs index 6c2d42e20..75fb1a7ef 100644 --- a/src/ledger/src/store/mod.rs +++ b/src/ledger/src/store/mod.rs @@ -579,7 +579,7 @@ impl LedgerState { /// Initialize a new Ledger structure. pub fn new(basedir: &str, prefix: Option<&str>) -> Result { let prefix = if let Some(p) = prefix { - format!("{}_", p) + format!("{p}_",) } else { "".to_owned() }; @@ -1402,7 +1402,7 @@ impl LedgerStatus { /// Load or init LedgerStatus from snapshot #[inline(always)] pub fn new(basedir: &str, snapshot_file: &str) -> Result { - let path = format!("{}/{}", basedir, snapshot_file); + let path = format!("{basedir}/{snapshot_file}",); match fs::read_to_string(path) { Ok(s) => serde_json::from_str(&s).c(d!()), Err(e) => { @@ -1480,8 +1480,7 @@ impl LedgerStatus { // Check to see that this nrpt has not been seen before if self.sliding_set.has_key_at(seq_id as usize, rand) { return Err(eg!(format!( - "No replay token ({:?}, {})seen before at possible replay", - rand, seq_id + "No replay token ({rand:?}, {seq_id})seen before at possible replay", ))); } } @@ -1744,7 +1743,7 @@ impl LedgerStatus { no_replay_token.get_seq_id() as usize, ); if let Err(e) = self.sliding_set.insert(rand, seq_id) { - pd!(format!("Error inserting into window: {}", e)); + pd!(format!("Error inserting into window: {e}",)); } } block.no_replay_tokens.clear(); diff --git a/src/libs/bitmap/src/lib.rs b/src/libs/bitmap/src/lib.rs index fbf2bed15..a30a08527 100644 --- a/src/libs/bitmap/src/lib.rs +++ b/src/libs/bitmap/src/lib.rs @@ -293,8 +293,7 @@ impl BlockHeader { && block_contents != BIT_HEADER { return Err(eg!(format!( - "That content type ({}) is invalid.", - block_contents + "That content type ({block_contents}) is invalid.", ))); } @@ -671,10 +670,10 @@ impl BitMap { let file_size = file.seek(SeekFrom::End(0)).c(d!())?; if file_size % BLOCK_SIZE as u64 != 0 { - return Err(eg!(format!("That file size ({}) is invalid.", file_size))); + return Err(eg!(format!("That file size ({file_size}) is invalid.",))); } - file.seek(SeekFrom::Start(0)).c(d!())?; + file.rewind().c(d!())?; let total_blocks = file_size / BLOCK_SIZE as u64; // Reserve space in our vectors. @@ -737,11 +736,11 @@ impl BitMap { if validate_checksums { if let Err(e) = block.validate(BIT_ARRAY, i as u64) { - println!("Block {} failed validation: {}", i, e); + println!("Block {i} failed validation: {e}",); pass = false; } } else if let Err(e) = header.validate(BIT_ARRAY, i as u64) { - println!("Block {} failed validation: {}", i, e); + println!("Block {i} failed validation: {e}"); pass = false; } @@ -1254,7 +1253,7 @@ impl BitMap { let bytes_consumed = list_size as usize * INDEX_SIZE; if index + bytes_consumed > bytes.len() { - return Err(eg!(format!("An index list was too long: {}", list_size))); + return Err(eg!(format!("An index list was too long: {list_size}",))); } for _ in 0..list_size { diff --git a/src/libs/bitmap/src/test.rs b/src/libs/bitmap/src/test.rs index 58ff122d0..619aeb2be 100755 --- a/src/libs/bitmap/src/test.rs +++ b/src/libs/bitmap/src/test.rs @@ -30,7 +30,7 @@ fn test_header() { assert!(header.bit_id == id * BLOCK_BITS as u64); if let Err(e) = header.validate(BIT_ARRAY, id) { - panic!("Validation failed: {}", e); + panic!("Validation failed: {e}",); } header.magic ^= 1; @@ -138,7 +138,7 @@ fn test_basic_bitmap() { let mut bitmap = BitMap::create(file).unwrap(); if let Err(e) = bitmap.write() { - panic!("Write failed: {}", e); + panic!("Write failed: {e}",); } // Check our definition of the checksum of an empty tree. @@ -184,15 +184,15 @@ fn test_basic_bitmap() { // Try a flush now and then. if i % (BLOCK_BITS / 2) == 0 { if let Err(e) = bitmap.flush_old(0) { - panic!("flush_old failed: {}", e); + panic!("flush_old failed: {e}",); } } } let checksum1 = bitmap.compute_checksum(); let checksum2 = bitmap.compute_checksum(); - println!("Checksum 1: {:?}", checksum1); - println!("Checksum 2: {:?}", checksum2); + println!("Checksum 1: {checksum1:?}",); + println!("Checksum 2: {checksum2:?}",); assert!(checksum1 == checksum2); bitmap.clear_checksum_cache(); @@ -203,7 +203,7 @@ fn test_basic_bitmap() { let s1 = bitmap.serialize_partial(vec![0, BLOCK_BITS], 1); if let Err(x) = BitMap::deserialize(&s1) { - panic!("deserialize(&s1) failed: {}", x); + panic!("deserialize(&s1) failed: {x}",); } // Pick a random version number and serialize the entire @@ -212,7 +212,7 @@ fn test_basic_bitmap() { let s2 = bitmap.serialize(sparse_version); if let Err(x) = BitMap::deserialize(&s2) { - panic!("deserialize(&s2) failed: {}", x); + panic!("deserialize(&s2) failed: {x}",); } // Create SparseMaps from the serialized forms. @@ -237,7 +237,7 @@ fn test_basic_bitmap() { // Check that the sparse bitmap matches the source bitmap. if bitmap_result != sparse_result { - panic!("Sparse mismatch at {}", i); + panic!("Sparse mismatch at {i}",); } // Now check the partial bitmap. @@ -284,11 +284,11 @@ fn test_basic_bitmap() { let bits_initialized = bitmap.size(); if let Err(e) = bitmap.write() { - panic!("write failed: {}", e); + panic!("write failed: {e}",); } if let Err(e) = bitmap.flush_old(0) { - panic!("flush_old failed: {}", e); + panic!("flush_old failed: {e}",); } assert!(bitmap.validate(true)); diff --git a/src/libs/globutils/src/lib.rs b/src/libs/globutils/src/lib.rs index f2da30690..ffa3c81ab 100644 --- a/src/libs/globutils/src/lib.rs +++ b/src/libs/globutils/src/lib.rs @@ -48,7 +48,7 @@ pub fn fresh_tmp_dir() -> PathBuf { // Convert a u64 into a string with commas. fn commas_u64(input: u64) -> String { if input < 10000 { - return format!("{}", input); + return format!("{input}",); } let mut value = input; @@ -62,7 +62,7 @@ fn commas_u64(input: u64) -> String { if value == 1000 { result = "1,000".to_owned() + &result; } else { - result = format!("{}", value) + &result; + result = format!("{value}",) + &result; } result diff --git a/src/libs/globutils/src/logging.rs b/src/libs/globutils/src/logging.rs index 0b257fcdf..81e1cba02 100644 --- a/src/libs/globutils/src/logging.rs +++ b/src/libs/globutils/src/logging.rs @@ -16,17 +16,17 @@ pub fn init_logging(verbose: Option<&str>) { env_filter = env_filter.add_directive(LevelFilter::DEBUG.into()); } else { env_filter = - env_filter.add_directive(format!("{}=debug", module).parse().unwrap()); + env_filter.add_directive(format!("{module}=debug",).parse().unwrap()); } } if let Ok(rust_log) = env::var("RUST_LOG") { - println!("{}", rust_log); + println!("{rust_log}",); if !rust_log.is_empty() { for directive in rust_log.split(',').filter_map(|s| match s.parse() { Ok(directive) => Some(directive), Err(err) => { - eprintln!("Ignoring directive `{}`: {}", s, err); + eprintln!("Ignoring directive `{s}`: {err}",); None } }) { diff --git a/src/libs/merkle_tree/src/lib.rs b/src/libs/merkle_tree/src/lib.rs index 4db52c3e1..1d81d8f8b 100644 --- a/src/libs/merkle_tree/src/lib.rs +++ b/src/libs/merkle_tree/src/lib.rs @@ -438,8 +438,7 @@ impl Block { for i in 0..limit { if self.hashes[i] == HashValue::new() { return Err(eg!(format!( - "Hash entry {} for block {} at level {} is invalid.", - i, id, level + "Hash entry {i} for block {id} at level {level} is invalid.", ))); } } @@ -583,7 +582,7 @@ impl Drop for AppendOnlyMerkle { #[inline(always)] fn drop(&mut self) { if let Err(e) = self.write() { - panic!("AppendOnlyMerkle: drop failed, err = {}", e); + panic!("AppendOnlyMerkle: drop failed, err = {e}",); } } } @@ -672,7 +671,7 @@ impl AppendOnlyMerkle { let save = path.to_owned() + &ext; if path::Path::new(&save).exists() { - return Err(eg!(format!("Rebuild path {} already exists.", save))); + return Err(eg!(format!("Rebuild path {save} already exists.",))); } // Rename the level zero file out of the way and then create @@ -709,7 +708,7 @@ impl AppendOnlyMerkle { let file_size = input.seek(SeekFrom::End(0)).c(d!())?; let block_count = file_size / BLOCK_SIZE as u64; - input.seek(SeekFrom::Start(0)).c(d!())?; + input.rewind().c(d!())?; self.files[0] = input; let mut entries = 0; @@ -807,8 +806,7 @@ impl AppendOnlyMerkle { Ok(b) => b, Err(x) => { return Err(eg!(format!( - "Reconstruction of block {} at level {} failed: {}", - block_id, level, x + "Reconstruction of block {block_id} at level {level} failed: {x}", ))); } }; @@ -907,7 +905,7 @@ impl AppendOnlyMerkle { let path = self.path.clone(); let extension = if level > 0 { - format!(".{}", level) + format!(".{level}",) } else { "".to_string() }; @@ -966,7 +964,7 @@ impl AppendOnlyMerkle { return self.recover_file(level); } - if self.files[level].seek(SeekFrom::Start(0)).is_err() { + if self.files[level].rewind().is_err() { return self.recover_file(level); } @@ -1251,7 +1249,7 @@ impl AppendOnlyMerkle { let (block, prev) = items; if let Err(x) = block.set_hash(¤t_hash) { - return Err(eg!(format!("The tree is corrupted: set_hash: {}", x))); + return Err(eg!(format!("The tree is corrupted: set_hash: {x}",))); } // If the block is full, and all the previous blocks are @@ -1344,8 +1342,7 @@ impl AppendOnlyMerkle { pub fn generate_proof(&self, transaction_id: u64, version: u64) -> Result { if transaction_id >= self.entry_count { return Err(eg!(format!( - "That transaction id ({}) does not exist.", - transaction_id + "That transaction id ({transaction_id}) does not exist.", ))); } @@ -1696,8 +1693,7 @@ impl AppendOnlyMerkle { Ok(n) => { if n != start_offset { return Err(eg!(format!( - "A seek to {} returned {}.", - start_offset, n + "A seek to {start_offset} returned {n}.", ))); } } @@ -1721,8 +1717,7 @@ impl AppendOnlyMerkle { if i < total_blocks - 1 && !block.full() { return Err(eg!(format!( - "Block {} at level {} should be full.", - i, level + "Block {i} at level {level} should be full.", ))); } @@ -1772,8 +1767,7 @@ impl AppendOnlyMerkle { if disk_bytes != expected_size { return Err(eg!(format!( - "check_disk: The file size ({}) at level {} should be {}.", - disk_bytes, level, expected_size + "check_disk: The file size ({disk_bytes}) at level {level} should be {expected_size}.", ))); } @@ -1783,13 +1777,12 @@ impl AppendOnlyMerkle { if flushed && blocks_on_disk != list_length { return Err(eg!(format!( - "check_disk: The count {} at level {} should be {}.", - blocks_on_disk, level, list_length + "check_disk: The count {blocks_on_disk} at level {level} should be {list_length}.", ))); } - if let Err(x) = self.files[level].seek(SeekFrom::Start(0)) { - return Err(eg!(format!("check_disk: The read seek failed: {}", x))); + if let Err(x) = self.files[level].rewind() { + return Err(eg!(format!("check_disk: The read seek failed: {x}",))); } let mut entry_count = 0_u64; @@ -1817,7 +1810,7 @@ impl AppendOnlyMerkle { current.push(block); } Err(x) => { - return Err(eg!(format!("check_disk: A read failed: {}", x))); + return Err(eg!(format!("check_disk: A read failed: {x}",))); } } } @@ -1828,9 +1821,8 @@ impl AppendOnlyMerkle { // contents if the memory has been flushed. if flushed && entry_count != entries_at_this_level { return Err(eg!(format!( - "check_disk: The entry counts ({}, {}) \ - at level {} didn't match.", - entry_count, entries_at_this_level, level + "check_disk: The entry counts ({entry_count}, {entries_at_this_level}) \ + at level {level} didn't match.", ))); } @@ -1936,8 +1928,7 @@ impl AppendOnlyMerkle { if !last && !last_block_full { return Err(eg!(format!( - "check: Block {} at level {} should be full.", - block_id, level + "check: Block {block_id} at level {level} should be full.", ))); } @@ -1957,8 +1948,7 @@ impl AppendOnlyMerkle { if leaf_count != leaves_at_this_level { return Err(eg!(format!( - "check: The entry counts ({}, {}) at level {} did not match", - leaf_count, leaves_at_this_level, level + "check: The entry counts ({leaf_count}, {leaves_at_this_level}) at level {level} did not match", ))); } @@ -1974,9 +1964,8 @@ impl AppendOnlyMerkle { if last_level && leaves_at_this_level > 0 { return Err(eg!(format!( - "Level {} has {} blocks, with {} upper leaves, \ + "Level {level} has {last_blocks} blocks, with {leaves_at_this_level} upper leaves, \ but no levels remain.", - level, last_blocks, leaves_at_this_level ))); } } @@ -2088,7 +2077,7 @@ mod tests { #[test] fn test_info() { println!("The block size is {} bytes.", mem::size_of::()); - println!("A block contains {} leaves.", LEAVES_IN_BLOCK); + println!("A block contains {LEAVES_IN_BLOCK} leaves.",); } // Do some basic tests on the block header code to make sure that @@ -2098,7 +2087,7 @@ mod tests { let mut header = BlockHeader::new(3, 5); if let Err(e) = header.check(3, 5) { - panic!("new() returned an invalid header: {}", e); + panic!("new() returned an invalid header: {e}",); } header.header_mark ^= 1; @@ -2131,7 +2120,7 @@ mod tests { fn check_block(block: &Block, level: usize, id: u64, disk_format: bool) { if let Err(e) = block.check(level, id, disk_format) { - panic!("Unexpected block check error: {}", e); + panic!("Unexpected block check error: {e}",); } } @@ -2162,13 +2151,13 @@ mod tests { hash.hash[1] = (i & 0xff) as u8; if let Err(e) = block.set_hash(&hash) { - panic!("Unexpected set_hash error: {} at {}", e, i); + panic!("Unexpected set_hash error: {e} at {i}"); } block.set_checksum(); if let Err(e) = block.check(1, 2, false) { - panic!("Block check failure at iteration {}: {}", i, e); + panic!("Block check failure at iteration {i}: {e}"); } // If the block is not full, there will still be hash entries @@ -2211,7 +2200,7 @@ mod tests { check_block(&block, 1, 2, false); if block.valid_leaves() != i as u64 + 1 { - panic!("valid_leaves() should be {}", i); + panic!("valid_leaves() should be {i}",); } if !block.full() { @@ -2226,7 +2215,7 @@ mod tests { let error = block.set_hash(&hash); if let Ok(()) = error { - panic!("Missing error at iteration {}.", i); + panic!("Missing error at iteration {i}.",); } } @@ -2237,7 +2226,7 @@ mod tests { // Now check that mismatched block ids and levels are // caught. First, make sure that the block is valid. if let Err(e) = block.check(1, 2, false) { - panic!("The block was corrupted by set_hash: {}", e); + panic!("The block was corrupted by set_hash: {e}",); } if block.check(0, 2, false).is_ok() { @@ -2258,7 +2247,7 @@ mod tests { block.header.check_bits.bits[0] ^= 1; if let Err(e) = block.check(1, 2, false) { - panic!("Testing error: {}", e); + panic!("Testing error: {e}",); } // Now corrupt checksum[last] and do the checks. @@ -2271,7 +2260,7 @@ mod tests { block.header.check_bits.bits[CHECK_SIZE - 1] ^= 1; if let Err(e) = block.check(1, 2, false) { - panic!("Testing error: {}", e); + panic!("Testing error: {e}",); } // Okay, corrupt a hash in the subtree. @@ -2333,7 +2322,7 @@ mod tests { let mut tree = match result { Ok(tree) => tree, Err(x) => { - panic!("Unexpected error: {}", x); + panic!("Unexpected error: {x}",); } }; @@ -2341,7 +2330,7 @@ mod tests { check_tree(&tree); if let Err(x) = AppendOnlyMerkle::open(&path) { - panic!("read() got an error: {}", x); + panic!("read() got an error: {x}",); } if tree.path() != path { @@ -2360,7 +2349,7 @@ mod tests { tree = match AppendOnlyMerkle::open(&path) { Err(x) => { - panic!("Open failed: {}", x); + panic!("Open failed: {x}",); } Ok(x) => x, }; @@ -2386,7 +2375,7 @@ mod tests { // Check that the image can be read and is reasonable. match AppendOnlyMerkle::open(&path) { Err(x) => { - panic!("The open failed: {}", x); + panic!("The open failed: {x}",); } Ok(new_tree) => { if new_tree.total_size() != tree.total_size() { @@ -2398,12 +2387,12 @@ mod tests { let level_path = tree.file_path(1); if let Err(x) = fs::remove_file(&level_path) { - panic!("remove_file failed: {}", x); + panic!("remove_file failed: {x}",); } let mut tree = match AppendOnlyMerkle::open(&path) { Err(x) => { - panic!("Open failed to rebuild: {}", x); + panic!("Open failed to rebuild: {x}",); } Ok(tree) => tree, }; @@ -2415,7 +2404,7 @@ mod tests { // Now make sure that the new write path deals well with // disk reset operations. if let Err(e) = tree.reset_disk() { - panic!("Unexpected error: {}", e); + panic!("Unexpected error: {e}",); } for _i in 0..2 * LEAVES_IN_BLOCK { @@ -2455,25 +2444,25 @@ mod tests { fn check_tree(tree: &AppendOnlyMerkle) { if let Err(e) = tree.check() { - panic!("Got check error: {}", e); + panic!("Got check error: {e}",); } } fn check_disk_tree(tree: &mut AppendOnlyMerkle, flushed: bool) { if let Err(e) = tree.check_disk(flushed) { - panic!("Got disk check error: {}", e); + panic!("Got disk check error: {e}",); } } fn write_tree(tree: &mut AppendOnlyMerkle) { if let Err(e) = tree.write() { - panic!("tree.write failed: {}", e); + panic!("tree.write failed: {e}",); } } fn reset_tree(tree: &mut AppendOnlyMerkle) { if let Err(e) = tree.reset_disk() { - panic!("tree.reset_disk failed: {}", e); + panic!("tree.reset_disk failed: {e}",); } } @@ -2482,7 +2471,7 @@ mod tests { let result = tree.append_hash(&hash); if let Err(x) = result { - panic!("append_hash failed: {}", x); + panic!("append_hash failed: {x}",); } result.unwrap() @@ -2500,7 +2489,7 @@ mod tests { let mut tree = match result { Err(x) => { - panic!("Unexpected error: {}", x); + panic!("Unexpected error: {x}",); } Ok(tree) => tree, }; @@ -2544,7 +2533,7 @@ mod tests { check_disk_tree(&mut tree, false); if let Err(x) = AppendOnlyMerkle::open(&path) { - panic!("Open failed: {}", x); + panic!("Open failed: {x}",); } } @@ -2577,11 +2566,11 @@ mod tests { // Try a reconstruct match tree.reconstruct(1, 0) { Err(x) => { - panic!("reconstruct failed: {}", x); + panic!("reconstruct failed: {x}",); } Ok(block) => { if let Err(e) = block.check(1, 0, true) { - panic!("The reconstruct block is bad: {}", e); + panic!("The reconstruct block is bad: {e}",); } for i in 0..HASHES_IN_BLOCK { @@ -2630,7 +2619,7 @@ mod tests { check_disk_tree(&mut tree, true); if let Err(x) = AppendOnlyMerkle::open(&path) { - panic!("open failed: {}", x); + panic!("open failed: {x}",); } reset_tree(&mut tree); @@ -2662,7 +2651,7 @@ mod tests { match result { Err(x) => { - panic!("The open failed: {}", x); + panic!("The open failed: {x}",); } Ok(x) => { tree = x; @@ -2685,7 +2674,7 @@ mod tests { // Okay, do a minimal test of the rewrite function. if let Err(e) = tree.reset_disk() { - panic!("test_tree: failed at tree.reset_disk with error {}", e); + panic!("test_tree: failed at tree.reset_disk with error {e}",); } println!("Syncing and checking the reopened tree."); @@ -2697,7 +2686,7 @@ mod tests { let tree = match AppendOnlyMerkle::rebuild(&path) { Err(x) => { - panic!("Rebuild failed: {}", x); + panic!("Rebuild failed: {x}",); } Ok(tree) => tree, }; @@ -2710,7 +2699,7 @@ mod tests { for i in 0..count { if tree.leaf(i as usize) != create_test_hash(i, false) { - panic!("Leaf {} does not match.", i); + panic!("Leaf {i} does not match.",); } } @@ -2837,7 +2826,7 @@ mod tests { } } - println!("Got {} hashes.", count); + println!("Got {count} hashes.",); assert!(count == 9); let last = entry.hashes.len() - 1; println!("hashes[last = {}] = {}", last, entry.hashes[last].desc()); @@ -2870,7 +2859,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(x) => { - panic!("Error on open: {}", x); + panic!("Error on open: {x}",); } }; @@ -2895,7 +2884,7 @@ mod tests { for i in 0..tree.total_size() { match tree.generate_proof(i, tree.total_size()) { Err(x) => { - panic!("Error on proof for transaction {}: {}", i, x); + panic!("Error on proof for transaction {i}: {x}"); } Ok(proof) => { check_proof(&tree, &proof, i); @@ -2918,7 +2907,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(x) => { - panic!("Error on open: {}", x); + panic!("Error on open: {x}",); } }; @@ -2934,7 +2923,7 @@ mod tests { // of a test. match tree.generate_proof(id, tree.total_size()) { Err(x) => { - panic!("Error on proof for transaction {}: {}", i, x); + panic!("Error on proof for transaction {i}: {x}"); } Ok(proof) => { assert!(id == i); @@ -2961,7 +2950,7 @@ mod tests { // Generating a proof for a non-existent transaction // should fail. if let Ok(_x) = tree.generate_proof(transactions, tree.total_size()) { - panic!("Transaction {} does not exist.", transactions); + panic!("Transaction {transactions} does not exist.",); } // @@ -3009,7 +2998,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(e) => { - panic!("Create failed: {}", e); + panic!("Create failed: {e}",); } }; @@ -3036,24 +3025,24 @@ mod tests { let mut tree: AppendOnlyMerkle = match serde_json::from_str(&encoded) { Ok(x) => x, Err(e) => { - panic!("from_str failed: {}", e); + panic!("from_str failed: {e}",); } }; if let Err(e) = tree.finish_deserialize() { - panic!("test_serde: tree.finish_deserialize failed with err {}", e); + panic!("test_serde: tree.finish_deserialize failed with err {e}",); } if let Err(e) = tree.check() { - panic!("test_serde: tree.check failed with err {}", e); + panic!("test_serde: tree.check failed with err {e}",); } if let Err(e) = tree.write() { - panic!("test_serde: tree.write failed with err {}", e); + panic!("test_serde: tree.write failed with err {e}",); } if let Err(e) = tree.check_disk(true) { - panic!("test_serde: tree.check_disk failed with err {}", e); + panic!("test_serde: tree.check_disk failed with err {e}",); } if tree.total_size() != size as u64 { @@ -3079,7 +3068,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(e) => { - panic!("Create failed: {}", e); + panic!("Create failed: {e}",); } }; @@ -3093,11 +3082,11 @@ mod tests { match tree.reconstruct(1, 0) { Err(x) => { - panic!("Reconstruct failed: {}", x); + panic!("Reconstruct failed: {x}",); } Ok(block) => { if let Err(e) = block.check(1, 0, true) { - panic!("block.check failed with {}", e); + panic!("block.check failed with {e}",); } for i in 0..HASHES_IN_BLOCK { @@ -3160,7 +3149,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(tree) => tree, Err(x) => { - panic!("create failed: {}", x); + panic!("create failed: {x}",); } }; @@ -3169,7 +3158,7 @@ mod tests { } if let Err(e) = tree.write() { - panic!("test_basic_rebuild: tree.write failed with {}", e); + panic!("test_basic_rebuild: tree.write failed with {e}",); } let fake = path.to_owned() + "." + &tree.files.len().to_string(); @@ -3177,9 +3166,9 @@ mod tests { let result = OpenOptions::new().create(true).write(true).open(&fake); if let Err(x) = result { - panic!("I cannot create {}: {}", fake, x); + panic!("I cannot create {fake}: {x}"); } else { - println!("Created {}.", fake); + println!("Created {fake}."); } let final_size = tree.total_size(); @@ -3188,7 +3177,7 @@ mod tests { let tree = match AppendOnlyMerkle::rebuild(&path) { Ok(tree) => tree, Err(x) => { - panic!("rebuild failed: {}", x); + panic!("rebuild failed: {x}",); } }; @@ -3202,7 +3191,7 @@ mod tests { for i in 0..4 * LEAVES_IN_BLOCK { if tree.leaf(i) != create_test_hash(i as u64, false) { - panic!("Leaf {} does not match.", i); + panic!("Leaf {i} does not match.",); } } @@ -3228,7 +3217,7 @@ mod tests { let result = fs::remove_file(&fake_ext); if let Err(x) = result { - panic!("File {} was not deleted: {}", fake_ext, x); + panic!("File {fake_ext} was not deleted: {x}"); } } } diff --git a/src/libs/sliding_set/src/lib.rs b/src/libs/sliding_set/src/lib.rs index 9fd715a6c..a6690ec02 100644 --- a/src/libs/sliding_set/src/lib.rs +++ b/src/libs/sliding_set/src/lib.rs @@ -65,15 +65,14 @@ impl SlidingSet { if index <= self.current && index + self.width >= (self.current + 1) { if self.map[index % self.width].contains(&key) { Err(eg!(format!( - "SlidingSet::insert: ({:?}, {}) already in set", - key, index + "SlidingSet::insert: ({key:?}, {index}) already in set", ))) } else { self.map[index % self.width].push(key); Ok(()) } } else { - Err(eg!(format!("({:?}, {}) is out of range", key, index))) + Err(eg!(format!("({key:?}, {index}) is out of range",))) } } } diff --git a/src/libs/sparse_merkle_tree/src/lib.rs b/src/libs/sparse_merkle_tree/src/lib.rs index df1b606a0..e06cace5c 100644 --- a/src/libs/sparse_merkle_tree/src/lib.rs +++ b/src/libs/sparse_merkle_tree/src/lib.rs @@ -480,7 +480,7 @@ mod tests { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); TempRocksDB::open(path).expect("failed to open rocksdb") } @@ -910,7 +910,7 @@ fn test_nullfier() { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let rocksdb = TempRocksDB::open(path).expect("failed to open rocksdb"); let mut smt = SmtMap256::new(rocksdb);