Skip to content

Commit 193609f

Browse files
tnullnotmandatory
andcommitted
f Duplicate event logic rather than business logic
Co-authored-by: Steve Myers <github@notmandatory.org>
1 parent 80be94d commit 193609f

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

src/wallet/mod.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,23 +2578,39 @@ impl Wallet {
25782578
block: &Block,
25792579
height: u32,
25802580
) -> Result<Vec<WalletEvent>, CannotConnectError> {
2581-
let connected_to = match height.checked_sub(1) {
2582-
Some(prev_height) => BlockId {
2583-
height: prev_height,
2584-
hash: block.header.prev_blockhash,
2585-
},
2586-
None => BlockId {
2587-
height,
2588-
hash: block.block_hash(),
2589-
},
2590-
};
2591-
self.apply_block_connected_to_events(block, height, connected_to)
2592-
.map_err(|err| match err {
2593-
ApplyHeaderError::InconsistentBlocks => {
2594-
unreachable!("connected_to is derived from the block so must be consistent")
2595-
}
2596-
ApplyHeaderError::CannotConnect(err) => err,
2581+
// snapshot of chain tip and transactions before update
2582+
let chain_tip1 = self.chain.tip().block_id();
2583+
let wallet_txs1 = self
2584+
.transactions()
2585+
.map(|wtx| {
2586+
(
2587+
wtx.tx_node.txid,
2588+
(wtx.tx_node.tx.clone(), wtx.chain_position),
2589+
)
25972590
})
2591+
.collect::<BTreeMap<Txid, (Arc<Transaction>, ChainPosition<ConfirmationBlockTime>)>>();
2592+
2593+
self.apply_block(block, height)?;
2594+
2595+
// chain tip and transactions after update
2596+
let chain_tip2 = self.chain.tip().block_id();
2597+
let wallet_txs2 = self
2598+
.transactions()
2599+
.map(|wtx| {
2600+
(
2601+
wtx.tx_node.txid,
2602+
(wtx.tx_node.tx.clone(), wtx.chain_position),
2603+
)
2604+
})
2605+
.collect::<BTreeMap<Txid, (Arc<Transaction>, ChainPosition<ConfirmationBlockTime>)>>();
2606+
2607+
Ok(wallet_events(
2608+
self,
2609+
chain_tip1,
2610+
chain_tip2,
2611+
wallet_txs1,
2612+
wallet_txs2,
2613+
))
25982614
}
25992615

26002616
/// Applies relevant transactions from `block` of `height` to the wallet, and connects the

0 commit comments

Comments
 (0)