Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
tiannian committed Jul 19, 2023
1 parent 97e52fb commit 9de36f9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
10 changes: 5 additions & 5 deletions src/components/contracts/modules/account/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use crate::{storage::*, App, Config};
use config::abci::global_cfg::CFG;
use enterprise_web3::{BALANCE_MAP, WEB3_SERVICE_START_HEIGHT};
use fp_core::{account::SmartAccount, context::Context};
use fp_storage::{Borrow, BorrowMut};
use fp_storage::BorrowMut;
use fp_traits::account::AccountAsset;
use fp_types::crypto::Address;
use primitive_types::{H160, U256};
use ruc::*;

impl<C: Config> AccountAsset<Address> for App<C> {
fn total_issuance(ctx: &Context) -> U256 {
TotalIssuance::get(ctx.state.read().borrow()).unwrap_or_default()
TotalIssuance::get(&ctx.state.read()).unwrap_or_default()
}

fn account_of(
Expand All @@ -20,9 +20,9 @@ impl<C: Config> AccountAsset<Address> for App<C> {
) -> Option<SmartAccount> {
let version = height.unwrap_or(0);
if version == 0 {
AccountStore::get(ctx.state.read().borrow(), who)
AccountStore::get(&ctx.state.read(), who)
} else {
AccountStore::get_ver(ctx.state.read().borrow(), who, version)
AccountStore::get_ver(&ctx.state.read(), who, version)
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ impl<C: Config> AccountAsset<Address> for App<C> {
}

fn allowance(ctx: &Context, owner: &Address, spender: &Address) -> U256 {
Allowances::get(ctx.state.read().borrow(), owner, spender).unwrap_or_default()
Allowances::get(&ctx.state.read(), owner, spender).unwrap_or_default()
}

fn approve(
Expand Down
18 changes: 9 additions & 9 deletions src/components/contracts/modules/ethereum/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use fp_core::{
};
use fp_events::Event;
use fp_evm::{BlockId, CallOrCreateInfo, Runner, TransactionStatus};
use fp_storage::{Borrow, BorrowMut};
use fp_storage::BorrowMut;
use fp_types::crypto::Address;
use fp_types::{
actions::evm as EvmAction,
Expand Down Expand Up @@ -472,13 +472,13 @@ impl<C: Config> App<C> {
id: Option<BlockId>,
) -> Option<Vec<TransactionStatus>> {
let hash = HA256::new(Self::block_hash(ctx, id).unwrap_or_default());
CurrentTransactionStatuses::get(ctx.db.read().borrow(), &hash)
CurrentTransactionStatuses::get(&ctx.db.read(), &hash)
}

/// Get the block with given block id.
pub fn current_block(&self, ctx: &Context, id: Option<BlockId>) -> Option<Block> {
let hash = HA256::new(Self::block_hash(ctx, id).unwrap_or_default());
CurrentBlock::get(ctx.db.read().borrow(), &hash)
CurrentBlock::get(&ctx.db.read(), &hash)
}

/// Get receipts with given block id.
Expand All @@ -488,12 +488,12 @@ impl<C: Config> App<C> {
id: Option<BlockId>,
) -> Option<Vec<ethereum::ReceiptV0>> {
let hash = HA256::new(Self::block_hash(ctx, id).unwrap_or_default());
CurrentReceipts::get(ctx.db.read().borrow(), &hash)
CurrentReceipts::get(&ctx.db.read(), &hash)
}

/// Get current block hash
pub fn current_block_hash(ctx: &Context) -> Option<H256> {
if let Some(number) = CurrentBlockNumber::get(ctx.db.read().borrow()) {
if let Some(number) = CurrentBlockNumber::get(&ctx.db.read()) {
Self::get_hash(ctx, number)
} else {
None
Expand All @@ -502,7 +502,7 @@ impl<C: Config> App<C> {

/// Get current block number
pub fn current_block_number(ctx: &Context) -> Option<U256> {
CurrentBlockNumber::get(ctx.db.read().borrow())
CurrentBlockNumber::get(&ctx.db.read())
}

/// Get header hash of given block id.
Expand All @@ -519,7 +519,7 @@ impl<C: Config> App<C> {

/// The index of the transaction in the block
pub fn transaction_index(ctx: &Context, hash: H256) -> Option<(U256, u32)> {
TransactionIndex::get(ctx.db.read().borrow(), &HA256::new(hash))
TransactionIndex::get(&ctx.db.read(), &HA256::new(hash))
}

fn logs_bloom(logs: Vec<ethereum::Log>, bloom: &mut Bloom) {
Expand All @@ -532,7 +532,7 @@ impl<C: Config> App<C> {
}

fn get_hash(ctx: &Context, number: U256) -> Option<H256> {
if let Some(hash) = BlockHash::get(ctx.db.read().borrow(), &number) {
if let Some(hash) = BlockHash::get(&ctx.db.read(), &number) {
return Some(hash.h256());
}
None
Expand All @@ -541,7 +541,7 @@ impl<C: Config> App<C> {
pub fn migrate(ctx: &mut Context) -> Result<()> {
//Migrate existing transaction indices from chain-state to rocksdb.
let txn_idxs: Vec<(HA256, (U256, u32))> =
TransactionIndex::iterate(ctx.state.read().borrow());
TransactionIndex::iterate(&ctx.state.read());
let txn_idxs_cnt = txn_idxs.len();

for idx in txn_idxs {
Expand Down
13 changes: 6 additions & 7 deletions src/components/contracts/modules/evm/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{App, Config};
use ethereum_types::{H160, H256, U256};
use fp_core::context::Context;
use fp_evm::Account;
use fp_storage::{Borrow, BorrowMut};
use fp_storage::BorrowMut;
use fp_traits::{
account::AccountAsset,
evm::{AddressMapping, OnChargeEVMTransaction},
Expand All @@ -16,8 +16,7 @@ impl<C: Config> App<C> {
/// Check whether an account is empty.
pub fn is_account_empty(ctx: &Context, address: &HA160) -> bool {
let account = Self::account_basic(ctx, address);
let code_len =
AccountCodes::decode_len(ctx.state.read().borrow(), address).unwrap_or(0);
let code_len = AccountCodes::decode_len(&ctx.state.read(), address).unwrap_or(0);

account.nonce == U256::zero() && account.balance == U256::zero() && code_len == 0
}
Expand Down Expand Up @@ -48,9 +47,9 @@ impl<C: Config> App<C> {

let version = height.unwrap_or(0);
if version == 0 {
AccountCodes::get_bytes(ctx.state.read().borrow(), address)
AccountCodes::get_bytes(&ctx.state.read(), address)
} else {
AccountCodes::get_ver_bytes(ctx.state.read().borrow(), address, version)
AccountCodes::get_ver_bytes(&ctx.state.read(), address, version)
}
}

Expand All @@ -63,9 +62,9 @@ impl<C: Config> App<C> {
) -> Option<H256> {
let version = height.unwrap_or(0);
if version == 0 {
AccountStorages::get(ctx.state.read().borrow(), address, index)
AccountStorages::get(&ctx.state.read(), address, index)
} else {
AccountStorages::get_ver(ctx.state.read().borrow(), address, index, version)
AccountStorages::get_ver(&ctx.state.read(), address, index, version)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use fp_core::{
transaction::{ActionResult, Executable},
};
use fp_evm::TransactionStatus;
use fp_storage::{Borrow, BorrowMut};
use fp_storage::BorrowMut;
use fp_traits::evm::EthereumDecimalsMapping;
use fp_traits::{
account::AccountAsset,
Expand Down Expand Up @@ -1181,7 +1181,7 @@ impl<C: Config> AppModule for App<C> {
match path[0] {
"contract-number" => {
let contracts: Vec<(HA160, Vec<u8>)> =
storage::AccountCodes::iterate(ctx.state.read().borrow());
storage::AccountCodes::iterate(&ctx.state.read());
resp.value = serde_json::to_vec(&contracts.len()).unwrap_or_default();
resp
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fp_core::{
};
// use fp_storage::{hash::StoragePrefixKey, Deref, StatelessStore};
use abci::{RequestQuery, ResponseQuery};
use fp_storage::{Borrow, BorrowMut};
use fp_storage::BorrowMut;
use fp_types::{actions::template::Action, crypto::Address};
use ruc::Result;
use std::marker::PhantomData;
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<C: Config> AppModule for App<C> {
return resp;
}

let value = ValueStore::get(ctx.state.read().borrow()).unwrap_or_default();
let value = ValueStore::get(&ctx.state.read()).unwrap_or_default();

// let value: u64 = <ValueStoreInstance as StatelessStore>::get_obj(
// ctx.store.read().deref(),
Expand Down
15 changes: 7 additions & 8 deletions src/components/contracts/modules/xhub/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::storage::*;
use crate::{App, Config};
use fp_core::{context::Context, ensure, transaction::ActionResult};
use fp_storage::{Borrow, BorrowMut};
use fp_storage::BorrowMut;
use fp_traits::{account::AccountAsset, evm::DecimalsMapping};
use fp_types::actions::xhub::NonConfidentialTransfer;
use fp_types::{actions::xhub::NonConfidentialOutput, crypto::Address};
Expand Down Expand Up @@ -52,13 +52,12 @@ impl<C: Config> App<C> {
ctx: &Context,
mut outputs: Vec<NonConfidentialOutput>,
) -> Result<()> {
let ops =
if let Some(mut ori_outputs) = PendingUTXOs::get(ctx.db.read().borrow()) {
ori_outputs.append(&mut outputs);
ori_outputs
} else {
outputs
};
let ops = if let Some(mut ori_outputs) = PendingUTXOs::get(&ctx.db.read()) {
ori_outputs.append(&mut outputs);
ori_outputs
} else {
outputs
};
PendingUTXOs::put(ctx.db.write().borrow_mut(), &ops)
}

Expand Down
9 changes: 2 additions & 7 deletions src/ledger/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,7 @@ impl Staking {
&self,
h: BlockHeight,
) -> Option<&ValidatorData> {
self.validator_info
.range(0..=h)
.rev()
.next()
.map(|(_, v)| v)
self.validator_info.range(0..=h).next_back().map(|(_, v)| v)
}

/// Remove the validators that will be used for the specified height.
Expand All @@ -391,8 +387,7 @@ impl Staking {
) -> Option<&mut ValidatorData> {
self.validator_info
.range_mut(0..=h)
.rev()
.next()
.next_back()
.map(|(_, v)| v)
}

Expand Down

0 comments on commit 9de36f9

Please sign in to comment.