Skip to content

Commit

Permalink
Clippy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Sep 7, 2023
1 parent c866c21 commit d6dc6b2
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 83 deletions.
2 changes: 1 addition & 1 deletion lib/ain-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn get_dst20_deploy_input(init_bytecode: Vec<u8>, name: &str, symbol: &str)
}

pub fn dst20_address_from_token_id(token_id: u64) -> Result<H160> {
let number_str = format!("{:x}", token_id);
let number_str = format!("{token_id:x}");
let padded_number_str = format!("{number_str:0>38}");
let final_str = format!("ff{padded_number_str}");

Expand Down
6 changes: 3 additions & 3 deletions lib/ain-evm/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ pub fn intrinsics_contract(
}

/// Returns transfer domain address, bytecode and null storage
pub fn transfer_domain_contract() -> Result<DeployContractInfo> {
pub fn transfer_domain_contract() -> DeployContractInfo {
let FixedContract {
contract,
fixed_address,
} = get_transferdomain_contract();

Ok(DeployContractInfo {
DeployContractInfo {
address: fixed_address,
bytecode: Bytes::from(contract.runtime_bytecode),
storage: Vec::new(),
})
}
}

pub fn dst20_contract(
Expand Down
8 changes: 4 additions & 4 deletions lib/ain-evm/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl EVMCoreService {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn create_queue(&self) -> Result<u64> {
Expand All @@ -352,7 +352,7 @@ impl EVMCoreService {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn remove_queue(&self, queue_id: u64) {
Expand All @@ -362,7 +362,7 @@ impl EVMCoreService {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn remove_txs_above_hash_in(
Expand All @@ -379,7 +379,7 @@ impl EVMCoreService {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn get_target_block_in(&self, queue_id: u64) -> Result<U256> {
Expand Down
16 changes: 8 additions & 8 deletions lib/ain-evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl EVMServices {
let datadir = ain_cpp_imports::get_datadir();
let path = PathBuf::from(datadir).join("evm");
if !path.exists() {
std::fs::create_dir(&path)?
std::fs::create_dir(&path)?;
}

if let Some(state_input_path) = ain_cpp_imports::get_state_input_json() {
Expand Down Expand Up @@ -108,7 +108,7 @@ impl EVMServices {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn construct_block_in_queue(
Expand Down Expand Up @@ -200,7 +200,7 @@ impl EVMServices {
address,
storage,
bytecode,
} = transfer_domain_contract()?;
} = transfer_domain_contract();

debug!("deploying {:x?} bytecode {:#?}", address, bytecode);
executor.deploy_contract(address, bytecode, storage)?;
Expand Down Expand Up @@ -246,7 +246,7 @@ impl EVMServices {
total_priority_fees
);

let extra_data = format!("DFI: {}", dvm_block_number).into_bytes();
let extra_data = format!("DFI: {dvm_block_number}").into_bytes();
let gas_limit = self.storage.get_attributes_or_default()?.block_gas_limit;
let block = Block::new(
PartialHeader {
Expand Down Expand Up @@ -348,7 +348,7 @@ impl EVMServices {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn push_tx_in_queue(&self, queue_id: u64, tx: QueueTx, hash: XHash) -> Result<()> {
Expand Down Expand Up @@ -387,7 +387,7 @@ impl EVMServices {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn is_dst20_deployed_or_queued(
Expand Down Expand Up @@ -422,7 +422,7 @@ impl EVMServices {
address,
}));

let is_queued = self.core.tx_queues.get(queue_id)?.is_queued(deploy_tx);
let is_queued = self.core.tx_queues.get(queue_id)?.is_queued(&deploy_tx);

Ok(is_queued)
}
Expand Down Expand Up @@ -540,7 +540,7 @@ fn get_dst20_migration_txs(mnview_ptr: usize) -> Result<Vec<QueueTxItem>> {
}));
txs.push(QueueTxItem {
tx,
tx_hash: Default::default(),
tx_hash: String::default(),
gas_used: U256::zero(),
state_root: H256::default(),
});
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-evm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<'backend> AinExecutor<'backend> {
storage,
} = dst20_contract(self.backend, address, &name, &symbol)?;

self.deploy_contract(address, bytecode.clone(), storage)?;
self.deploy_contract(address, bytecode, storage)?;
let (tx, receipt) = dst20_deploy_contract_tx(token_id, &base_fee, &name, &symbol)?;

Ok(ApplyTxResult {
Expand Down
4 changes: 2 additions & 2 deletions lib/ain-evm/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl LogService {

pub fn get_logs_from_filter(
&self,
filter: LogsFilter,
filter_type: FilterType,
filter: &LogsFilter,
filter_type: &FilterType,
) -> Result<Vec<LogIndex>> {
let block_number = match filter_type {
FilterType::GetFilterChanges => filter.last_block_height,
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-evm/src/precompiles/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl LinearCostPrecompile for Sha256 {
}

/// The ECRecoverPublicKey precompile.
/// Similar to ECRecover, but returns the pubkey (not the corresponding Ethereum address)
/// Similar to `ECRecover`, but returns the pubkey (not the corresponding Ethereum address)
pub struct ECRecoverPublicKey;

impl LinearCostPrecompile for ECRecoverPublicKey {
Expand Down
12 changes: 5 additions & 7 deletions lib/ain-evm/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl LegacyUnsignedTransaction {
let sig = s.0.serialize();

let sig = TransactionSignature::new(
s.1.serialize() as u64 % 2 + chain_id * 2 + 35,
u64::from(s.1.serialize()) % 2 + chain_id * 2 + 35,
H256::from_slice(&sig[0..32]),
H256::from_slice(&sig[32..64]),
)
Expand Down Expand Up @@ -266,8 +266,8 @@ impl SignedTx {
pub fn v(&self) -> u64 {
match &self.transaction {
TransactionV2::Legacy(tx) => tx.signature.v(),
TransactionV2::EIP2930(tx) => tx.odd_y_parity as u64,
TransactionV2::EIP1559(tx) => tx.odd_y_parity as u64,
TransactionV2::EIP2930(tx) => u64::from(tx.odd_y_parity),
TransactionV2::EIP1559(tx) => u64::from(tx.odd_y_parity),
}
}

Expand All @@ -289,16 +289,14 @@ impl SignedTx {

pub fn max_fee_per_gas(&self) -> Option<U256> {
match &self.transaction {
TransactionV2::Legacy(_) => None,
TransactionV2::EIP2930(_) => None,
TransactionV2::Legacy(_) | TransactionV2::EIP2930(_) => None,
TransactionV2::EIP1559(tx) => Some(tx.max_fee_per_gas),
}
}

pub fn max_priority_fee_per_gas(&self) -> Option<U256> {
match &self.transaction {
TransactionV2::Legacy(_) => None,
TransactionV2::EIP2930(_) => None,
TransactionV2::Legacy(_) | TransactionV2::EIP2930(_) => None,
TransactionV2::EIP1559(tx) => Some(tx.max_priority_fee_per_gas),
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/ain-evm/src/transaction/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl SystemTx {
match self {
SystemTx::TransferDomain(data) => Some(data.signed_tx.sender),
SystemTx::DST20Bridge(data) => Some(data.signed_tx.sender),
_ => None,
SystemTx::DeployContract(_) => None,
}
}
}
Expand All @@ -48,9 +48,10 @@ pub enum TransferDirection {

impl From<bool> for TransferDirection {
fn from(direction: bool) -> TransferDirection {
match direction {
true => TransferDirection::EvmIn,
false => TransferDirection::EvmOut,
if direction {
TransferDirection::EvmIn
} else {
TransferDirection::EvmOut
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions lib/ain-evm/src/txqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl TransactionQueueMap {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn create(&self, target_block: U256, state_root: H256) -> u64 {
Expand All @@ -69,7 +69,7 @@ impl TransactionQueueMap {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn remove(&self, queue_id: u64) -> Option<Arc<TransactionQueue>> {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl TransactionQueueMap {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn push_in(
Expand All @@ -139,7 +139,7 @@ impl TransactionQueueMap {
///
/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn remove_txs_above_hash_in(
Expand All @@ -163,29 +163,29 @@ impl TransactionQueueMap {

/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn get_total_gas_used_in(&self, queue_id: u64) -> Result<U256> {
self.with_transaction_queue(queue_id, |queue| queue.get_total_gas_used())
self.with_transaction_queue(queue_id, TransactionQueue::get_total_gas_used)
}

/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn get_target_block_in(&self, queue_id: u64) -> Result<U256> {
self.with_transaction_queue(queue_id, |queue| queue.get_target_block())
self.with_transaction_queue(queue_id, TransactionQueue::get_target_block)
}

/// # Safety
///
/// Result cannot be used safety unless cs_main lock is taken on C++ side
/// Result cannot be used safety unless `cs_main` lock is taken on C++ side
/// across all usages. Note: To be replaced with a proper lock flow later.
///
pub unsafe fn get_latest_state_root_in(&self, queue_id: u64) -> Result<H256> {
self.with_transaction_queue(queue_id, |queue| queue.get_latest_state_root())
self.with_transaction_queue(queue_id, TransactionQueue::get_latest_state_root)
}

/// Apply the closure to the queue associated with the queue ID.
Expand Down Expand Up @@ -288,7 +288,7 @@ impl TransactionQueue {
.insert(signed_tx.sender, signed_tx.nonce());
data.total_gas_used += gas_used;
}
_ => (),
QueueTx::SystemTx(_) => (),
}
data.transactions.push(QueueTxItem {
tx,
Expand Down Expand Up @@ -361,17 +361,16 @@ impl TransactionQueue {
let data = self.data.lock().unwrap();
data.transactions
.last()
.map(|tx_item| tx_item.state_root)
.unwrap_or(data.initial_state_root)
.map_or(data.initial_state_root, |tx_item| tx_item.state_root)
}

pub fn is_queued(&self, tx: QueueTx) -> bool {
pub fn is_queued(&self, tx: &QueueTx) -> bool {
self.data
.lock()
.unwrap()
.transactions
.iter()
.any(|queued| queued.tx == tx)
.any(|queued| &queued.tx == tx)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ain-grpc/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl From<Receipt> for ReceiptResult {
block_number: b.block_number,
contract_address: b.contract_address,
cumulative_gas_used: b.cumulative_gas,
effective_gas_price: Default::default(),
effective_gas_price: U256::default(),
from: b.from,
gas_used: data.used_gas,
logs: {
Expand Down
6 changes: 3 additions & 3 deletions lib/ain-grpc/src/rpc/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ impl MetachainDebugRPCServer for MetachainDebugRPCModule {
ro_handle.iter().for_each(|el| match el {
Ok((_, v)) => {
if let Ok(account) = Account::decode(&Rlp::new(&v)) {
debug!("[log_account_states] account {:?}", account)
debug!("[log_account_states] account {:?}", account);
} else {
debug!("[log_account_states] Error decoding account {:?}", v)
debug!("[log_account_states] Error decoding account {:?}", v);
}
}
Err(e) => {
debug!("[log_account_states] Error on iter element {e}")
debug!("[log_account_states] Error on iter element {e}");
}
});

Expand Down
Loading

0 comments on commit d6dc6b2

Please sign in to comment.