.unwrap();
wallet.insert_tx(tx0.clone());
- insert_anchor_from_conf(
+ insert_anchor(
&mut wallet,
tx0.compute_txid(),
- ChainPosition::Confirmed(ConfirmationBlockTime {
+ ConfirmationBlockTime {
block_id: BlockId {
height: 1_000,
hash: BlockHash::all_zeros(),
},
confirmation_time: 100,
- }),
+ },
);
wallet.insert_tx(tx1.clone());
- insert_anchor_from_conf(
+ insert_anchor(
&mut wallet,
tx1.compute_txid(),
- ChainPosition::Confirmed(ConfirmationBlockTime {
+ ConfirmationBlockTime {
block_id: BlockId {
height: 2_000,
hash: BlockHash::all_zeros(),
},
confirmation_time: 200,
- }),
+ },
);
(wallet, tx1.compute_txid())
FeeRate::from_sat_per_kwu(sat_kwu)
}
-/// Simulates confirming a tx with `txid` at the specified `position` by inserting an anchor
-/// at the lowest height in local chain that is greater or equal to `position`'s height,
-/// assuming the confirmation time matches `ConfirmationTime::Confirmed`.
-pub fn insert_anchor_from_conf(
- wallet: &mut Wallet,
- txid: Txid,
- position: ChainPosition<ConfirmationBlockTime>,
-) {
- if let ChainPosition::Confirmed(anchor) = position {
- wallet
- .apply_update(Update {
- tx_update: tx_graph::TxUpdate {
- anchors: [(anchor, txid)].into(),
- ..Default::default()
- },
+/// Simulates confirming a tx with `txid` by applying an update to the wallet containing
+/// the given `anchor`. Note: to be considered confirmed the anchor block must exist in
+/// the current active chain.
+pub fn insert_anchor(wallet: &mut Wallet, txid: Txid, anchor: ConfirmationBlockTime) {
+ wallet
+ .apply_update(Update {
+ tx_update: tx_graph::TxUpdate {
+ anchors: [(anchor, txid)].into(),
..Default::default()
- })
- .unwrap();
- }
+ },
+ ..Default::default()
+ })
+ .unwrap();
}
wallet.insert_tx(tx);
match height {
- ChainPosition::Confirmed { .. } => {
- insert_anchor_from_conf(wallet, txid, height);
+ ChainPosition::Confirmed(anchor) => {
+ insert_anchor(wallet, txid, anchor);
}
ChainPosition::Unconfirmed(last_seen) => {
insert_seen_at(wallet, txid, last_seen);
};
let txid = small_output_tx.compute_txid();
wallet.insert_tx(small_output_tx);
- let chain_position = ChainPosition::Confirmed(ConfirmationBlockTime {
- block_id: wallet.latest_checkpoint().get(2000).unwrap().block_id(),
+ let anchor = ConfirmationBlockTime {
+ block_id: wallet.latest_checkpoint().block_id(),
confirmation_time: 200,
- });
- insert_anchor_from_conf(&mut wallet, txid, chain_position);
+ };
+ insert_anchor(&mut wallet, txid, anchor);
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
.unwrap()
};
let txid = small_output_tx.compute_txid();
wallet.insert_tx(small_output_tx.clone());
- let chain_position = ChainPosition::Confirmed(ConfirmationBlockTime {
- block_id: wallet.latest_checkpoint().get(2000).unwrap().block_id(),
+ let anchor = ConfirmationBlockTime {
+ block_id: wallet.latest_checkpoint().block_id(),
confirmation_time: 200,
- });
- insert_anchor_from_conf(&mut wallet, txid, chain_position);
+ };
+ insert_anchor(&mut wallet, txid, anchor);
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
.unwrap()
wallet.insert_tx(tx);
- let chain_position = ChainPosition::Confirmed(ConfirmationBlockTime {
+ let anchor = ConfirmationBlockTime {
block_id: wallet.latest_checkpoint().get(42).unwrap().block_id(),
confirmation_time: 42_000,
- });
- insert_anchor_from_conf(&mut wallet, txid, chain_position);
+ };
+ insert_anchor(&mut wallet, txid, anchor);
wallet.build_fee_bump(txid).unwrap().finish().unwrap();
}
};
let txid = tx.compute_txid();
wallet.insert_tx(tx.clone());
- let chain_position = ChainPosition::Confirmed(ConfirmationBlockTime {
+ let anchor = ConfirmationBlockTime {
block_id: wallet.latest_checkpoint().block_id(),
confirmation_time: 42_000,
- });
- insert_anchor_from_conf(&mut wallet, txid, chain_position);
+ };
+ insert_anchor(&mut wallet, txid, anchor);
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
.unwrap()
value: Amount::from_sat(25_000),
}],
};
- let position: ChainPosition<ConfirmationBlockTime> = wallet
- .transactions()
- .last()
- .unwrap()
- .chain_position
- .cloned();
wallet.insert_tx(init_tx.clone());
- insert_anchor_from_conf(&mut wallet, init_tx.compute_txid(), position);
+ let anchor = ConfirmationBlockTime {
+ block_id: wallet.latest_checkpoint().block_id(),
+ confirmation_time: 200,
+ };
+ insert_anchor(&mut wallet, init_tx.compute_txid(), anchor);
let outpoint = OutPoint {
txid: init_tx.compute_txid(),
}],
};
let txid = init_tx.compute_txid();
- let pos: ChainPosition<ConfirmationBlockTime> = wallet
- .transactions()
- .last()
- .unwrap()
- .chain_position
- .cloned();
wallet.insert_tx(init_tx);
- insert_anchor_from_conf(&mut wallet, txid, pos);
+ let anchor = ConfirmationBlockTime {
+ block_id: wallet.latest_checkpoint().block_id(),
+ confirmation_time: 200,
+ };
+ insert_anchor(&mut wallet, txid, anchor);
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX")
.unwrap()
};
let txid = coinbase_tx.compute_txid();
wallet.insert_tx(coinbase_tx);
- let chain_position = ChainPosition::Confirmed(ConfirmationBlockTime {
+ let anchor = ConfirmationBlockTime {
block_id: confirmation_block_id,
confirmation_time: 30_000,
- });
- insert_anchor_from_conf(&mut wallet, txid, chain_position);
+ };
+ insert_anchor(&mut wallet, txid, anchor);
let not_yet_mature_time = confirmation_height + COINBASE_MATURITY - 1;
let maturity_time = confirmation_height + COINBASE_MATURITY;
.address;
let chain_position = ChainPosition::Confirmed(ConfirmationBlockTime {
block_id: BlockId {
- height: 8000,
+ height: 2000,
hash: BlockHash::all_zeros(),
},
confirmation_time: 0,