Skip to content

Commit

Permalink
Merge pull request #924 from everx-labs/fix-clippy
Browse files Browse the repository at this point in the history
Fix clippy warnings
  • Loading branch information
IgorKoval authored Jul 26, 2024
2 parents 88389a3 + 4181bc5 commit 73590a6
Show file tree
Hide file tree
Showing 30 changed files with 252 additions and 284 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 8 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
23 changes: 8 additions & 15 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ACCOUNT_FIELDS: &str = r#"
const DEFAULT_PATH: &str = ".";

async fn query_accounts(config: &Config, addresses: Vec<String>, fields: &str) -> Result<Vec<Value>, String> {
let ton = create_client_verbose(&config)?;
let ton = create_client_verbose(config)?;

if !config.is_json {
println!("Processing...");
Expand Down Expand Up @@ -86,7 +86,7 @@ pub async fn get_account(config: &Config, addresses: Vec<String>, 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.");
}
Expand Down Expand Up @@ -156,7 +156,7 @@ pub async fn get_account(config: &Config, addresses: Vec<String>, dumptvc: Optio
);
} else {
print_account(
&config,
config,
Some(acc_type),
Some(address.clone()),
Some(balance),
Expand All @@ -170,7 +170,7 @@ pub async fn get_account(config: &Config, addresses: Vec<String>, 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!();
Expand All @@ -195,11 +195,7 @@ pub async fn get_account(config: &Config, addresses: Vec<String>, 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 {
Expand Down Expand Up @@ -232,7 +228,7 @@ pub async fn get_account(config: &Config, addresses: Vec<String>, 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...");
Expand All @@ -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))?;

Expand All @@ -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<String>, 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() {
Expand Down Expand Up @@ -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))?;

Expand Down Expand Up @@ -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))?;
Expand Down
13 changes: 5 additions & 8 deletions src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?
Expand Down Expand Up @@ -185,7 +185,6 @@ pub async fn send_message_and_wait(
message: msg.clone(),
abi: abi.clone(),
send_events: false,
..Default::default()
},
callback,
).await
Expand Down Expand Up @@ -231,7 +230,6 @@ pub async fn process_message(
ParamsOfProcessMessage {
message_encode_params: msg.clone(),
send_events: true,
..Default::default()
},
callback,
).await
Expand All @@ -241,7 +239,6 @@ pub async fn process_message(
ParamsOfProcessMessage {
message_encode_params: msg.clone(),
send_events: true,
..Default::default()
},
|_| { async move {} },
).await
Expand All @@ -259,7 +256,7 @@ pub async fn call_contract_with_result(
keys: Option<String>,
is_fee: bool,
) -> Result<Value, String> {
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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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)?;
Expand Down
16 changes: 7 additions & 9 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -72,13 +72,11 @@ fn print_paths(prefix: &str) {
return;
}
let mut saved_path: Vec<PathBuf> = 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() {
Expand Down Expand Up @@ -150,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::<AbiContract>(&abi) {
for function in abi_contract.functions {
if function.name.starts_with(word_being_completed) {
Expand Down
21 changes: 11 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config> = 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<FullConfig> = 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::<FullConfig>(&conf_str)
.unwrap_or(FullConfig::default());
.unwrap_or_default();
global_config.path = path.to_string();
global_config
} else {
full_config.unwrap()
};
full_config.path = path.to_string();
full_config
Expand Down Expand Up @@ -345,13 +347,12 @@ 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<String> = endpoints
.replace('[', "")
.replace(']', "")
.replace(['[', ']'], "")
.split(',')
.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();
Expand Down
4 changes: 2 additions & 2 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub fn nodeid_from_pubkey(key: &[u8]) -> Result<String, String> {
}
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()))
}
Loading

0 comments on commit 73590a6

Please sign in to comment.