Skip to content

Commit

Permalink
Fixing clippy warnings (#90)
Browse files Browse the repository at this point in the history
* Fixing clippy errors

* cargo fmt
  • Loading branch information
Angel-Petrov authored Nov 29, 2023
1 parent ed5e1f4 commit 557b7ba
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{env::args, io, str::FromStr};
use avalanche_types::{evm::abi, jsonrpc::client::evm as json_client_evm, key, wallet};
use ethers_core::{
abi::{Function, StateMutability},
types::{H160, U256},
types::H160,
};

/// cargo run --example evm_contract_counter_increment --features="jsonrpc_client evm" -- [HTTP RPC ENDPOINT] [PRIVATE KEY] [CONTRACT ADDRESS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use avalanche_types::{
};
use ethers_core::{
abi::{encode as abi_encode, Function, StateMutability, Token},
types::{H160, U256},
types::H160,
};

/// cargo run --example evm_contract_counter_increment_append_calldata --features="jsonrpc_client evm" -- [HTTP RPC ENDPOINT] [PRIVATE KEY] [FORWARDER CONTRACT ADDRESS] [RECIPIENT CONTRACT ADDRESS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{env::args, io, str::FromStr};
use avalanche_types::{evm::abi, jsonrpc::client::evm as json_client_evm, key, wallet};
use ethers_core::{
abi::{Function, Param, ParamType, StateMutability, Token},
types::{H160, U256},
types::H160,
};

/// cargo run --example evm_contract_counter_increment_forwarder_proxy_call --features="jsonrpc_client evm" -- [HTTP RPC ENDPOINT] [PRIVATE KEY] [FORWARDER CONTRACT ADDRESS] [RECIPIENT CONTRACT ADDRESS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{env::args, io, str::FromStr};
use avalanche_types::{evm::abi, jsonrpc::client::evm as json_client_evm, key, wallet};
use ethers_core::{
abi::{Function, Param, ParamType, StateMutability, Token},
types::{H160, U256},
types::H160,
};

/// cargo run --example evm_contract_simple_registry_register --features="jsonrpc_client evm" -- [HTTP RPC ENDPOINT] [PRIVATE KEY] [CONTRACT ADDRESS]
Expand Down
6 changes: 1 addition & 5 deletions crates/avalanche-types/src/avalanchego/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,11 @@ pub const DEFAULT_PROCESS_CONTEXT_FILE: &str = "/data/process.json";

impl Default for Config {
fn default() -> Self {
Self::default()
Self::default_main()
}
}

