[bdk_chain_redesign] Add ..in_chain methods

Add methods to `TxGraph` and `IndexedTxGraph` that gets in-best-chain
data (such as transactions, txouts, unspent txouts).
This commit is contained in:
志宇
2023-03-26 11:24:30 +08:00
parent 61a8606fbc
commit 43b648fee0
10 changed files with 236 additions and 64 deletions

View File

@@ -7,7 +7,7 @@ use bdk_chain::{
chain_graph::*,
collections::HashSet,
sparse_chain,
tx_graph::{self, GraphedTx, TxGraph},
tx_graph::{self, TxGraph, TxInGraph},
BlockId, TxHeight,
};
use bitcoin::{
@@ -371,7 +371,7 @@ fn test_get_tx_in_chain() {
cg.get_tx_in_chain(tx.txid()),
Some((
&TxHeight::Unconfirmed,
GraphedTx {
TxInGraph {
txid: tx.txid(),
tx: &tx,
anchors: &BTreeSet::new(),
@@ -411,15 +411,15 @@ fn test_iterate_transactions() {
vec![
(
&TxHeight::Confirmed(0),
GraphedTx::from_tx(&txs[2], &BTreeSet::new())
TxInGraph::from_tx(&txs[2], &BTreeSet::new())
),
(
&TxHeight::Confirmed(1),
GraphedTx::from_tx(&txs[0], &BTreeSet::new())
TxInGraph::from_tx(&txs[0], &BTreeSet::new())
),
(
&TxHeight::Unconfirmed,
GraphedTx::from_tx(&txs[1], &BTreeSet::new())
TxInGraph::from_tx(&txs[1], &BTreeSet::new())
),
]
);

View File

@@ -9,7 +9,7 @@ use bdk_chain::{
bitcoin::{secp256k1::Secp256k1, OutPoint, PackedLockTime, Transaction, TxOut},
Descriptor,
},
tx_graph::GraphedTx,
tx_graph::TxInGraph,
BlockId, ConfirmationTime, TxHeight,
};
use bitcoin::{BlockHash, TxIn};
@@ -45,7 +45,7 @@ fn test_insert_tx() {
.collect::<Vec<_>>(),
vec![(
&ConfirmationTime::Unconfirmed,
GraphedTx::from_tx(&tx, &BTreeSet::new())
TxInGraph::from_tx(&tx, &BTreeSet::new())
)]
);

View File

@@ -2,7 +2,7 @@
mod common;
use bdk_chain::{
collections::*,
tx_graph::{Additions, GraphedTx, TxGraph},
tx_graph::{Additions, TxGraph, TxInGraph},
BlockId,
};
use bitcoin::{
@@ -157,7 +157,7 @@ fn insert_tx_can_retrieve_full_tx_from_graph() {
let _ = graph.insert_tx(tx.clone());
assert_eq!(
graph.get_tx(tx.txid()),
Some(GraphedTx::from_tx(&tx, &BTreeSet::new()))
Some(TxInGraph::from_tx(&tx, &BTreeSet::new()))
);
}