From ae6d610fe91ddda752f57eabee1bb5125c0c5b42 Mon Sep 17 00:00:00 2001 From: Mikhael Skvortsov Date: Tue, 8 Aug 2023 18:44:16 +0300 Subject: [PATCH 1/2] Fix clippy warnings --- build.rs | 12 +++-- src/account.rs | 23 +++------ src/call.rs | 13 ++--- src/completion.rs | 14 +++--- src/config.rs | 17 ++++--- src/convert.rs | 4 +- src/crypto.rs | 8 +-- src/debot/interfaces/signing_box_input.rs | 2 +- src/debot/pipechain.rs | 1 + src/debot/processor.rs | 4 +- src/debot/term_browser.rs | 2 +- src/debot/term_encryption_box.rs | 2 +- src/debug.rs | 52 ++++++++++---------- src/decode.rs | 46 ++++++++--------- src/deploy.rs | 5 +- src/depool.rs | 17 +++---- src/genaddr.rs | 3 +- src/getconfig.rs | 29 ++++++----- src/helpers.rs | 51 ++++++++++--------- src/main.rs | 60 +++++++++++------------ src/message.rs | 15 +++--- src/multisig.rs | 21 +++----- src/replay.rs | 20 +++----- src/run.rs | 38 +++++++------- src/sendfile.rs | 2 +- src/test.rs | 9 ++-- 26 files changed, 220 insertions(+), 250 deletions(-) diff --git a/build.rs b/build.rs index 30d2113a..29f0e075 100644 --- a/build.rs +++ b/build.rs @@ -13,32 +13,36 @@ use std::process::Command; fn main() { + if cfg!(target_os = "windows") { + println!("cargo:rustc-link-arg=/stack:{}", 8 * 1024 * 1024); + } + let mut git_branch = String::from("Unknown"); let mut git_commit = String::from("Unknown"); let mut commit_date = String::from("Unknown"); let mut build_time = String::from("Unknown"); let branch = Command::new("git") - .args(&["rev-parse", "--abbrev-ref", "HEAD"]) + .args(["rev-parse", "--abbrev-ref", "HEAD"]) .output(); if let Ok(branch) = branch { git_branch = String::from_utf8(branch.stdout).unwrap_or_else(|_| "Unknown".to_string()); } - let last = Command::new("git").args(&["rev-parse", "HEAD"]).output(); + let last = Command::new("git").args(["rev-parse", "HEAD"]).output(); if let Ok(last) = last { git_commit = String::from_utf8(last.stdout).unwrap_or_else(|_| "Unknown".to_string()); } let time = Command::new("git") - .args(&["log", "-1", "--date=iso", "--pretty=format:%cd"]) + .args(["log", "-1", "--date=iso", "--pretty=format:%cd"]) .output(); if let Ok(time) = time { commit_date = String::from_utf8(time.stdout).unwrap_or_else(|_| "Unknown".to_string()); } - let b_time = Command::new("date").args(&["+%Y-%m-%d %T %z"]).output(); + let b_time = Command::new("date").args(["+%Y-%m-%d %T %z"]).output(); if let Ok(b_time) = b_time { build_time = String::from_utf8(b_time.stdout).unwrap_or_else(|_| "Unknown".to_string()); } diff --git a/src/account.rs b/src/account.rs index 958f5c3b..e1f7f028 100644 --- a/src/account.rs +++ b/src/account.rs @@ -34,7 +34,7 @@ const ACCOUNT_FIELDS: &str = r#" const DEFAULT_PATH: &str = "."; async fn query_accounts(config: &Config, addresses: Vec, fields: &str) -> Result, String> { - let ton = create_client_verbose(&config)?; + let ton = create_client_verbose(config)?; if !config.is_json { println!("Processing..."); @@ -86,7 +86,7 @@ pub async fn get_account(config: &Config, addresses: Vec, dumptvc: Optio } return Ok(()); } - let accounts = query_accounts(&config, addresses.clone(), ACCOUNT_FIELDS).await?; + let accounts = query_accounts(config, addresses.clone(), ACCOUNT_FIELDS).await?; if !config.is_json { println!("Succeeded."); } @@ -156,7 +156,7 @@ pub async fn get_account(config: &Config, addresses: Vec, dumptvc: Optio ); } else { print_account( - &config, + config, Some(acc_type), Some(address.clone()), Some(balance), @@ -170,7 +170,7 @@ pub async fn get_account(config: &Config, addresses: Vec, dumptvc: Optio } else if config.is_json { json_res = json_account(Some(acc_type), Some(address.clone()), None, None, None, None, None, None); } else { - print_account(&config, Some(acc_type), Some(address.clone()), None, None, None, None, None, None); + print_account(config, Some(acc_type), Some(address.clone()), None, None, None, None, None, None); } if !config.is_json { println!(); @@ -195,11 +195,7 @@ pub async fn get_account(config: &Config, addresses: Vec, dumptvc: Optio } else if config.is_json { println!("{{\n}}"); } else { - if config.is_json { - println!("{{\n}}"); - } else { - println!("Account not found."); - } + println!("Account not found."); } if dumptvc.is_some() || dumpboc.is_some() && addresses.len() == 1 && accounts.len() == 1 { @@ -232,7 +228,7 @@ pub async fn get_account(config: &Config, addresses: Vec, dumptvc: Optio } pub async fn calc_storage(config: &Config, addr: &str, period: u32) -> Result<(), String> { - let ton = create_client_verbose(&config)?; + let ton = create_client_verbose(config)?; if !config.is_json { println!("Processing..."); @@ -242,14 +238,13 @@ pub async fn calc_storage(config: &Config, addr: &str, period: u32) -> Result<() ton.clone(), addr, "boc", - ).await.map_err(|e| e)?; + ).await?; let res = calc_storage_fee( ton.clone(), ParamsOfCalcStorageFee { account: boc, period, - ..Default::default() } ).await.map_err(|e| format!("failed to calculate storage fee: {}", e))?; @@ -265,7 +260,7 @@ pub async fn calc_storage(config: &Config, addr: &str, period: u32) -> Result<() } pub async fn dump_accounts(config: &Config, addresses: Vec, path: Option<&str>) -> Result<(), String> { - let accounts = query_accounts(&config, addresses.clone(), "id boc").await?; + let accounts = query_accounts(config, addresses.clone(), "id boc").await?; let mut addresses = addresses.clone(); check_dir(path.unwrap_or(""))?; for account in accounts.iter() { @@ -322,7 +317,6 @@ pub async fn wait_for_change(config: &Config, account_address: &str, wait_secs: limit: None, order: None, result: "last_trans_lt".to_owned(), - ..Default::default() } ).await.map_err(|e| format!("Failed to query the account: {}", e))?; @@ -365,7 +359,6 @@ pub async fn wait_for_change(config: &Config, account_address: &str, wait_secs: }, })), result: "last_trans_lt".to_owned(), - ..Default::default() }, callback ).await.map_err(|e| format!("Failed to subscribe: {}", e))?; diff --git a/src/call.rs b/src/call.rs index e8dfe780..970585e5 100644 --- a/src/call.rs +++ b/src/call.rs @@ -118,7 +118,7 @@ pub async fn emulate_locally( let addr = ever_block::MsgAddressInt::from_str(addr) .map_err(|e| format!("couldn't decode address: {}", e))?; state = base64::encode( - &ever_block::write_boc( + ever_block::write_boc( &Account::with_address(addr) .serialize() .map_err(|e| format!("couldn't create dummy account for deploy emulation: {}", e))? @@ -185,7 +185,6 @@ pub async fn send_message_and_wait( message: msg.clone(), abi: abi.clone(), send_events: false, - ..Default::default() }, callback, ).await @@ -231,7 +230,6 @@ pub async fn process_message( ParamsOfProcessMessage { message_encode_params: msg.clone(), send_events: true, - ..Default::default() }, callback, ).await @@ -241,7 +239,6 @@ pub async fn process_message( ParamsOfProcessMessage { message_encode_params: msg.clone(), send_events: true, - ..Default::default() }, |_| { async move {} }, ).await @@ -259,7 +256,7 @@ pub async fn call_contract_with_result( keys: Option, is_fee: bool, ) -> Result { - let ton = if config.debug_fail != "None".to_string() { + let ton = if config.debug_fail != "None" { init_debug_logger(&format!("call_{}_{}.log", addr, method))?; create_client(config)? } else { @@ -293,7 +290,7 @@ pub async fn call_contract_with_client( let needs_encoded_msg = is_fee || config.async_call || config.local_run || - config.debug_fail != "None".to_string(); + config.debug_fail != "None"; let message = if needs_encoded_msg { let msg = encode_message(ton.clone(), msg_params.clone()).await @@ -335,7 +332,7 @@ pub async fn call_contract_with_client( ..DebugParams::new(config, bc_config) }; debug_error(&e, debug_params).await?; - return Err(format!("{:#}", e)); + Err(format!("{:#}", e)) } } } @@ -370,7 +367,7 @@ pub async fn call_contract( pub async fn call_contract_with_msg(config: &Config, str_msg: String, abi_path: &str) -> Result<(), String> { - let ton = create_client_verbose(&config)?; + let ton = create_client_verbose(config)?; let abi = load_abi(abi_path, config).await?; let (msg, _) = unpack_message(&str_msg)?; diff --git a/src/completion.rs b/src/completion.rs index 8329b80d..00c1197e 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -16,7 +16,7 @@ extern crate core; use std::collections::BTreeMap; use std::path::PathBuf; use serde::{Deserialize, Serialize}; -use ever_client::abi::{AbiContract}; +use ever_client::abi::AbiContract; #[derive(Serialize, Deserialize, Clone)] pub struct ContractData { @@ -72,13 +72,11 @@ fn print_paths(prefix: &str) { return; } let mut saved_path: Vec = vec![]; - for path in paths.unwrap() { - if let Ok(path) = path { - let path = path.path(); - let path_str = path.to_str().unwrap(); - if path_str.starts_with(prefix) { - saved_path.push(path); - } + for path in paths.unwrap().flatten() { + let path = path.path(); + let path_str = path.to_str().unwrap(); + if path_str.starts_with(prefix) { + saved_path.push(path); } } if saved_path.len() == 1 && saved_path[0].is_dir() { diff --git a/src/config.rs b/src/config.rs index 449dba3f..273eb6b8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -288,19 +288,21 @@ impl FullConfig { pub fn from_file(path: &str) -> FullConfig { let conf_str = std::fs::read_to_string(path).ok().unwrap_or_default(); let config: serde_json::error::Result = serde_json::from_str(&conf_str); - if config.is_ok() && config.as_ref().unwrap() != &Config::default() { - return FullConfig::new(config.unwrap(), path.to_string()); + if let Ok(config) = config { + if config != Config::default() { + return FullConfig::new(config, path.to_string()); + } } let full_config: serde_json::error::Result = serde_json::from_str(&conf_str); - let mut full_config = if full_config.is_err() { - let conf_str = std::fs::read_to_string(&global_config_path()).ok() + let mut full_config = if let Ok(full_config) = full_config { + full_config + } else { + let conf_str = std::fs::read_to_string(global_config_path()).ok() .unwrap_or_default(); let mut global_config = serde_json::from_str::(&conf_str) .unwrap_or(FullConfig::default()); global_config.path = path.to_string(); global_config - } else { - full_config.unwrap() }; full_config.path = path.to_string(); full_config @@ -345,8 +347,7 @@ impl FullConfig { pub fn add_endpoint(path: &str, url: &str, endpoints: &str) -> Result<(), String> { let mut fconf = FullConfig::from_file(path); let mut new_endpoints : Vec = endpoints - .replace('[', "") - .replace(']', "") + .replace(['[', ']'], "") .split(',') .map(|s| s.to_string()) .collect(); diff --git a/src/convert.rs b/src/convert.rs index 06e2cfbb..ba288d49 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -52,9 +52,9 @@ pub fn nodeid_from_pubkey(key: &[u8]) -> Result { } let mut hasher = Sha256::new(); // node id magic - hasher.update(&[0xc6, 0xb4, 0x13, 0x48]); + hasher.update([0xc6, 0xb4, 0x13, 0x48]); //key hasher.update(key); - Ok(hex::encode(&hasher.finalize())) + Ok(hex::encode(hasher.finalize())) } diff --git a/src/crypto.rs b/src/crypto.rs index 8cc9375a..2055a8d7 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -43,7 +43,6 @@ pub fn gen_seed_phrase() -> Result { ParamsOfMnemonicFromRandom { dictionary: Some(MnemonicDictionary::English), word_count: Some(WORD_COUNT), - ..Default::default() }, ) .map_err(|e| format!("{}", e)) @@ -58,7 +57,6 @@ pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result dictionary: Some(MnemonicDictionary::English), word_count: Some(WORD_COUNT), phrase: mnemonic.to_string(), - ..Default::default() }, ).map_err(|e| format!("{}", e))?; @@ -67,7 +65,6 @@ pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result ParamsOfHDKeyDeriveFromXPrvPath { xprv: hdk_master.xprv.clone(), path: HD_PATH.to_string(), - ..Default::default() }, ).map_err(|e| format!("{}", e))?; @@ -75,7 +72,6 @@ pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result client.clone(), ParamsOfHDKeySecretFromXPrv { xprv: hdk_root.xprv.clone(), - ..Default::default() }, ).map_err(|e| format!("{}", e))?; @@ -83,7 +79,6 @@ pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result client, ParamsOfNaclSignKeyPairFromSecret { secret: secret.secret.clone(), - ..Default::default() }, ).map_err(|e| format!("failed to get KeyPair from secret key: {}", e))?; @@ -102,7 +97,6 @@ pub fn generate_keypair_from_secret(secret: String) -> Result { client, ParamsOfNaclSignKeyPairFromSecret { secret, - ..Default::default() }, ).map_err(|e| format!("failed to get KeyPair from secret key: {}", e))?; // special case if secret contains public key too. @@ -165,7 +159,7 @@ pub fn generate_keypair(keys_path: Option<&str>, mnemonic: Option<&str>, config: } }; - let keys = if mnemonic.contains(" ") { + let keys = if mnemonic.contains(' ') { generate_keypair_from_mnemonic(&mnemonic)? } else { generate_keypair_from_secret(mnemonic)? diff --git a/src/debot/interfaces/signing_box_input.rs b/src/debot/interfaces/signing_box_input.rs index ef8c5212..039abde3 100644 --- a/src/debot/interfaces/signing_box_input.rs +++ b/src/debot/interfaces/signing_box_input.rs @@ -84,7 +84,7 @@ impl SigningBoxInput { self.handles.write().await.push(signing_box); Ok((answer_id, json!({ "handle": handle.0}))) } - Err(e) => return Err(format!("{:?}", e)), + Err(e) => Err(format!("{:?}", e)), Ok(handle) => { Ok((answer_id, json!({ "handle": handle}) )) } diff --git a/src/debot/pipechain.rs b/src/debot/pipechain.rs index 24d144cf..a11cce56 100644 --- a/src/debot/pipechain.rs +++ b/src/debot/pipechain.rs @@ -5,6 +5,7 @@ use std::default::Default; fn default_init_method() -> String { "start".to_string() } fn default_mandatory() -> bool { false } +#[allow(clippy::enum_variant_names)] #[derive(Deserialize, Clone, PartialEq)] pub enum ApproveKind { ApproveOnChainCall, diff --git a/src/debot/processor.rs b/src/debot/processor.rs index 7b09fb99..83a26162 100644 --- a/src/debot/processor.rs +++ b/src/debot/processor.rs @@ -67,7 +67,7 @@ impl ChainProcessor { &mut self, in_interface: &str, in_method: &str, - in_params: &Value + _in_params: &Value ) -> Result, ProcessorError> { let chlink = self.chain_iter.next().ok_or( if self.interactive() { @@ -81,7 +81,7 @@ impl ChainProcessor { ChainLink::Input {interface, method, params, mandatory} => { if interface != in_interface { if !mandatory { - self.next_input(in_interface, in_method, in_params) + self.next_input(in_interface, in_method, _in_params) } else { Err(ProcessorError::UnexpectedInterface) } diff --git a/src/debot/term_browser.rs b/src/debot/term_browser.rs index bf06759a..44fa6644 100644 --- a/src/debot/term_browser.rs +++ b/src/debot/term_browser.rs @@ -326,7 +326,7 @@ pub async fn run_debot_browser( while let Some(msg) = next_msg { let parsed = parse_message( ton.clone(), - ParamsOfParse { boc: msg.clone(), ..Default::default() }, + ParamsOfParse { boc: msg.clone() }, ) .map_err(|e| format!("{}", e))? .parsed; diff --git a/src/debot/term_encryption_box.rs b/src/debot/term_encryption_box.rs index cb4605d8..ae0b7f9e 100644 --- a/src/debot/term_encryption_box.rs +++ b/src/debot/term_encryption_box.rs @@ -50,7 +50,7 @@ impl TerminalEncryptionBox { let mut writer = io::stdout(); let enter_str = "enter seed phrase or path to keypair file"; let value = input(enter_str, &mut reader, &mut writer); - let pair = load_keypair(&value).map_err(|e| e)?; + let pair = load_keypair(&value)?; key = format!("{:064}", pair.secret); } diff --git a/src/debug.rs b/src/debug.rs index 450d9a4b..a1f4499b 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -20,7 +20,7 @@ use crate::config::Config; use crate::helpers::{load_ton_address, create_client, load_abi, now_ms, construct_account_from_tvc, query_account_field, query_with_limit, create_client_verbose, abi_from_matches_or_config, load_debug_info, wc_from_matches_or_config, - get_blockchain_config, load_params, create_client_local}; + get_blockchain_config, load_params, create_client_local, CallbackType}; use crate::replay::{ fetch, CONFIG_ADDR, replay, DUMP_NONE, DUMP_CONFIG, DUMP_ACCOUNT }; @@ -60,9 +60,10 @@ pub fn debug_level_from_env() -> log::LevelFilter { } else if debug_level.eq_ignore_ascii_case("trace") { return log::LevelFilter::Trace; } - return TEST_MAX_LEVEL; + TEST_MAX_LEVEL + } else { + MAX_LEVEL } - return MAX_LEVEL; } struct DebugLogger { @@ -417,7 +418,7 @@ async fn debug_transaction_command(matches: &ArgMatches<'_>, config: &Config, is if !config.is_json { print_args!(tx_id, trace_path, config_path, contract_path); } - let address = query_address(tx_id.unwrap(), &config).await?; + let address = query_address(tx_id.unwrap(), config).await?; (tx_id.unwrap().to_string(), address) } else { let address = @@ -430,7 +431,7 @@ async fn debug_transaction_command(matches: &ArgMatches<'_>, config: &Config, is print_args!(address, trace_path, config_path, contract_path); } let address = address.unwrap(); - let transactions = query_transactions(&address, &config).await?; + let transactions = query_transactions(&address, config).await?; let tr_id = choose_transaction(transactions)?; (tr_id, address) }; @@ -512,7 +513,7 @@ async fn replay_transaction_command(matches: &ArgMatches<'_>, config: &Config) - print_args!(input, tx_id, output, config_path); } - let ton_client = create_client(&config)?; + let ton_client = create_client(config)?; let trans = query_collection( ton_client.clone(), ParamsOfQueryCollection { @@ -525,7 +526,6 @@ async fn replay_transaction_command(matches: &ArgMatches<'_>, config: &Config) - result: "lt block { start_lt } boc".to_string(), limit: Some(1), order: None, - ..Default::default() }, ).await .map_err(|e| format!("Failed to query transaction: {}", e))?; @@ -608,7 +608,7 @@ fn parse_now(matches: &ArgMatches<'_>) -> Result { fn load_decode_abi(matches: &ArgMatches<'_>, config: &Config) -> Option { let abi = matches.value_of("DECODE_ABI") .map(|s| s.to_owned()) - .or(abi_from_matches_or_config(matches, &config).ok()); + .or(abi_from_matches_or_config(matches, config).ok()); match abi { Some(path) => match std::fs::read_to_string(path) { Ok(res) => Some(res), @@ -624,23 +624,25 @@ fn load_decode_abi(matches: &ArgMatches<'_>, config: &Config) -> Option } async fn debug_call_command(matches: &ArgMatches<'_>, full_config: &FullConfig, is_getter: bool) -> Result<(), String> { - let (input, opt_abi, sign) = contract_data_from_matches_or_config_alias(matches, full_config)?; - let input = input.as_ref(); + let contract_data = contract_data_from_matches_or_config_alias(matches, full_config)?; + let input = contract_data.address.as_ref(); let output = Some(matches.value_of("LOG_PATH").unwrap_or(DEFAULT_TRACE_PATH)); let method = Some(matches.value_of("METHOD").or(full_config.config.method.as_deref()) .ok_or("Method is not defined. Supply it in the config file or command line.")?); let is_boc = matches.is_present("BOC"); let is_tvc = matches.is_present("TVC"); - let abi = load_abi(opt_abi.as_ref().unwrap(), &full_config.config).await?; + let abi = load_abi(contract_data.abi.as_ref().unwrap(), &full_config.config).await?; let params = Some(unpack_alternative_params( matches, - opt_abi.as_ref().unwrap(), + contract_data.abi.as_ref().unwrap(), method.unwrap(), &full_config.config ).await?); if !full_config.config.is_json { - print_args!(input, method, params, sign, opt_abi, output); + let keys = &contract_data.keys; + let abi = &contract_data.abi; + print_args!(input, method, params, keys, abi, output); } let input = input.unwrap(); @@ -679,7 +681,7 @@ async fn debug_call_command(matches: &ArgMatches<'_>, full_config: &FullConfig, ).await? .message } else { - let keys = sign.map(|k| load_keypair(&k)).transpose()?; + let keys = contract_data.keys.map(|k| load_keypair(&k)).transpose()?; let header = FunctionHeader { expire: Some((now / 1000) as u32 + full_config.config.lifetime), @@ -789,13 +791,13 @@ async fn debug_message_command(matches: &ArgMatches<'_>, config: &Config) -> Res print_args!(input, message, output, debug_info); } - let ton_client = create_client(&config)?; + let ton_client = create_client(config)?; let input = input.unwrap(); let account = if is_boc { Account::construct_from_file(input) .map_err(|e| format!(" failed to load account from the file {}: {}", input, e))? } else { - let address = load_ton_address(input, &config)?; + let address = load_ton_address(input, config)?; let account = query_account_field(ton_client.clone(), &address, "boc").await?; Account::construct_from_base64(&account) .map_err(|e| format!("Failed to construct account: {}", e))? @@ -860,7 +862,7 @@ async fn debug_message_command(matches: &ArgMatches<'_>, config: &Config) -> Res async fn debug_deploy_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let tvc = matches.value_of("TVC"); let output = Some(matches.value_of("LOG_PATH").unwrap_or(DEFAULT_TRACE_PATH)); - let opt_abi = Some(abi_from_matches_or_config(matches, &config)?); + let opt_abi = Some(abi_from_matches_or_config(matches, config)?); let debug_info = matches.value_of("DBG_INFO").map(|s| s.to_string()) .or(load_debug_info(opt_abi.as_ref().unwrap())); let sign = matches.value_of("KEYS") @@ -1247,7 +1249,7 @@ fn trace_callback_minimal(info: &EngineTraceInfo, debug_info: Option<&DbgInfo>) } fn get_position(info: &EngineTraceInfo, debug_info: Option<&DbgInfo>) -> Result { - let debug_info = debug_info.ok_or_else(|| String::new())?; + let debug_info = debug_info.ok_or_else(String::new)?; let cell_hash = info.cmd_code.cell().repr_hash(); let offset = info.cmd_code.pos(); match debug_info.get(&cell_hash) { @@ -1259,7 +1261,7 @@ fn get_position(info: &EngineTraceInfo, debug_info: Option<&DbgInfo>) -> Result< } } -fn generate_callback(matches: Option<&ArgMatches<'_>>, config: &Config) -> Arc { +fn generate_callback(matches: Option<&ArgMatches<'_>>, config: &Config) -> CallbackType { if let Some(matches) = matches { let opt_abi = abi_from_matches_or_config(matches, config); let debug_info = matches.value_of("DBG_INFO").map(|s| s.to_string()) @@ -1292,7 +1294,7 @@ fn generate_callback(matches: Option<&ArgMatches<'_>>, config: &Config) -> Arc, config: &Config) let mut addresses = vec!(); let lines = std::io::BufReader::new(file).lines(); - for line in lines { - if let Ok(line) = line { - if !line.is_empty() && !line.starts_with('#'){ - addresses.push(load_ton_address(&line, config)?); - } + for line in lines.flatten() { + if !line.is_empty() && !line.starts_with('#'){ + addresses.push(load_ton_address(&line, config)?); } } if addresses.iter().collect::>().len() < addresses.len() { @@ -1326,7 +1326,7 @@ pub async fn sequence_diagram_command(matches: &ArgMatches<'_>, config: &Config) }) } -fn infer_address_width(input: &Vec, min_width: usize) -> Result { +fn infer_address_width(input: &[String], min_width: usize) -> Result { let max_width = input.iter().fold(0, |acc, item| { std::cmp::max(acc, item.len()) }); diff --git a/src/decode.rs b/src/decode.rs index 5c32f4f9..48cd0b29 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -129,7 +129,7 @@ async fn decode_data_command(m: &ArgMatches<'_>, config: &Config) -> Result<(), async fn decode_body_command(m: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let body = m.value_of("BODY"); - let abi = Some(abi_from_matches_or_config(m, &config)?); + let abi = Some(abi_from_matches_or_config(m, config)?); if !config.is_json { print_args!(body, abi); } @@ -202,10 +202,10 @@ pub async fn print_account_data(account: &Account, tvc_path: Option<&str>, confi }; let data = tree_of_cells_into_base64(account.get_data().as_ref())?; - let data = hex::encode(base64::decode(&data) + let data = hex::encode(base64::decode(data) .map_err(|e| format!("Failed to decode base64: {}", e))?); print_account( - &config, + config, Some(state), Some(address), Some(balance), @@ -226,7 +226,7 @@ pub async fn print_account_data(account: &Account, tvc_path: Option<&str>, confi async fn decode_message_command(m: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let msg = m.value_of("MSG"); - let abi = Some(abi_from_matches_or_config(m, &config)?); + let abi = Some(abi_from_matches_or_config(m, config)?); if !config.is_json { print_args!(msg, abi); } @@ -274,7 +274,7 @@ async fn decode_message_command(m: &ArgMatches<'_>, config: &Config) -> Result<( async fn decode_tvc_fields(m: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let tvc = m.value_of("TVC"); - let abi = Some(abi_from_matches_or_config(m, &config)?); + let abi = Some(abi_from_matches_or_config(m, config)?); if !config.is_json { print_args!(tvc, abi); } @@ -300,14 +300,14 @@ async fn decode_tvc_fields(m: &ArgMatches<'_>, config: &Config) -> Result<(), St async fn decode_account_fields(m: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let address = m.value_of("ADDRESS"); - let abi = Some(abi_from_matches_or_config(m, &config)?); + let abi = Some(abi_from_matches_or_config(m, config)?); if !config.is_json { print_args!(address, abi); } let abi = load_abi(abi.as_ref().unwrap(), config).await?; - let ton = create_client_verbose(&config)?; - let address = load_ton_address(address.unwrap(), &config)?; + let ton = create_client_verbose(config)?; + let address = load_ton_address(address.unwrap(), config)?; let data = query_account_field(ton.clone(), &address, "data").await?; let res = decode_account_data( @@ -362,7 +362,7 @@ async fn decode_body(body_base64: &str, abi_path: &str, is_json: bool, config: & if let Ok(has_sign) = flag { if has_sign { let signature_bytes = slice.get_next_bytes(64).unwrap(); - signature = Some(hex::encode(&signature_bytes)); + signature = Some(hex::encode(signature_bytes)); } } } @@ -399,8 +399,8 @@ async fn decode_message(msg_boc: Vec, abi_path: Option) -> Result) -> Result { @@ -425,7 +425,7 @@ async fn decode_tvc_command(m: &ArgMatches<'_>, config: &Config) -> Result<(), S let ton = if is_local { create_client_local()? } else { - create_client_verbose(&config)? + create_client_verbose(config)? }; let input = input.unwrap().to_owned(); @@ -467,7 +467,7 @@ pub mod msg_printer { Some(cell) => { let bytes = write_boc(cell) .map_err(|e| format!("failed to serialize tree of cells: {}", e))?; - Ok(base64::encode(&bytes)) + Ok(base64::encode(bytes)) } None => Ok("".to_string()) } @@ -478,7 +478,6 @@ pub mod msg_printer { ton, ParamsOfGetCompilerVersion { code, - ..Default::default() } ); @@ -583,17 +582,14 @@ pub mod msg_printer { }; let output = res.value.take().ok_or("failed to obtain the result")?; let mut decoded = json!({res.name : output}); - match res.header { - Some(header) => { - if header.expire.is_some() || header.pubkey.is_some() || header.time.is_some() { - decoded["BodyHeader"] = json!({ - "expire": json!(header.expire.map(|exp| format!("{exp}")).unwrap_or("None".to_string())), - "time": json!(header.time.map(|time| format!("{time}")).unwrap_or("None".to_string())), - "pubkey": json!(header.pubkey.unwrap_or("None".to_string())), - }) - } - }, - None => {} + if let Some(header) = res.header { + if header.expire.is_some() || header.pubkey.is_some() || header.time.is_some() { + decoded["BodyHeader"] = json!({ + "expire": json!(header.expire.map(|exp| format!("{exp}")).unwrap_or("None".to_string())), + "time": json!(header.time.map(|time| format!("{time}")).unwrap_or("None".to_string())), + "pubkey": json!(header.pubkey.unwrap_or("None".to_string())), + }) + } } Ok(decoded) } diff --git a/src/deploy.rs b/src/deploy.rs index 04a188c6..ffc71941 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -56,7 +56,7 @@ pub async fn deploy_contract( } if config.async_call { - let abi = load_abi(&abi, config).await?; + let abi = load_abi(abi, config).await?; send_message_and_wait(ton, Some(abi), enc_msg.message, @@ -152,7 +152,7 @@ pub async fn prepare_deploy_message_params( wc: i32, signature_id: Option, ) -> Result<(ParamsOfEncodeMessage, String), String> { - let tvc = base64::encode(&tvc_bytes); + let tvc = base64::encode(tvc_bytes); let data_map_supported = abi.abi().unwrap().data_map_supported(); let address = if data_map_supported { @@ -184,7 +184,6 @@ pub async fn prepare_deploy_message_params( function_name, input: Some(params), header, - ..Default::default() }); let signer = if let Some(keys) = keys { Signer::Keys { keys } diff --git a/src/depool.rs b/src/depool.rs index 3cefa71f..1ab71442 100644 --- a/src/depool.rs +++ b/src/depool.rs @@ -372,7 +372,7 @@ impl<'a> DepoolCmd<'a> { pub async fn execute(mut self) -> Result<(), String> { let body = std::mem::take(&mut self.body); - let call_args = CallArgs::submit_with_args(self.m, &self.depool, &format!("{}", self.value), true, body).await?; + let call_args = CallArgs::submit_with_args(self.m, self.depool, &format!("{}", self.value), true, body).await?; let msig_args = MultisigArgs::new(self.m, self.config, call_args)?; let since = now(); @@ -396,7 +396,6 @@ impl<'a> DepoolCmd<'a> { filter: Some(answer_filter(&wallet, &depool, since)), result: "id body created_at created_at_string".to_owned(), timeout: Some(self.config.timeout), - ..Default::default() }, ).await.map_err(|e| println!("failed to query message: {}", e)); @@ -438,7 +437,6 @@ impl<'a> DepoolCmd<'a> { filter: Some(answer_filter(&depool, &wallet, since)), result: "id body created_at created_at_string value".to_owned(), timeout: Some(self.config.timeout), - ..Default::default() }, ).await.map_err(|e| println!("failed to query answer: {}", e)); if message.is_ok() { @@ -543,10 +541,10 @@ pub async fn depool_command(m: &ArgMatches<'_>, config: &mut Config) -> Result<( } } if let Some(m) = m.subcommand_matches("events") { - return events_command(m, &config, &depool).await + return events_command(m, config, &depool).await } if let Some(m) = m.subcommand_matches("answers") { - return answer_command(m, &config, &depool).await + return answer_command(m, config, &depool).await } if let Some(m) = m.subcommand_matches("replenish") { return DepoolCmd::replenish(m, config, &depool).await?.execute().await; @@ -654,8 +652,8 @@ async fn print_event(ton: TonClient, event: &serde_json::Value) -> Result<(), St } async fn get_events(config: &Config, depool: &str, since: u32) -> Result<(), String> { - let ton = create_client_verbose(&config)?; - let _addr = load_ton_address(depool, &config)?; + let ton = create_client_verbose(config)?; + let _addr = load_ton_address(depool, config)?; let events = ever_client::net::query_collection( ton.clone(), @@ -676,8 +674,8 @@ async fn get_events(config: &Config, depool: &str, since: u32) -> Result<(), Str } async fn wait_for_event(config: &Config, depool: &str) -> Result<(), String> { - let ton = create_client_verbose(&config)?; - let _addr = load_ton_address(depool, &config)?; + let ton = create_client_verbose(config)?; + let _addr = load_ton_address(depool, config)?; println!("Waiting for a new event..."); let event = ever_client::net::wait_for_collection( ton.clone(), @@ -686,7 +684,6 @@ async fn wait_for_event(config: &Config, depool: &str) -> Result<(), String> { filter: Some(events_filter(depool, now())), result: "id body created_at created_at_string".to_owned(), timeout: Some(config.timeout), - ..Default::default() }, ).await.map_err(|e| println!("failed to query event: {}", e)); diff --git a/src/genaddr.rs b/src/genaddr.rs index 83780741..0c6f8cbd 100644 --- a/src/genaddr.rs +++ b/src/genaddr.rs @@ -87,7 +87,7 @@ pub async fn generate_address( if new_keys && keys_file.is_some() { let keys_json = serde_json::to_string_pretty(&keys.clone().unwrap()) .map_err(|e| format!("failed to serialize the keypair: {}", e))?; - std::fs::write(keys_file.unwrap(), &keys_json) + std::fs::write(keys_file.unwrap(), keys_json) .map_err(|e| format!("failed to save the keypair: {}", e))?; } @@ -130,7 +130,6 @@ fn calc_userfriendly_address(address: &str, bounce: bool, test: bool) -> Result< ParamsOfConvertAddress { address: address.to_owned(), output_format: AddressStringFormat::Base64{ url: true, bounce, test }, - ..Default::default() } ) .map(|r| r.address) diff --git a/src/getconfig.rs b/src/getconfig.rs index 3d627bcf..23be27d2 100644 --- a/src/getconfig.rs +++ b/src/getconfig.rs @@ -273,22 +273,23 @@ async fn query_config(ton: &TonClient, result: &str) -> Result, St ).await { Ok(result) => { if result.is_empty() { - return Ok(None); + Ok(None) + } else { + Ok(Some(result[0]["master"]["config"].clone())) } - return Ok(Some(result[0]["master"]["config"].clone())) }, Err(e) => { if e.message.contains("Server responded with code 400") { - return Ok(None); + Ok(None) } else { - return Err(format!("failed to query master block config: {}", e)) + Err(format!("failed to query master block config: {}", e)) } } } } pub async fn query_global_config(config: &Config, index: Option<&str>) -> Result<(), String> { - let ton = create_client_verbose(&config)?; + let ton = create_client_verbose(config)?; let request = QUERY_FIELDS.to_owned(); let mut config_value = if let Some(config_value) = query_config(&ton, &request).await? { @@ -359,7 +360,7 @@ pub async fn gen_update_config_message( let msg_bytes = message.write_to_bytes() .map_err(|e| format!(r#"failed to serialize message": {}"#, e))?; - let msg_hex = hex::encode(&msg_bytes); + let msg_hex = hex::encode(msg_bytes); if is_json { println!("{{\"Message\": \"{}\"}}", msg_hex); @@ -374,22 +375,21 @@ pub fn serialize_config_param(config_str: &str) -> Result<(Cell, u32), String> { let config_json: serde_json::Value = serde_json::from_str(config_str) .map_err(|e| format!(r#"failed to parse "new_param_file": {}"#, e))?; let config_json = config_json.as_object() - .ok_or(format!(r#""new_param_file" is not json object"#))?; + .ok_or(r#""new_param_file" is not json object"#.to_string())?; if config_json.len() != 1 { Err(r#""new_param_file" is not a valid json"#.to_string())?; } let mut key_number = None; - for key in config_json.keys() { - if !key.starts_with("p") { + if let Some(key) = config_json.keys().next() { + if !key.starts_with('p') { Err(r#""new_param_file" is not a valid json"#.to_string())?; } - key_number = Some(key.trim_start_matches("p").to_string()); - break; + key_number = Some(key.trim_start_matches('p').to_string()); } let key_number = key_number - .ok_or(format!(r#""new_param_file" is not a valid json"#))? + .ok_or(r#""new_param_file" is not a valid json"#.to_string())? .parse::() .map_err(|e| format!(r#""new_param_file" is not a valid json: {}"#, e))?; @@ -491,7 +491,7 @@ fn convert_to_uint(value: &[u8], bits_count: usize) -> TokenValue { } pub async fn dump_blockchain_config(config: &Config, path: &str) -> Result<(), String> { - let ton = create_client_verbose(&config)?; + let ton = create_client_verbose(config)?; let last_key_block_query = query_with_limit( ton.clone(), @@ -513,11 +513,10 @@ pub async fn dump_blockchain_config(config: &Config, path: &str) -> Result<(), S ton.clone(), ParamsOfGetBlockchainConfig { block_boc: block, - ..Default::default() }, ).map_err(|e| format!("Failed to get blockchain config: {}", e))?; - let bc_config = base64::decode(&bc_config.config_boc) + let bc_config = base64::decode(bc_config.config_boc) .map_err(|e| format!("Failed to decode BOC: {}", e))?; std::fs::write(path, bc_config) .map_err(|e| format!("Failed to write data to the file {}: {}", path, e))?; diff --git a/src/helpers.rs b/src/helpers.rs index eeeaf814..713333b8 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -34,6 +34,7 @@ use url::Url; use crate::call::parse_params; use crate::{FullConfig, resolve_net_name}; use crate::replay::{CONFIG_ADDR, construct_blockchain_config}; +use ever_vm::executor::{Engine, EngineTraceInfo}; pub const HD_PATH: &str = "m/44'/396'/0'/0/0"; pub const WORD_COUNT: u8 = 12; @@ -41,6 +42,8 @@ pub const WORD_COUNT: u8 = 12; const CONFIG_BASE_NAME: &str = "ever-cli.conf.json"; const GLOBAL_CONFIG_PATH: &str = ".ever-cli.global.conf.json"; +pub type CallbackType = Arc; + pub fn default_config_name() -> String { env::current_dir() .map(|dir| { @@ -125,7 +128,7 @@ pub fn get_server_endpoints(config: &Config) -> Vec { cur_endpoints.iter_mut().map(|end| { let mut end = end.trim_end_matches('/').to_owned(); if config.project_id.is_some() { - end.push_str("/"); + end.push('/'); end.push_str(&config.project_id.clone().unwrap()); } end.to_owned() @@ -203,11 +206,11 @@ pub async fn query_raw( { let context = create_client_verbose(config)?; - let filter = filter.map(|s| serde_json::from_str(s)).transpose() + let filter = filter.map(serde_json::from_str).transpose() .map_err(|e| format!("Failed to parse filter field: {}", e))?; let limit = limit.map(|s| s.parse::()).transpose() .map_err(|e| format!("Failed to parse limit field: {}", e))?; - let order = order.map(|s| serde_json::from_str(s)).transpose() + let order = order.map(serde_json::from_str).transpose() .map_err(|e| format!("Failed to parse order field: {}", e))?; let query = ever_client::net::query_collection( @@ -218,7 +221,6 @@ pub async fn query_raw( limit, order, result: result.to_owned(), - ..Default::default() } ).await.map_err(|e| format!("Failed to execute query: {}", e))?; @@ -242,7 +244,6 @@ pub async fn query_with_limit( result: result.to_owned(), order, limit, - ..Default::default() }, ) .await @@ -319,11 +320,11 @@ pub async fn load_abi_str(abi_path: &str, config: &Config) -> Result Result { @@ -333,8 +334,8 @@ pub async fn load_abi(abi_path: &str, config: &Config) -> Result { pub async fn load_ton_abi(abi_path: &str, config: &Config) -> Result { let abi_str = load_abi_str(abi_path, config).await?; - Ok(ever_abi::Contract::load(abi_str.as_bytes()) - .map_err(|e| format!("Failed to load ABI: {}", e))?) + ever_abi::Contract::load(abi_str.as_bytes()) + .map_err(|e| format!("Failed to load ABI: {}", e)) } pub async fn load_file_with_url(url: &str, timeout: u64) -> Result, String> { @@ -588,9 +589,9 @@ pub fn check_dir(path: &str) -> Result<(), String> { #[derive(PartialEq)] pub enum AccountSource { - NETWORK, - BOC, - TVC, + Network, + Boc, + Tvc, } pub async fn load_account( @@ -600,11 +601,11 @@ pub async fn load_account( config: &Config ) -> Result<(Account, String), String> { match source_type { - AccountSource::NETWORK => { + AccountSource::Network => { let ton_client = match ton_client { Some(ton_client) => ton_client, None => { - create_client(&config)? + create_client(config)? } }; let boc = query_account_field(ton_client.clone(),source, "boc").await?; @@ -613,7 +614,7 @@ pub async fn load_account( boc)) }, _ => { - let account = if source_type == &AccountSource::BOC { + let account = if source_type == &AccountSource::Boc { Account::construct_from_file(source) .map_err(|e| format!(" failed to load account from the file {}: {}", source, e))? } else { @@ -621,7 +622,7 @@ pub async fn load_account( }; let account_bytes = account.write_to_bytes() .map_err(|e| format!(" failed to load data from the account: {}", e))?; - Ok((account, base64::encode(&account_bytes))) + Ok((account, base64::encode(account_bytes))) }, } } @@ -670,7 +671,7 @@ pub fn parse_lifetime(lifetime: Option<&str>, config: &Config) -> Result { + ($( $arg:expr ),* ) => { println!("Input arguments:"); $( println!( @@ -709,10 +710,16 @@ pub fn wc_from_matches_or_config(matches: &ArgMatches<'_>, config: &Config) -> R .unwrap_or(config.wc)) } +pub struct ContractData { + pub address: Option, + pub abi: Option, + pub keys: Option, +} + pub fn contract_data_from_matches_or_config_alias( matches: &ArgMatches<'_>, full_config: &FullConfig -) -> Result<(Option, Option, Option), String> { +) -> Result { let address = matches.value_of("ADDRESS") .map(|s| s.to_string()) .or(full_config.config.addr.clone()) @@ -732,7 +739,7 @@ pub fn contract_data_from_matches_or_config_alias( .map(|s| s.to_string()) .or(full_config.config.keys_path.clone()) .or(keys); - Ok((address, Some(abi), keys)) + Ok(ContractData { address, abi: Some(abi), keys }) } pub fn blockchain_config_from_default_json() -> Result { @@ -981,7 +988,7 @@ pub fn blockchain_config_from_default_json() -> Result ] } }"#; - let map = serde_json::from_str::>(&json) + let map = serde_json::from_str::>(json) .map_err(|e| format!("Failed to parse config params as json: {e}"))?; let config_params = ever_block_json::parse_config(&map) .map_err(|e| format!("Failed to parse config params: {e}"))?; diff --git a/src/main.rs b/src/main.rs index bea410a1..3c1ece6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1164,7 +1164,7 @@ fn getkeypair_command(matches: &ArgMatches, config: &Config) -> Result<(), Strin async fn send_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let message = matches.value_of("MESSAGE"); - let abi = Some(abi_from_matches_or_config(matches, &config)?); + let abi = Some(abi_from_matches_or_config(matches, config)?); if !config.is_json { print_args!(message, abi); @@ -1177,7 +1177,7 @@ async fn body_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), S let method = matches.value_of("METHOD"); let params = matches.value_of("PARAMS"); let output = matches.value_of("OUTPUT"); - let abi = Some(abi_from_matches_or_config(matches, &config)?); + let abi = Some(abi_from_matches_or_config(matches, config)?); let params = Some(load_params(params.unwrap())?); if !config.is_json { print_args!(method, params, abi, output); @@ -1220,7 +1220,7 @@ async fn call_command(matches: &ArgMatches<'_>, config: &Config, call: CallType) let output = matches.value_of("OUTPUT"); let signature_id = matches.value_of("SIGNATURE_ID"); - let abi = Some(abi_from_matches_or_config(matches, &config)?); + let abi = Some(abi_from_matches_or_config(matches, config)?); let keys = matches.value_of("KEYS") .or(matches.value_of("SIGN")) @@ -1231,11 +1231,11 @@ async fn call_command(matches: &ArgMatches<'_>, config: &Config, call: CallType) if !config.is_json { print_args!(address, method, params, abi, keys, signature_id, lifetime, output); } - let address = load_ton_address(address.unwrap(), &config)?; + let address = load_ton_address(address.unwrap(), config)?; match call { CallType::Call | CallType::Fee => { - let is_fee = if let CallType::Fee = call { true } else { false }; + let is_fee = matches!(call, CallType::Fee); call_contract( config, address.as_str(), @@ -1286,28 +1286,28 @@ async fn callx_command(matches: &ArgMatches<'_>, full_config: &FullConfig) -> Re let config = &full_config.config; let method = Some(matches.value_of("METHOD").or(config.method.as_deref()) .ok_or("Method is not defined. Supply it in the config file or command line.")?); - let (address, abi, keys) = contract_data_from_matches_or_config_alias(matches, full_config)?; + let contract_data = contract_data_from_matches_or_config_alias(matches, full_config)?; let params = unpack_alternative_params( matches, - abi.as_ref().unwrap(), + contract_data.abi.as_ref().unwrap(), method.unwrap(), config ).await?; let params = Some(load_params(¶ms)?); if !config.is_json { - print_args!(address, method, params, abi, keys); + print_args!(contract_data.address, method, params, contract_data.abi, contract_data.keys); } - let address = load_ton_address(address.unwrap().as_str(), &config)?; + let address = load_ton_address(contract_data.address.unwrap().as_str(), config)?; call_contract( config, address.as_str(), - &abi.unwrap(), - &method.unwrap(), + &contract_data.abi.unwrap(), + method.unwrap(), ¶ms.unwrap(), - keys, + contract_data.keys, false, ).await } @@ -1323,16 +1323,16 @@ async fn runget_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), print_args!(address, method, params); } let source_type = if matches.is_present("TVC") { - AccountSource::TVC + AccountSource::Tvc } else if matches.is_present("BOC") { - AccountSource::BOC + AccountSource::Boc } else { - AccountSource::NETWORK + AccountSource::Network }; - let address = if source_type != AccountSource::NETWORK { + let address = if source_type != AccountSource::Network { address.unwrap().to_string() } else { - load_ton_address(address.unwrap(), &config)? + load_ton_address(address.unwrap(), config)? }; let bc_config = matches.value_of("BCCONFIG"); run_get_method(config, &address, method.unwrap(), params, source_type, bc_config).await @@ -1389,8 +1389,8 @@ async fn deployx_command(matches: &ArgMatches<'_>, full_config: &mut FullConfig) let config = &full_config.config; let tvc = matches.value_of("TVC"); let wc = wc_from_matches_or_config(matches, config)?; - let abi = Some(abi_from_matches_or_config(matches, &config)?); let method = matches.value_of("METHOD").unwrap_or("constructor"); + let abi = Some(abi_from_matches_or_config(matches, config)?); let params = Some(unpack_alternative_params( matches, abi.as_ref().unwrap(), @@ -1441,7 +1441,7 @@ fn config_command(matches: &ArgMatches, mut full_config: FullConfig, is_json: bo )? } else if let Some(alias_matches) = alias_matches.subcommand_matches("remove") { full_config.remove_alias(alias_matches.value_of("ALIAS").unwrap())? - } else if let Some(_) = alias_matches.subcommand_matches("reset") { + } else if alias_matches.subcommand_matches("reset").is_some() { full_config.aliases = BTreeMap::new(); full_config.to_file(&full_config.path)?; } @@ -1473,7 +1473,7 @@ async fn genaddr_command(matches: &ArgMatches<'_>, config: &Config) -> Result<() let abi = match abi_from_matches_or_config(matches, config) { Ok(abi) => Some(abi), Err(err) => { - match load_abi_from_tvc(tvc.clone().unwrap()) { + match load_abi_from_tvc(tvc.unwrap()) { Some(abi) => Some(abi), None => return Err(err) } @@ -1500,7 +1500,7 @@ async fn account_command(matches: &ArgMatches<'_>, config: &Config) -> Result<() let mut formatted_list = vec![]; for address in addresses_list.iter() { if !is_boc { - let formatted = load_ton_address(address, &config)?; + let formatted = load_ton_address(address, config)?; formatted_list.push(formatted); } else { if !std::path::Path::new(address).exists() { @@ -1515,14 +1515,14 @@ async fn account_command(matches: &ArgMatches<'_>, config: &Config) -> Result<() if !config.is_json { print_args!(addresses); } - get_account(&config, formatted_list, tvcname, bocname, is_boc).await + get_account(config, formatted_list, tvcname, bocname, is_boc).await } async fn dump_accounts_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let addresses_list = matches.values_of("ADDRESS").unwrap().collect::>(); let mut formatted_list = vec![]; for address in addresses_list.iter() { - let formatted = load_ton_address(address, &config)?; + let formatted = load_ton_address(address, config)?; formatted_list.push(formatted); } let path = matches.value_of("PATH"); @@ -1535,7 +1535,7 @@ async fn dump_accounts_command(matches: &ArgMatches<'_>, config: &Config) -> Res async fn account_wait_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), String> { let address = matches.value_of("ADDRESS").unwrap(); - let address = load_ton_address(address, &config)?; + let address = load_ton_address(address, config)?; let timeout = matches.value_of("TIMEOUT").unwrap_or("30").parse::() .map_err(|e| format!("failed to parse timeout: {}", e))?; wait_for_change(config, &address, timeout).await @@ -1556,14 +1556,14 @@ async fn storage_command(matches: &ArgMatches<'_>, config: &Config) -> Result<() if !config.is_json { print_args!(address, period); } - let address = load_ton_address(address.unwrap(), &config)?; + let address = load_ton_address(address.unwrap(), config)?; let period = period.map(|val| { u32::from_str_radix(val, 10) .map_err(|e| format!("failed to parse period: {}", e)) }) .transpose()? .unwrap_or(DEF_STORAGE_PERIOD); - calc_storage(&config, address.as_str(), period).await + calc_storage(config, address.as_str(), period).await } async fn proposal_create_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), String> { @@ -1576,7 +1576,7 @@ async fn proposal_create_command(matches: &ArgMatches<'_>, config: &Config) -> R if !config.is_json { print_args!(address, comment, keys, lifetime); } - let address = load_ton_address(address.unwrap(), &config)?; + let address = load_ton_address(address.unwrap(), config)?; let lifetime = parse_lifetime(lifetime, config)?; create_proposal( @@ -1599,7 +1599,7 @@ async fn proposal_vote_command(matches: &ArgMatches<'_>, config: &Config) -> Res if !config.is_json { print_args!(address, id, keys, lifetime); } - let address = load_ton_address(address.unwrap(), &config)?; + let address = load_ton_address(address.unwrap(), config)?; let lifetime = parse_lifetime(lifetime, config)?; vote(config, address.as_str(), keys, id.unwrap(), lifetime, offline).await?; @@ -1613,7 +1613,7 @@ async fn proposal_decode_command(matches: &ArgMatches<'_>, config: &Config) -> R if !config.is_json { print_args!(address, id); } - let address = load_ton_address(address.unwrap(), &config)?; + let address = load_ton_address(address.unwrap(), config)?; decode_proposal(config, address.as_str(), id.unwrap()).await } @@ -1656,7 +1656,7 @@ fn nodeid_command(matches: &ArgMatches, config: &Config) -> Result<(), String> { convert::nodeid_from_pubkey(&vec)? } else if let Some(pair) = keypair { let pair = crypto::load_keypair(pair)?; - convert::nodeid_from_pubkey(&hex::decode(&pair.public) + convert::nodeid_from_pubkey(&hex::decode(pair.public.clone()) .map_err(|e| format!("failed to decode public key: {}", e))?)? } else { return Err("Either public key or key pair parameter should be provided".to_owned()); diff --git a/src/message.rs b/src/message.rs index f4587f08..9cf84aef 100644 --- a/src/message.rs +++ b/src/message.rs @@ -64,7 +64,7 @@ pub fn prepare_message_params ( signature_id: Option, ) -> Result { let keys = keys.map(|k| load_keypair(&k)).transpose()?; - let params = serde_json::from_str(¶ms) + let params = serde_json::from_str(params) .map_err(|e| format!("arguments are not in json format: {}", e))?; let call_set = Some(CallSet { @@ -77,8 +77,8 @@ pub fn prepare_message_params ( abi, address: Some(addr.to_owned()), call_set, - signer: if keys.is_some() { - Signer::Keys { keys: keys.unwrap() } + signer: if let Some(keys) = keys { + Signer::Keys { keys } } else { Signer::None }, @@ -171,12 +171,12 @@ pub async fn generate_message( let (client,signature_id) = create_client_with_signature_id(config,signature_id)?; - let ton_addr = load_ton_address(addr, &config) - .map_err(|e| format!("failed to parse address: {}", e.to_string()))?; + let ton_addr = load_ton_address(addr, config) + .map_err(|e| format!("failed to parse address: {}", e))?; let abi = load_abi(abi, config).await?; - let expire_at = lifetime + timestamp.clone().map(|ms| (ms / 1000) as u32).unwrap_or(now()); + let expire_at = lifetime + timestamp.map(|ms| (ms / 1000) as u32).unwrap_or(now()); let header = FunctionHeader { expire: Some(expire_at), time: timestamp, @@ -213,8 +213,7 @@ pub fn display_generated_message( print_encoded_message(msg, is_json); let msg_bytes = pack_message(msg, method, is_raw)?; - if output.is_some() { - let out_file = output.unwrap(); + if let Some(out_file) = output { std::fs::write(out_file, msg_bytes) .map_err(|e| format!("cannot write message to file: {}", e))?; if !is_json { diff --git a/src/multisig.rs b/src/multisig.rs index 0c8dbf49..34218230 100644 --- a/src/multisig.rs +++ b/src/multisig.rs @@ -207,7 +207,7 @@ impl CallArgs { let value = convert::convert_token(value)?; let comment = matches.value_of("PURPOSE").map(|s| s.to_owned()); let body = if let Some(ref txt) = comment { - encode_transfer_body(&txt).await? + encode_transfer_body(txt).await? } else { "".to_owned() }; @@ -250,22 +250,17 @@ impl CallArgs { } else { SAFEMULTISIG_V2_LINK } + } else if is_setcode { + SETCODEMULTISIG_LINK } else { - if is_setcode { - SETCODEMULTISIG_LINK - } else { - SAFEMULTISIG_LINK - } + SAFEMULTISIG_LINK }; let image = load_file_with_url(target, 30000).await?; let owners = matches.value_of("OWNERS").map(|owners| { owners - .replace('[', "") - .replace(']', "") - .replace('\"', "") - .replace('\'', "") + .replace(['[', ']', '\"', '\''], "") .replace("0x", "") .split(',') .map(|o| format!("0x{}", o)) @@ -320,7 +315,7 @@ impl MultisigArgs { .ok_or("sign key is not defined".to_string())?; let v2 = matches.is_present("V2"); - let addr = load_ton_address(&address, &config)?; + let addr = load_ton_address(&address, config)?; let mut abi = serde_json::from_str::(MSIG_ABI).unwrap_or_default(); if v2 { abi.version = Some("2.3".to_owned()); @@ -376,7 +371,7 @@ impl MultisigArgs { &self.keys } pub fn image(&self) -> Option<&[u8]> { - self.call_args.image.as_ref().map(|v| v.as_slice()) + self.call_args.image.as_deref() } pub async fn execute(self, config: &Config) -> Result { call::call_contract_with_result( @@ -531,7 +526,7 @@ async fn multisig_deploy_command(matches: &ArgMatches<'_>, config: &Config) -> R println!("Wallet address: {}", address); } - let ton = create_client_verbose(&config)?; + let ton = create_client_verbose(config)?; if let Some(value) = matches.value_of("VALUE") { let params = format!(r#"{{"dest":"{}","amount":"{}"}}"#, address, value); diff --git a/src/replay.rs b/src/replay.rs index 095a0283..2270d758 100644 --- a/src/replay.rs +++ b/src/replay.rs @@ -32,7 +32,7 @@ use ever_executor::{BlockchainConfig, ExecuteParams, OrdinaryTransactionExecutor use ever_block::{BuilderData, SliceData, UInt256, write_boc}; use ever_vm::executor::{Engine, EngineTraceInfo}; -use crate::config::Config; +use crate::{config::Config, helpers::CallbackType}; use crate::helpers::{create_client, get_blockchain_config}; pub static CONFIG_ADDR: &str = "-1:5555555555555555555555555555555555555555555555555555555555555555"; @@ -92,7 +92,6 @@ pub async fn fetch(config: &Config, account_address: &str, filename: &str, lt_bo aggregation_fn: AggregationFn::COUNT }, ]), - ..Default::default() }, ) .await @@ -115,7 +114,6 @@ pub async fn fetch(config: &Config, account_address: &str, filename: &str, lt_bo result: "accounts { id boc }".to_owned(), limit: Some(1), order: None, - ..Default::default() }, ) .await; @@ -177,7 +175,6 @@ pub async fn fetch(config: &Config, account_address: &str, filename: &str, lt_bo order: Some(vec![ OrderBy { path: "lt".to_owned(), direction: SortDirection::ASC } ]), - ..Default::default() }, ); query.await @@ -281,7 +278,7 @@ pub async fn replay( input_filename: &str, config_filename: &str, txnid: &str, - trace_callback: Option>, + trace_callback: Option, init_trace_last_logger: impl FnOnce() -> Result<(), String>, dump_mask: u8, cli_config: &Config, @@ -315,12 +312,10 @@ pub async fn replay( let state = choose(&mut account_state, &mut config_state); let tr = state.tr.as_ref().ok_or("failed to obtain state transaction")?; - if iterate_config { - if cur_block_lt == 0 || cur_block_lt != tr.block_lt { - assert!(tr.block_lt > cur_block_lt); - cur_block_lt = tr.block_lt; - config = construct_blockchain_config(&config_account)?; - } + if iterate_config && (cur_block_lt == 0 || cur_block_lt != tr.block_lt) { + assert!(tr.block_lt > cur_block_lt); + cur_block_lt = tr.block_lt; + config = construct_blockchain_config(&config_account)?; } let mut account_root = state.account.serialize() @@ -478,7 +473,6 @@ pub async fn fetch_block(config: &Config, block_id: &str, filename: &str) -> eve result: "workchain_id end_lt boc".to_owned(), limit: None, order: None, - ..Default::default() }, ).await?; @@ -503,7 +497,7 @@ pub async fn fetch_block(config: &Config, block_id: &str, filename: &str) -> eve account_block.transaction_iterate(|tr| { let cell = tr.serialize()?; let bytes = write_boc(&cell)?; - txns.push((cell.repr_hash().to_hex_string(), base64::encode(&bytes))); + txns.push((cell.repr_hash().to_hex_string(), base64::encode(bytes))); Ok(true) })?; accounts.push((account_name, txns)); diff --git a/src/run.rs b/src/run.rs index f9a1f121..d579ce07 100644 --- a/src/run.rs +++ b/src/run.rs @@ -29,18 +29,18 @@ use crate::replay::construct_blockchain_config; pub async fn run_command(matches: &ArgMatches<'_>, full_config: &FullConfig, is_alternative: bool) -> Result<(), String> { let config = &full_config.config; let (address, abi_path) = if is_alternative { - let (address,abi, _) = contract_data_from_matches_or_config_alias(matches, full_config)?; - (address.unwrap(), abi.unwrap()) + let contract_data = contract_data_from_matches_or_config_alias(matches, full_config)?; + (contract_data.address.unwrap(), contract_data.abi.unwrap()) } else { (matches.value_of("ADDRESS").unwrap().to_string(), - abi_from_matches_or_config(matches, &config)?) + abi_from_matches_or_config(matches, config)?) }; let account_source = if matches.is_present("TVC") { - AccountSource::TVC + AccountSource::Tvc } else if matches.is_present("BOC") { - AccountSource::BOC + AccountSource::Boc } else { - AccountSource::NETWORK + AccountSource::Network }; let method = if is_alternative { @@ -50,9 +50,9 @@ pub async fn run_command(matches: &ArgMatches<'_>, full_config: &FullConfig, is_ matches.value_of("METHOD").unwrap() }; let trace_path; - let ton_client = if account_source == AccountSource::NETWORK { + let ton_client = if account_source == AccountSource::Network { trace_path = format!("run_{}_{}.log", address, method); - create_client(&config)? + create_client(config)? } else { trace_path = "trace.log".to_string(); create_client_local()? @@ -62,12 +62,12 @@ pub async fn run_command(matches: &ArgMatches<'_>, full_config: &FullConfig, is_ &account_source, &address, Some(ton_client.clone()), - &config + config ).await?; let address = match account_source { - AccountSource::NETWORK => address, - AccountSource::BOC => account.get_addr().unwrap().to_string(), - AccountSource::TVC => std::iter::repeat("0").take(64).collect() + AccountSource::Network => address, + AccountSource::Boc => account.get_addr().unwrap().to_string(), + AccountSource::Tvc => "0".repeat(64), }; run(matches, config, Some(ton_client), &address, account_boc, abi_path, is_alternative, trace_path).await } @@ -117,7 +117,7 @@ async fn run( let msg = prepare_message( ton_client.clone(), - &address, + address, abi.clone(), method, ¶ms, @@ -127,7 +127,7 @@ async fn run( None, ).await?; - let execution_options = prepare_execution_options(bc_config.clone())?; + let execution_options = prepare_execution_options(bc_config)?; let result = run_tvm( ton_client.clone(), ParamsOfRunTvm { @@ -199,8 +199,8 @@ fn prepare_execution_options(bc_config: Option<&str>) -> Result, source_type: AccountSource, bc_config: Option<&str>) -> Result<(), String> { - let ton = if source_type == AccountSource::NETWORK { - create_client_verbose(&config)? + let ton = if source_type == AccountSource::Network { + create_client_verbose(config)? } else { create_client_local()? }; @@ -225,7 +225,7 @@ pub async fn run_get_method(config: &Config, addr: &str, method: &str, params: O ..Default::default() }, ).await - .map_err(|e| format!("run failed: {}", e.to_string()))? + .map_err(|e| format!("run failed: {}", e))? .output; if !config.is_json { @@ -235,10 +235,8 @@ pub async fn run_get_method(config: &Config, addr: &str, method: &str, params: O let mut res = Map::new(); match result { Value::Array(array) => { - let mut i = 0; - for val in array.iter() { + for (i, val) in array.iter().enumerate() { res.insert(format!("value{}", i), val.to_owned()); - i = 1 + i; } }, _ => { diff --git a/src/sendfile.rs b/src/sendfile.rs index 35831835..a02522b1 100644 --- a/src/sendfile.rs +++ b/src/sendfile.rs @@ -15,7 +15,7 @@ use crate::config::Config; use crate::call::send_message_and_wait; pub async fn sendfile(config: &Config, msg_boc: &str) -> Result<(), String> { - let ton = create_client_verbose(&config)?; + let ton = create_client_verbose(config)?; let boc_vec = std::fs::read(msg_boc) .map_err(|e| format!("failed to read boc file: {}", e))?; let tvm_msg = ever_sdk::Contract::deserialize_message(&boc_vec[..]) diff --git a/src/test.rs b/src/test.rs index e81f8b5d..eddd1ceb 100644 --- a/src/test.rs +++ b/src/test.rs @@ -252,7 +252,6 @@ async fn test_deploy(matches: &ArgMatches<'_>, config: &Config) -> Result<(), St function_name, input: Some(params), header, - ..Default::default() }); let mut account; let mut message; @@ -344,7 +343,7 @@ async fn test_ticktock(matches: &ArgMatches<'_>, config: &Config) -> Result<(), let trace_path = matches.value_of("LOG_PATH").unwrap_or(DEFAULT_TRACE_PATH); let is_tock = matches.is_present("IS_TOCK"); - let mut account = Account::construct_from_file(&input) + let mut account = Account::construct_from_file(input) .map_err(|e| format!("Failed to load Account from the file {input}: {e}"))?; if let Some(state_init) = account.state_init_mut().as_mut() { state_init.set_special(TickTock::with_values(true, true)); @@ -378,7 +377,7 @@ async fn test_ticktock(matches: &ArgMatches<'_>, config: &Config) -> Result<(), let account = Account::construct_from_cell(account_root) .map_err(|e| format!("Failed to construct Account after transaction: {e}"))?; account - .write_to_file(&input) + .write_to_file(input) .map_err(|e| format!("Failed write to file {:?}: {e}", input))?; if !config.is_json { println!("Account written to {:?}", input); @@ -403,9 +402,9 @@ pub fn test_sign_command(matches: &ArgMatches<'_>, config: &Config) -> Result<() return Err("nor data neither cell parameter".to_string()); }; let pair = match matches.value_of("KEYS") { - Some(keys) => crypto::load_keypair(&keys)?, + Some(keys) => crypto::load_keypair(keys)?, None => match &config.keys_path { - Some(keys) => crypto::load_keypair(&keys)?, + Some(keys) => crypto::load_keypair(keys)?, None => return Err("nor signing keys in the params neither in the config".to_string()), }, }; From 4181bc58cef62abca64c6c049619da499ef3cd13 Mon Sep 17 00:00:00 2001 From: IgorKoval Date: Wed, 17 Jul 2024 15:47:42 +0300 Subject: [PATCH 2/2] Clippy --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- src/completion.rs | 2 +- src/config.rs | 4 ++-- src/debug.rs | 24 ++++++++++++------------ src/decode.rs | 2 +- src/deploy.rs | 2 +- src/getconfig.rs | 2 +- src/helpers.rs | 2 +- src/replay.rs | 16 +++++++--------- tests/browser.rs | 2 +- tests/test_cli.rs | 2 +- 12 files changed, 34 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4fd2f5a..c818c517 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -847,7 +847,7 @@ dependencies = [ [[package]] name = "ever-cli" -version = "0.38.2" +version = "0.38.3" dependencies = [ "anyhow", "assert_cmd", @@ -2767,18 +2767,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.62" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.62" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 66c04661..c64cc118 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ license = 'Apache-2.0' name = 'ever-cli' readme = 'README.md' repository = 'https://github.com/everx-labs/ever-cli' -version = '0.38.2' +version = '0.38.3' default-run = 'ever-cli' [dependencies] diff --git a/src/completion.rs b/src/completion.rs index 00c1197e..4a6a60bc 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -148,7 +148,7 @@ fn main() { if abi_path.is_none() { return; } - if let Ok(abi) = std::fs::read_to_string(&abi_path.unwrap()) { + if let Ok(abi) = std::fs::read_to_string(abi_path.unwrap()) { if let Ok(abi_contract) = serde_json::from_str::(&abi) { for function in abi_contract.functions { if function.name.starts_with(word_being_completed) { diff --git a/src/config.rs b/src/config.rs index 273eb6b8..62a351b1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -300,7 +300,7 @@ impl FullConfig { let conf_str = std::fs::read_to_string(global_config_path()).ok() .unwrap_or_default(); let mut global_config = serde_json::from_str::(&conf_str) - .unwrap_or(FullConfig::default()); + .unwrap_or_default(); global_config.path = path.to_string(); global_config }; @@ -352,7 +352,7 @@ impl FullConfig { .map(|s| s.to_string()) .collect(); - let old_endpoints = fconf.endpoints_map.entry(url.to_string()).or_insert(vec![]); + let old_endpoints = fconf.endpoints_map.entry(url.to_string()).or_default(); old_endpoints.append(&mut new_endpoints); old_endpoints.sort(); old_endpoints.dedup(); diff --git a/src/debug.rs b/src/debug.rs index a1f4499b..b268ee9c 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -40,7 +40,7 @@ use std::fs::File; use serde_json::{Value, json}; use ever_assembler::DbgInfo; use ever_block::CommonMessage::Std; -use ever_vm::executor::{Engine, EngineTraceInfo, EngineTraceInfoType}; +use ever_vm::executor::{EngineTraceInfo, EngineTraceInfoType}; use crate::decode::msg_printer::serialize_msg; use crate::deploy::prepare_deploy_message; @@ -94,7 +94,7 @@ impl log::Log for DebugLogger { match record.target() { "tvm" | "executor" => { match std::fs::OpenOptions::new() - .write(true) + .append(true) .create(true) .open(&self.tvm_trace) @@ -626,23 +626,23 @@ fn load_decode_abi(matches: &ArgMatches<'_>, config: &Config) -> Option async fn debug_call_command(matches: &ArgMatches<'_>, full_config: &FullConfig, is_getter: bool) -> Result<(), String> { let contract_data = contract_data_from_matches_or_config_alias(matches, full_config)?; let input = contract_data.address.as_ref(); - let output = Some(matches.value_of("LOG_PATH").unwrap_or(DEFAULT_TRACE_PATH)); - let method = Some(matches.value_of("METHOD").or(full_config.config.method.as_deref()) - .ok_or("Method is not defined. Supply it in the config file or command line.")?); + let output = matches.value_of("LOG_PATH").unwrap_or(DEFAULT_TRACE_PATH); + let method = matches.value_of("METHOD").or(full_config.config.method.as_deref()) + .ok_or("Method is not defined. Supply it in the config file or command line.")?; let is_boc = matches.is_present("BOC"); let is_tvc = matches.is_present("TVC"); let abi = load_abi(contract_data.abi.as_ref().unwrap(), &full_config.config).await?; let params = Some(unpack_alternative_params( matches, contract_data.abi.as_ref().unwrap(), - method.unwrap(), + method, &full_config.config ).await?); if !full_config.config.is_json { let keys = &contract_data.keys; let abi = &contract_data.abi; - print_args!(input, method, params, keys, abi, output); + print_args!(input, Some(method), params, keys, abi, Some(output)); } let input = input.unwrap(); @@ -672,7 +672,7 @@ async fn debug_call_command(matches: &ArgMatches<'_>, full_config: &FullConfig, ton_client.clone(), &addr, abi.clone(), - method.unwrap(), + method, ¶ms, None, None, @@ -691,7 +691,7 @@ async fn debug_call_command(matches: &ArgMatches<'_>, full_config: &FullConfig, let params = serde_json::from_str(¶ms) .map_err(|e| format!("params are not in json format: {e}"))?; let call_set = CallSet { - function_name: method.unwrap().to_string(), + function_name: method.to_string(), input: Some(params), header: Some(header) }; @@ -723,7 +723,7 @@ async fn debug_call_command(matches: &ArgMatches<'_>, full_config: &FullConfig, let mut acc_root = account.serialize() .map_err(|e| format!("Failed to serialize account: {}", e))?; - let trace_path = output.unwrap(); + let trace_path = output; init_debug_logger(trace_path)?; let bc_config = get_blockchain_config(&full_config.config, matches.value_of("CONFIG_PATH")).await?; @@ -980,7 +980,7 @@ pub async fn decode_messages(tr: &Transaction, abi: Option, config: &Con let mut output = vec![]; for InRefValue(common_msg) in msgs { let msg = common_msg.get_std().unwrap(); - let mut ser_msg = serialize_msg(&msg, abi.clone(), config).await + let mut ser_msg = serialize_msg(msg, abi.clone(), config).await .map_err(|e| format!("Failed to serialize message: {}", e))?; let msg_cell = msg.serialize() .map_err(|e| format!("Failed to serialize out message: {}", e))?; @@ -1311,7 +1311,7 @@ pub async fn sequence_diagram_command(matches: &ArgMatches<'_>, config: &Config) let mut addresses = vec!(); let lines = std::io::BufReader::new(file).lines(); - for line in lines.flatten() { + for line in lines.map_while(Result::ok) { if !line.is_empty() && !line.starts_with('#'){ addresses.push(load_ton_address(&line, config)?); } diff --git a/src/decode.rs b/src/decode.rs index 48cd0b29..0f68b140 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -636,6 +636,6 @@ mod tests { async fn test_decode_body_json() { let body = "te6ccgEBAQEARAAAgwAAALqUCTqWL8OX7JivfJrAAzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMQAAAAAAAAAAAAAAAEeGjADA=="; let config = Config::default(); - let _out = decode_body(body, "tests/samples/wallet.abi.json", true, &config).await.unwrap(); + decode_body(body, "tests/samples/wallet.abi.json", true, &config).await.unwrap(); } } diff --git a/src/deploy.rs b/src/deploy.rs index ffc71941..683ed1d8 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -164,7 +164,7 @@ pub async fn prepare_deploy_message_params( abi.clone() ).await? } else { - let tvc_cell = ever_block::boc::read_single_root_boc(&tvc_bytes).unwrap(); + let tvc_cell = ever_block::boc::read_single_root_boc(tvc_bytes).unwrap(); let tvc_hash = tvc_cell.repr_hash(); format!("{}:{}", wc, tvc_hash.as_hex_string()) }; diff --git a/src/getconfig.rs b/src/getconfig.rs index 23be27d2..0744a7f9 100644 --- a/src/getconfig.rs +++ b/src/getconfig.rs @@ -475,7 +475,7 @@ fn prepare_message_new_config_param_solidity( .map_err(|err| err.to_string())?; let body = function .encode_input(&header, ¶meters, false, Some(&secret), Some(config_contract_address.clone())) - .and_then(|builder| SliceData::load_builder(builder)) + .and_then(SliceData::load_builder) .map_err(|err| format!("cannot prepare message body {}", err))?; let hdr = ExternalInboundMessageHeader::new(MsgAddressExt::AddrNone, config_contract_address); diff --git a/src/helpers.rs b/src/helpers.rs index 713333b8..ffeab694 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1035,7 +1035,7 @@ pub fn decode_data(data: &str, param_name: &str) -> Result, String> { } pub fn insert_pubkey_to_init_data(pubkey: Option, opt_init_data: Option<&str>) -> Result { - let init_data = opt_init_data.unwrap_or_else(|| "{}"); + let init_data = opt_init_data.unwrap_or("{}"); let mut js_init_data = serde_json::from_str(init_data) .map_err(|e| format!("Failed to decode initial data as json: {}", e))?; diff --git a/src/replay.rs b/src/replay.rs index 2270d758..ebda27da 100644 --- a/src/replay.rs +++ b/src/replay.rs @@ -30,7 +30,6 @@ use ever_client::net::{ use ever_executor::{BlockchainConfig, ExecuteParams, OrdinaryTransactionExecutor, TickTockTransactionExecutor, TransactionExecutor}; use ever_block::{BuilderData, SliceData, UInt256, write_boc}; -use ever_vm::executor::{Engine, EngineTraceInfo}; use crate::{config::Config, helpers::CallbackType}; use crate::helpers::{create_client, get_blockchain_config}; @@ -97,8 +96,7 @@ pub async fn fetch(config: &Config, account_address: &str, filename: &str, lt_bo .await .map_err(|e| format!("Failed to fetch txns count: {}", e))?; let tr_count = u64::from_str_radix( - tr_count.values.as_array().ok_or("Failed to parse value".to_string())? - .get(0).ok_or("Failed to parse value".to_string())? + tr_count.values.as_array().ok_or("Failed to parse value".to_string())?.first().ok_or("Failed to parse value".to_string())? .as_str().ok_or("Failed to parse value".to_string())?, 10) .map_err(|e| format!("Failed to parse decimal int: {}", e))?; @@ -137,7 +135,7 @@ pub async fn fetch(config: &Config, account_address: &str, filename: &str, lt_bo println!("account {}: zerostate not found, writing out default initial state", account_address); } let data = format!("{{\"id\":\"{}\",\"boc\":\"{}\"}}\n", - account_address, base64::encode(&Account::default().write_to_bytes() + account_address, base64::encode(Account::default().write_to_bytes() .map_err(|e| format!("failed to serialize account: {}", e))?)); writer.write_all(data.as_bytes()).map_err(|e| format!("Failed to write to file: {}", e))?; } @@ -385,7 +383,7 @@ pub async fn replay( trace_callback, ..ExecuteParams::default() }; - let common_message: Option = msg.map(|m| CommonMessage::Std(m)); + let common_message: Option = msg.map(CommonMessage::Std); let tr = executor.execute_with_libs_and_params( common_message.as_ref(), &mut account_root, @@ -416,7 +414,7 @@ pub async fn replay( last_tr_lt: Arc::new(AtomicU64::new(tr.tr.logical_time())), ..ExecuteParams::default() }; - let common_message: Option = msg.map(|m| CommonMessage::Std(m)); + let common_message: Option = msg.map(CommonMessage::Std); let tr_local = executor.execute_with_libs_and_params( common_message.as_ref(), &mut account_root, @@ -482,10 +480,10 @@ pub async fn fetch_block(config: &Config, block_id: &str, filename: &str) -> eve let mut accounts = vec!(); - let wid = block.result.get(0).unwrap()["workchain_id"].as_i64().unwrap(); - let end_lt = block.result.get(0).unwrap()["end_lt"].as_str().unwrap().trim_start_matches("0x"); + let wid = block.result.first().unwrap()["workchain_id"].as_i64().unwrap(); + let end_lt = block.result.first().unwrap()["end_lt"].as_str().unwrap().trim_start_matches("0x"); let end_lt = u64::from_str_radix(end_lt, 16).unwrap(); - let block = Block::construct_from_base64(block.result.get(0).unwrap()["boc"].as_str().unwrap())?; + let block = Block::construct_from_base64(block.result.first().unwrap()["boc"].as_str().unwrap())?; let extra = block.read_extra()?; let account_blocks = extra.read_account_blocks()?; diff --git a/tests/browser.rs b/tests/browser.rs index b349a178..2d1ed655 100644 --- a/tests/browser.rs +++ b/tests/browser.rs @@ -158,7 +158,7 @@ fn test_pipechain_inputs() -> Result<(), Box> { .assert() .success(); - let _ = std::fs::remove_file(path_to_pipechain_tmp)?; + std::fs::remove_file(path_to_pipechain_tmp)?; let out_value: serde_json::Value = serde_json::from_slice(&assert.get_output().stdout).unwrap(); let eq = predicate::eq(return_value); diff --git a/tests/test_cli.rs b/tests/test_cli.rs index 52ae6772..768ba21e 100644 --- a/tests/test_cli.rs +++ b/tests/test_cli.rs @@ -3088,7 +3088,7 @@ fn test_alternative_paths() -> Result<(), Box> { set_config( &["--abi"], - &[&*SAFEMSIG_ABI_LINK], + &[SAFEMSIG_ABI_LINK], Some(config_path) )?;