Skip to content

Commit 95e681a

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

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
@@ -2566,23 +2566,39 @@ impl Wallet {
25662566
block: &Block,
25672567
height: u32,
25682568
) -> Result<Vec<WalletEvent>, CannotConnectError> {
2569-
let connected_to = match height.checked_sub(1) {
2570-
Some(prev_height) => BlockId {
2571-
height: prev_height,
2572-
hash: block.header.prev_blockhash,
2573-
},
2574-
None => BlockId {
2575-
height,
2576-
hash: block.block_hash(),
2577-
},
2578-
};
2579-
self.apply_block_connected_to_events(block, height, connected_to)
2580-
.map_err(|err| match err {
2581-
ApplyHeaderError::InconsistentBlocks => {
2582-
unreachable!("connected_to is derived from the block so must be consistent")
2583-
}
2584-
ApplyHeaderError::CannotConnect(err) => err,
2569+
// snapshot of chain tip and transactions before update
2570+
let chain_tip1 = self.chain.tip().block_id();
2571+
let wallet_txs1 = self
2572+
.transactions()
2573+
.map(|wtx| {
2574+
(
2575+
wtx.tx_node.txid,
2576+
(wtx.tx_node.tx.clone(), wtx.chain_position),
2577+
)
25852578
})
2579+
.collect::<BTreeMap<Txid, (Arc<Transaction>, ChainPosition<ConfirmationBlockTime>)>>();
2580+
2581+
self.apply_block(block, height)?;
2582+
2583+
// chain tip and transactions after update
2584+
let chain_tip2 = self.chain.tip().block_id();
2585+
let wallet_txs2 = self
2586+
.transactions()
2587+
.map(|wtx| {
2588+
(
2589+
wtx.tx_node.txid,
2590+
(wtx.tx_node.tx.clone(), wtx.chain_position),
2591+
)
2592+
})
2593+
.collect::<BTreeMap<Txid, (Arc<Transaction>, ChainPosition<ConfirmationBlockTime>)>>();
2594+
2595+
Ok(wallet_events(
2596+
self,
2597+
chain_tip1,
2598+
chain_tip2,
2599+
wallet_txs1,
2600+
wallet_txs2,
2601+
))
25862602
}
25872603

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

0 commit comments

Comments
 (0)