Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.1.48.0.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"crates/chain",
"crates/file_store",
]
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ members = [
"nursery/coin_select"
]

[workspace.package]
authors = ["Bitcoin Dev Kit Developers"]
# [workspace.package]
# authors = ["Bitcoin Dev Kit Developers"]
16 changes: 16 additions & 0 deletions build-msrv-crates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh
trap '
signal=$?;
cleanup
exit $signal;
' INT

cleanup() {
mv Cargo.tmp.toml Cargo.toml 2>/dev/null
}

cp Cargo.toml Cargo.tmp.toml
cp Cargo.1.48.0.toml Cargo.toml
cat Cargo.toml
cargo +1.48.0 build --release
cleanup
4 changes: 2 additions & 2 deletions crates/bdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ keywords = ["bitcoin", "wallet", "descriptor", "psbt"]
readme = "README.md"
license = "MIT OR Apache-2.0"
authors = ["Bitcoin Dev Kit Developers"]
edition = "2021"
rust-version = "1.57"
edition = "2018"
# rust-version = "1.57"

[dependencies]
log = "^0.4"
Expand Down
4 changes: 2 additions & 2 deletions crates/bdk/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3050,7 +3050,7 @@ fn test_spend_coinbase() {
builder.finish(),
Err(Error::InsufficientFunds {
needed: _,
available: 0
available: 0,
})
));

Expand All @@ -3063,7 +3063,7 @@ fn test_spend_coinbase() {
builder.finish(),
Err(Error::InsufficientFunds {
needed: _,
available: 0
available: 0,
})
);

Expand Down
5 changes: 3 additions & 2 deletions crates/chain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "bdk_chain"
version = "0.4.0"
edition = "2021"
rust-version = "1.57"
edition = "2018"
# rust-version = "1.48"
homepage = "https://bitcoindevkit.org"
repository = "https://github.com/bitcoindevkit/bdk"
documentation = "https://docs.rs/bdk_chain"
Expand All @@ -28,3 +28,4 @@ rand = "0.8"
default = ["std", "miniscript"]
std = []
serde = ["serde_crate", "bitcoin/serde" ]
doc_include_readme = []
20 changes: 19 additions & 1 deletion crates/chain/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# BDK Chain

BDK keychain tracker, tools for storing and indexing chain data.
This crate is a collection of core structures for [Bitcoin Dev Kit] (alpha release).

The goal of this crate is to give wallets the mechanisms needed to:

1. Figure out what data they need to fetch.
2. Process the data in a way that never leads to inconsistent states.
3. Fully index that data and expose it to be consumed without friction.

Our design goals for these mechanisms are:

1. Data source agnostic -- nothing in `bdk_chain` cares about where you get data from or whether
you do it synchronously or asynchronously. If you know a fact about the blockchain, you can just
tell `bdk_chain`'s APIs about it, and that information will be integrated, if it can be done
consistently.
2. Error-free APIs.
3. Data persistence agnostic -- `bdk_chain` does not care where you cache on-chain data, what you
cache or how you fetch it.

[Bitcoin Dev Kit]: https://bitcoindevkit.org/
2 changes: 1 addition & 1 deletion crates/chain/src/chain_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct ChainGraph<P = TxHeight> {
graph: TxGraph,
}

