diff --git a/crates/chain/src/tx_data_traits.rs b/crates/chain/src/tx_data_traits.rs index c957a3e57..0206bde22 100644 --- a/crates/chain/src/tx_data_traits.rs +++ b/crates/chain/src/tx_data_traits.rs @@ -128,6 +128,17 @@ impl Append for Vec { } } +impl Append for Option { + // If other is Some then replace self's value with other's value, if other is None do nothing. + fn append(&mut self, other: Self) { + other.and_then(|v| self.replace(v)); + } + + fn is_empty(&self) -> bool { + self.is_none() + } +} + macro_rules! impl_append_for_tuple { ($($a:ident $b:tt)*) => { impl<$($a),*> Append for ($($a,)*) where $($a: Append),* { diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index f84c3a3dc..cd01950a5 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -559,10 +559,7 @@ impl TxGraph { } for (outpoint, txout) in changeset.txouts { - let tx_entry = self - .txs - .entry(outpoint.txid) - .or_insert_with(Default::default); + let tx_entry = self.txs.entry(outpoint.txid).or_default(); match tx_entry { (TxNodeInternal::Whole(_), _, _) => { /* do nothing since we already have full tx */ @@ -575,13 +572,13 @@ impl TxGraph { for (anchor, txid) in changeset.anchors { if self.anchors.insert((anchor.clone(), txid)) { - let (_, anchors, _) = self.txs.entry(txid).or_insert_with(Default::default); + let (_, anchors, _) = self.txs.entry(txid).or_default(); anchors.insert(anchor); } } for (txid, new_last_seen) in changeset.last_seen { - let (_, _, last_seen) = self.txs.entry(txid).or_insert_with(Default::default); + let (_, _, last_seen) = self.txs.entry(txid).or_default(); if new_last_seen > *last_seen { *last_seen = new_last_seen; }