impl Config {
pub fn default() -> Self {
Self::default_main()
}

/// The defaults do not match with the ones in avalanchego,
/// as this is for avalanche-ops based deployments.
pub fn default_main() -> Self {
Expand Down
55 changes: 19 additions & 36 deletions crates/avalanche-types/src/avalanchego/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ pub const DEFAULT_INITIAL_STAKE_DURATION_OFFSET: u64 = 5400; // 1.5 hour

impl Default for Genesis {
fn default() -> Self {
Self::default()
}
}

impl Genesis {
pub fn default() -> Self {
let now_unix = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("unexpected None duration_since")
Expand All @@ -119,7 +113,9 @@ impl Genesis {
message: Some(String::new()),
}
}
}

impl Genesis {
/// Creates a new Genesis object with "keys" number of generated pre-funded keys.
pub fn new<T: key::secp256k1::ReadOnly>(network_id: u32, seed_keys: &[T]) -> io::Result<Self> {
// maximize total supply
Expand All @@ -146,8 +142,10 @@ impl Genesis {
log::info!("allocate {} for each key in C-chain", c_alloc_per_key);

// allocation for C-chain
let mut default_c_alloc = coreth_genesis::AllocAccount::default();
default_c_alloc.balance = primitive_types::U256::from(c_alloc_per_key);
let default_c_alloc = coreth_genesis::AllocAccount {
balance: primitive_types::U256::from(c_alloc_per_key),
..Default::default()
};

// "initial_staked_funds" addresses use all P-chain balance
// so keep the remaining balance for other keys than "last" key
Expand All @@ -160,14 +158,15 @@ impl Genesis {

for k in seed_keys.iter() {
// allocation for X/P-chain
let mut xp_alloc = Allocation::default();
xp_alloc.eth_addr = Some(k.eth_address());
xp_alloc.avax_addr = Some(k.hrp_address(network_id, "X").unwrap());
xp_alloc.initial_amount = Some(xp_alloc_per_key);
xp_alloc.unlock_schedule = Some(vec![LockedAmount {
amount: Some(xp_alloc_per_key),
..Default::default()
}]);
let xp_alloc = Allocation {
eth_addr: Some(k.eth_address()),
avax_addr: Some(k.hrp_address(network_id, "X").unwrap()),
initial_amount: Some(xp_alloc_per_key),
unlock_schedule: Some(vec![LockedAmount {
amount: Some(xp_alloc_per_key),
..Default::default()
}]),
};
xp_allocs.push(xp_alloc);

c_allocs.insert(
Expand All @@ -178,8 +177,10 @@ impl Genesis {

// make sure to use different network ID than "local" network ID
// ref. https://github.com/ava-labs/avalanche-ops/issues/8
let mut c_chain_genesis = coreth_genesis::Genesis::default();
c_chain_genesis.alloc = Some(c_allocs);
let c_chain_genesis = coreth_genesis::Genesis {
alloc: Some(c_allocs),
..Default::default()
};

Ok(Self {
network_id,
Expand Down Expand Up @@ -305,12 +306,6 @@ pub const DEFAULT_LOCKED_AMOUNT_P_CHAIN: u64 = 200000000000000000;

impl Default for Allocation {
fn default() -> Self {
Self::default()
}
}

impl Allocation {
pub fn default() -> Self {
let unlock_empty = LockedAmount::default();
Self {
avax_addr: None,
Expand Down Expand Up @@ -339,12 +334,6 @@ pub struct LockedAmount {

impl Default for LockedAmount {
fn default() -> Self {
Self::default()
}
}

impl LockedAmount {
pub fn default() -> Self {
// NOTE: to place lock-time, use this:
// let now_unix = SystemTime::now()
// .duration_since(SystemTime::UNIX_EPOCH)
Expand Down Expand Up @@ -374,12 +363,6 @@ pub const DEFAULT_DELEGATION_FEE: u32 = 62500;

impl Default for Staker {
fn default() -> Self {
Self::default()
}
}

impl Staker {
pub fn default() -> Self {
Self {
node_id: None,
reward_address: None,
Expand Down
10 changes: 3 additions & 7 deletions crates/avalanche-types/src/coreth/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,9 @@ pub const DEFAULT_LOG_JSON_FORMAT: bool = true;
pub const DEFAULT_OFFLINE_PRUNING_DATA_DIR: &str = "/data/c-chain-offline-pruning";

impl Default for Config {
fn default() -> Self {
Self::default()
}
}

impl Config {
/// The defaults do not match with the ones in avalanchego,
/// as this is for avalanche-ops based deployments.
pub fn default() -> Self {
fn default() -> Self {
Self {
snowman_api_enabled: None,
coreth_admin_api_enabled: Some(DEFAULT_CORETH_ADMIN_API_ENABLED),
Expand Down Expand Up @@ -254,7 +248,9 @@ impl Config {
tx_lookup_limit: None,
}
}
}

impl Config {
pub fn encode_json(&self) -> io::Result<String> {
serde_json::to_string(&self)
.map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
Expand Down
20 changes: 2 additions & 18 deletions crates/avalanche-types/src/coreth/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ pub const DEFAULT_INITIAL_AMOUNT: &str = "0x204FCE5E3E25026110000000";

impl Default for Genesis {
fn default() -> Self {
Self::default()
}
}

impl Genesis {
pub fn default() -> Self {
let mut alloc = BTreeMap::new();
alloc.insert(
// ref. <https://github.com/ava-labs/coreth/blob/v0.11.5/params/config.go>
Expand Down Expand Up @@ -98,7 +92,9 @@ impl Genesis {
base_fee: None,
}
}
}

impl Genesis {
pub fn encode_json(&self) -> io::Result<String> {
serde_json::to_string(&self)
.map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
Expand Down Expand Up @@ -185,12 +181,6 @@ pub struct ChainConfig {

impl Default for ChainConfig {
fn default() -> Self {
Self::default()
}
}

impl ChainConfig {
pub fn default() -> Self {
Self {
// don't use local ID "43112" to avoid config override
// ref. <https://github.com/ava-labs/coreth/blob/v0.8.6/plugin/evm/vm.go#L326-L328>
Expand Down Expand Up @@ -252,12 +242,6 @@ pub struct AllocAccount {

impl Default for AllocAccount {
fn default() -> Self {
Self::default()
}
}

impl AllocAccount {
pub fn default() -> Self {
Self {
code: None,
storage: None,
Expand Down
6 changes: 6 additions & 0 deletions crates/avalanche-types/src/evm/eip1559/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ impl Transaction {
}
}

impl Default for Transaction {
fn default() -> Self {
Self::new()
}
}

/// Decodes the RLP-encoded signed "ethers_core::types::transaction::eip2718::TypedTransaction" bytes.
/// ref. <https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendrawtransaction>
pub fn decode_signed_rlp(b: impl AsRef<[u8]>) -> io::Result<(TypedTransaction, Signature)> {
Expand Down
6 changes: 6 additions & 0 deletions crates/avalanche-types/src/evm/eip712/gsn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ impl Tx {
}
}

impl Default for Tx {
fn default() -> Self {
Self::new()
}
}

/// Implements "type_hash".
/// ref. "ethers_core::types::transaction::eip712::EIP712_DOMAIN_TYPE_HASH"
/// ref. <https://github.com/opengsn/gsn/blob/master/packages/contracts/src/forwarder/Forwarder.sol> "registerRequestType"
Expand Down
16 changes: 2 additions & 14 deletions crates/avalanche-types/src/subnet/config/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@ pub struct SnowballParameters {
}

impl Default for SnowballParameters {
fn default() -> Self {
Self::default()
}
}

impl SnowballParameters {
/// The defaults do not match with the ones in avalanchego,
/// as this is for avalanche-ops based deployments.
pub fn default() -> Self {
fn default() -> Self {
Self {
k: 20,
alpha: 15,
Expand All @@ -66,15 +60,9 @@ pub struct Parameters {
}

impl Default for Parameters {
fn default() -> Self {
Self::default()
}
}

impl Parameters {
/// The defaults do not match with the ones in avalanchego,
/// as this is for avalanche-ops based deployments.
pub fn default() -> Self {
fn default() -> Self {
Self {
snowball_parameters: SnowballParameters::default(),
parents: 5,
Expand Down
8 changes: 1 addition & 7 deletions crates/avalanche-types/src/subnet/config/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ pub struct SenderConfig {
}

impl Default for SenderConfig {
fn default() -> Self {
Self::default()
}
}

impl SenderConfig {
/// The defaults do not match with the ones in avalanchego,
/// as this is for avalanche-ops based deployments.
pub fn default() -> Self {
fn default() -> Self {
Self {
gossip_accepted_frontier_validator_size: 0,
gossip_accepted_frontier_non_validator_size: 0,
Expand Down
10 changes: 3 additions & 7 deletions crates/avalanche-types/src/subnet/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@ pub struct Config {
}

impl Default for Config {
fn default() -> Self {
Self::default()
}
}

impl Config {
/// The defaults do not match with the ones in avalanchego,
/// as this is for avalanche-ops based deployments.
pub fn default() -> Self {
fn default() -> Self {
Self {
gossip_sender_config: gossip::SenderConfig::default(),
validator_only: false,
consensus_parameters: consensus::Parameters::default(),
proposer_min_block_delay: 1000 * 1000 * 1000, // 1-second
}
}
}

impl Config {
pub fn encode_json(&self) -> io::Result<String> {
serde_json::to_string(&self)
.map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl super::AppSender for AppSenderClient {

let mut id_bytes: Vec<Bytes> = Vec::with_capacity(node_ids.len());
for node_id in node_ids.iter() {
let node_id = node_id;
id_bytes.push(Bytes::from(node_id.to_vec()))
}

Expand Down
10 changes: 3 additions & 7 deletions crates/avalanche-types/src/subnet_evm/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,9 @@ pub const DEFAULT_LOG_LEVEL: &str = "info";
pub const DEFAULT_LOG_JSON_FORMAT: bool = true;

impl Default for Config {
fn default() -> Self {
Self::default()
}
}

impl Config {
/// The defaults do not match with the ones in avalanchego,
/// as this is for avalanche-ops based deployments.
pub fn default() -> Self {
fn default() -> Self {
Self {
snowman_api_enabled: None,
admin_api_enabled: Some(DEFAULT_ADMIN_API_ENABLED),
Expand Down Expand Up @@ -314,7 +308,9 @@ impl Config {
accepted_cache_size: Some(32),
}
}
}

impl Config {
pub fn encode_json(&self) -> io::Result<String> {
serde_json::to_string(&self)
.map_err(|e| Error::new(ErrorKind::Other, format!("failed to serialize JSON {}", e)))
Expand Down
Loading

0 comments on commit 557b7ba

Please sign in to comment.