impl<P> Default for ChainGraph<P> {
impl<P: Ord> Default for ChainGraph<P> {
fn default() -> Self {
Self {
chain: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions crates/chain/src/indexed_tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct IndexedTxGraph<A, I> {
graph: TxGraph<A>,
}

impl<A, I: Default> Default for IndexedTxGraph<A, I> {
impl<A: Ord, I: Default> Default for IndexedTxGraph<A, I> {
fn default() -> Self {
Self {
graph: Default::default(),
Expand All @@ -25,7 +25,7 @@ impl<A, I: Default> Default for IndexedTxGraph<A, I> {
}
}

impl<A, I> IndexedTxGraph<A, I> {
impl<A: Ord, I> IndexedTxGraph<A, I> {
/// Construct a new [`IndexedTxGraph`] with a given `index`.
pub fn new(index: I) -> Self {
Self {
Expand Down Expand Up @@ -183,7 +183,7 @@ pub struct IndexedAdditions<A, IA> {
pub index_additions: IA,
}

impl<A, IA: Default> Default for IndexedAdditions<A, IA> {
impl<A: Ord, IA: Default> Default for IndexedAdditions<A, IA> {
fn default() -> Self {
Self {
graph_additions: Default::default(),
Expand Down
12 changes: 6 additions & 6 deletions crates/chain/src/keychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<K: Ord> Append for DerivationAdditions<K> {
}
}

impl<K> Default for DerivationAdditions<K> {
impl<K: Ord> Default for DerivationAdditions<K> {
fn default() -> Self {
Self(Default::default())
}
Expand All @@ -111,7 +111,7 @@ pub struct KeychainScan<K, P> {
pub last_active_indices: BTreeMap<K, u32>,
}

impl<K, P> Default for KeychainScan<K, P> {
impl<K: Ord, P: Ord> Default for KeychainScan<K, P> {
fn default() -> Self {
Self {
update: Default::default(),
Expand All @@ -120,7 +120,7 @@ impl<K, P> Default for KeychainScan<K, P> {
}
}

impl<K, P> From<ChainGraph<P>> for KeychainScan<K, P> {
impl<K: Ord, P> From<ChainGraph<P>> for KeychainScan<K, P> {
fn from(update: ChainGraph<P>) -> Self {
KeychainScan {
update,
Expand Down Expand Up @@ -152,7 +152,7 @@ pub struct KeychainChangeSet<K, P> {
pub chain_graph: chain_graph::ChangeSet<P>,
}

impl<K, P> Default for KeychainChangeSet<K, P> {
impl<K: Ord, P> Default for KeychainChangeSet<K, P> {
fn default() -> Self {
Self {
chain_graph: Default::default(),
Expand Down Expand Up @@ -182,7 +182,7 @@ impl<K, P> KeychainChangeSet<K, P> {
}
}

impl<K, P> From<chain_graph::ChangeSet<P>> for KeychainChangeSet<K, P> {
impl<K: Ord, P> From<chain_graph::ChangeSet<P>> for KeychainChangeSet<K, P> {
fn from(changeset: chain_graph::ChangeSet<P>) -> Self {
Self {
chain_graph: changeset,
Expand All @@ -191,7 +191,7 @@ impl<K, P> From<chain_graph::ChangeSet<P>> for KeychainChangeSet<K, P> {
}
}

impl<K, P> From<DerivationAdditions<K>> for KeychainChangeSet<K, P> {
impl<K: Ord, P> From<DerivationAdditions<K>> for KeychainChangeSet<K, P> {
fn from(additions: DerivationAdditions<K>) -> Self {
Self {
derivation_indices: additions,
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/keychain/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Persist<K, P, B> {
stage: keychain::KeychainChangeSet<K, P>,
}

impl<K, P, B> Persist<K, P, B> {
impl<K: Ord, P, B> Persist<K, P, B> {
/// Create a new `Persist` from a [`PersistBackend`].
pub fn new(backend: B) -> Self {
Self {
Expand Down
23 changes: 13 additions & 10 deletions crates/chain/src/keychain/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ where
scan: &KeychainScan<K, P>,
) -> Result<KeychainChangeSet<K, P>, chain_graph::UpdateError<P>> {
// TODO: `KeychainTxOutIndex::determine_additions`
let mut derivation_indices = scan.last_active_indices.clone();
derivation_indices.retain(|keychain, index| {
match self.txout_index.last_revealed_index(keychain) {
Some(existing) => *index > existing,
None => true,
}
});
let derivation_indices = scan
.last_active_indices
.iter()
.filter_map(
|(keychain, index)| match self.txout_index.last_revealed_index(keychain) {
Some(existing) if *index <= existing => None,
_ => Some((keychain.clone(), *index)),
},
)
.collect::<BTreeMap<K, u32>>();

Ok(KeychainChangeSet {
derivation_indices: DerivationAdditions(derivation_indices),
Expand Down Expand Up @@ -234,7 +237,7 @@ where
let mut untrusted_pending = 0;
let mut confirmed = 0;
let last_sync_height = self.chain().latest_checkpoint().map(|latest| latest.height);
for ((keychain, _), utxo) in self.full_utxos() {
for (keychain_index, utxo) in self.full_utxos() {
let chain_position = &utxo.chain_position;

match chain_position.height() {
Expand All @@ -253,7 +256,7 @@ where
}
}
TxHeight::Unconfirmed => {
if should_trust(keychain) {
if should_trust(&keychain_index.0) {
trusted_pending += utxo.txout.value;
} else {
untrusted_pending += utxo.txout.value;
Expand All @@ -280,7 +283,7 @@ where
}
}

impl<K, P> Default for KeychainTracker<K, P> {
impl<K: Ord, P: Ord> Default for KeychainTracker<K, P> {
fn default() -> Self {
Self {
txout_index: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/keychain/txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct KeychainTxOutIndex<K> {
lookahead: BTreeMap<K, u32>,
}

impl<K> Default for KeychainTxOutIndex<K> {
impl<K: Ord> Default for KeychainTxOutIndex<K> {
fn default() -> Self {
Self {
inner: SpkTxOutIndex::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/sparse_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<P> AsRef<SparseChain<P>> for SparseChain<P> {
}
}

impl<P> Default for SparseChain<P> {
impl<P: Ord> Default for SparseChain<P> {
fn default() -> Self {
Self {
checkpoints: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/spk_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where
fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.next_index = self
.next_index
.saturating_add(u32::try_from(n).unwrap_or(u32::MAX));
.saturating_add(core::convert::TryFrom::try_from(n).unwrap_or(u32::MAX));
self.next()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/spk_txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct SpkTxOutIndex<I> {
spk_txouts: BTreeSet<(I, OutPoint)>,
}

impl<I> Default for SpkTxOutIndex<I> {
impl<I: Ord> Default for SpkTxOutIndex<I> {
fn default() -> Self {
Self {
txouts: Default::default(),
Expand Down
8 changes: 4 additions & 4 deletions crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct TxGraph<A = ()> {
empty_outspends: HashSet<Txid>,
}

impl<A> Default for TxGraph<A> {
impl<A: Ord> Default for TxGraph<A> {
fn default() -> Self {
Self {
txs: Default::default(),
Expand Down Expand Up @@ -171,7 +171,7 @@ impl<A> TxGraph<A> {
TxNodeInternal::Partial(txouts) => Some(
txouts
.iter()
.map(|(&vout, txout)| (OutPoint::new(*txid, vout), txout)),
.map(move |(&vout, txout)| (OutPoint::new(*txid, vout), txout)),
),
})
.flatten()
Expand Down Expand Up @@ -384,7 +384,7 @@ impl<A: Clone + Ord> TxGraph<A> {
update.txs.insert(
outpoint.txid,
(
TxNodeInternal::Partial([(outpoint.vout, txout)].into()),
TxNodeInternal::Partial(core::iter::once((outpoint.vout, txout)).collect()),
BTreeSet::new(),
0,
),
Expand Down Expand Up @@ -989,7 +989,7 @@ pub struct Additions<A = ()> {
pub last_seen: BTreeMap<Txid, u64>,
}

impl<A> Default for Additions<A> {
impl<A: Ord> Default for Additions<A> {
fn default() -> Self {
Self {
tx: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/electrum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bdk_electrum"
version = "0.2.0"
edition = "2021"
edition = "2018"
homepage = "https://bitcoindevkit.org"
repository = "https://github.com/bitcoindevkit/bdk"
documentation = "https://docs.rs/bdk_electrum"
Expand Down
2 changes: 1 addition & 1 deletion crates/esplora/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bdk_esplora"
version = "0.2.0"
edition = "2021"
edition = "2018"
homepage = "https://bitcoindevkit.org"
repository = "https://github.com/bitcoindevkit/bdk"
documentation = "https://docs.rs/bdk_esplora"
Expand Down
2 changes: 1 addition & 1 deletion crates/file_store/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bdk_file_store"
version = "0.1.0"
edition = "2021"
edition = "2018"
license = "MIT OR Apache-2.0"
repository = "https://github.com/bitcoindevkit/bdk"
documentation = "https://docs.rs/bdk_file_store"
Expand Down
2 changes: 1 addition & 1 deletion example-crates/keychain_tracker_electrum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "keychain_tracker_electrum_example"
version = "0.1.0"
edition = "2021"
edition = "2018"

[dependencies]
bdk_chain = { path = "../../crates/chain", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion example-crates/keychain_tracker_esplora/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "keychain_tracker_esplora_example"
version = "0.1.0"
edition = "2021"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion example-crates/keychain_tracker_example_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "keychain_tracker_example_cli"
version = "0.1.0"
edition = "2021"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion example-crates/wallet_electrum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wallet_electrum_example"
version = "0.1.0"
edition = "2021"
edition = "2018"

[dependencies]
bdk = { path = "../../crates/bdk" }
Expand Down
2 changes: 1 addition & 1 deletion example-crates/wallet_esplora/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bdk-esplora-wallet-example"
version = "0.1.0"
edition = "2021"
edition = "2018"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
Loading