Skip to content

Commit e71770f

Browse files
Merge #1206: chore: rename ConfirmationTimeAnchor to ConfirmationTimeHeightAnchor
0112c67 chore: rename `ConfirmationTimeAnchor` to `ConfirmationTimeHeightAnchor` (Wei Chen) Pull request description: ### Description Closes #1187. An `Anchor` implementation that records both height and time should have both attributes included in the name. ### 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: notmandatory: ACK 0112c67 Tree-SHA512: 024cbc83c8aca36baeaf2ce36979d62f235ffea7702e7ac8d4e7669cbc1730f7e1469ba78bf3da6c5a14abedbf1a9e832bdd66fdaa154ad2bef29cb187e1c504
2 parents 298f6cb + 0112c67 commit e71770f

File tree

8 files changed

+54
-45
lines changed

8 files changed

+54
-45
lines changed

crates/bdk/src/wallet/mod.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bdk_chain::{
2525
keychain::{self, KeychainTxOutIndex},
2626
local_chain::{self, CannotConnectError, CheckPoint, CheckPointIter, LocalChain},
2727
tx_graph::{CanonicalTx, TxGraph},
28-
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut,
28+
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeHeightAnchor, FullTxOut,
2929
IndexedTxGraph, Persist, PersistBackend,
3030
};
3131
use bitcoin::consensus::encode::serialize;
@@ -89,7 +89,7 @@ pub struct Wallet<D = ()> {
8989
signers: Arc<SignersContainer>,
9090
change_signers: Arc<SignersContainer>,
9191
chain: LocalChain,
92-
indexed_graph: IndexedTxGraph<ConfirmationTimeAnchor, KeychainTxOutIndex<KeychainKind>>,
92+
indexed_graph: IndexedTxGraph<ConfirmationTimeHeightAnchor, KeychainTxOutIndex<KeychainKind>>,
9393
persist: Persist<D, ChangeSet>,
9494
network: Network,
9595
secp: SecpCtx,
@@ -105,7 +105,7 @@ pub struct Update {
105105
pub last_active_indices: BTreeMap<KeychainKind, u32>,
106106

107107
/// Update for the wallet's internal [`TxGraph`].
108-
pub graph: TxGraph<ConfirmationTimeAnchor>,
108+
pub graph: TxGraph<ConfirmationTimeHeightAnchor>,
109109

110110
/// Update for the wallet's internal [`LocalChain`].
111111
///
@@ -124,8 +124,10 @@ pub struct ChangeSet {
124124
/// Changes to [`IndexedTxGraph`].
125125
///
126126
/// [`IndexedTxGraph`]: bdk_chain::indexed_tx_graph::IndexedTxGraph
127-
pub indexed_tx_graph:
128-
indexed_tx_graph::ChangeSet<ConfirmationTimeAnchor, keychain::ChangeSet<KeychainKind>>,
127+
pub indexed_tx_graph: indexed_tx_graph::ChangeSet<
128+
ConfirmationTimeHeightAnchor,
129+
keychain::ChangeSet<KeychainKind>,
130+
>,
129131
}
130132

131133
impl Append for ChangeSet {
@@ -148,12 +150,17 @@ impl From<local_chain::ChangeSet> for ChangeSet {
148150
}
149151
}
150152

151-
impl From<indexed_tx_graph::ChangeSet<ConfirmationTimeAnchor, keychain::ChangeSet<KeychainKind>>>
152-
for ChangeSet
153+
impl
154+
From<
155+
indexed_tx_graph::ChangeSet<
156+
ConfirmationTimeHeightAnchor,
157+
keychain::ChangeSet<KeychainKind>,
158+
>,
159+
> for ChangeSet
153160
{
154161
fn from(
155162
indexed_tx_graph: indexed_tx_graph::ChangeSet<
156-
ConfirmationTimeAnchor,
163+
ConfirmationTimeHeightAnchor,
157164
keychain::ChangeSet<KeychainKind>,
158165
>,
159166
) -> Self {
@@ -279,8 +286,10 @@ impl<D> Wallet<D> {
279286
{
280287
let secp = Secp256k1::new();
281288
let mut chain = LocalChain::default();
282-
let mut indexed_graph =
283-
IndexedTxGraph::<ConfirmationTimeAnchor, KeychainTxOutIndex<KeychainKind>>::default();
289+
let mut indexed_graph = IndexedTxGraph::<
290+
ConfirmationTimeHeightAnchor,
291+
KeychainTxOutIndex<KeychainKind>,
292+
>::default();
284293

285294
let (descriptor, keymap) = into_wallet_descriptor_checked(descriptor, &secp, network)
286295
.map_err(NewError::Descriptor)?;
@@ -654,7 +663,7 @@ impl<D> Wallet<D> {
654663
pub fn get_tx(
655664
&self,
656665
txid: Txid,
657-
) -> Option<CanonicalTx<'_, Transaction, ConfirmationTimeAnchor>> {
666+
) -> Option<CanonicalTx<'_, Transaction, ConfirmationTimeHeightAnchor>> {
658667
let graph = self.indexed_graph.graph();
659668

660669
Some(CanonicalTx {
@@ -724,7 +733,7 @@ impl<D> Wallet<D> {
724733
tip_height: self.chain.tip().map(|b| b.height()),
725734
tx_height: height,
726735
})
727-
.map(|(&anchor_height, &hash)| ConfirmationTimeAnchor {
736+
.map(|(&anchor_height, &hash)| ConfirmationTimeHeightAnchor {
728737
anchor_block: BlockId {
729738
height: anchor_height,
730739
hash,
@@ -756,7 +765,7 @@ impl<D> Wallet<D> {
756765
/// Iterate over the transactions in the wallet.
757766
pub fn transactions(
758767
&self,
759-
) -> impl Iterator<Item = CanonicalTx<'_, Transaction, ConfirmationTimeAnchor>> + '_ {
768+
) -> impl Iterator<Item = CanonicalTx<'_, Transaction, ConfirmationTimeHeightAnchor>> + '_ {
760769
self.indexed_graph.graph().list_chain_txs(
761770
&self.chain,
762771
self.chain.tip().map(|cp| cp.block_id()).unwrap_or_default(),
@@ -1973,7 +1982,7 @@ impl<D> Wallet<D> {
19731982
}
19741983

19751984
/// Get a reference to the inner [`TxGraph`].
1976-
pub fn tx_graph(&self) -> &TxGraph<ConfirmationTimeAnchor> {
1985+
pub fn tx_graph(&self) -> &TxGraph<ConfirmationTimeHeightAnchor> {
19771986
self.indexed_graph.graph()
19781987
}
19791988

@@ -1988,8 +1997,8 @@ impl<D> Wallet<D> {
19881997
}
19891998
}
19901999

1991-
impl<D> AsRef<bdk_chain::tx_graph::TxGraph<ConfirmationTimeAnchor>> for Wallet<D> {
1992-
fn as_ref(&self) -> &bdk_chain::tx_graph::TxGraph<ConfirmationTimeAnchor> {
2000+
impl<D> AsRef<bdk_chain::tx_graph::TxGraph<ConfirmationTimeHeightAnchor>> for Wallet<D> {
2001+
fn as_ref(&self) -> &bdk_chain::tx_graph::TxGraph<ConfirmationTimeHeightAnchor> {
19932002
self.indexed_graph.graph()
19942003
}
19952004
}
@@ -2028,7 +2037,7 @@ where
20282037
fn new_local_utxo(
20292038
keychain: KeychainKind,
20302039
derivation_index: u32,
2031-
full_txo: FullTxOut<ConfirmationTimeAnchor>,
2040+
full_txo: FullTxOut<ConfirmationTimeHeightAnchor>,
20322041
) -> LocalUtxo {
20332042
LocalUtxo {
20342043
outpoint: full_txo.outpoint,

crates/chain/src/chain_data.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl ConfirmationTime {
7474
}
7575
}
7676

77-
impl From<ChainPosition<ConfirmationTimeAnchor>> for ConfirmationTime {
78-
fn from(observed_as: ChainPosition<ConfirmationTimeAnchor>) -> Self {
77+
impl From<ChainPosition<ConfirmationTimeHeightAnchor>> for ConfirmationTime {
78+
fn from(observed_as: ChainPosition<ConfirmationTimeHeightAnchor>) -> Self {
7979
match observed_as {
8080
ChainPosition::Confirmed(a) => Self::Confirmed {
8181
height: a.confirmation_height,
@@ -193,7 +193,7 @@ impl AnchorFromBlockPosition for ConfirmationHeightAnchor {
193193
derive(serde::Deserialize, serde::Serialize),
194194
serde(crate = "serde_crate")
195195
)]
196-
pub struct ConfirmationTimeAnchor {
196+
pub struct ConfirmationTimeHeightAnchor {
197197
/// The anchor block.
198198
pub anchor_block: BlockId,
199199
/// The confirmation height of the chain data being anchored.
@@ -202,7 +202,7 @@ pub struct ConfirmationTimeAnchor {
202202
pub confirmation_time: u64,
203203
}
204204

205-
impl Anchor for ConfirmationTimeAnchor {
205+
impl Anchor for ConfirmationTimeHeightAnchor {
206206
fn anchor_block(&self) -> BlockId {
207207
self.anchor_block
208208
}
@@ -212,7 +212,7 @@ impl Anchor for ConfirmationTimeAnchor {
212212
}
213213
}
214214

215-
impl AnchorFromBlockPosition for ConfirmationTimeAnchor {
215+
impl AnchorFromBlockPosition for ConfirmationTimeHeightAnchor {
216216
fn from_block_position(block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
217217
Self {
218218
anchor_block: block_id,

crates/electrum/src/electrum_ext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bdk_chain::{
22
bitcoin::{OutPoint, ScriptBuf, Transaction, Txid},
33
local_chain::{self, CheckPoint},
44
tx_graph::{self, TxGraph},
5-
Anchor, BlockId, ConfirmationHeightAnchor, ConfirmationTimeAnchor,
5+
Anchor, BlockId, ConfirmationHeightAnchor, ConfirmationTimeHeightAnchor,
66
};
77
use electrum_client::{Client, ElectrumApi, Error, HeaderNotification};
88
use std::{
@@ -57,7 +57,7 @@ impl RelevantTxids {
5757
}
5858

5959
/// Finalizes [`RelevantTxids`] with `new_txs` and anchors of type
60-
/// [`ConfirmationTimeAnchor`].
60+
/// [`ConfirmationTimeHeightAnchor`].
6161
///
6262
/// **Note:** The confirmation time might not be precisely correct if there has been a reorg.
6363
/// Electrum's API intends that we use the merkle proof API, we should change `bdk_electrum` to
@@ -67,7 +67,7 @@ impl RelevantTxids {
6767
client: &Client,
6868
seen_at: Option<u64>,
6969
missing: Vec<Txid>,
70-
) -> Result<TxGraph<ConfirmationTimeAnchor>, Error> {
70+
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
7171
let graph = self.into_tx_graph(client, seen_at, missing)?;
7272

7373
let relevant_heights = {
@@ -103,7 +103,7 @@ impl RelevantTxids {
103103
.map(|(height_anchor, txid)| {
104104
let confirmation_height = height_anchor.confirmation_height;
105105
let confirmation_time = height_to_time[&confirmation_height];
106-
let time_anchor = ConfirmationTimeAnchor {
106+
let time_anchor = ConfirmationTimeHeightAnchor {
107107
anchor_block: height_anchor.anchor_block,
108108
confirmation_height,
109109
confirmation_time,

crates/esplora/src/async_ext.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bdk_chain::{
44
bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
55
collections::{BTreeMap, BTreeSet},
66
local_chain::{self, CheckPoint},
7-
BlockId, ConfirmationTimeAnchor, TxGraph,
7+
BlockId, ConfirmationTimeHeightAnchor, TxGraph,
88
};
99
use esplora_client::{Error, TxStatus};
1010
use futures::{stream::FuturesOrdered, TryStreamExt};
@@ -40,7 +40,7 @@ pub trait EsploraAsyncExt {
4040
/// indices.
4141
///
4242
/// * `keychain_spks`: keychains that we want to scan transactions for
43-
/// * `txids`: transactions for which we want updated [`ConfirmationTimeAnchor`]s
43+
/// * `txids`: transactions for which we want updated [`ConfirmationTimeHeightAnchor`]s
4444
/// * `outpoints`: transactions associated with these outpoints (residing, spending) that we
4545
/// want to include in the update
4646
///
@@ -58,7 +58,7 @@ pub trait EsploraAsyncExt {
5858
outpoints: impl IntoIterator<IntoIter = impl Iterator<Item = OutPoint> + Send> + Send,
5959
stop_gap: usize,
6060
parallel_requests: usize,
61-
) -> Result<(TxGraph<ConfirmationTimeAnchor>, BTreeMap<K, u32>), Error>;
61+
) -> Result<(TxGraph<ConfirmationTimeHeightAnchor>, BTreeMap<K, u32>), Error>;
6262

6363
/// Convenience method to call [`scan_txs_with_keychains`] without requiring a keychain.
6464
///
@@ -70,7 +70,7 @@ pub trait EsploraAsyncExt {
7070
txids: impl IntoIterator<IntoIter = impl Iterator<Item = Txid> + Send> + Send,
7171
outpoints: impl IntoIterator<IntoIter = impl Iterator<Item = OutPoint> + Send> + Send,
7272
parallel_requests: usize,
73-
) -> Result<TxGraph<ConfirmationTimeAnchor>, Error> {
73+
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
7474
self.scan_txs_with_keychains(
7575
[(
7676
(),
@@ -211,10 +211,10 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
211211
outpoints: impl IntoIterator<IntoIter = impl Iterator<Item = OutPoint> + Send> + Send,
212212
stop_gap: usize,
213213
parallel_requests: usize,
214-
) -> Result<(TxGraph<ConfirmationTimeAnchor>, BTreeMap<K, u32>), Error> {
214+
) -> Result<(TxGraph<ConfirmationTimeHeightAnchor>, BTreeMap<K, u32>), Error> {
215215
type TxsOfSpkIndex = (u32, Vec<esplora_client::Tx>);
216216
let parallel_requests = Ord::max(parallel_requests, 1);
217-
let mut graph = TxGraph::<ConfirmationTimeAnchor>::default();
217+
let mut graph = TxGraph::<ConfirmationTimeHeightAnchor>::default();
218218
let mut last_active_indexes = BTreeMap::<K, u32>::new();
219219

220220
for (keychain, spks) in keychain_spks {

crates/esplora/src/blocking_ext.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bdk_chain::collections::{BTreeMap, BTreeSet};
55
use bdk_chain::{
66
bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
77
local_chain::{self, CheckPoint},
8-
BlockId, ConfirmationTimeAnchor, TxGraph,
8+
BlockId, ConfirmationTimeHeightAnchor, TxGraph,
99
};
1010
use esplora_client::{Error, TxStatus};
1111

@@ -38,7 +38,7 @@ pub trait EsploraExt {
3838
/// indices.
3939
///
4040
/// * `keychain_spks`: keychains that we want to scan transactions for
41-
/// * `txids`: transactions for which we want updated [`ConfirmationTimeAnchor`]s
41+
/// * `txids`: transactions for which we want updated [`ConfirmationTimeHeightAnchor`]s
4242
/// * `outpoints`: transactions associated with these outpoints (residing, spending) that we
4343
/// want to include in the update
4444
///
@@ -53,7 +53,7 @@ pub trait EsploraExt {
5353
outpoints: impl IntoIterator<Item = OutPoint>,
5454
stop_gap: usize,
5555
parallel_requests: usize,
56-
) -> Result<(TxGraph<ConfirmationTimeAnchor>, BTreeMap<K, u32>), Error>;
56+
) -> Result<(TxGraph<ConfirmationTimeHeightAnchor>, BTreeMap<K, u32>), Error>;
5757

5858
/// Convenience method to call [`scan_txs_with_keychains`] without requiring a keychain.
5959
///
@@ -65,7 +65,7 @@ pub trait EsploraExt {
6565
txids: impl IntoIterator<Item = Txid>,
6666
outpoints: impl IntoIterator<Item = OutPoint>,
6767
parallel_requests: usize,
68-
) -> Result<TxGraph<ConfirmationTimeAnchor>, Error> {
68+
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
6969
self.scan_txs_with_keychains(
7070
[(
7171
(),
@@ -199,10 +199,10 @@ impl EsploraExt for esplora_client::BlockingClient {
199199
outpoints: impl IntoIterator<Item = OutPoint>,
200200
stop_gap: usize,
201201
parallel_requests: usize,
202-
) -> Result<(TxGraph<ConfirmationTimeAnchor>, BTreeMap<K, u32>), Error> {
202+
) -> Result<(TxGraph<ConfirmationTimeHeightAnchor>, BTreeMap<K, u32>), Error> {
203203
type TxsOfSpkIndex = (u32, Vec<esplora_client::Tx>);
204204
let parallel_requests = Ord::max(parallel_requests, 1);
205-
let mut graph = TxGraph::<ConfirmationTimeAnchor>::default();
205+
let mut graph = TxGraph::<ConfirmationTimeHeightAnchor>::default();
206206
let mut last_active_indexes = BTreeMap::<K, u32>::new();
207207

208208
for (keychain, spks) in keychain_spks {

crates/esplora/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![doc = include_str!("../README.md")]
2-
use bdk_chain::{BlockId, ConfirmationTimeAnchor};
2+
use bdk_chain::{BlockId, ConfirmationTimeHeightAnchor};
33
use esplora_client::TxStatus;
44

55
pub use esplora_client;
@@ -16,15 +16,15 @@ pub use async_ext::*;
1616

1717
const ASSUME_FINAL_DEPTH: u32 = 15;
1818

19-
fn anchor_from_status(status: &TxStatus) -> Option<ConfirmationTimeAnchor> {
19+
fn anchor_from_status(status: &TxStatus) -> Option<ConfirmationTimeHeightAnchor> {
2020
if let TxStatus {
2121
block_height: Some(height),
2222
block_hash: Some(hash),
2323
block_time: Some(time),
2424
..
2525
} = status.clone()
2626
{
27-
Some(ConfirmationTimeAnchor {
27+
Some(ConfirmationTimeHeightAnchor {
2828
anchor_block: BlockId { height, hash },
2929
confirmation_height: height,
3030
confirmation_time: time,

example-crates/example_bitcoind_rpc_polling/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bdk_chain::{
1515
bitcoin::{Block, Transaction},
1616
indexed_tx_graph, keychain,
1717
local_chain::{self, CheckPoint, LocalChain},
18-
ConfirmationTimeAnchor, IndexedTxGraph,
18+
ConfirmationTimeHeightAnchor, IndexedTxGraph,
1919
};
2020
use example_cli::{
2121
anyhow,
@@ -37,7 +37,7 @@ const DB_COMMIT_DELAY: Duration = Duration::from_secs(60);
3737

3838
type ChangeSet = (
3939
local_chain::ChangeSet,
40-
indexed_tx_graph::ChangeSet<ConfirmationTimeAnchor, keychain::ChangeSet<Keychain>>,
40+
indexed_tx_graph::ChangeSet<ConfirmationTimeHeightAnchor, keychain::ChangeSet<Keychain>>,
4141
);
4242

4343
#[derive(Debug)]

example-crates/example_esplora/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bdk_chain::{
99
indexed_tx_graph::{self, IndexedTxGraph},
1010
keychain,
1111
local_chain::{self, CheckPoint, LocalChain},
12-
Append, ConfirmationTimeAnchor,
12+
Append, ConfirmationTimeHeightAnchor,
1313
};
1414

1515
use bdk_esplora::{esplora_client, EsploraExt};
@@ -25,7 +25,7 @@ const DB_PATH: &str = ".bdk_esplora_example.db";
2525

2626
type ChangeSet = (
2727
local_chain::ChangeSet,
28-
indexed_tx_graph::ChangeSet<ConfirmationTimeAnchor, keychain::ChangeSet<Keychain>>,
28+
indexed_tx_graph::ChangeSet<ConfirmationTimeHeightAnchor, keychain::ChangeSet<Keychain>>,
2929
);
3030

3131
#[derive(Subcommand, Debug, Clone)]

0 commit comments

Comments
 (0)