Skip to content

Commit 1c3cbef

Browse files
committed
[chain_redesign] Remove old structures
Other changes: * The `async-https` feature of `bdk_esplora` is no longer default. * Rename `ObservedAs` to `ChainPosition`. * Set temporary MSRV to 1.60.0 to compile all workspace members will all features.
1 parent 5860704 commit 1c3cbef

File tree

48 files changed

+306
-7157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+306
-7157
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ members = [
44
"crates/chain",
55
"crates/file_store",
66
"crates/electrum",
7+
"crates/esplora",
78
"example-crates/example_cli",
89
"example-crates/example_electrum",
9-
"example-crates/keychain_tracker_electrum",
10-
"example-crates/keychain_tracker_esplora",
11-
"example-crates/keychain_tracker_example_cli",
1210
"example-crates/wallet_electrum",
1311
"example-crates/wallet_esplora",
1412
"example-crates/wallet_esplora_async",

crates/bdk/src/wallet/export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ impl FullyNodedExport {
130130
.transactions()
131131
.next()
132132
.map_or(0, |canonical_tx| match canonical_tx.observed_as {
133-
bdk_chain::ObservedAs::Confirmed(a) => a.confirmation_height,
134-
bdk_chain::ObservedAs::Unconfirmed(_) => 0,
133+
bdk_chain::ChainPosition::Confirmed(a) => a.confirmation_height,
134+
bdk_chain::ChainPosition::Unconfirmed(_) => 0,
135135
})
136136
} else {
137137
0

crates/bdk/src/wallet/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bdk_chain::{
2525
keychain::{KeychainTxOutIndex, LocalChangeSet, LocalUpdate},
2626
local_chain::{self, LocalChain, UpdateNotConnectedError},
2727
tx_graph::{CanonicalTx, TxGraph},
28-
Append, BlockId, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut, ObservedAs, Persist,
28+
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut, Persist,
2929
PersistBackend,
3030
};
3131
use bitcoin::consensus::encode::serialize;
@@ -1015,7 +1015,7 @@ impl<D> Wallet<D> {
10151015
let pos = graph
10161016
.get_chain_position(&self.chain, chain_tip, txid)
10171017
.ok_or(Error::TransactionNotFound)?;
1018-
if let ObservedAs::Confirmed(_) = pos {
1018+
if let ChainPosition::Confirmed(_) = pos {
10191019
return Err(Error::TransactionConfirmed);
10201020
}
10211021

@@ -1258,8 +1258,8 @@ impl<D> Wallet<D> {
12581258
.graph()
12591259
.get_chain_position(&self.chain, chain_tip, input.previous_output.txid)
12601260
.map(|observed_as| match observed_as {
1261-
ObservedAs::Confirmed(a) => a.confirmation_height,
1262-
ObservedAs::Unconfirmed(_) => u32::MAX,
1261+
ChainPosition::Confirmed(a) => a.confirmation_height,
1262+
ChainPosition::Unconfirmed(_) => u32::MAX,
12631263
});
12641264
let current_height = sign_options
12651265
.assume_height
@@ -1775,7 +1775,7 @@ where
17751775
fn new_local_utxo(
17761776
keychain: KeychainKind,
17771777
derivation_index: u32,
1778-
full_txo: FullTxOut<ObservedAs<ConfirmationTimeAnchor>>,
1778+
full_txo: FullTxOut<ConfirmationTimeAnchor>,
17791779
) -> LocalUtxo {
17801780
LocalUtxo {
17811781
outpoint: full_txo.outpoint,

crates/bdk/tests/wallet.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use bdk::Error;
88
use bdk::FeeRate;
99
use bdk::KeychainKind;
1010
use bdk_chain::BlockId;
11+
use bdk_chain::ConfirmationTime;
1112
use bdk_chain::COINBASE_MATURITY;
12-
use bdk_chain::{ConfirmationTime, TxHeight};
1313
use bitcoin::hashes::Hash;
1414
use bitcoin::BlockHash;
1515
use bitcoin::Script;
@@ -23,7 +23,7 @@ use core::str::FromStr;
2323
mod common;
2424
use common::*;
2525

26-
fn receive_output(wallet: &mut Wallet, value: u64, height: TxHeight) -> OutPoint {
26+
fn receive_output(wallet: &mut Wallet, value: u64, height: ConfirmationTime) -> OutPoint {
2727
let tx = Transaction {
2828
version: 1,
2929
lock_time: PackedLockTime(0),
@@ -34,18 +34,7 @@ fn receive_output(wallet: &mut Wallet, value: u64, height: TxHeight) -> OutPoint
3434
}],
3535
};
3636

37-
wallet
38-
.insert_tx(
39-
tx.clone(),
40-
match height {
41-
TxHeight::Confirmed(height) => ConfirmationTime::Confirmed {
42-
height,
43-
time: 42_000,
44-
},
45-
TxHeight::Unconfirmed => ConfirmationTime::Unconfirmed { last_seen: 0 },
46-
},
47-
)
48-
.unwrap();
37+
wallet.insert_tx(tx.clone(), height).unwrap();
4938

5039
OutPoint {
5140
txid: tx.txid(),
@@ -54,7 +43,10 @@ fn receive_output(wallet: &mut Wallet, value: u64, height: TxHeight) -> OutPoint
5443
}
5544

5645
fn receive_output_in_latest_block(wallet: &mut Wallet, value: u64) -> OutPoint {
57-
let height = wallet.latest_checkpoint().map(|id| id.height).into();
46+
let height = match wallet.latest_checkpoint() {
47+
Some(BlockId { height, .. }) => ConfirmationTime::Confirmed { height, time: 0 },
48+
None => ConfirmationTime::Unconfirmed { last_seen: 0 },
49+
};
5850
receive_output(wallet, value, height)
5951
}
6052

@@ -1941,7 +1933,11 @@ fn test_bump_fee_unconfirmed_inputs_only() {
19411933
let (psbt, __details) = builder.finish().unwrap();
19421934
// Now we receive one transaction with 0 confirmations. We won't be able to use that for
19431935
// fee bumping, as it's still unconfirmed!
1944-
receive_output(&mut wallet, 25_000, TxHeight::Unconfirmed);
1936+
receive_output(
1937+
&mut wallet,
1938+
25_000,
1939+
ConfirmationTime::Unconfirmed { last_seen: 0 },
1940+
);
19451941
let mut tx = psbt.extract_tx();
19461942
let txid = tx.txid();
19471943
for txin in &mut tx.input {
@@ -1966,7 +1962,7 @@ fn test_bump_fee_unconfirmed_input() {
19661962
let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX").unwrap();
19671963
// We receive a tx with 0 confirmations, which will be used as an input
19681964
// in the drain tx.
1969-
receive_output(&mut wallet, 25_000, TxHeight::Unconfirmed);
1965+
receive_output(&mut wallet, 25_000, ConfirmationTime::unconfirmed(0));
19701966
let mut builder = wallet.build_tx();
19711967
builder
19721968
.drain_wallet()

0 commit comments

Comments
 (0)