deps(bdk): bump bitcoin to 0.32.0, miniscript to 12.0.0
deps(chain): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0` fix(chain): use `minimal_non_dust()` instead of `dust_value()` fix(chain): use `compute_txid()` instead of `txid` deps(testenv): bump `electrsd` to `0.28.0` deps(electrum): bump `electrum-client` to `0.20.0` fix(electrum): use `compute_txid()` instead of `txid` deps(esplora): bump `esplora-client` to `0.8.0` deps(bitcoind_rpc): bump `bitcoin` to `0.32.0`, `bitcoincore-rpc` to `0.19.0` fix(bitcoind_rpc): use `compute_txid()` instead of `txid` fix(nursery/tmp_plan): use proper `sighash` errors, and fix the expected `Signature` fields fix(sqlite): use `compute_txid()` instead of `txid` deps(hwi): bump `hwi` to `0.9.0` deps(wallet): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0` fix(wallet): use `compute_txid()` and `minimal_non_dust()` - update to use `compute_txid()` instead of deprecated `txid()` - update to use `minimal_non_dust()` instead of `dust_value()` - remove unused `bitcoin::hex::FromHex`. fix(wallet): uses `.into` conversion on `Network` for `NetworkKind` - uses `.into()` when appropriate, otherwise use the explicit `NetworkKind`, and it's `.is_mainnet()` method. fix(wallet): add P2wpkh, Taproot, InputsIndex errors to `SignerError` fix(wallet): fields on taproot, and ecdsa `Signature` structure fix(wallet/wallet): convert `Weight` to `usize` for now - converts the `bitcoin-units::Weight` type to `usize` with help of `to_wu()` method. - it should be updated/refactored in the future to handle the `Weight` type throughout the code instead of current `usize`, only converting it for now. - allows the usage of deprecated `is_provably_unspendable()`, needs further discussion if suggested `is_op_return` is suitable. - update the expect field to `signature`, as it was renamed from `sig`. fix(wallet/wallet): use `is_op_return` instead of `is_provably_unspendable` fix(wallet/wallet): use `relative::Locktime` instead of `Sequence` fix(wallet/descriptor): use `ParsePublicKeyError` fix(wallet/descriptor): use `.into()` to convert from `AbsLockTime` and `RelLockTime` to `absolute::LockTime` and `relative::LockTime` fix(wallet/wallet): use `Message::from_digest()` instead of relying on deprecated `ThirtyTwoByteHash` trait. fix(wallet/descriptor+wallet): expect `Threshold` type, and handle it internally fix(wallet/wallet): remove `0x` prefix from expected `TxId` display fix(examples): use `compute_txid()` instead of `txid` fix(ci): remove usage of `bitcoin/no-std` feature - remove comment: `# The `no-std` feature it's implied when the `std` feature is disabled.`
This commit is contained in:
@@ -13,13 +13,12 @@ readme = "README.md"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# For no-std, remember to enable the bitcoin/no-std feature
|
||||
bitcoin = { version = "0.31.0", default-features = false }
|
||||
bitcoin = { version = "0.32.0", default-features = false }
|
||||
serde_crate = { package = "serde", version = "1", optional = true, features = ["derive", "rc"] }
|
||||
|
||||
# Use hashbrown as a feature flag to have HashSet and HashMap from it.
|
||||
hashbrown = { version = "0.9.1", optional = true, features = ["serde"] }
|
||||
miniscript = { version = "11.0.0", optional = true, default-features = false }
|
||||
miniscript = { version = "12.0.0", optional = true, default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.8"
|
||||
|
||||
@@ -31,7 +31,7 @@ impl DescriptorExt for Descriptor<DescriptorPublicKey> {
|
||||
self.at_derivation_index(0)
|
||||
.expect("descriptor can't have hardened derivation")
|
||||
.script_pubkey()
|
||||
.dust_value()
|
||||
.minimal_non_dust()
|
||||
.to_sat()
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ where
|
||||
let mut graph = tx_graph::ChangeSet::default();
|
||||
for (tx, anchors) in txs {
|
||||
if self.index.is_tx_relevant(tx) {
|
||||
let txid = tx.txid();
|
||||
let txid = tx.compute_txid();
|
||||
graph.append(self.graph.insert_tx(tx.clone()));
|
||||
for anchor in anchors {
|
||||
graph.append(self.graph.insert_anchor(txid, anchor));
|
||||
@@ -234,7 +234,7 @@ where
|
||||
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
||||
changeset.indexer.append(self.index.index_tx(tx));
|
||||
if self.index.is_tx_relevant(tx) {
|
||||
let txid = tx.txid();
|
||||
let txid = tx.compute_txid();
|
||||
let anchor = A::from_block_position(block, block_id, tx_pos);
|
||||
changeset.graph.append(self.graph.insert_tx(tx.clone()));
|
||||
changeset
|
||||
@@ -261,7 +261,7 @@ where
|
||||
let mut graph = tx_graph::ChangeSet::default();
|
||||
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
||||
let anchor = A::from_block_position(&block, block_id, tx_pos);
|
||||
graph.append(self.graph.insert_anchor(tx.txid(), anchor));
|
||||
graph.append(self.graph.insert_anchor(tx.compute_txid(), anchor));
|
||||
graph.append(self.graph.insert_tx(tx.clone()));
|
||||
}
|
||||
let indexer = self.index_tx_graph_changeset(&graph);
|
||||
|
||||
@@ -251,7 +251,7 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
|
||||
fn index_tx(&mut self, tx: &bitcoin::Transaction) -> Self::ChangeSet {
|
||||
let mut changeset = super::ChangeSet::<K>::default();
|
||||
for (op, txout) in tx.output.iter().enumerate() {
|
||||
changeset.append(self.index_txout(OutPoint::new(tx.txid(), op as u32), txout));
|
||||
changeset.append(self.index_txout(OutPoint::new(tx.compute_txid(), op as u32), txout));
|
||||
}
|
||||
changeset
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
|
||||
/// 2. When getting new data from the chain, you usually scan it before incorporating it into your chain state.
|
||||
pub fn scan(&mut self, tx: &Transaction) -> BTreeSet<I> {
|
||||
let mut scanned_indices = BTreeSet::new();
|
||||
let txid = tx.txid();
|
||||
let txid = tx.compute_txid();
|
||||
for (i, txout) in tx.output.iter().enumerate() {
|
||||
let op = OutPoint::new(txid, i as u32);
|
||||
if let Some(spk_i) = self.scan_txout(op, txout) {
|
||||
|
||||
@@ -43,7 +43,7 @@ use alloc::vec::Vec;
|
||||
/// let mut graph_a = TxGraph::<BlockId>::default();
|
||||
/// let _ = graph_a.insert_tx(tx.clone());
|
||||
/// graph_a.insert_anchor(
|
||||
/// tx.txid(),
|
||||
/// tx.compute_txid(),
|
||||
/// BlockId {
|
||||
/// height: 1,
|
||||
/// hash: Hash::hash("first".as_bytes()),
|
||||
@@ -58,7 +58,7 @@ use alloc::vec::Vec;
|
||||
/// let mut graph_b = TxGraph::<ConfirmationHeightAnchor>::default();
|
||||
/// let _ = graph_b.insert_tx(tx.clone());
|
||||
/// graph_b.insert_anchor(
|
||||
/// tx.txid(),
|
||||
/// tx.compute_txid(),
|
||||
/// ConfirmationHeightAnchor {
|
||||
/// anchor_block: BlockId {
|
||||
/// height: 2,
|
||||
@@ -76,7 +76,7 @@ use alloc::vec::Vec;
|
||||
/// let mut graph_c = TxGraph::<ConfirmationTimeHeightAnchor>::default();
|
||||
/// let _ = graph_c.insert_tx(tx.clone());
|
||||
/// graph_c.insert_anchor(
|
||||
/// tx.txid(),
|
||||
/// tx.compute_txid(),
|
||||
/// ConfirmationTimeHeightAnchor {
|
||||
/// anchor_block: BlockId {
|
||||
/// height: 2,
|
||||
|
||||
@@ -445,7 +445,7 @@ impl<A> TxGraph<A> {
|
||||
&'g self,
|
||||
tx: &'g Transaction,
|
||||
) -> impl Iterator<Item = (usize, Txid)> + '_ {
|
||||
let txid = tx.txid();
|
||||
let txid = tx.compute_txid();
|
||||
tx.input
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -516,9 +516,10 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
pub fn insert_tx<T: Into<Arc<Transaction>>>(&mut self, tx: T) -> ChangeSet<A> {
|
||||
let tx = tx.into();
|
||||
let mut update = Self::default();
|
||||
update
|
||||
.txs
|
||||
.insert(tx.txid(), (TxNodeInternal::Whole(tx), BTreeSet::new(), 0));
|
||||
update.txs.insert(
|
||||
tx.compute_txid(),
|
||||
(TxNodeInternal::Whole(tx), BTreeSet::new(), 0),
|
||||
);
|
||||
self.apply_update(update)
|
||||
}
|
||||
|
||||
@@ -533,7 +534,7 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
) -> ChangeSet<A> {
|
||||
let mut changeset = ChangeSet::<A>::default();
|
||||
for (tx, seen_at) in txs {
|
||||
changeset.append(self.insert_seen_at(tx.txid(), seen_at));
|
||||
changeset.append(self.insert_seen_at(tx.compute_txid(), seen_at));
|
||||
changeset.append(self.insert_tx(tx));
|
||||
}
|
||||
changeset
|
||||
@@ -642,7 +643,7 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
pub fn apply_changeset(&mut self, changeset: ChangeSet<A>) {
|
||||
for wrapped_tx in changeset.txs {
|
||||
let tx = wrapped_tx.as_ref();
|
||||
let txid = tx.txid();
|
||||
let txid = tx.compute_txid();
|
||||
|
||||
tx.input
|
||||
.iter()
|
||||
@@ -660,7 +661,7 @@ impl<A: Clone + Ord> TxGraph<A> {
|
||||
}
|
||||
Some((TxNodeInternal::Whole(tx), _, _)) => {
|
||||
debug_assert_eq!(
|
||||
tx.as_ref().txid(),
|
||||
tx.as_ref().compute_txid(),
|
||||
txid,
|
||||
"tx should produce txid that is same as key"
|
||||
);
|
||||
@@ -825,7 +826,7 @@ impl<A: Anchor> TxGraph<A> {
|
||||
// resulting array will also include `tx`
|
||||
let unconfirmed_ancestor_txs =
|
||||
TxAncestors::new_include_root(self, tx.clone(), |_, ancestor_tx: Arc<Transaction>| {
|
||||
let tx_node = self.get_tx_node(ancestor_tx.as_ref().txid())?;
|
||||
let tx_node = self.get_tx_node(ancestor_tx.as_ref().compute_txid())?;
|
||||
// We're filtering the ancestors to keep only the unconfirmed ones (= no anchors in
|
||||
// the best chain)
|
||||
for block in tx_node.anchors {
|
||||
@@ -843,7 +844,7 @@ impl<A: Anchor> TxGraph<A> {
|
||||
// and our unconf descendants' last seen.
|
||||
let unconfirmed_descendants_txs = TxDescendants::new_include_root(
|
||||
self,
|
||||
tx.as_ref().txid(),
|
||||
tx.as_ref().compute_txid(),
|
||||
|_, descendant_txid: Txid| {
|
||||
let tx_node = self.get_tx_node(descendant_txid)?;
|
||||
// We're filtering the ancestors to keep only the unconfirmed ones (= no anchors in
|
||||
@@ -884,7 +885,7 @@ impl<A: Anchor> TxGraph<A> {
|
||||
return Ok(None);
|
||||
}
|
||||
if conflicting_tx.last_seen_unconfirmed == *last_seen
|
||||
&& conflicting_tx.as_ref().txid() > tx.as_ref().txid()
|
||||
&& conflicting_tx.as_ref().compute_txid() > tx.as_ref().compute_txid()
|
||||
{
|
||||
// Conflicting tx has priority if txid of conflicting tx > txid of original tx
|
||||
return Ok(None);
|
||||
@@ -1255,7 +1256,7 @@ impl<A> ChangeSet<A> {
|
||||
tx.output
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vout, txout)| (OutPoint::new(tx.txid(), vout as _), txout))
|
||||
.map(move |(vout, txout)| (OutPoint::new(tx.compute_txid(), vout as _), txout))
|
||||
})
|
||||
.chain(self.txouts.iter().map(|(op, txout)| (*op, txout)))
|
||||
}
|
||||
|
||||
@@ -125,14 +125,14 @@ pub fn init_graph<'a, A: Anchor + Clone + 'a>(
|
||||
.collect(),
|
||||
};
|
||||
|
||||
tx_ids.insert(tx_tmp.tx_name, tx.txid());
|
||||
tx_ids.insert(tx_tmp.tx_name, tx.compute_txid());
|
||||
spk_index.scan(&tx);
|
||||
let _ = graph.insert_tx(tx.clone());
|
||||
for anchor in tx_tmp.anchors.iter() {
|
||||
let _ = graph.insert_anchor(tx.txid(), anchor.clone());
|
||||
let _ = graph.insert_anchor(tx.compute_txid(), anchor.clone());
|
||||
}
|
||||
if let Some(seen_at) = tx_tmp.last_seen {
|
||||
let _ = graph.insert_seen_at(tx.txid(), seen_at);
|
||||
let _ = graph.insert_seen_at(tx.compute_txid(), seen_at);
|
||||
}
|
||||
}
|
||||
(graph, spk_index, tx_ids)
|
||||
|
||||
@@ -52,7 +52,7 @@ fn insert_relevant_txs() {
|
||||
|
||||
let tx_b = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_a.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_a.compute_txid(), 0),
|
||||
..Default::default()
|
||||
}],
|
||||
..common::new_tx(1)
|
||||
@@ -60,7 +60,7 @@ fn insert_relevant_txs() {
|
||||
|
||||
let tx_c = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_a.txid(), 1),
|
||||
previous_output: OutPoint::new(tx_a.compute_txid(), 1),
|
||||
..Default::default()
|
||||
}],
|
||||
..common::new_tx(2)
|
||||
@@ -196,7 +196,7 @@ fn test_list_owned_txouts() {
|
||||
// tx3 spends tx2 and gives a change back in trusted keychain. Confirmed at Block 2.
|
||||
let tx3 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx2.txid(), 0),
|
||||
previous_output: OutPoint::new(tx2.compute_txid(), 0),
|
||||
..Default::default()
|
||||
}],
|
||||
output: vec![TxOut {
|
||||
@@ -340,16 +340,22 @@ fn test_list_owned_txouts() {
|
||||
balance,
|
||||
) = fetch(0, &graph);
|
||||
|
||||
assert_eq!(confirmed_txouts_txid, [tx1.txid()].into());
|
||||
assert_eq!(confirmed_txouts_txid, [tx1.compute_txid()].into());
|
||||
assert_eq!(
|
||||
unconfirmed_txouts_txid,
|
||||
[tx2.txid(), tx3.txid(), tx4.txid(), tx5.txid()].into()
|
||||
[
|
||||
tx2.compute_txid(),
|
||||
tx3.compute_txid(),
|
||||
tx4.compute_txid(),
|
||||
tx5.compute_txid()
|
||||
]
|
||||
.into()
|
||||
);
|
||||
|
||||
assert_eq!(confirmed_utxos_txid, [tx1.txid()].into());
|
||||
assert_eq!(confirmed_utxos_txid, [tx1.compute_txid()].into());
|
||||
assert_eq!(
|
||||
unconfirmed_utxos_txid,
|
||||
[tx3.txid(), tx4.txid(), tx5.txid()].into()
|
||||
[tx3.compute_txid(), tx4.compute_txid(), tx5.compute_txid()].into()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@@ -374,17 +380,20 @@ fn test_list_owned_txouts() {
|
||||
) = fetch(1, &graph);
|
||||
|
||||
// tx2 gets into confirmed txout set
|
||||
assert_eq!(confirmed_txouts_txid, [tx1.txid(), tx2.txid()].into());
|
||||
assert_eq!(
|
||||
confirmed_txouts_txid,
|
||||
[tx1.compute_txid(), tx2.compute_txid()].into()
|
||||
);
|
||||
assert_eq!(
|
||||
unconfirmed_txouts_txid,
|
||||
[tx3.txid(), tx4.txid(), tx5.txid()].into()
|
||||
[tx3.compute_txid(), tx4.compute_txid(), tx5.compute_txid()].into()
|
||||
);
|
||||
|
||||
// tx2 doesn't get into confirmed utxos set
|
||||
assert_eq!(confirmed_utxos_txid, [tx1.txid()].into());
|
||||
assert_eq!(confirmed_utxos_txid, [tx1.compute_txid()].into());
|
||||
assert_eq!(
|
||||
unconfirmed_utxos_txid,
|
||||
[tx3.txid(), tx4.txid(), tx5.txid()].into()
|
||||
[tx3.compute_txid(), tx4.compute_txid(), tx5.compute_txid()].into()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@@ -411,13 +420,22 @@ fn test_list_owned_txouts() {
|
||||
// tx3 now gets into the confirmed txout set
|
||||
assert_eq!(
|
||||
confirmed_txouts_txid,
|
||||
[tx1.txid(), tx2.txid(), tx3.txid()].into()
|
||||
[tx1.compute_txid(), tx2.compute_txid(), tx3.compute_txid()].into()
|
||||
);
|
||||
assert_eq!(
|
||||
unconfirmed_txouts_txid,
|
||||
[tx4.compute_txid(), tx5.compute_txid()].into()
|
||||
);
|
||||
assert_eq!(unconfirmed_txouts_txid, [tx4.txid(), tx5.txid()].into());
|
||||
|
||||
// tx3 also gets into confirmed utxo set
|
||||
assert_eq!(confirmed_utxos_txid, [tx1.txid(), tx3.txid()].into());
|
||||
assert_eq!(unconfirmed_utxos_txid, [tx4.txid(), tx5.txid()].into());
|
||||
assert_eq!(
|
||||
confirmed_utxos_txid,
|
||||
[tx1.compute_txid(), tx3.compute_txid()].into()
|
||||
);
|
||||
assert_eq!(
|
||||
unconfirmed_utxos_txid,
|
||||
[tx4.compute_txid(), tx5.compute_txid()].into()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
balance,
|
||||
@@ -442,12 +460,21 @@ fn test_list_owned_txouts() {
|
||||
|
||||
assert_eq!(
|
||||
confirmed_txouts_txid,
|
||||
[tx1.txid(), tx2.txid(), tx3.txid()].into()
|
||||
[tx1.compute_txid(), tx2.compute_txid(), tx3.compute_txid()].into()
|
||||
);
|
||||
assert_eq!(
|
||||
unconfirmed_txouts_txid,
|
||||
[tx4.compute_txid(), tx5.compute_txid()].into()
|
||||
);
|
||||
assert_eq!(unconfirmed_txouts_txid, [tx4.txid(), tx5.txid()].into());
|
||||
|
||||
assert_eq!(confirmed_utxos_txid, [tx1.txid(), tx3.txid()].into());
|
||||
assert_eq!(unconfirmed_utxos_txid, [tx4.txid(), tx5.txid()].into());
|
||||
assert_eq!(
|
||||
confirmed_utxos_txid,
|
||||
[tx1.compute_txid(), tx3.compute_txid()].into()
|
||||
);
|
||||
assert_eq!(
|
||||
unconfirmed_utxos_txid,
|
||||
[tx4.compute_txid(), tx5.compute_txid()].into()
|
||||
);
|
||||
|
||||
// Coinbase is still immature
|
||||
assert_eq!(
|
||||
|
||||
@@ -47,7 +47,7 @@ fn spk_txout_sent_and_received() {
|
||||
lock_time: absolute::LockTime::ZERO,
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint {
|
||||
txid: tx1.txid(),
|
||||
txid: tx1.compute_txid(),
|
||||
vout: 0,
|
||||
},
|
||||
..Default::default()
|
||||
|
||||
@@ -130,11 +130,11 @@ fn insert_txouts() {
|
||||
|
||||
// Mark it as confirmed.
|
||||
assert_eq!(
|
||||
graph.insert_anchor(update_txs.txid(), conf_anchor),
|
||||
graph.insert_anchor(update_txs.compute_txid(), conf_anchor),
|
||||
ChangeSet {
|
||||
txs: [].into(),
|
||||
txouts: [].into(),
|
||||
anchors: [(conf_anchor, update_txs.txid())].into(),
|
||||
anchors: [(conf_anchor, update_txs.compute_txid())].into(),
|
||||
last_seen: [].into()
|
||||
}
|
||||
);
|
||||
@@ -149,7 +149,11 @@ fn insert_txouts() {
|
||||
ChangeSet {
|
||||
txs: [Arc::new(update_txs.clone())].into(),
|
||||
txouts: update_ops.clone().into(),
|
||||
anchors: [(conf_anchor, update_txs.txid()), (unconf_anchor, h!("tx2"))].into(),
|
||||
anchors: [
|
||||
(conf_anchor, update_txs.compute_txid()),
|
||||
(unconf_anchor, h!("tx2"))
|
||||
]
|
||||
.into(),
|
||||
last_seen: [(h!("tx2"), 1000000)].into()
|
||||
}
|
||||
);
|
||||
@@ -183,7 +187,9 @@ fn insert_txouts() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
graph.tx_outputs(update_txs.txid()).expect("should exists"),
|
||||
graph
|
||||
.tx_outputs(update_txs.compute_txid())
|
||||
.expect("should exists"),
|
||||
[(
|
||||
0u32,
|
||||
&TxOut {
|
||||
@@ -200,7 +206,11 @@ fn insert_txouts() {
|
||||
ChangeSet {
|
||||
txs: [Arc::new(update_txs.clone())].into(),
|
||||
txouts: update_ops.into_iter().chain(original_ops).collect(),
|
||||
anchors: [(conf_anchor, update_txs.txid()), (unconf_anchor, h!("tx2"))].into(),
|
||||
anchors: [
|
||||
(conf_anchor, update_txs.compute_txid()),
|
||||
(unconf_anchor, h!("tx2"))
|
||||
]
|
||||
.into(),
|
||||
last_seen: [(h!("tx2"), 1000000)].into()
|
||||
}
|
||||
);
|
||||
@@ -235,7 +245,7 @@ fn insert_tx_graph_keeps_track_of_spend() {
|
||||
};
|
||||
|
||||
let op = OutPoint {
|
||||
txid: tx1.txid(),
|
||||
txid: tx1.compute_txid(),
|
||||
vout: 0,
|
||||
};
|
||||
|
||||
@@ -261,7 +271,7 @@ fn insert_tx_graph_keeps_track_of_spend() {
|
||||
|
||||
assert_eq!(
|
||||
graph1.outspends(op),
|
||||
&iter::once(tx2.txid()).collect::<HashSet<_>>()
|
||||
&iter::once(tx2.compute_txid()).collect::<HashSet<_>>()
|
||||
);
|
||||
assert_eq!(graph2.outspends(op), graph1.outspends(op));
|
||||
}
|
||||
@@ -281,7 +291,9 @@ fn insert_tx_can_retrieve_full_tx_from_graph() {
|
||||
let mut graph = TxGraph::<()>::default();
|
||||
let _ = graph.insert_tx(tx.clone());
|
||||
assert_eq!(
|
||||
graph.get_tx(tx.txid()).map(|tx| tx.as_ref().clone()),
|
||||
graph
|
||||
.get_tx(tx.compute_txid())
|
||||
.map(|tx| tx.as_ref().clone()),
|
||||
Some(tx)
|
||||
);
|
||||
}
|
||||
@@ -301,7 +313,7 @@ fn insert_tx_displaces_txouts() {
|
||||
|
||||
let changeset = tx_graph.insert_txout(
|
||||
OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 0,
|
||||
},
|
||||
TxOut {
|
||||
@@ -314,7 +326,7 @@ fn insert_tx_displaces_txouts() {
|
||||
|
||||
let _ = tx_graph.insert_txout(
|
||||
OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 0,
|
||||
},
|
||||
TxOut {
|
||||
@@ -328,7 +340,7 @@ fn insert_tx_displaces_txouts() {
|
||||
assert_eq!(
|
||||
tx_graph
|
||||
.get_txout(OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 0
|
||||
})
|
||||
.unwrap()
|
||||
@@ -337,7 +349,7 @@ fn insert_tx_displaces_txouts() {
|
||||
);
|
||||
assert_eq!(
|
||||
tx_graph.get_txout(OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 1
|
||||
}),
|
||||
None
|
||||
@@ -361,7 +373,7 @@ fn insert_txout_does_not_displace_tx() {
|
||||
|
||||
let _ = tx_graph.insert_txout(
|
||||
OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 0,
|
||||
},
|
||||
TxOut {
|
||||
@@ -372,7 +384,7 @@ fn insert_txout_does_not_displace_tx() {
|
||||
|
||||
let _ = tx_graph.insert_txout(
|
||||
OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 0,
|
||||
},
|
||||
TxOut {
|
||||
@@ -384,7 +396,7 @@ fn insert_txout_does_not_displace_tx() {
|
||||
assert_eq!(
|
||||
tx_graph
|
||||
.get_txout(OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 0
|
||||
})
|
||||
.unwrap()
|
||||
@@ -393,7 +405,7 @@ fn insert_txout_does_not_displace_tx() {
|
||||
);
|
||||
assert_eq!(
|
||||
tx_graph.get_txout(OutPoint {
|
||||
txid: tx.txid(),
|
||||
txid: tx.compute_txid(),
|
||||
vout: 1
|
||||
}),
|
||||
None
|
||||
@@ -443,14 +455,14 @@ fn test_calculate_fee() {
|
||||
input: vec![
|
||||
TxIn {
|
||||
previous_output: OutPoint {
|
||||
txid: intx1.txid(),
|
||||
txid: intx1.compute_txid(),
|
||||
vout: 0,
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
TxIn {
|
||||
previous_output: OutPoint {
|
||||
txid: intx2.txid(),
|
||||
txid: intx2.compute_txid(),
|
||||
vout: 0,
|
||||
},
|
||||
..Default::default()
|
||||
@@ -543,7 +555,7 @@ fn test_walk_ancestors() {
|
||||
// tx_b0 spends tx_a0
|
||||
let tx_b0 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_a0.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_a0.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL, TxOut::NULL],
|
||||
@@ -553,7 +565,7 @@ fn test_walk_ancestors() {
|
||||
// tx_b1 spends tx_a0
|
||||
let tx_b1 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_a0.txid(), 1),
|
||||
previous_output: OutPoint::new(tx_a0.compute_txid(), 1),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -572,7 +584,7 @@ fn test_walk_ancestors() {
|
||||
// tx_c0 spends tx_b0
|
||||
let tx_c0 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_b0.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_b0.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -582,7 +594,7 @@ fn test_walk_ancestors() {
|
||||
// tx_c1 spends tx_b0
|
||||
let tx_c1 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_b0.txid(), 1),
|
||||
previous_output: OutPoint::new(tx_b0.compute_txid(), 1),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -593,11 +605,11 @@ fn test_walk_ancestors() {
|
||||
let tx_c2 = Transaction {
|
||||
input: vec![
|
||||
TxIn {
|
||||
previous_output: OutPoint::new(tx_b1.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_b1.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
},
|
||||
TxIn {
|
||||
previous_output: OutPoint::new(tx_b2.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_b2.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
},
|
||||
],
|
||||
@@ -617,7 +629,7 @@ fn test_walk_ancestors() {
|
||||
// tx_d0 spends tx_c1
|
||||
let tx_d0 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_c1.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_c1.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -628,11 +640,11 @@ fn test_walk_ancestors() {
|
||||
let tx_d1 = Transaction {
|
||||
input: vec![
|
||||
TxIn {
|
||||
previous_output: OutPoint::new(tx_c2.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_c2.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
},
|
||||
TxIn {
|
||||
previous_output: OutPoint::new(tx_c3.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_c3.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
},
|
||||
],
|
||||
@@ -643,7 +655,7 @@ fn test_walk_ancestors() {
|
||||
// tx_e0 spends tx_d1
|
||||
let tx_e0 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_d1.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_d1.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -665,7 +677,7 @@ fn test_walk_ancestors() {
|
||||
]);
|
||||
|
||||
[&tx_a0, &tx_b1].iter().for_each(|&tx| {
|
||||
let changeset = graph.insert_anchor(tx.txid(), tip.block_id());
|
||||
let changeset = graph.insert_anchor(tx.compute_txid(), tip.block_id());
|
||||
assert!(!changeset.is_empty());
|
||||
});
|
||||
|
||||
@@ -682,7 +694,7 @@ fn test_walk_ancestors() {
|
||||
// Only traverse unconfirmed ancestors of tx_e0 this time
|
||||
graph
|
||||
.walk_ancestors(tx_e0.clone(), |depth, tx| {
|
||||
let tx_node = graph.get_tx_node(tx.txid())?;
|
||||
let tx_node = graph.get_tx_node(tx.compute_txid())?;
|
||||
for block in tx_node.anchors {
|
||||
match local_chain.is_block_in_chain(block.anchor_block(), tip.block_id()) {
|
||||
Ok(Some(true)) => return None,
|
||||
@@ -746,15 +758,15 @@ fn test_conflicting_descendants() {
|
||||
// tx_b spends tx_a
|
||||
let tx_b = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_a.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_a.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
..common::new_tx(2)
|
||||
};
|
||||
|
||||
let txid_a = tx_a.txid();
|
||||
let txid_b = tx_b.txid();
|
||||
let txid_a = tx_a.compute_txid();
|
||||
let txid_b = tx_b.compute_txid();
|
||||
|
||||
let mut graph = TxGraph::<()>::default();
|
||||
let _ = graph.insert_tx(tx_a);
|
||||
@@ -778,7 +790,7 @@ fn test_descendants_no_repeat() {
|
||||
let txs_b = (0..3)
|
||||
.map(|vout| Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_a.txid(), vout),
|
||||
previous_output: OutPoint::new(tx_a.compute_txid(), vout),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -789,7 +801,7 @@ fn test_descendants_no_repeat() {
|
||||
let txs_c = (0..2)
|
||||
.map(|vout| Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(txs_b[vout as usize].txid(), vout),
|
||||
previous_output: OutPoint::new(txs_b[vout as usize].compute_txid(), vout),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -800,11 +812,11 @@ fn test_descendants_no_repeat() {
|
||||
let tx_d = Transaction {
|
||||
input: vec![
|
||||
TxIn {
|
||||
previous_output: OutPoint::new(txs_c[0].txid(), 0),
|
||||
previous_output: OutPoint::new(txs_c[0].compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
},
|
||||
TxIn {
|
||||
previous_output: OutPoint::new(txs_c[1].txid(), 0),
|
||||
previous_output: OutPoint::new(txs_c[1].compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
},
|
||||
],
|
||||
@@ -814,7 +826,7 @@ fn test_descendants_no_repeat() {
|
||||
|
||||
let tx_e = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_d.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_d.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![TxOut::NULL],
|
||||
@@ -848,11 +860,11 @@ fn test_descendants_no_repeat() {
|
||||
.chain(core::iter::once(&tx_e))
|
||||
{
|
||||
let _ = graph.insert_tx(tx.clone());
|
||||
expected_txids.push(tx.txid());
|
||||
expected_txids.push(tx.compute_txid());
|
||||
}
|
||||
|
||||
let descendants = graph
|
||||
.walk_descendants(tx_a.txid(), |_, txid| Some(txid))
|
||||
.walk_descendants(tx_a.compute_txid(), |_, txid| Some(txid))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(descendants, expected_txids);
|
||||
@@ -888,7 +900,7 @@ fn test_chain_spends() {
|
||||
// The first confirmed transaction spends vout: 0. And is confirmed at block 98.
|
||||
let tx_1 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_0.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_0.compute_txid(), 0),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![
|
||||
@@ -907,7 +919,7 @@ fn test_chain_spends() {
|
||||
// The second transactions spends vout:1, and is unconfirmed.
|
||||
let tx_2 = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_0.txid(), 1),
|
||||
previous_output: OutPoint::new(tx_0.compute_txid(), 1),
|
||||
..TxIn::default()
|
||||
}],
|
||||
output: vec![
|
||||
@@ -931,7 +943,7 @@ fn test_chain_spends() {
|
||||
|
||||
for (ht, tx) in [(95, &tx_0), (98, &tx_1)] {
|
||||
let _ = graph.insert_anchor(
|
||||
tx.txid(),
|
||||
tx.compute_txid(),
|
||||
ConfirmationHeightAnchor {
|
||||
anchor_block: tip.block_id(),
|
||||
confirmation_height: ht,
|
||||
@@ -941,19 +953,23 @@ fn test_chain_spends() {
|
||||
|
||||
// Assert that confirmed spends are returned correctly.
|
||||
assert_eq!(
|
||||
graph.get_chain_spend(&local_chain, tip.block_id(), OutPoint::new(tx_0.txid(), 0)),
|
||||
graph.get_chain_spend(
|
||||
&local_chain,
|
||||
tip.block_id(),
|
||||
OutPoint::new(tx_0.compute_txid(), 0)
|
||||
),
|
||||
Some((
|
||||
ChainPosition::Confirmed(&ConfirmationHeightAnchor {
|
||||
anchor_block: tip.block_id(),
|
||||
confirmation_height: 98
|
||||
}),
|
||||
tx_1.txid(),
|
||||
tx_1.compute_txid(),
|
||||
)),
|
||||
);
|
||||
|
||||
// Check if chain position is returned correctly.
|
||||
assert_eq!(
|
||||
graph.get_chain_position(&local_chain, tip.block_id(), tx_0.txid()),
|
||||
graph.get_chain_position(&local_chain, tip.block_id(), tx_0.compute_txid()),
|
||||
// Some(ObservedAs::Confirmed(&local_chain.get_block(95).expect("block expected"))),
|
||||
Some(ChainPosition::Confirmed(&ConfirmationHeightAnchor {
|
||||
anchor_block: tip.block_id(),
|
||||
@@ -963,25 +979,33 @@ fn test_chain_spends() {
|
||||
|
||||
// Even if unconfirmed tx has a last_seen of 0, it can still be part of a chain spend.
|
||||
assert_eq!(
|
||||
graph.get_chain_spend(&local_chain, tip.block_id(), OutPoint::new(tx_0.txid(), 1)),
|
||||
Some((ChainPosition::Unconfirmed(0), tx_2.txid())),
|
||||
graph.get_chain_spend(
|
||||
&local_chain,
|
||||
tip.block_id(),
|
||||
OutPoint::new(tx_0.compute_txid(), 1)
|
||||
),
|
||||
Some((ChainPosition::Unconfirmed(0), tx_2.compute_txid())),
|
||||
);
|
||||
|
||||
// Mark the unconfirmed as seen and check correct ObservedAs status is returned.
|
||||
let _ = graph.insert_seen_at(tx_2.txid(), 1234567);
|
||||
let _ = graph.insert_seen_at(tx_2.compute_txid(), 1234567);
|
||||
|
||||
// Check chain spend returned correctly.
|
||||
assert_eq!(
|
||||
graph
|
||||
.get_chain_spend(&local_chain, tip.block_id(), OutPoint::new(tx_0.txid(), 1))
|
||||
.get_chain_spend(
|
||||
&local_chain,
|
||||
tip.block_id(),
|
||||
OutPoint::new(tx_0.compute_txid(), 1)
|
||||
)
|
||||
.unwrap(),
|
||||
(ChainPosition::Unconfirmed(1234567), tx_2.txid())
|
||||
(ChainPosition::Unconfirmed(1234567), tx_2.compute_txid())
|
||||
);
|
||||
|
||||
// A conflicting transaction that conflicts with tx_1.
|
||||
let tx_1_conflict = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_0.txid(), 0),
|
||||
previous_output: OutPoint::new(tx_0.compute_txid(), 0),
|
||||
..Default::default()
|
||||
}],
|
||||
..common::new_tx(0)
|
||||
@@ -990,13 +1014,13 @@ fn test_chain_spends() {
|
||||
|
||||
// Because this tx conflicts with an already confirmed transaction, chain position should return none.
|
||||
assert!(graph
|
||||
.get_chain_position(&local_chain, tip.block_id(), tx_1_conflict.txid())
|
||||
.get_chain_position(&local_chain, tip.block_id(), tx_1_conflict.compute_txid())
|
||||
.is_none());
|
||||
|
||||
// Another conflicting tx that conflicts with tx_2.
|
||||
let tx_2_conflict = Transaction {
|
||||
input: vec![TxIn {
|
||||
previous_output: OutPoint::new(tx_0.txid(), 1),
|
||||
previous_output: OutPoint::new(tx_0.compute_txid(), 1),
|
||||
..Default::default()
|
||||
}],
|
||||
..common::new_tx(0)
|
||||
@@ -1004,12 +1028,12 @@ fn test_chain_spends() {
|
||||
|
||||
// Insert in graph and mark it as seen.
|
||||
let _ = graph.insert_tx(tx_2_conflict.clone());
|
||||
let _ = graph.insert_seen_at(tx_2_conflict.txid(), 1234568);
|
||||
let _ = graph.insert_seen_at(tx_2_conflict.compute_txid(), 1234568);
|
||||
|
||||
// This should return a valid observation with correct last seen.
|
||||
assert_eq!(
|
||||
graph
|
||||
.get_chain_position(&local_chain, tip.block_id(), tx_2_conflict.txid())
|
||||
.get_chain_position(&local_chain, tip.block_id(), tx_2_conflict.compute_txid())
|
||||
.expect("position expected"),
|
||||
ChainPosition::Unconfirmed(1234568)
|
||||
);
|
||||
@@ -1017,14 +1041,21 @@ fn test_chain_spends() {
|
||||
// Chain_spend now catches the new transaction as the spend.
|
||||
assert_eq!(
|
||||
graph
|
||||
.get_chain_spend(&local_chain, tip.block_id(), OutPoint::new(tx_0.txid(), 1))
|
||||
.get_chain_spend(
|
||||
&local_chain,
|
||||
tip.block_id(),
|
||||
OutPoint::new(tx_0.compute_txid(), 1)
|
||||
)
|
||||
.expect("expect observation"),
|
||||
(ChainPosition::Unconfirmed(1234568), tx_2_conflict.txid())
|
||||
(
|
||||
ChainPosition::Unconfirmed(1234568),
|
||||
tx_2_conflict.compute_txid()
|
||||
)
|
||||
);
|
||||
|
||||
// Chain position of the `tx_2` is now none, as it is older than `tx_2_conflict`
|
||||
assert!(graph
|
||||
.get_chain_position(&local_chain, tip.block_id(), tx_2.txid())
|
||||
.get_chain_position(&local_chain, tip.block_id(), tx_2.compute_txid())
|
||||
.is_none());
|
||||
}
|
||||
|
||||
@@ -1065,7 +1096,7 @@ fn test_changeset_last_seen_append() {
|
||||
fn update_last_seen_unconfirmed() {
|
||||
let mut graph = TxGraph::<()>::default();
|
||||
let tx = new_tx(0);
|
||||
let txid = tx.txid();
|
||||
let txid = tx.compute_txid();
|
||||
|
||||
// insert a new tx
|
||||
// initially we have a last_seen of 0, and no anchors
|
||||
|
||||
Reference in New Issue
Block a user