self.stage.append(additions.into());
}
- /// Inserts an `anchor` for a transaction with the given `txid`.
- ///
- /// This stages the changes, you must persist them later.
- pub fn insert_anchor(&mut self, txid: Txid, anchor: ConfirmationTimeHeightAnchor) {
- let indexed_graph_changeset = self.indexed_graph.insert_anchor(txid, anchor);
- self.stage.append(indexed_graph_changeset.into());
- }
-
- /// Inserts a unix timestamp of when a transaction is seen in the mempool.
- ///
- /// This is used for transaction conflict resolution where the transaction with the
- /// later last-seen is prioritized. This stages the changes, you must persist them later.
- pub fn insert_seen_at(&mut self, txid: Txid, seen_at: u64) {
- let indexed_graph_changeset = self.indexed_graph.insert_seen_at(txid, seen_at);
- self.stage.append(indexed_graph_changeset.into());
- }
-
/// Calculates the fee of a given transaction. Returns [`Amount::ZERO`] if `tx` is a coinbase transaction.
///
/// To calculate the fee for a [`Transaction`] with inputs not owned by this wallet you must
macro_rules! doctest_wallet {
() => {{
use $crate::bitcoin::{BlockHash, Transaction, absolute, TxOut, Network, hashes::Hash};
- use $crate::chain::{ConfirmationTimeHeightAnchor, BlockId};
- use $crate::{KeychainKind, wallet::Wallet};
+ use $crate::chain::{ConfirmationTimeHeightAnchor, BlockId, TxGraph};
+ use $crate::wallet::{Update, Wallet};
+ use $crate::KeychainKind;
let descriptor = "tr([73c5da0a/86'/0'/0']tprv8fMn4hSKPRC1oaCPqxDb1JWtgkpeiQvZhsr8W2xuy3GEMkzoArcAWTfJxYb6Wj8XNNDWEjfYKK4wGQXh3ZUXhDF2NcnsALpWTeSwarJt7Vc/0/*)";
let change_descriptor = "tr([73c5da0a/86'/0'/0']tprv8fMn4hSKPRC1oaCPqxDb1JWtgkpeiQvZhsr8W2xuy3GEMkzoArcAWTfJxYb6Wj8XNNDWEjfYKK4wGQXh3ZUXhDF2NcnsALpWTeSwarJt7Vc/1/*)";
let block = BlockId { height: 1_000, hash: BlockHash::all_zeros() };
let _ = wallet.insert_checkpoint(block);
let _ = wallet.insert_tx(tx);
- wallet
- .insert_anchor(
- txid,
- ConfirmationTimeHeightAnchor {
- confirmation_height: 500,
- confirmation_time: 50_000,
- anchor_block: block,
- }
- );
-
+ let anchor = ConfirmationTimeHeightAnchor {
+ confirmation_height: 500,
+ confirmation_time: 50_000,
+ anchor_block: block,
+ };
+ let mut graph = TxGraph::default();
+ let _ = graph.insert_anchor(txid, anchor);
+ let update = Update { graph, ..Default::default() };
+ wallet.apply_update(update).unwrap();
wallet
}}
}
insert_anchor_from_conf(wallet, txid, height);
}
ConfirmationTime::Unconfirmed { last_seen } => {
- wallet.insert_seen_at(txid, last_seen);
+ insert_seen_at(wallet, txid, last_seen);
}
}
receive_output(wallet, value, anchor)
}
+fn insert_seen_at(wallet: &mut Wallet, txid: Txid, seen_at: u64) {
+ use bdk_wallet::wallet::Update;
+ let mut graph = bdk_chain::TxGraph::default();
+ let _ = graph.insert_seen_at(txid, seen_at);
+ wallet
+ .apply_update(Update {
+ graph,
+ ..Default::default()
+ })
+ .unwrap();
+}
+
// The satisfaction size of a P2WPKH is 112 WU =
// 1 (elements in witness) + 1 (OP_PUSH) + 33 (pk) + 1 (OP_PUSH) + 72 (signature + sighash) + 1*4 (script len)
// On the witness itself, we have to push once for the pk (33WU) and once for signature + sighash (72WU), for
};
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let external_policy = wallet.policies(KeychainKind::External).unwrap().unwrap();
let root_id = external_policy.id;
let tx = psbt.extract_tx().expect("failed to extract tx");
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
wallet.build_fee_bump(txid).unwrap().finish().unwrap();
}
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder.fee_rate(FeeRate::BROADCAST_MIN);
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder.fee_absolute(Amount::from_sat(10));
let tx = psbt.extract_tx().expect("failed to extract tx");
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder.fee_absolute(Amount::ZERO);
let tx = psbt.extract_tx().expect("failed to extract tx");
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let feerate = FeeRate::from_sat_per_kwu(625); // 2.5 sat/vb
let mut builder = wallet.build_fee_bump(txid).unwrap();
let original_fee = check_fee!(wallet, psbt);
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let feerate = FeeRate::from_sat_per_kwu(625); // 2.5 sat/vb
let mut builder = wallet.build_fee_bump(txid).unwrap();
let original_sent_received = wallet.sent_and_received(&tx);
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
assert_eq!(original_sent_received.0, Amount::from_sat(25_000));
// for the new feerate, it should be enough to reduce the output, but since we specify
let original_sent_received = wallet.sent_and_received(&tx);
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
assert_eq!(original_sent_received.0, Amount::from_sat(25_000));
let mut builder = wallet.build_fee_bump(txid).unwrap();
let original_details = wallet.sent_and_received(&tx);
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder.fee_rate(FeeRate::from_sat_per_vb_unchecked(50));
let original_sent_received = wallet.sent_and_received(&tx);
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder.fee_absolute(Amount::from_sat(6_000));
let tx = psbt.extract_tx().expect("failed to extract tx");
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
// Now bump the fees, the wallet should add an extra input and a change output, and leave
// the original output untouched.
assert_eq!(tx.output.len(), 2);
let txid = tx.compute_txid();
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
// We set a fee high enough that during rbf we are forced to add
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
}
wallet.insert_tx(tx.clone());
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
// the new fee_rate is low enough that just reducing the change would be fine, but we force
// the addition of an extra input with `add_utxo()`
let mut builder = wallet.build_fee_bump(txid).unwrap();
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
}
wallet.insert_tx(tx.clone());
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
// the new fee_rate is low enough that just reducing the change would be fine, but we force
// the addition of an extra input with `add_utxo()`
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
}
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder.fee_rate(FeeRate::from_sat_per_vb_unchecked(25));
builder.finish().unwrap();
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
}
wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 0);
+ insert_seen_at(&mut wallet, txid, 0);
let mut builder = wallet.build_fee_bump(txid).unwrap();
builder
let tx = psbt.extract_tx().unwrap();
let txid = tx.compute_txid();
let _ = wallet.insert_tx(tx);
- wallet.insert_seen_at(txid, 2);
+ insert_seen_at(&mut wallet, txid, 2);
assert!(wallet.list_unspent().next().is_none());
assert_eq!(wallet.balance().total().to_sat(), 0);
}