Skip to content

Commit

Permalink
automatic lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Nov 25, 2021
1 parent ebd3dff commit 97ad777
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
60 changes: 30 additions & 30 deletions explorer/src/api/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl Branch {
) -> FieldResult<
Option<Connection<IndexCursor, Block, ConnectionFields<BlockCount>, EmptyFields>>,
> {
let epoch_data = match extract_context(&context).db.get_epoch(epoch.0).await {
let epoch_data = match extract_context(context).db.get_epoch(epoch.0).await {
Some(epoch_data) => epoch_data,
None => return Ok(None),
};
Expand Down Expand Up @@ -498,7 +498,7 @@ impl Block {
async fn fetch_explorer_block(&self, db: &ExplorerDb) -> FieldResult<Arc<ExplorerBlock>> {
let mut contents = self.contents.lock().await;
if let Some(block) = &*contents {
Ok(Arc::clone(&block))
Ok(Arc::clone(block))
} else {
let block = db.get_block(&self.hash).await.ok_or_else(|| {
ApiError::InternalError("Couldn't find block's contents in explorer".to_owned())
Expand Down Expand Up @@ -537,7 +537,7 @@ impl Block {

/// Date the Block was included in the blockchain
pub async fn date(&self, context: &Context<'_>) -> FieldResult<BlockDate> {
self.fetch_explorer_block(&extract_context(&context).db)
self.fetch_explorer_block(&extract_context(context).db)
.await
.map(|b| b.date().into())
}
Expand All @@ -554,7 +554,7 @@ impl Block {
Connection<IndexCursor, Transaction, ConnectionFields<TransactionCount>, EmptyFields>,
> {
let explorer_block = self
.fetch_explorer_block(&extract_context(&context).db)
.fetch_explorer_block(&extract_context(context).db)
.await?;

let mut transactions: Vec<&ExplorerTransaction> =
Expand Down Expand Up @@ -632,13 +632,13 @@ impl Block {
}

pub async fn chain_length(&self, context: &Context<'_>) -> FieldResult<ChainLength> {
self.fetch_explorer_block(&extract_context(&context).db)
self.fetch_explorer_block(&extract_context(context).db)
.await
.map(|block| ChainLength(block.chain_length()))
}

pub async fn leader(&self, context: &Context<'_>) -> FieldResult<Option<Leader>> {
self.fetch_explorer_block(&extract_context(&context).db)
self.fetch_explorer_block(&extract_context(context).db)
.await
.map(|block| match block.producer() {
BlockProducer::StakePool(pool) => {
Expand All @@ -652,32 +652,32 @@ impl Block {
}

pub async fn previous_block(&self, context: &Context<'_>) -> FieldResult<Block> {
self.fetch_explorer_block(&extract_context(&context).db)
self.fetch_explorer_block(&extract_context(context).db)
.await
.map(|b| Block::from_valid_hash(b.parent_hash))
}

pub async fn total_input(&self, context: &Context<'_>) -> FieldResult<Value> {
self.fetch_explorer_block(&extract_context(&context).db)
self.fetch_explorer_block(&extract_context(context).db)
.await
.map(|block| Value(block.total_input))
}

pub async fn total_output(&self, context: &Context<'_>) -> FieldResult<Value> {
self.fetch_explorer_block(&extract_context(&context).db)
self.fetch_explorer_block(&extract_context(context).db)
.await
.map(|block| Value(block.total_output))
}

pub async fn is_confirmed(&self, context: &Context<'_>) -> bool {
extract_context(&context)
extract_context(context)
.db
.is_block_confirmed(&self.hash)
.await
}

pub async fn branches(&self, context: &Context<'_>) -> FieldResult<Vec<Branch>> {
let branches = self.get_branches(&extract_context(&context).db).await?;
let branches = self.get_branches(&extract_context(context).db).await?;

Ok(branches)
}
Expand Down Expand Up @@ -738,7 +738,7 @@ pub struct Transaction {

impl Transaction {
async fn from_id(id: FragmentId, context: &Context<'_>) -> FieldResult<Transaction> {
let block_hashes = extract_context(&context)
let block_hashes = extract_context(context)
.db
.find_blocks_by_transaction(&id)
.await;
Expand Down Expand Up @@ -772,7 +772,7 @@ impl Transaction {

async fn get_blocks(&self, context: &Context<'_>) -> FieldResult<Vec<Arc<ExplorerBlock>>> {
let block_ids = if self.block_hashes.is_empty() {
extract_context(&context)
extract_context(context)
.db
.find_blocks_by_transaction(&self.id)
.await
Expand All @@ -789,7 +789,7 @@ impl Transaction {
let mut result = Vec::new();

for block_id in block_ids {
let block = extract_context(&context)
let block = extract_context(context)
.db
.get_block(&block_id)
.await
Expand Down Expand Up @@ -925,7 +925,7 @@ impl Address {
async fn id(&self, context: &Context<'_>) -> String {
match &self.id {
ExplorerAddress::New(addr) => chain_addr::AddressReadable::from_address(
&extract_context(&context).settings.address_bech32_prefix,
&extract_context(context).settings.address_bech32_prefix,
addr,
)
.to_string(),
Expand Down Expand Up @@ -997,7 +997,7 @@ pub struct Pool {

impl Pool {
async fn from_string_id(id: &str, db: &ExplorerDb) -> FieldResult<Pool> {
let id = certificate::PoolId::from_str(&id)?;
let id = certificate::PoolId::from_str(id)?;
let blocks = db
.get_stake_pool_blocks(&id)
.await
Expand Down Expand Up @@ -1048,7 +1048,7 @@ impl Pool {
) -> FieldResult<Connection<IndexCursor, Block, ConnectionFields<BlockCount>>> {
let blocks = match &self.blocks {
Some(b) => b.clone(),
None => extract_context(&context)
None => extract_context(context)
.db
.get_stake_pool_blocks(&self.id)
.await
Expand Down Expand Up @@ -1116,7 +1116,7 @@ impl Pool {
pub async fn registration(&self, context: &Context<'_>) -> FieldResult<PoolRegistration> {
match &self.data {
Some(data) => Ok(data.registration.clone().into()),
None => extract_context(&context)
None => extract_context(context)
.db
.get_stake_pool_data(&self.id)
.await
Expand All @@ -1128,7 +1128,7 @@ impl Pool {
pub async fn retirement(&self, context: &Context<'_>) -> FieldResult<Option<PoolRetirement>> {
match &self.data {
Some(data) => Ok(data.retirement.clone().map(PoolRetirement::from)),
None => extract_context(&context)
None => extract_context(context)
.db
.get_stake_pool_data(&self.id)
.await
Expand All @@ -1152,7 +1152,7 @@ impl Settings {

pub async fn epoch_stability_depth(&self, context: &Context<'_>) -> EpochStabilityDepth {
From::from(
&extract_context(&context)
&extract_context(context)
.db
.blockchain_config
.epoch_stability_depth,
Expand Down Expand Up @@ -1206,19 +1206,19 @@ impl Epoch {
}

pub async fn first_block(&self, context: &Context<'_>) -> Option<Block> {
self.get_epoch_data(&extract_context(&context).db)
self.get_epoch_data(&extract_context(context).db)
.await
.map(|data| Block::from_valid_hash(data.first_block))
}

pub async fn last_block(&self, context: &Context<'_>) -> Option<Block> {
self.get_epoch_data(&extract_context(&context).db)
self.get_epoch_data(&extract_context(context).db)
.await
.map(|data| Block::from_valid_hash(data.last_block))
}

pub async fn total_blocks(&self, context: &Context<'_>) -> BlockCount {
self.get_epoch_data(&extract_context(&context).db)
self.get_epoch_data(&extract_context(context).db)
.await
.map_or(0u32.into(), |data| data.total_blocks.into())
}
Expand Down Expand Up @@ -1308,7 +1308,7 @@ impl VotePlanStatus {
) -> FieldResult<Self> {
let vote_plan_id = chain_impl_mockchain::certificate::VotePlanId::from_str(&vote_plan_id.0)
.map_err(|err| -> FieldError { ApiError::InvalidAddress(err.to_string()).into() })?;
if let Some(vote_plan) = extract_context(&context)
if let Some(vote_plan) = extract_context(context)
.db
.get_vote_plan_by_id(&vote_plan_id)
.await
Expand Down Expand Up @@ -1488,15 +1488,15 @@ pub struct Query;
#[Object]
impl Query {
async fn block(&self, context: &Context<'_>, id: String) -> FieldResult<Block> {
Block::from_string_hash(id, &extract_context(&context).db).await
Block::from_string_hash(id, &extract_context(context).db).await
}

async fn blocks_by_chain_length(
&self,
context: &Context<'_>,
length: ChainLength,
) -> FieldResult<Vec<Block>> {
let blocks = extract_context(&context)
let blocks = extract_context(context)
.db
.find_blocks_by_chain_length(length.0)
.await
Expand All @@ -1516,7 +1516,7 @@ impl Query {

/// get all current tips, sorted (descending) by their length
pub async fn branches(&self, context: &Context<'_>) -> Vec<Branch> {
extract_context(&context)
extract_context(context)
.db
.get_branches()
.await
Expand All @@ -1529,13 +1529,13 @@ impl Query {
/// get the block that the ledger currently considers as the main branch's
/// tip
async fn tip(&self, context: &Context<'_>) -> Branch {
let (hash, state_ref) = extract_context(&context).db.get_tip().await;
let (hash, state_ref) = extract_context(context).db.get_tip().await;
Branch::from_id_and_state(hash, state_ref)
}

pub async fn branch(&self, context: &Context<'_>, id: String) -> FieldResult<Branch> {
let id = HeaderHash::from_str(&id)?;
Branch::try_from_id(id, &extract_context(context)).await
Branch::try_from_id(id, extract_context(context)).await
}

pub async fn epoch(&self, _context: &Context<'_>, id: EpochNumber) -> Epoch {
Expand All @@ -1547,7 +1547,7 @@ impl Query {
}

pub async fn stake_pool(&self, context: &Context<'_>, id: PoolId) -> FieldResult<Pool> {
Pool::from_string_id(&id.0.to_string(), &extract_context(&context).db).await
Pool::from_string_id(&id.0.to_string(), &extract_context(context).db).await
}

pub async fn settings(&self, _context: &Context<'_>) -> FieldResult<Settings> {
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/db/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl ExplorerTransaction {
.and_then(|block_id| {
context
.prev_blocks
.lookup(&block_id)
.lookup(block_id)
.map(|block| &block.transactions[&tx].outputs[index as usize])
})
.or_else(|| {
Expand Down
12 changes: 6 additions & 6 deletions explorer/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl ExplorerDb {

pub async fn get_block(&self, block_id: &HeaderHash) -> Option<Arc<ExplorerBlock>> {
for (_hash, state_ref) in self.multiverse.tips().await.iter() {
if let Some(b) = state_ref.state().blocks.lookup(&block_id) {
if let Some(b) = state_ref.state().blocks.lookup(block_id) {
return Some(Arc::clone(b));
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl ExplorerDb {
let mut tips = Vec::new();

for (hash, state_ref) in self.multiverse.tips().await.drain(..) {
if let Some(b) = state_ref.state().blocks.lookup(&block_id) {
if let Some(b) = state_ref.state().blocks.lookup(block_id) {
block = block.or_else(|| Some(Arc::clone(b)));
tips.push((hash, state_ref));
}
Expand All @@ -320,7 +320,7 @@ impl ExplorerDb {
.await
.unwrap();

if let Some(block) = current_branch.state().blocks.lookup(&block_id) {
if let Some(block) = current_branch.state().blocks.lookup(block_id) {
let confirmed_block_chain_length: ChainLength = self
.stable_store
.confirmed_block_chain_length
Expand Down Expand Up @@ -357,7 +357,7 @@ impl ExplorerDb {
state_ref
.state()
.transactions
.lookup(&transaction_id)
.lookup(transaction_id)
.map(|arc| *arc.clone())
})
.collect();
Expand Down Expand Up @@ -408,7 +408,7 @@ impl ExplorerDb {
vote_plan_id: &VotePlanId,
) -> Option<Arc<ExplorerVotePlan>> {
for (_hash, state_ref) in self.multiverse.tips().await.iter() {
if let Some(b) = state_ref.state().vote_plans.lookup(&vote_plan_id) {
if let Some(b) = state_ref.state().vote_plans.lookup(vote_plan_id) {
return Some(Arc::clone(b));
}
}
Expand Down Expand Up @@ -537,7 +537,7 @@ fn apply_block_to_stake_pools(
let mut blocks = match &block.producer() {
indexing::BlockProducer::StakePool(id) => blocks
.update(
&id,
id,
|array: &Arc<PersistentSequence<HeaderHash>>| -> std::result::Result<_, Infallible> {
Ok(Some(Arc::new(array.append(block.id()))))
},
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/db/multiverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Multiverse {

pub(super) async fn get_ref(&self, hash: &HeaderHash) -> Option<multiverse::Ref<State>> {
let guard = self.inner.read().await;
guard.multiverse.get_ref(&hash)
guard.multiverse.get_ref(hash)
}

/// run the garbage collection of the multiverse
Expand Down

0 comments on commit 97ad777

Please sign in to comment.