Skip to content

Commit

Permalink
chore: update book to alpha 5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jan 31, 2024
1 parent cf8ebf1 commit 500b1ba
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 57 deletions.
8 changes: 4 additions & 4 deletions companion-code/architecture/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion companion-code/architecture/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bdk = { version = "=1.0.0-alpha.4" }
bdk = { version = "=1.0.0-alpha.5" }
92 changes: 76 additions & 16 deletions companion-code/architecture/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@ use bdk::chain::bitcoin::{BlockHash, Transaction};
use bdk::chain::example_utils::tx_from_hex;
use bdk::chain::local_chain::{LocalChain, Update};
use bdk::chain::local_chain::CheckPoint;
use bdk::chain::{BlockId, ConfirmationTimeHeightAnchor, TxGraph};
use bdk::chain::{BlockId, ConfirmationTimeHeightAnchor, SpkTxOutIndex, TxGraph};

use bdk::bitcoin::Network;
use bdk::Wallet;
use bdk::bitcoin::{absolute, Network, TxOut};
use bdk::bitcoin::ScriptBuf;
use bdk::{KeychainKind, Wallet};
use std::collections::BTreeMap;
use std::str::FromStr;
use bdk::chain::indexed_tx_graph::Indexer;
use bdk::chain::keychain::KeychainTxOutIndex;
use bdk::descriptor::Descriptor;
use bdk::keys::{DescriptorPublicKey};

fn main() -> () {
// checkpoints();
// local_chain();
// anchors();
// updates();
checkpoints();
local_chain();
anchors();
updates();
changesets();
indexers();
}

fn checkpoints() -> () {
let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdRvpdnGWLRrcEkQzdxBanKRFLucEZ2NopN8KFB4ir8hzht33JKFj4WmKwdW4qCbePqHK8gm1cDU6BBTkmGjUhpFWjyr7M1Z/84'/1'/0'/0/*)";

let mut wallet = Wallet::new_or_load(external_descriptor, None, (), Network::Testnet).unwrap();
let wallet = Wallet::new_or_load(external_descriptor, None, (), Network::Testnet).unwrap();

let genesis_block_checkpoint: CheckPoint = wallet.latest_checkpoint();
println!(
Expand Down Expand Up @@ -57,8 +64,8 @@ fn local_chain() -> () {
(3, Hash::hash("third".as_bytes())),
(12, Hash::hash("twelve".as_bytes())),
]
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
).unwrap();

println!("### Local chain ### \n{:#?}\n", local_chain);
Expand Down Expand Up @@ -101,8 +108,8 @@ fn anchors() -> () {
(2, Hash::hash("second".as_bytes())),
(3, Hash::hash("third".as_bytes())),
]
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
).unwrap();

graph.insert_anchor(
Expand Down Expand Up @@ -174,8 +181,8 @@ fn changesets() -> () {
(2, Hash::hash("second".as_bytes())),
(3, Hash::hash("third".as_bytes())),
]
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
).unwrap();

let other_chain = LocalChain::from_blocks(
Expand All @@ -184,8 +191,8 @@ fn changesets() -> () {
(3, Hash::hash("third".as_bytes())),
(5, Hash::hash("fifth".as_bytes())),
]
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
.into_iter()
.collect::<BTreeMap<u32, BlockHash>>(),
).unwrap();

