diff --git a/lib/.rustfmt.toml b/lib/.rustfmt.toml index 65106950ef..a0c1282281 100644 --- a/lib/.rustfmt.toml +++ b/lib/.rustfmt.toml @@ -1,2 +1,3 @@ unstable_features = true group_imports = "StdExternalCrate" +imports_granularity = "Crate" diff --git a/lib/Cargo.lock b/lib/Cargo.lock index d018c99fc9..b29ffffde6 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -85,11 +85,11 @@ version = "0.1.0" dependencies = [ "anyhow", "ethereum", + "ethereum-types", "ethers", "ethers-solc", "hex", "lazy_static", - "primitive-types", "serde_json", "sha3", "sp-core", @@ -130,7 +130,6 @@ dependencies = [ "lru", "num", "once_cell", - "primitive-types", "rand 0.8.5", "ripemd", "rlp", @@ -173,7 +172,6 @@ dependencies = [ "log", "num-traits", "prettyplease 0.2.12", - "primitive-types", "proc-macro2", "prost", "prost-build", @@ -202,9 +200,9 @@ dependencies = [ "cxx-gen", "ethabi", "ethereum", + "ethereum-types", "hex", "log", - "primitive-types", "proc-macro2", "rlp", "serde_json", @@ -3186,9 +3184,9 @@ version = "0.1.0" dependencies = [ "ain-grpc", "ethereum", + "ethereum-types", "hex", "jsonrpsee 0.18.2", - "primitive-types", "serde", "serde_json", "structopt", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 0ff8537364..5f2e19dd10 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -69,7 +69,6 @@ jsonrpsee-types = "0.16" ethereum = "0.14" ethereum-types = "0.14" keccak-hash = "0.10" -primitive-types = { version = "0.12", default-features = false, features = ["serde"] } rlp = "0.5" ethabi = "18.0.0" diff --git a/lib/Makefile.am b/lib/Makefile.am index 08bf42e49a..4034291eda 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -80,7 +80,7 @@ clippy: # cause conflicts across toolchains .PHONY: fmt-check fmt-check: - $(CARGO) fmt $(CARGO_MANIFEST_ARG) --all --check 2> >(grep -v -E 'group_imports|unstable_features') + $(CARGO) fmt $(CARGO_MANIFEST_ARG) --all --check 2> >(grep -v -E 'group_imports|unstable_features|imports_granularity') .PHONY: fmt fmt: diff --git a/lib/ain-contracts/Cargo.toml b/lib/ain-contracts/Cargo.toml index 9bff3aa5bc..bbfc25c5d4 100644 --- a/lib/ain-contracts/Cargo.toml +++ b/lib/ain-contracts/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -primitive-types.workspace = true +ethereum-types.workspace = true anyhow.workspace = true ethereum.workspace = true serde_json.workspace = true diff --git a/lib/ain-contracts/build.rs b/lib/ain-contracts/build.rs index e776fae045..8c8a474330 100644 --- a/lib/ain-contracts/build.rs +++ b/lib/ain-contracts/build.rs @@ -1,6 +1,4 @@ -use std::env; -use std::fs; -use std::path::PathBuf; +use std::{env, fs, path::PathBuf}; use anyhow::format_err; use ethers_solc::{Project, ProjectPathsConfig, Solc}; diff --git a/lib/ain-contracts/src/lib.rs b/lib/ain-contracts/src/lib.rs index 94a6c3ce4a..035377203e 100644 --- a/lib/ain-contracts/src/lib.rs +++ b/lib/ain-contracts/src/lib.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use anyhow::format_err; -use primitive_types::{H160, H256}; +use ethereum_types::{H160, H256}; use sp_core::{Blake2Hasher, Hasher}; pub type Result = std::result::Result; diff --git a/lib/ain-cpp-imports/build.rs b/lib/ain-cpp-imports/build.rs index 1afdc5d00c..caa92ce419 100644 --- a/lib/ain-cpp-imports/build.rs +++ b/lib/ain-cpp-imports/build.rs @@ -1,5 +1,4 @@ -use std::env; -use std::path::PathBuf; +use std::{env, path::PathBuf}; use anyhow::{format_err, Result}; diff --git a/lib/ain-evm/Cargo.toml b/lib/ain-evm/Cargo.toml index 5e46a65847..71e2c384ab 100644 --- a/lib/ain-evm/Cargo.toml +++ b/lib/ain-evm/Cargo.toml @@ -8,7 +8,6 @@ ain-cpp-imports = { path = "../ain-cpp-imports" } ain-contracts = { path = "../ain-contracts" } evm = { workspace = true, default-features = false, features = ["with-serde"] } -primitive-types = { workspace = true, default-features = false, features = ["serde"] } log.workspace = true rlp.workspace = true libsecp256k1.workspace = true diff --git a/lib/ain-evm/src/backend.rs b/lib/ain-evm/src/backend.rs index b007754785..651a96ec38 100644 --- a/lib/ain-evm/src/backend.rs +++ b/lib/ain-evm/src/backend.rs @@ -1,22 +1,20 @@ -use std::error::Error; -use std::sync::Arc; +use std::{error::Error, sync::Arc}; use ethereum::{Account, Log}; +use ethereum_types::{H160, H256, U256}; use evm::backend::{Apply, ApplyBackend, Backend, Basic}; use hash_db::Hasher as _; use log::{debug, trace}; -use primitive_types::{H160, H256, U256}; use rlp::{Decodable, Encodable, Rlp}; -use sp_core::hexdisplay::AsBytesRef; -use sp_core::Blake2Hasher; +use sp_core::{hexdisplay::AsBytesRef, Blake2Hasher}; use vsdb_trie_db::{MptOnce, MptRo}; -use crate::Result; use crate::{ storage::{traits::BlockStorage, Storage}, traits::BridgeBackend, transaction::SignedTx, trie::TrieDBStore, + Result, }; type Hasher = Blake2Hasher; diff --git a/lib/ain-evm/src/block.rs b/lib/ain-evm/src/block.rs index 112e08013e..dbb45e1458 100644 --- a/lib/ain-evm/src/block.rs +++ b/lib/ain-evm/src/block.rs @@ -1,15 +1,19 @@ -use std::cmp::{max, Ordering}; -use std::sync::Arc; +use std::{ + cmp::{max, Ordering}, + sync::Arc, +}; use anyhow::format_err; use ethereum::{BlockAny, TransactionAny}; +use ethereum_types::U256; use keccak_hash::H256; use log::{debug, trace}; -use primitive_types::U256; use statrs::statistics::{Data, OrderStatistics}; -use crate::storage::{traits::BlockStorage, Storage}; -use crate::Result; +use crate::{ + storage::{traits::BlockStorage, Storage}, + Result, +}; pub struct BlockService { storage: Arc, diff --git a/lib/ain-evm/src/core.rs b/lib/ain-evm/src/core.rs index 962b411e4e..b7b5c05b4d 100644 --- a/lib/ain-evm/src/core.rs +++ b/lib/ain-evm/src/core.rs @@ -1,29 +1,27 @@ -use std::path::PathBuf; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; use anyhow::format_err; use ethereum::{AccessList, Account, Block, Log, PartialHeader, TransactionV2}; -use ethereum_types::{Bloom, BloomInput, H160, U256}; +use ethereum_types::{Bloom, BloomInput, H160, H256, U256}; use log::debug; -use primitive_types::H256; use vsdb_core::vsdb_set_base_dir; -use crate::backend::{BackendError, EVMBackend, InsufficientBalance, Vicinity}; -use crate::block::INITIAL_BASE_FEE; -use crate::executor::TxResponse; -use crate::fee::calculate_prepay_gas_fee; -use crate::gas::check_tx_intrinsic_gas; -use crate::receipt::ReceiptService; -use crate::storage::traits::BlockStorage; -use crate::storage::Storage; -use crate::transaction::system::{SystemTx, TransferDirection, TransferDomainData}; -use crate::trie::TrieDBStore; -use crate::txqueue::{QueueTx, TransactionQueueMap}; -use crate::weiamount::WeiAmount; use crate::{ - executor::AinExecutor, + backend::{BackendError, EVMBackend, InsufficientBalance, Vicinity}, + block::INITIAL_BASE_FEE, + executor::{AinExecutor, TxResponse}, + fee::calculate_prepay_gas_fee, + gas::check_tx_intrinsic_gas, + receipt::ReceiptService, + storage::{traits::BlockStorage, Storage}, traits::{Executor, ExecutorContext}, - transaction::SignedTx, + transaction::{ + system::{SystemTx, TransferDirection, TransferDomainData}, + SignedTx, + }, + trie::TrieDBStore, + txqueue::{QueueTx, TransactionQueueMap}, + weiamount::WeiAmount, Result, }; diff --git a/lib/ain-evm/src/ecrecover.rs b/lib/ain-evm/src/ecrecover.rs index 4df022fee7..37df2cfa75 100644 --- a/lib/ain-evm/src/ecrecover.rs +++ b/lib/ain-evm/src/ecrecover.rs @@ -1,6 +1,5 @@ -use libsecp256k1::Error; -use libsecp256k1::{PublicKey, RecoveryId, Signature}; -use primitive_types::{H160, H256}; +use ethereum_types::{H160, H256}; +use libsecp256k1::{Error, PublicKey, RecoveryId, Signature}; use sha3::Digest; pub fn recover_public_key( @@ -30,8 +29,8 @@ pub fn public_key_to_address(pubkey: &PublicKey) -> H160 { #[cfg(test)] mod tests { + use ethereum_types::*; use hex_literal::hex; - use primitive_types::*; use super::{public_key_to_address, recover_public_key}; diff --git a/lib/ain-evm/src/evm.rs b/lib/ain-evm/src/evm.rs index e8c6ba9539..9cdb27119a 100644 --- a/lib/ain-evm/src/evm.rs +++ b/lib/ain-evm/src/evm.rs @@ -1,5 +1,4 @@ -use std::path::PathBuf; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; use ain_contracts::{ get_dst20_contract, get_reserved_contract, get_transferdomain_contract, Contract, FixedContract, @@ -9,32 +8,32 @@ use ethereum::{ Block, EIP1559ReceiptData, LegacyTransaction, PartialHeader, ReceiptV3, TransactionAction, TransactionSignature, TransactionV2, }; -use ethereum_types::{Bloom, H160, H64, U256}; +use ethereum_types::{Bloom, H160, H256, H64, U256}; use log::debug; -use primitive_types::H256; -use crate::backend::{EVMBackend, Vicinity}; -use crate::block::BlockService; -use crate::contract::{ - bridge_dst20, counter_contract, dst20_contract, transfer_domain_contract, DST20BridgeInfo, - DeployContractInfo, +use crate::{ + backend::{EVMBackend, Vicinity}, + block::BlockService, + contract::{ + bridge_dst20, counter_contract, dst20_contract, transfer_domain_contract, DST20BridgeInfo, + DeployContractInfo, + }, + core::{EVMCoreService, XHash}, + executor::{AinExecutor, TxResponse}, + fee::{calculate_gas_fee, calculate_prepay_gas_fee}, + filters::FilterService, + log::LogService, + receipt::ReceiptService, + storage::{traits::BlockStorage, Storage}, + traits::Executor, + transaction::{ + system::{DST20Data, DeployContractData, SystemTx, TransferDirection, TransferDomainData}, + SignedTx, LOWER_H256, + }, + trie::GENESIS_STATE_ROOT, + txqueue::{BlockData, QueueTx, QueueTxItem}, + Result, }; -use crate::core::{EVMCoreService, XHash}; -use crate::executor::{AinExecutor, TxResponse}; -use crate::fee::{calculate_gas_fee, calculate_prepay_gas_fee}; -use crate::filters::FilterService; -use crate::log::LogService; -use crate::receipt::ReceiptService; -use crate::storage::traits::BlockStorage; -use crate::storage::Storage; -use crate::traits::Executor; -use crate::transaction::system::{ - DST20Data, DeployContractData, SystemTx, TransferDirection, TransferDomainData, -}; -use crate::transaction::{SignedTx, LOWER_H256}; -use crate::trie::GENESIS_STATE_ROOT; -use crate::txqueue::{BlockData, QueueTx, QueueTxItem}; -use crate::Result; pub struct EVMServices { pub core: EVMCoreService, diff --git a/lib/ain-evm/src/executor.rs b/lib/ain-evm/src/executor.rs index db42350371..67f1e9879d 100644 --- a/lib/ain-evm/src/executor.rs +++ b/lib/ain-evm/src/executor.rs @@ -1,21 +1,20 @@ use ethereum::{EIP658ReceiptData, Log, ReceiptV3}; -use ethereum_types::{Bloom, U256}; +use ethereum_types::{Bloom, H160, H256, U256}; use evm::{ backend::{ApplyBackend, Backend}, executor::stack::{MemoryStackState, StackExecutor, StackSubstateMetadata}, Config, CreateScheme, ExitReason, }; use log::trace; -use primitive_types::{H160, H256}; -use crate::bytes::Bytes; -use crate::precompiles::MetachainPrecompiles; -use crate::Result; use crate::{ backend::EVMBackend, + bytes::Bytes, core::EVMCoreService, + precompiles::MetachainPrecompiles, traits::{BridgeBackend, Executor, ExecutorContext}, transaction::SignedTx, + Result, }; pub struct AinExecutor<'backend> { diff --git a/lib/ain-evm/src/fee.rs b/lib/ain-evm/src/fee.rs index 414bf50da5..e518ec6bc3 100644 --- a/lib/ain-evm/src/fee.rs +++ b/lib/ain-evm/src/fee.rs @@ -4,8 +4,7 @@ use anyhow::format_err; use ethereum::TransactionV2; use ethereum_types::U256; -use crate::transaction::SignedTx; -use crate::Result; +use crate::{transaction::SignedTx, Result}; pub fn calculate_prepay_gas_fee(signed_tx: &SignedTx) -> Result { match &signed_tx.transaction { diff --git a/lib/ain-evm/src/filters.rs b/lib/ain-evm/src/filters.rs index b12d77fa14..023c579c83 100644 --- a/lib/ain-evm/src/filters.rs +++ b/lib/ain-evm/src/filters.rs @@ -1,8 +1,7 @@ -use std::collections::HashMap; -use std::sync::RwLock; +use std::{collections::HashMap, sync::RwLock}; +use ethereum_types::{H160, H256, U256}; use log::debug; -use primitive_types::{H160, H256, U256}; #[derive(Clone, Debug)] pub enum Filter { diff --git a/lib/ain-evm/src/gas.rs b/lib/ain-evm/src/gas.rs index c21bea6fd6..7c1470b7a9 100644 --- a/lib/ain-evm/src/gas.rs +++ b/lib/ain-evm/src/gas.rs @@ -6,8 +6,7 @@ use evm::{ }; use log::debug; -use crate::transaction::SignedTx; -use crate::Result; +use crate::{transaction::SignedTx, Result}; fn get_tx_cost(signed_tx: &SignedTx) -> TransactionCost { let access_list = signed_tx diff --git a/lib/ain-evm/src/log.rs b/lib/ain-evm/src/log.rs index 028cb174e6..5e771c3d00 100644 --- a/lib/ain-evm/src/log.rs +++ b/lib/ain-evm/src/log.rs @@ -1,16 +1,16 @@ -use std::collections::HashMap; -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; use ethereum::ReceiptV3; +use ethereum_types::{H160, H256, U256}; use log::debug; -use primitive_types::{H160, H256, U256}; use serde::{Deserialize, Serialize}; -use crate::filters::LogsFilter; -use crate::receipt::Receipt; -use crate::storage::traits::LogStorage; -use crate::storage::Storage; -use crate::Result; +use crate::{ + filters::LogsFilter, + receipt::Receipt, + storage::{traits::LogStorage, Storage}, + Result, +}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct LogIndex { diff --git a/lib/ain-evm/src/receipt.rs b/lib/ain-evm/src/receipt.rs index 3c229fe306..7d370a254f 100644 --- a/lib/ain-evm/src/receipt.rs +++ b/lib/ain-evm/src/receipt.rs @@ -1,16 +1,17 @@ use std::sync::Arc; -use ethereum::util::ordered_trie_root; -use ethereum::{EnvelopedEncodable, ReceiptV3}; +use ethereum::{util::ordered_trie_root, EnvelopedEncodable, ReceiptV3}; +use ethereum_types::{H160, H256, U256}; use keccak_hash::keccak; -use primitive_types::{H160, H256, U256}; use rlp::RlpStream; use serde::{Deserialize, Serialize}; -use crate::evm::ReceiptAndOptionalContractAddress; -use crate::storage::{traits::ReceiptStorage, Storage}; -use crate::transaction::SignedTx; -use crate::Result; +use crate::{ + evm::ReceiptAndOptionalContractAddress, + storage::{traits::ReceiptStorage, Storage}, + transaction::SignedTx, + Result, +}; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Receipt { @@ -106,7 +107,7 @@ impl ReceiptService { mod test { use std::str::FromStr; - use primitive_types::{H160, U256}; + use ethereum_types::{H160, U256}; use crate::receipt::get_contract_address; diff --git a/lib/ain-evm/src/services.rs b/lib/ain-evm/src/services.rs index 2cf6e63a83..a5f14d5aed 100644 --- a/lib/ain-evm/src/services.rs +++ b/lib/ain-evm/src/services.rs @@ -1,14 +1,19 @@ -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, Mutex}; -use std::thread::{self, JoinHandle}; +use std::{ + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, Mutex, + }, + thread::{self, JoinHandle}, +}; use anyhow::Result; use jsonrpsee_server::ServerHandle as HttpServerHandle; -use tokio::runtime::{Builder, Handle as AsyncHandle}; -use tokio::sync::mpsc::{self, Sender}; +use tokio::{ + runtime::{Builder, Handle as AsyncHandle}, + sync::mpsc::{self, Sender}, +}; -use crate::evm::EVMServices; -use crate::storage::traits::FlushableStorage; +use crate::{evm::EVMServices, storage::traits::FlushableStorage}; // TODO: SERVICES needs to go into its own core crate now, // and this crate be dedicated to evm diff --git a/lib/ain-evm/src/storage/block_store.rs b/lib/ain-evm/src/storage/block_store.rs index 639d12579d..d7907aec3c 100644 --- a/lib/ain-evm/src/storage/block_store.rs +++ b/lib/ain-evm/src/storage/block_store.rs @@ -1,19 +1,20 @@ -use std::fs; -use std::path::Path; -use std::{collections::HashMap, marker::PhantomData, sync::Arc}; +use std::{collections::HashMap, fs, marker::PhantomData, path::Path, sync::Arc}; use anyhow::format_err; use ethereum::{BlockAny, TransactionV2}; +use ethereum_types::{H160, H256, U256}; use log::debug; -use primitive_types::{H160, H256, U256}; - -use super::db::{Column, ColumnName, LedgerColumn, Rocks}; -use super::traits::{BlockStorage, FlushableStorage, ReceiptStorage, Rollback, TransactionStorage}; -use crate::log::LogIndex; -use crate::receipt::Receipt; -use crate::storage::db::columns; -use crate::storage::traits::LogStorage; -use crate::Result; + +use super::{ + db::{Column, ColumnName, LedgerColumn, Rocks}, + traits::{BlockStorage, FlushableStorage, ReceiptStorage, Rollback, TransactionStorage}, +}; +use crate::{ + log::LogIndex, + receipt::Receipt, + storage::{db::columns, traits::LogStorage}, + Result, +}; #[derive(Debug, Clone)] pub struct BlockStore(Arc); diff --git a/lib/ain-evm/src/storage/cache.rs b/lib/ain-evm/src/storage/cache.rs index b7115d4f56..b3d9995899 100644 --- a/lib/ain-evm/src/storage/cache.rs +++ b/lib/ain-evm/src/storage/cache.rs @@ -1,10 +1,9 @@ -use std::borrow::ToOwned; -use std::{num::NonZeroUsize, sync::RwLock}; +use std::{borrow::ToOwned, num::NonZeroUsize, sync::RwLock}; use ain_cpp_imports::Attributes; use ethereum::{BlockAny, TransactionV2}; +use ethereum_types::{H256, U256}; use lru::LruCache; -use primitive_types::{H256, U256}; use super::traits::{AttributesStorage, BlockStorage, Rollback, TransactionStorage}; use crate::Result; diff --git a/lib/ain-evm/src/storage/db.rs b/lib/ain-evm/src/storage/db.rs index dcd2eda94b..40bdef30a3 100644 --- a/lib/ain-evm/src/storage/db.rs +++ b/lib/ain-evm/src/storage/db.rs @@ -1,16 +1,17 @@ -use std::path::PathBuf; -use std::{collections::HashMap, marker::PhantomData, path::Path, sync::Arc}; +use std::{ + collections::HashMap, + marker::PhantomData, + path::{Path, PathBuf}, + sync::Arc, +}; use bincode; use ethereum::{BlockAny, TransactionV2}; -use primitive_types::{H160, H256, U256}; +use ethereum_types::{H160, H256, U256}; use rocksdb::{ColumnFamily, ColumnFamilyDescriptor, Options, DB}; -use serde::de::DeserializeOwned; -use serde::Serialize; +use serde::{de::DeserializeOwned, Serialize}; -use crate::log::LogIndex; -use crate::receipt::Receipt; -use crate::Result; +use crate::{log::LogIndex, receipt::Receipt, Result}; fn get_db_options() -> Options { let mut options = Options::default(); diff --git a/lib/ain-evm/src/storage/mod.rs b/lib/ain-evm/src/storage/mod.rs index 1bc7bb53e1..cd18cb089b 100644 --- a/lib/ain-evm/src/storage/mod.rs +++ b/lib/ain-evm/src/storage/mod.rs @@ -7,7 +7,7 @@ use std::{collections::HashMap, path::Path}; use ain_cpp_imports::Attributes; use ethereum::{BlockAny, TransactionV2}; -use primitive_types::{H160, H256, U256}; +use ethereum_types::{H160, H256, U256}; use self::{ block_store::BlockStore, @@ -17,10 +17,7 @@ use self::{ TransactionStorage, }, }; -use crate::log::LogIndex; -use crate::receipt::Receipt; -use crate::storage::traits::LogStorage; -use crate::Result; +use crate::{log::LogIndex, receipt::Receipt, storage::traits::LogStorage, Result}; #[derive(Debug)] pub struct Storage { diff --git a/lib/ain-evm/src/storage/traits.rs b/lib/ain-evm/src/storage/traits.rs index e401c2e944..aedde9cb0d 100644 --- a/lib/ain-evm/src/storage/traits.rs +++ b/lib/ain-evm/src/storage/traits.rs @@ -1,19 +1,17 @@ -use std::collections::HashMap; -use std::fs::File; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; +use std::{ + collections::HashMap, + fs::File, + io::Write, + path::{Path, PathBuf}, +}; use ain_cpp_imports::Attributes; -use ethereum::BlockAny; -use ethereum::TransactionV2; +use ethereum::{BlockAny, TransactionV2}; +use ethereum_types::{H160, U256}; use keccak_hash::H256; use log::debug; -use primitive_types::{H160, U256}; -use crate::log::LogIndex; -use crate::receipt::Receipt; -use crate::Result; +use crate::{log::LogIndex, receipt::Receipt, Result}; pub trait BlockStorage { fn get_block_by_number(&self, number: &U256) -> Result>; diff --git a/lib/ain-evm/src/traits.rs b/lib/ain-evm/src/traits.rs index cc98c1ac4a..704f425011 100644 --- a/lib/ain-evm/src/traits.rs +++ b/lib/ain-evm/src/traits.rs @@ -1,9 +1,8 @@ use ethereum::{AccessList, ReceiptV3}; +use ethereum_types::{H160, U256}; use evm::Config; -use primitive_types::{H160, U256}; -use crate::Result; -use crate::{executor::TxResponse, transaction::SignedTx}; +use crate::{executor::TxResponse, transaction::SignedTx, Result}; #[derive(Debug)] pub struct ExecutorContext<'a> { diff --git a/lib/ain-evm/src/transaction/mod.rs b/lib/ain-evm/src/transaction/mod.rs index b1bdb13230..c24a57fa28 100644 --- a/lib/ain-evm/src/transaction/mod.rs +++ b/lib/ain-evm/src/transaction/mod.rs @@ -4,8 +4,8 @@ use ethereum::{ AccessList, EnvelopedDecoderError, EnvelopedEncodable, LegacyTransaction, TransactionAction, TransactionSignature, TransactionV2, }; +use ethereum_types::{H160, H256, U256}; use libsecp256k1::PublicKey; -use primitive_types::{H160, H256, U256}; use rlp::RlpStream; use sha3::Digest; @@ -306,8 +306,10 @@ impl SignedTx { } } -use std::convert::{TryFrom, TryInto}; -use std::fmt; +use std::{ + convert::{TryFrom, TryInto}, + fmt, +}; #[derive(Debug)] pub enum TransactionError { @@ -358,17 +360,13 @@ impl From> for TransactionError { #[cfg(test)] mod tests { - use std::error::Error; - use std::fs; - use std::path::Path; + use std::{error::Error, fs, path::Path}; use ethereum::{AccessListItem, EnvelopedEncodable}; - use ethereum_types::{H160, U64}; - use primitive_types::{H256, U256}; + use ethereum_types::{H160, H256, U256, U64}; use serde::Deserialize; - use crate::bytes::Bytes; - use crate::transaction::SignedTx; + use crate::{bytes::Bytes, transaction::SignedTx}; #[test] fn test_signed_tx_from_raw_tx() { diff --git a/lib/ain-evm/src/transaction/system.rs b/lib/ain-evm/src/transaction/system.rs index 0b856f2497..b054aad3f7 100644 --- a/lib/ain-evm/src/transaction/system.rs +++ b/lib/ain-evm/src/transaction/system.rs @@ -1,4 +1,4 @@ -use primitive_types::H160; +use ethereum_types::H160; use super::SignedTx; diff --git a/lib/ain-evm/src/trie.rs b/lib/ain-evm/src/trie.rs index 38e2e513aa..fc2737fdcf 100644 --- a/lib/ain-evm/src/trie.rs +++ b/lib/ain-evm/src/trie.rs @@ -1,19 +1,17 @@ -use std::fs; -use std::io::BufReader; -use std::path::PathBuf; -use std::sync::Arc; +use std::{fs, io::BufReader, path::PathBuf, sync::Arc}; +use ethereum_types::H256; use evm::backend::{Backend, Basic}; use log::debug; -use primitive_types::H256; use serde::{Deserialize, Serialize}; use vsdb_trie_db::MptStore; -use crate::backend::{EVMBackend, Vicinity}; -use crate::genesis::GenesisData; -use crate::storage::traits::PersistentState; -use crate::storage::Storage; -use crate::Result; +use crate::{ + backend::{EVMBackend, Vicinity}, + genesis::GenesisData, + storage::{traits::PersistentState, Storage}, + Result, +}; pub static TRIE_DB_STORE: &str = "trie_db_store.bin"; pub static GENESIS_STATE_ROOT: &str = diff --git a/lib/ain-evm/src/txqueue.rs b/lib/ain-evm/src/txqueue.rs index f95a6fb459..a799859f04 100644 --- a/lib/ain-evm/src/txqueue.rs +++ b/lib/ain-evm/src/txqueue.rs @@ -7,9 +7,11 @@ use ethereum::{Block, TransactionV2}; use ethereum_types::{H160, U256}; use rand::Rng; -use crate::core::XHash; -use crate::receipt::Receipt; -use crate::transaction::{system::SystemTx, SignedTx}; +use crate::{ + core::XHash, + receipt::Receipt, + transaction::{system::SystemTx, SignedTx}, +}; type Result = std::result::Result; diff --git a/lib/ain-evm/src/weiamount.rs b/lib/ain-evm/src/weiamount.rs index dc93c19ff0..2994242ad1 100644 --- a/lib/ain-evm/src/weiamount.rs +++ b/lib/ain-evm/src/weiamount.rs @@ -1,5 +1,5 @@ use anyhow::format_err; -use primitive_types::U256; +use ethereum_types::U256; use crate::Result; diff --git a/lib/ain-evm/tests/block.rs b/lib/ain-evm/tests/block.rs index 53a78a4889..513c239a48 100644 --- a/lib/ain-evm/tests/block.rs +++ b/lib/ain-evm/tests/block.rs @@ -2,9 +2,8 @@ use std::str::FromStr; -use ain_evm::evm::EVMServices; -use ain_evm::transaction::SignedTx; -use primitive_types::{H160, H256, U256}; +use ain_evm::{evm::EVMServices, transaction::SignedTx}; +use ethereum_types::{H160, H256, U256}; #[test] fn test_finalize_block_and_do_not_update_state() { diff --git a/lib/ain-grpc/Cargo.toml b/lib/ain-grpc/Cargo.toml index d8b758b384..cf0dabea57 100644 --- a/lib/ain-grpc/Cargo.toml +++ b/lib/ain-grpc/Cargo.toml @@ -20,7 +20,6 @@ serde = { workspace = true, features = ["derive"] } serde_json.workspace = true tokio = { workspace = true, features = ["rt-multi-thread"] } tonic.workspace = true -primitive-types.workspace = true ethereum.workspace = true ethereum-types.workspace = true hex.workspace = true diff --git a/lib/ain-grpc/build.rs b/lib/ain-grpc/build.rs index d96583e4f2..fdb6529f34 100644 --- a/lib/ain-grpc/build.rs +++ b/lib/ain-grpc/build.rs @@ -1,10 +1,13 @@ -use std::cell::RefCell; -use std::collections::HashMap; -use std::fs::{DirEntry, File}; -use std::io::{Read, Write}; -use std::path::{Path, PathBuf}; -use std::rc::Rc; -use std::{env, fs, io}; +use std::{ + cell::RefCell, + collections::HashMap, + env, fs, + fs::{DirEntry, File}, + io, + io::{Read, Write}, + path::{Path, PathBuf}, + rc::Rc, +}; use anyhow::{format_err, Result}; use proc_macro2::{Span, TokenStream}; diff --git a/lib/ain-grpc/src/block.rs b/lib/ain-grpc/src/block.rs index 5f7fe04d5b..d0e0b2afb7 100644 --- a/lib/ain-grpc/src/block.rs +++ b/lib/ain-grpc/src/block.rs @@ -2,8 +2,7 @@ use std::fmt; use ain_evm::bytes::Bytes; use ethereum::{BlockAny, TransactionV2}; -use ethereum_types::H64; -use primitive_types::{H160, H256, U256}; +use ethereum_types::{H160, H256, H64, U256}; use rlp::Encodable; use serde::{ de::{Error, MapAccess, Visitor}, diff --git a/lib/ain-grpc/src/call_request.rs b/lib/ain-grpc/src/call_request.rs index e402a47346..7f96258f5e 100644 --- a/lib/ain-grpc/src/call_request.rs +++ b/lib/ain-grpc/src/call_request.rs @@ -1,6 +1,6 @@ use ain_evm::bytes::Bytes; use ethereum::AccessListItem; -use primitive_types::{H160, U256}; +use ethereum_types::{H160, U256}; use serde::Deserialize; /// Call request diff --git a/lib/ain-grpc/src/filters.rs b/lib/ain-grpc/src/filters.rs index f89e3093fe..52532162ab 100644 --- a/lib/ain-grpc/src/filters.rs +++ b/lib/ain-grpc/src/filters.rs @@ -1,9 +1,8 @@ -use primitive_types::{H160, H256}; +use ethereum_types::{H160, H256}; use serde::{Serialize, Serializer}; use serde_with::{serde_as, OneOrMany}; -use crate::block::BlockNumber; -use crate::transaction_log::LogResult; +use crate::{block::BlockNumber, transaction_log::LogResult}; #[serde_as] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] diff --git a/lib/ain-grpc/src/impls.rs b/lib/ain-grpc/src/impls.rs index df2c5de5b0..b5fee3e480 100644 --- a/lib/ain-grpc/src/impls.rs +++ b/lib/ain-grpc/src/impls.rs @@ -1,10 +1,11 @@ -use std::convert::From; -use std::mem::size_of_val; +use std::{convert::From, mem::size_of_val}; use ethereum::BlockAny; -use crate::codegen::types::EthBlockInfo; -use crate::utils::{format_h256, format_u256}; +use crate::{ + codegen::types::EthBlockInfo, + utils::{format_h256, format_u256}, +}; impl From for EthBlockInfo { fn from(block: BlockAny) -> Self { diff --git a/lib/ain-grpc/src/lib.rs b/lib/ain-grpc/src/lib.rs index 780ec75988..5d3b290b6b 100644 --- a/lib/ain-grpc/src/lib.rs +++ b/lib/ain-grpc/src/lib.rs @@ -19,8 +19,11 @@ mod utils; #[cfg(test)] mod tests; -use std::sync::{atomic::Ordering, Arc}; -use std::{net::SocketAddr, path::PathBuf}; +use std::{ + net::SocketAddr, + path::PathBuf, + sync::{atomic::Ordering, Arc}, +}; use ain_evm::services::{Services, IS_SERVICES_INIT_CALL, SERVICES}; use anyhow::{format_err, Result}; diff --git a/lib/ain-grpc/src/receipt.rs b/lib/ain-grpc/src/receipt.rs index 29324cbcb7..2a58496cfa 100644 --- a/lib/ain-grpc/src/receipt.rs +++ b/lib/ain-grpc/src/receipt.rs @@ -1,6 +1,6 @@ use ain_evm::receipt::Receipt; use ethereum::{EIP658ReceiptData, Log}; -use primitive_types::{H160, H256, U256}; +use ethereum_types::{H160, H256, U256}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] #[serde(rename_all = "camelCase")] diff --git a/lib/ain-grpc/src/rpc/debug.rs b/lib/ain-grpc/src/rpc/debug.rs index 5a7cd739bf..86caca7964 100644 --- a/lib/ain-grpc/src/rpc/debug.rs +++ b/lib/ain-grpc/src/rpc/debug.rs @@ -1,11 +1,12 @@ -use std::cmp; -use std::sync::Arc; +use std::{cmp, sync::Arc}; use ain_evm::{core::EthCallArgs, evm::EVMServices, executor::TxResponse}; use ethereum::Account; use ethereum_types::U256; -use jsonrpsee::core::{Error, RpcResult}; -use jsonrpsee::proc_macros::rpc; +use jsonrpsee::{ + core::{Error, RpcResult}, + proc_macros::rpc, +}; use log::debug; use rlp::{Decodable, Rlp}; diff --git a/lib/ain-grpc/src/rpc/eth.rs b/lib/ain-grpc/src/rpc/eth.rs index 8112736b35..eac9d8f5a7 100644 --- a/lib/ain-grpc/src/rpc/eth.rs +++ b/lib/ain-grpc/src/rpc/eth.rs @@ -1,32 +1,36 @@ -use std::convert::Into; -use std::str::FromStr; -use std::sync::Arc; +use std::{convert::Into, str::FromStr, sync::Arc}; use ain_cpp_imports::get_eth_priv_key; -use ain_evm::bytes::Bytes; -use ain_evm::core::EthCallArgs; -use ain_evm::evm::EVMServices; -use ain_evm::executor::TxResponse; -use ain_evm::filters::Filter; -use ain_evm::storage::traits::{BlockStorage, ReceiptStorage, TransactionStorage}; -use ain_evm::transaction::SignedTx; +use ain_evm::{ + bytes::Bytes, + core::EthCallArgs, + evm::EVMServices, + executor::TxResponse, + filters::Filter, + storage::traits::{BlockStorage, ReceiptStorage, TransactionStorage}, + transaction::SignedTx, +}; use ethereum::{EnvelopedEncodable, TransactionV2}; -use jsonrpsee::core::{Error, RpcResult}; -use jsonrpsee::proc_macros::rpc; +use ethereum_types::{H160, H256, U256}; +use jsonrpsee::{ + core::{Error, RpcResult}, + proc_macros::rpc, +}; use libsecp256k1::SecretKey; use log::{debug, trace}; -use primitive_types::{H160, H256, U256}; use super::to_jsonrpsee_custom_error; -use crate::block::{BlockNumber, RpcBlock, RpcFeeHistory}; -use crate::call_request::CallRequest; -use crate::codegen::types::EthTransactionInfo; -use crate::filters::{GetFilterChangesResult, NewFilterRequest}; -use crate::receipt::ReceiptResult; -use crate::sync::{SyncInfo, SyncState}; -use crate::transaction_log::{GetLogsRequest, LogResult}; -use crate::transaction_request::{TransactionMessage, TransactionRequest}; -use crate::utils::{format_h256, format_u256}; +use crate::{ + block::{BlockNumber, RpcBlock, RpcFeeHistory}, + call_request::CallRequest, + codegen::types::EthTransactionInfo, + filters::{GetFilterChangesResult, NewFilterRequest}, + receipt::ReceiptResult, + sync::{SyncInfo, SyncState}, + transaction_log::{GetLogsRequest, LogResult}, + transaction_request::{TransactionMessage, TransactionRequest}, + utils::{format_h256, format_u256}, +}; #[rpc(server, client, namespace = "eth")] pub trait MetachainRPC { diff --git a/lib/ain-grpc/src/rpc/net.rs b/lib/ain-grpc/src/rpc/net.rs index 525cfd2203..78fb1ce608 100644 --- a/lib/ain-grpc/src/rpc/net.rs +++ b/lib/ain-grpc/src/rpc/net.rs @@ -1,8 +1,10 @@ use std::sync::Arc; use ain_evm::evm::EVMServices; -use jsonrpsee::core::{Error, RpcResult}; -use jsonrpsee::proc_macros::rpc; +use jsonrpsee::{ + core::{Error, RpcResult}, + proc_macros::rpc, +}; #[rpc(server, client, namespace = "net")] pub trait MetachainNetRPC { diff --git a/lib/ain-grpc/src/sync.rs b/lib/ain-grpc/src/sync.rs index cf321a0f1e..4a6da337a0 100644 --- a/lib/ain-grpc/src/sync.rs +++ b/lib/ain-grpc/src/sync.rs @@ -1,4 +1,4 @@ -use primitive_types::U256; +use ethereum_types::U256; use serde::{Serialize, Serializer}; #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/lib/ain-grpc/src/tests.rs b/lib/ain-grpc/src/tests.rs index 2f53e559d0..ad57190d49 100644 --- a/lib/ain-grpc/src/tests.rs +++ b/lib/ain-grpc/src/tests.rs @@ -1,12 +1,10 @@ #![cfg(test_off)] -use std::str::FromStr; -use std::sync::Arc; +use std::{str::FromStr, sync::Arc}; -use ain_evm::handler::Handlers; -use ain_evm::transaction::SignedTx; +use ain_evm::{handler::Handlers, transaction::SignedTx}; use ethereum::{BlockV2, PartialHeader}; -use primitive_types::{H160, U256}; +use ethereum_types::{H160, U256}; use crate::codegen::types::*; diff --git a/lib/ain-grpc/src/transaction.rs b/lib/ain-grpc/src/transaction.rs index 2b57b17af2..02bc9c9f23 100644 --- a/lib/ain-grpc/src/transaction.rs +++ b/lib/ain-grpc/src/transaction.rs @@ -1,7 +1,6 @@ use ain_evm::transaction::{SignedTx, TransactionError}; -use ethereum::{AccessListItem, EnvelopedEncodable}; -use ethereum::{BlockAny, TransactionV2}; -use primitive_types::{H256, U256}; +use ethereum::{AccessListItem, BlockAny, EnvelopedEncodable, TransactionV2}; +use ethereum_types::{H256, U256}; use crate::{ codegen::types::{EthAccessList, EthTransactionInfo}, diff --git a/lib/ain-grpc/src/transaction_log.rs b/lib/ain-grpc/src/transaction_log.rs index 33a56bc556..0b69a9da39 100644 --- a/lib/ain-grpc/src/transaction_log.rs +++ b/lib/ain-grpc/src/transaction_log.rs @@ -1,6 +1,5 @@ -use ain_evm::bytes::Bytes; -use ain_evm::log::LogIndex; -use primitive_types::{H160, H256, U256}; +use ain_evm::{bytes::Bytes, log::LogIndex}; +use ethereum_types::{H160, H256, U256}; use serde_with::{serde_as, OneOrMany}; use crate::block::BlockNumber; diff --git a/lib/ain-grpc/src/utils.rs b/lib/ain-grpc/src/utils.rs index c89e2ca3f8..595f12308b 100644 --- a/lib/ain-grpc/src/utils.rs +++ b/lib/ain-grpc/src/utils.rs @@ -1,4 +1,4 @@ -use primitive_types::{H160, H256, U256}; +use ethereum_types::{H160, H256, U256}; pub fn format_h256(hash: H256) -> String { format!("{hash:#x}") diff --git a/lib/ain-rs-exports/Cargo.toml b/lib/ain-rs-exports/Cargo.toml index 45e1bee0d3..31481a625b 100644 --- a/lib/ain-rs-exports/Cargo.toml +++ b/lib/ain-rs-exports/Cargo.toml @@ -16,7 +16,7 @@ ain-contracts = { path = "../ain-contracts" } ethereum.workspace = true rlp.workspace = true -primitive-types.workspace = true +ethereum-types.workspace = true log.workspace = true hex.workspace = true serde_json.workspace = true diff --git a/lib/ain-rs-exports/build.rs b/lib/ain-rs-exports/build.rs index 9ac526b268..48c5bcc81a 100644 --- a/lib/ain-rs-exports/build.rs +++ b/lib/ain-rs-exports/build.rs @@ -1,7 +1,9 @@ -use std::env; -use std::fs::File; -use std::io::{Read, Write}; -use std::path::PathBuf; +use std::{ + env, + fs::File, + io::{Read, Write}, + path::PathBuf, +}; use proc_macro2::TokenStream; diff --git a/lib/ain-rs-exports/src/core.rs b/lib/ain-rs-exports/src/core.rs index 2e1b1d1854..727ae0d008 100644 --- a/lib/ain-rs-exports/src/core.rs +++ b/lib/ain-rs-exports/src/core.rs @@ -1,5 +1,4 @@ -use crate::ffi::CrossBoundaryResult; -use crate::prelude::*; +use crate::{ffi::CrossBoundaryResult, prelude::*}; pub fn ain_rs_preinit(result: &mut CrossBoundaryResult) { ain_grpc::preinit(); diff --git a/lib/ain-rs-exports/src/evm.rs b/lib/ain-rs-exports/src/evm.rs index d676632fc2..45a46fcc5a 100644 --- a/lib/ain-rs-exports/src/evm.rs +++ b/lib/ain-rs-exports/src/evm.rs @@ -1,23 +1,23 @@ use ain_contracts::{get_transferdomain_contract, FixedContract}; -use ain_evm::storage::traits::BlockStorage; -use ain_evm::transaction::system::{DST20Data, DeployContractData, SystemTx}; -use ain_evm::txqueue::QueueTx; use ain_evm::{ core::{ValidateTxInfo, XHash}, evm::FinalizedBlockInfo, services::SERVICES, - storage::traits::Rollback, - storage::traits::TransactionStorage, - transaction::{self, SignedTx}, + storage::traits::{BlockStorage, Rollback, TransactionStorage}, + transaction::{ + self, + system::{DST20Data, DeployContractData, SystemTx}, + SignedTx, + }, + txqueue::QueueTx, weiamount::{try_from_gwei, try_from_satoshi, WeiAmount}, }; use ethereum::{EnvelopedEncodable, TransactionAction, TransactionSignature, TransactionV2}; +use ethereum_types::{H160, U256}; use log::debug; -use primitive_types::{H160, U256}; use transaction::{LegacyUnsignedTransaction, TransactionError, LOWER_H256}; -use crate::ffi; -use crate::prelude::*; +use crate::{ffi, prelude::*}; /// Creates and signs a transaction. /// @@ -1013,7 +1013,7 @@ pub fn evm_unsafe_try_get_target_block_in_q( mod tests { #[test] fn test_hash_type_string() { - use primitive_types::H160; + use ethereum_types::H160; let num = 0b11010111_11010111_11010111_11010111_11010111_11010111_11010111_11010111; let num_h160 = H160::from_low_u64_be(num); let num_h160_string = format!("{:?}", num_h160); @@ -1022,7 +1022,7 @@ mod tests { let num_h160_test: H160 = num_h160_string.parse().unwrap(); assert_eq!(num_h160_test, num_h160); - use primitive_types::H256; + use ethereum_types::H256; let num_h256: H256 = "0x3186715414c5fbd73586662d26b83b66b5754036379d56e896a560a90e409351" .parse() .unwrap(); diff --git a/lib/ain-rs-exports/src/lib.rs b/lib/ain-rs-exports/src/lib.rs index 737b18ea7c..f60db29a3f 100644 --- a/lib/ain-rs-exports/src/lib.rs +++ b/lib/ain-rs-exports/src/lib.rs @@ -2,8 +2,7 @@ mod core; mod evm; mod prelude; -use crate::core::*; -use crate::evm::*; +use crate::{core::*, evm::*}; #[cxx::bridge] pub mod ffi { diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 6718ac2130..0afd5ddb67 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -8,7 +8,7 @@ ain-grpc = { path = "../ain-grpc" } jsonrpsee = { version = "0.18", features = ["http-client"] } structopt = "0.3.26" -primitive-types = "0.12.1" +ethereum-types.workspace = true serde = "1.0.160" serde_json = "1.0.96" hex = "0.4.3" diff --git a/lib/cli/src/main.rs b/lib/cli/src/main.rs index ecff45862f..f256e3596d 100644 --- a/lib/cli/src/main.rs +++ b/lib/cli/src/main.rs @@ -6,10 +6,10 @@ mod structs; use ain_grpc::block::BlockNumber; use command::execute_cli_command; +use ethereum_types::{H160, H256, U256}; use format::Format; use jsonrpsee::http_client::HttpClientBuilder; use params::{BaseChainParams, Chain}; -use primitive_types::{H160, H256, U256}; use structopt::StructOpt; use crate::structs::CallRequest; diff --git a/lib/cli/src/result.rs b/lib/cli/src/result.rs index 6080722638..1dd32bae5d 100644 --- a/lib/cli/src/result.rs +++ b/lib/cli/src/result.rs @@ -1,6 +1,5 @@ -use ain_grpc::block::RpcBlock; -use ain_grpc::codegen::types::EthTransactionInfo; -use primitive_types::{H256, U256}; +use ain_grpc::{block::RpcBlock, codegen::types::EthTransactionInfo}; +use ethereum_types::{H256, U256}; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] diff --git a/lib/cli/src/structs.rs b/lib/cli/src/structs.rs index 7196e61142..eb072ea362 100644 --- a/lib/cli/src/structs.rs +++ b/lib/cli/src/structs.rs @@ -1,6 +1,5 @@ use ethereum::AccessListItem; -use primitive_types::H160; -use primitive_types::U256; +use ethereum_types::{H160, U256}; use structopt::StructOpt; #[derive(Debug)]