Skip to content

Commit

Permalink
refactor: remove a meaningless Option
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettiSats committed Oct 2, 2023
1 parent 41ca63e commit a93ef52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/chain/src/chain_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait ChainOracle {
fn is_block_in_chain(
&self,
block: BlockId,
chain_tip: Option<&BlockId>,
chain_tip: BlockId,
) -> Result<Option<bool>, Self::Error>;

/// Get the best chain's chain tip.
Expand Down
7 changes: 1 addition & 6 deletions crates/chain/src/local_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,8 @@ impl ChainOracle for LocalChain {
fn is_block_in_chain(
&self,
block: BlockId,
chain_tip: Option<&BlockId>,
chain_tip: BlockId,
) -> Result<Option<bool>, Self::Error> {
let chain_tip = match chain_tip {
Some(x) => x,
None => return Ok(None),
};

if block.height > chain_tip.height {
return Ok(None);
}
Expand Down
9 changes: 7 additions & 2 deletions crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,18 @@ impl<A: Anchor> TxGraph<A> {
chain_tip: Option<BlockId>,
txid: Txid,
) -> Result<Option<ChainPosition<&A>>, C::Error> {
let chain_tip = match chain_tip {
Some(tip) => tip,
None => return Ok(None),
};

let (tx_node, anchors, last_seen) = match self.txs.get(&txid) {
Some(v) => v,
None => return Ok(None),
};

for anchor in anchors {
match chain.is_block_in_chain(anchor.anchor_block(), chain_tip.as_ref())? {
match chain.is_block_in_chain(anchor.anchor_block(), chain_tip)? {
Some(true) => return Ok(Some(ChainPosition::Confirmed(anchor))),
_ => continue,
}
Expand All @@ -691,7 +696,7 @@ impl<A: Anchor> TxGraph<A> {
// this tx cannot exist in the best chain
for conflicting_tx in self.walk_conflicts(tx, |_, txid| self.get_tx_node(txid)) {
for block in conflicting_tx.anchors.iter().map(A::anchor_block) {
if chain.is_block_in_chain(block, chain_tip.as_ref())? == Some(true) {
if chain.is_block_in_chain(block, chain_tip)? == Some(true) {
// conflicting tx is in best chain, so the current tx cannot be in best chain!
return Ok(None);
}
Expand Down

0 comments on commit a93ef52

Please sign in to comment.