Merge bitcoindevkit/bdk#1385: Fix last seen unconfirmed
a2a64ffb6efix(electrum)!: Remove `seen_at` param from `into_tx_graph` (valued mammal)37fca35ddefeat(tx_graph): Add method update_last_seen_unconfirmed (valued mammal) Pull request description: A method `update_last_seen_unconfirmed` is added for `TxGraph` that allows inserting a `seen_at` time for all unanchored transactions. fixes #1336 ### Changelog notice Changed: - Methods `into_tx_graph` and `into_confirmation_time_tx_graph`for `RelevantTxids` are changed to no longer accept a `seen_at` parameter. Added: - Added method `update_last_seen_unconfirmed` for `TxGraph`. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: evanlinjin: ACKa2a64ffb6eTree-SHA512: 9011e63314b0e3ffcd50dbf5024f82b365bab1cc834c0455d7410b682338339ed5284caa721ffc267c65fa26d35ff6ee86cde6052e82a6a79768547fbb7a45eb
This commit is contained in:
@@ -1058,6 +1058,34 @@ fn test_changeset_last_seen_append() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_last_seen_unconfirmed() {
|
||||
let mut graph = TxGraph::<()>::default();
|
||||
let tx = new_tx(0);
|
||||
let txid = tx.txid();
|
||||
|
||||
// insert a new tx
|
||||
// initially we have a last_seen of 0, and no anchors
|
||||
let _ = graph.insert_tx(tx);
|
||||
let tx = graph.full_txs().next().unwrap();
|
||||
assert_eq!(tx.last_seen_unconfirmed, 0);
|
||||
assert!(tx.anchors.is_empty());
|
||||
|
||||
// higher timestamp should update last seen
|
||||
let changeset = graph.update_last_seen_unconfirmed(2);
|
||||
assert_eq!(changeset.last_seen.get(&txid).unwrap(), &2);
|
||||
|
||||
// lower timestamp has no effect
|
||||
let changeset = graph.update_last_seen_unconfirmed(1);
|
||||
assert!(changeset.last_seen.is_empty());
|
||||
|
||||
// once anchored, last seen is not updated
|
||||
let _ = graph.insert_anchor(txid, ());
|
||||
let changeset = graph.update_last_seen_unconfirmed(4);
|
||||
assert!(changeset.is_empty());
|
||||
assert_eq!(graph.full_txs().next().unwrap().last_seen_unconfirmed, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_missing_blocks() {
|
||||
/// An anchor implementation for testing, made up of `(the_anchor_block, random_data)`.
|
||||
|
||||
Reference in New Issue
Block a user