diff --git a/companion-code/architecture/Cargo.lock b/companion-code/architecture/Cargo.lock index 87f62e4..4218e70 100644 --- a/companion-code/architecture/Cargo.lock +++ b/companion-code/architecture/Cargo.lock @@ -17,9 +17,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bdk" -version = "1.0.0-alpha.4" +version = "1.0.0-alpha.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73aec47ee5d0defa2e668115119312a4ee0c326b930c40701c70e6988547c3b3" +checksum = "21101f7c9d9fb1c3ece2da4e351c5885b4a72ae9a623fd0f6a0791e62fb12ea5" dependencies = [ "bdk_chain", "bitcoin", @@ -33,9 +33,9 @@ dependencies = [ [[package]] name = "bdk_chain" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24e125be9484902261ce85c0074958baf8b360893486cb9ce0c513e98bb990d" +checksum = "cbde024deaffc2ad0cf4e88b0bd84409fe03a16e39f579aa7161cff79f491b71" dependencies = [ "bitcoin", "miniscript", diff --git a/companion-code/architecture/Cargo.toml b/companion-code/architecture/Cargo.toml index cf89ecf..f98b11a 100644 --- a/companion-code/architecture/Cargo.toml +++ b/companion-code/architecture/Cargo.toml @@ -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" } diff --git a/companion-code/architecture/src/main.rs b/companion-code/architecture/src/main.rs index 0e51ca2..50dd14f 100644 --- a/companion-code/architecture/src/main.rs +++ b/companion-code/architecture/src/main.rs @@ -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!( @@ -57,8 +64,8 @@ fn local_chain() -> () { (3, Hash::hash("third".as_bytes())), (12, Hash::hash("twelve".as_bytes())), ] - .into_iter() - .collect::>(), + .into_iter() + .collect::>(), ).unwrap(); println!("### Local chain ### \n{:#?}\n", local_chain); @@ -101,8 +108,8 @@ fn anchors() -> () { (2, Hash::hash("second".as_bytes())), (3, Hash::hash("third".as_bytes())), ] - .into_iter() - .collect::>(), + .into_iter() + .collect::>(), ).unwrap(); graph.insert_anchor( @@ -174,8 +181,8 @@ fn changesets() -> () { (2, Hash::hash("second".as_bytes())), (3, Hash::hash("third".as_bytes())), ] - .into_iter() - .collect::>(), + .into_iter() + .collect::>(), ).unwrap(); let other_chain = LocalChain::from_blocks( @@ -184,8 +191,8 @@ fn changesets() -> () { (3, Hash::hash("third".as_bytes())), (5, Hash::hash("fifth".as_bytes())), ] - .into_iter() - .collect::>(), + .into_iter() + .collect::>(), ).unwrap(); let update = Update { @@ -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 = 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::::from_str("wpkh(025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357)", ).unwrap(); + let mut keychain_txout_index = KeychainTxOutIndex::::default(); + let mut keychain_txout_index = KeychainTxOutIndex::::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!(); +} diff --git a/companion-code/descriptors/Cargo.lock b/companion-code/descriptors/Cargo.lock index b334bfb..b165ffd 100644 --- a/companion-code/descriptors/Cargo.lock +++ b/companion-code/descriptors/Cargo.lock @@ -10,9 +10,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bdk" -version = "1.0.0-alpha.4" +version = "1.0.0-alpha.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73aec47ee5d0defa2e668115119312a4ee0c326b930c40701c70e6988547c3b3" +checksum = "21101f7c9d9fb1c3ece2da4e351c5885b4a72ae9a623fd0f6a0791e62fb12ea5" dependencies = [ "bdk_chain", "bitcoin", @@ -26,9 +26,9 @@ dependencies = [ [[package]] name = "bdk_chain" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24e125be9484902261ce85c0074958baf8b360893486cb9ce0c513e98bb990d" +checksum = "cbde024deaffc2ad0cf4e88b0bd84409fe03a16e39f579aa7161cff79f491b71" dependencies = [ "bitcoin", "miniscript", diff --git a/companion-code/descriptors/Cargo.toml b/companion-code/descriptors/Cargo.toml index 21598e8..bf9a23b 100644 --- a/companion-code/descriptors/Cargo.toml +++ b/companion-code/descriptors/Cargo.toml @@ -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" } diff --git a/companion-code/electrum/Cargo.lock b/companion-code/electrum/Cargo.lock index f081e98..ad6c60c 100644 --- a/companion-code/electrum/Cargo.lock +++ b/companion-code/electrum/Cargo.lock @@ -10,9 +10,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bdk" -version = "1.0.0-alpha.4" +version = "1.0.0-alpha.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73aec47ee5d0defa2e668115119312a4ee0c326b930c40701c70e6988547c3b3" +checksum = "21101f7c9d9fb1c3ece2da4e351c5885b4a72ae9a623fd0f6a0791e62fb12ea5" dependencies = [ "bdk_chain", "bitcoin", @@ -26,9 +26,9 @@ dependencies = [ [[package]] name = "bdk_chain" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24e125be9484902261ce85c0074958baf8b360893486cb9ce0c513e98bb990d" +checksum = "cbde024deaffc2ad0cf4e88b0bd84409fe03a16e39f579aa7161cff79f491b71" dependencies = [ "bitcoin", "miniscript", @@ -37,9 +37,9 @@ dependencies = [ [[package]] name = "bdk_electrum" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cf0a2291975e43c5d9d54e82a37f1223393f09678af1d5a47f29102d8e37452" +checksum = "06513112a7cc09c36cfe14e10bfddb0d26df284597da8d67066a1b7d05eee22d" dependencies = [ "bdk_chain", "electrum-client", @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "bdk_file_store" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e6238714cae8872338278de96d53a7252839007ef8149fe327ffd8cc164e236" +checksum = "88de9104b92ec18c65fd1579abc9f17a115a61f0ac8800ceda83d1db90f9ca23" dependencies = [ "bdk_chain", "bincode", diff --git a/companion-code/electrum/Cargo.toml b/companion-code/electrum/Cargo.toml index f995d0a..cb85f45 100644 --- a/companion-code/electrum/Cargo.toml +++ b/companion-code/electrum/Cargo.toml @@ -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" } diff --git a/companion-code/esplora/Cargo.lock b/companion-code/esplora/Cargo.lock index 47a47bb..4ddc434 100644 --- a/companion-code/esplora/Cargo.lock +++ b/companion-code/esplora/Cargo.lock @@ -63,9 +63,9 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bdk" -version = "1.0.0-alpha.4" +version = "1.0.0-alpha.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73aec47ee5d0defa2e668115119312a4ee0c326b930c40701c70e6988547c3b3" +checksum = "21101f7c9d9fb1c3ece2da4e351c5885b4a72ae9a623fd0f6a0791e62fb12ea5" dependencies = [ "bdk_chain", "bitcoin", @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "bdk_chain" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24e125be9484902261ce85c0074958baf8b360893486cb9ce0c513e98bb990d" +checksum = "cbde024deaffc2ad0cf4e88b0bd84409fe03a16e39f579aa7161cff79f491b71" dependencies = [ "bitcoin", "miniscript", @@ -90,9 +90,9 @@ dependencies = [ [[package]] name = "bdk_esplora" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45bd6eb826b533270bdfb507dfb927b1393cfdbb2e59f536489b8becd33ac8d2" +checksum = "a0208259118f26aaf6b598c8c6d89a2d03c6fa3dd97ebc29e4192e83e4ad4257" dependencies = [ "async-trait", "bdk_chain", @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "bdk_file_store" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e6238714cae8872338278de96d53a7252839007ef8149fe327ffd8cc164e236" +checksum = "88de9104b92ec18c65fd1579abc9f17a115a61f0ac8800ceda83d1db90f9ca23" dependencies = [ "bdk_chain", "bincode", diff --git a/companion-code/esplora/Cargo.toml b/companion-code/esplora/Cargo.toml index 97c88e8..86d53d2 100644 --- a/companion-code/esplora/Cargo.toml +++ b/companion-code/esplora/Cargo.toml @@ -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" } diff --git a/docs/book/electrum-wallet.md b/docs/book/electrum-wallet.md index aa10ab5..d03f357 100644 --- a/docs/book/electrum-wallet.md +++ b/docs/book/electrum-wallet.md @@ -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 diff --git a/docs/book/esplora-wallet.md b/docs/book/esplora-wallet.md index 2acb632..2085b91 100644 --- a/docs/book/esplora-wallet.md +++ b/docs/book/esplora-wallet.md @@ -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 diff --git a/docs/getting-started/getting-started.md b/docs/getting-started/getting-started.md index 334fbc3..ef08412 100644 --- a/docs/getting-started/getting-started.md +++ b/docs/getting-started/getting-started.md @@ -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.