let update = Update {
Expand All @@ -198,3 +205,56 @@ fn changesets() -> () {
println!("################ Chain after update #####################\n{:#?}\n", chain);
println!("################ Changeset ##############################\n{:#?}\n", changeset);
}

fn indexers() -> () {
print_page_link(String::from("architecture/indexers/"));

let spk1 = ScriptBuf::from_hex("001404f1e52ce2bab3423c6a8c63b7cd730d8f12542c").unwrap();
let spk2 = ScriptBuf::from_hex("00142b57404ae14f08c3a0c903feb2af7830605eb00f").unwrap();

let mut index: SpkTxOutIndex<i32> = SpkTxOutIndex::default();
index.insert_spk(0, spk1.clone());
index.insert_spk(1, spk2.clone());

println!(
"---------------- SpkTxoutIndex 1 ------------------------- \n{:#?}\n",
index
);

let tx1 = Transaction {
version: 0x02,
lock_time: absolute::LockTime::ZERO,
input: vec![],
output: vec![TxOut {
value: 42_000,
script_pubkey: spk1.clone(),
}],
};

index.index_tx(&tx1);

println!(
"---------------- SpkTxoutIndex 2 ------------------------- \n{:#?}\n",
index
);


let descriptor = Descriptor::<DescriptorPublicKey>::from_str("wpkh(025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357)", ).unwrap();
let mut keychain_txout_index = KeychainTxOutIndex::<KeychainKind>::default();
let mut keychain_txout_index = KeychainTxOutIndex::<KeychainKind>::default();
keychain_txout_index.add_keychain(KeychainKind::External, descriptor);
// keychain_txout_index.add_keychain(KeychainKind::Internal, internal_descriptor);

println!(
"---------------- KeychainTxOutIndex ------------------------- \n{:#?}\n",
keychain_txout_index
);
}

fn print_page_link(link: String) -> () {
println!();
println!("-------------------------------------------------------------------------------------");
println!("Companion code for https://bitcoindevkit.github.io/book-of-bdk/{}", link);
println!("-------------------------------------------------------------------------------------");
println!();
}
8 changes: 4 additions & 4 deletions companion-code/descriptors/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion companion-code/descriptors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bdk = { version = "=1.0.0-alpha.4" }
bdk = { version = "=1.0.0-alpha.5" }
16 changes: 8 additions & 8 deletions companion-code/electrum/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions companion-code/electrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bdk = { version = "=1.0.0-alpha.4" }
bdk_file_store = { version = "=0.4.0" }
bdk_electrum = { version = "=0.6.0" }
bdk = { version = "=1.0.0-alpha.5" }
bdk_file_store = { version = "=0.5.0" }
bdk_electrum = { version = "=0.7.0" }
16 changes: 8 additions & 8 deletions companion-code/esplora/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions companion-code/esplora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bdk = { version = "=1.0.0-alpha.4" }
bdk_file_store = { version = "=0.4.0" }
bdk_esplora = { version = "=0.6.0" }
bdk = { version = "=1.0.0-alpha.5" }
bdk_file_store = { version = "=0.5.0" }
bdk_esplora = { version = "=0.7.0" }
6 changes: 3 additions & 3 deletions docs/book/electrum-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bdk = { version = "=1.0.0-alpha.4" }
bdk_file_store = { version = "=0.4.0" }
bdk_electrum = { version = "=0.6.0" }
bdk = { version = "=1.0.0-alpha.5" }
bdk_file_store = { version = "=0.5.0" }
bdk_electrum = { version = "=0.7.0" }
```

### 3. Create your wallet
Expand Down
6 changes: 3 additions & 3 deletions docs/book/esplora-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bdk = { version = "1.0.0-alpha.4" }
bdk_file_store = { version = "0.4.0" }
bdk_esplora = { version = "0.6.0" }
bdk = { version = "1.0.0-alpha.5" }
bdk_file_store = { version = "0.5.0" }
bdk_esplora = { version = "0.7.0" }
```

### 3. Create your wallet
Expand Down
6 changes: 3 additions & 3 deletions docs/getting-started/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ cd my_bdk_app
2. Add `bdk` to your `Cargo.toml` file. Find the latest `bdk@1` release on [`crates.io`](https://crates.io/crates/bdk/versions), for example:

```shell
cargo add bdk@1.0.0-alpha.4
cargo add bdk@1.0.0-alpha.5
```

3. Add other required dependencies:

```shell
cargo add bdk_esplora@0.6.0
cargo add bdk_file_store@0.4.0
cargo add bdk_esplora@0.7.0
cargo add bdk_file_store@0.5.0
```

See the [Wallet with Electrum Example](../book/electrum-wallet.md) page for how to create and sync a wallet.
Expand Down

0 comments on commit 500b1ba

Please sign in to comment.