Skip to content

Commit

Permalink
Clippy automated fixes (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored Nov 1, 2023
1 parent cf7ca64 commit e8f8544
Show file tree
Hide file tree
Showing 33 changed files with 93 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ async fn main() -> io::Result<()> {
.build()
.await
.unwrap();
let evm_wallet = w
.evm(&signer, chain_rpc_url.as_str(), U256::from(chain_id))
.unwrap();
let evm_wallet = w.evm(&signer, chain_rpc_url.as_str(), chain_id).unwrap();

// parsed function of "increment()"
let func = Function {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn main() -> Result<()> {
.base_http_url(chain_rpc_url.clone())
.build()
.await?;
let evm_wallet = w.evm(&signer, chain_rpc_url.as_str(), U256::from(chain_id))?;
let evm_wallet = w.evm(&signer, chain_rpc_url.as_str(), chain_id)?;

// parsed function of "increment()"
let func = Function {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async fn main() -> io::Result<()> {
.domain_verifying_contract(forwarder_contract_addr)
//
// gasless transaction signer
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down Expand Up @@ -149,11 +149,7 @@ async fn main() -> io::Result<()> {
.await
.unwrap();
let gas_payer_evm_wallet = w
.evm(
&gas_payer_signer,
chain_rpc_url.as_str(),
U256::from(chain_id),
)
.evm(&gas_payer_signer, chain_rpc_url.as_str(), chain_id)
.unwrap();

let tx_id = gas_payer_evm_wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ async fn main() -> io::Result<()> {
.build()
.await
.unwrap();
let evm_wallet = w
.evm(&signer, chain_rpc_url.as_str(), U256::from(chain_id))
.unwrap();
let evm_wallet = w.evm(&signer, chain_rpc_url.as_str(), chain_id).unwrap();

// parsed function of "increment()"
let func = Function {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ async fn main() -> io::Result<()> {
.build()
.await
.unwrap();
let evm_wallet = w
.evm(&signer, chain_rpc_url.as_str(), U256::from(chain_id))
.unwrap();
let evm_wallet = w.evm(&signer, chain_rpc_url.as_str(), chain_id).unwrap();

// parsed function of "register(string name)"
let func = Function {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async fn main() -> io::Result<()> {
.domain_verifying_contract(forwarder_contract_addr)
//
// gasless transaction signer
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down Expand Up @@ -128,11 +128,7 @@ async fn main() -> io::Result<()> {
.await
.unwrap();
let gas_payer_evm_wallet = w
.evm(
&gas_payer_signer,
chain_rpc_url.as_str(),
U256::from(chain_id),
)
.evm(&gas_payer_signer, chain_rpc_url.as_str(), chain_id)
.unwrap();

let tx_id = gas_payer_evm_wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async fn main() -> io::Result<()> {
//
// trusted forwarder contract address
.domain_verifying_contract(forwarder_contract_addr)
.from(no_gas_key_info.h160_address.clone())
.from(no_gas_key_info.h160_address)
//
// contract address that this gasless transaction will interact with
.to(recipient_contract_addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> io::Result<()> {

let domain_verifying_contract = args().nth(4).expect("no domain_verifying_contract given");
let domain_verifying_contract =
H160::from_str(&domain_verifying_contract.trim_start_matches("0x")).unwrap();
H160::from_str(domain_verifying_contract.trim_start_matches("0x")).unwrap();
log::info!("domain_verifying_contract: {domain_verifying_contract}");

let domain_separator = Tx::new()
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/examples/proto_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.build()
.expect("failed to build reflection service");

let greeter_svc = GreeterServer::new(MyGreeter::default());
let greeter_svc = GreeterServer::new(MyGreeter);

utils::grpc::default_server()
.add_service(reflection_svc)
Expand Down
6 changes: 3 additions & 3 deletions crates/avalanche-types/src/avalanchego/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,14 @@ impl Config {
pub fn add_track_subnets(&mut self, ids: Option<String>) {
let mut all_ids = BTreeSet::new();
if let Some(existing) = &self.track_subnets {
let ss: Vec<&str> = existing.split(",").collect();
let ss: Vec<&str> = existing.split(',').collect();
for id in ss {
all_ids.insert(id.trim().to_string());
}
}

if let Some(new_ids) = &ids {
let ss: Vec<&str> = new_ids.split(",").collect();
let ss: Vec<&str> = new_ids.split(',').collect();
for id in ss {
all_ids.insert(id.trim().to_string());
}
Expand Down Expand Up @@ -576,7 +576,7 @@ impl Config {
));
}

let f = File::open(&file_path).map_err(|e| {
let f = File::open(file_path).map_err(|e| {
Error::new(
ErrorKind::Other,
format!("failed to open {} ({})", file_path, e),
Expand Down
16 changes: 7 additions & 9 deletions crates/avalanche-types/src/avalanchego/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,21 @@ impl Genesis {
));
}

let f = File::open(&file_path).map_err(|e| {
return Error::new(
let f = File::open(file_path).map_err(|e| {
Error::new(
ErrorKind::Other,
format!("failed to open {} ({})", file_path, e),
);
)
})?;

// load as it is
let genesis_file: GenesisFile = serde_json::from_reader(f).map_err(|e| {
return Error::new(ErrorKind::InvalidInput, format!("invalid JSON: {}", e));
})?;
let genesis_file: GenesisFile = serde_json::from_reader(f)
.map_err(|e| Error::new(ErrorKind::InvalidInput, format!("invalid JSON: {}", e)))?;

// make genesis strictly typed
let c_chain_genesis: coreth_genesis::Genesis =
serde_json::from_str(&genesis_file.c_chain_genesis).map_err(|e| {
return Error::new(ErrorKind::InvalidInput, format!("invalid JSON: {}", e));
})?;
serde_json::from_str(&genesis_file.c_chain_genesis)
.map_err(|e| Error::new(ErrorKind::InvalidInput, format!("invalid JSON: {}", e)))?;

let genesis = Genesis {
network_id: genesis_file.network_id,
Expand Down
4 changes: 2 additions & 2 deletions crates/avalanche-types/src/codec/serde/base64_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
{
let s = String::deserialize(deserializer)?;
base64::engine::general_purpose::STANDARD
.decode(&s)
.decode(s)
.map_err(serde::de::Error::custom)
}

Expand All @@ -37,7 +37,7 @@ impl<'de> DeserializeAs<'de, Vec<u8>> for Base64Bytes {
{
let s = String::deserialize(deserializer)?;
base64::engine::general_purpose::STANDARD
.decode(&s)
.decode(s)
.map_err(serde::de::Error::custom)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/coreth/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl Config {
));
}

let f = File::open(&file_path).map_err(|e| {
let f = File::open(file_path).map_err(|e| {
Error::new(
ErrorKind::Other,
format!("failed to open {} ({})", file_path, e),
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/evm/eip712/gsn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,5 +545,5 @@ fn foward_request_types() -> Types {
},
],
);
return types;
types
}
10 changes: 5 additions & 5 deletions crates/avalanche-types/src/evm/eip712/gsn/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl super::Tx {
log::info!("estimated gas {estimated_gas} -- now signing again with updated gas");

self.gas = estimated_gas;
Request::sign_to_request(&self, eth_signer).await
Request::sign_to_request(self, eth_signer).await
}

/// "sign_to_request" but with estimated gas via RPC endpoints.
Expand Down Expand Up @@ -96,7 +96,7 @@ impl super::Tx {
if elapsed.gt(&retry_timeout) {
break;
}
retries = retries + 1;
retries += 1;

match Self::sign_to_request_with_estimated_gas(
self,
Expand Down Expand Up @@ -125,7 +125,7 @@ impl super::Tx {
}
}
}
return Err(Error::new(ErrorKind::Other, "failed estimate_gas in time"));
Err(Error::new(ErrorKind::Other, "failed estimate_gas in time"))
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ impl Request {

let domain_verifying_contract =
if let Some(verifying_contract) = &self.forward_request.domain.verifying_contract {
verifying_contract.clone()
*verifying_contract
} else {
return Err(Error::new(
ErrorKind::InvalidInput,
Expand Down Expand Up @@ -501,7 +501,7 @@ impl Request {
let fwd_req_hash = tx
.encode_eip712()
.map_err(|e| Error::new(ErrorKind::Other, format!("failed encode_eip712 '{}'", e)))?;
let fwd_req_hash = H256::from_slice(&fwd_req_hash.to_vec());
let fwd_req_hash = H256::from_slice(fwd_req_hash.as_ref());

let signer_addr = sig.recover(RecoveryMessage::Hash(fwd_req_hash)).map_err(|e| {
Error::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/avalanche-types/src/key/secp256k1/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const ETH_ACCOUNT_EXT_PUB_KEY_DERIV_PATH: &str = "m/44'/60'/0'/0/0";
/// ref. <https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md>
/// ref. <https://iancoleman.io/bip39/>
pub fn gen_24() -> String {
let m = Mnemonic::random(&mut OsRng, Language::English);
let m = Mnemonic::random(OsRng, Language::English);
let s = m.phrase();
assert_eq!(s.split(' ').count(), 24);
String::from(s)
Expand Down
10 changes: 5 additions & 5 deletions crates/avalanche-types/src/subnet/rpc/database/memdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ async fn test_memdb() {
let mut db = Database::new();
let _ = db.put("foo".as_bytes(), "bar".as_bytes()).await;
let resp = db.has("foo".as_bytes()).await;
assert!(!resp.is_err());
assert_eq!(resp.unwrap(), true);
assert!(resp.is_ok());
assert!(resp.unwrap());

let mut db = Database::new();
let _ = db.put("foo".as_bytes(), "bar".as_bytes()).await;
let _ = db.delete("foo".as_bytes()).await;
let resp = db.has("foo".as_bytes()).await;
assert!(!resp.is_err());
assert_eq!(resp.unwrap(), false);
assert!(resp.is_ok());
assert!(!resp.unwrap());

let db = Database::new();
let resp = db.health_check().await;
assert!(!resp.is_err());
assert!(resp.is_ok());
let _ = db.close().await;
let resp = db.health_check().await;
assert_eq!(resp.err().unwrap().to_string(), "database closed");
Expand Down
4 changes: 2 additions & 2 deletions crates/avalanche-types/src/subnet/rpc/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ async fn clone_box_test() {
// create box and mutate underlying hashmap
let mut db = memdb::Database::new();
let resp = db.put("foo".as_bytes(), "bar".as_bytes()).await;
assert!(!resp.is_err());
assert!(resp.is_ok());

// clone and mutate
let mut cloned_db = db.clone();
let resp = cloned_db.delete("foo".as_bytes()).await;
assert!(!resp.is_err());
assert!(resp.is_ok());

// verify mutation
let resp = cloned_db.get("foo".as_bytes()).await;
Expand Down
Loading

0 comments on commit e8f8544

Please sign in to comment.