-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: delete basics.md, wip new full-wallet example
- Loading branch information
1 parent
82624dd
commit 413c4cf
Showing
12 changed files
with
202 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [ | ||
"examples/descriptors/Cargo.toml", | ||
"examples/rust/quickstart/Cargo.toml" | ||
"examples/rust/quickstart/Cargo.toml", | ||
"examples/rust/full-wallet/Cargo.toml" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
// for jvm | ||
implementation 'org.bitcoindevkit:bdk-jvm:<version>' | ||
// OR for android | ||
implementation 'org.bitcoindevkit:bdk-android:<version>' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// --8<-- [start:file] | ||
|
||
val mnemonic = Mnemonic(WordCount.WORDS12) | ||
val secretKey = DescriptorSecretKey( | ||
Network.SIGNET, | ||
mnemonic, | ||
null | ||
) | ||
|
||
val descriptor = Descriptor.newBip86( | ||
descriptorSecretKey, | ||
KeychainKind.EXTERNAL, | ||
Network.SIGNET | ||
) | ||
val changeDescriptor = Descriptor.newBip86( | ||
secretKey, | ||
KeychainKind.INTERNAL, | ||
Network.SIGNET | ||
) | ||
|
||
val wallet = Wallet( | ||
descriptor, | ||
changeDescriptor, | ||
Network.SIGNET | ||
) | ||
|
||
val addressInfo = wallet.revealNextAddress(KeychainKind.EXTERNAL) | ||
|
||
|
||
// --8<-- [start:client] | ||
val esploraClient: EsploraClient = EsploraClient("https://mutinynet.com/api") | ||
// --8<-- [end:client] | ||
|
||
// --8<-- [start:scan] | ||
val syncRequest = wallet.startSyncWithRevealedSpks() | ||
val update = try esploraClient.sync( | ||
syncRequest, | ||
5uL | ||
) | ||
wallet.applyUpdate(update) | ||
val balance = wallet.balance() | ||
// --8<-- [end:scan] | ||
|
||
// TODO: tx build + broadcast, recovery, storage, etc. | ||
|
||
// --8<-- [end:file] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "full-wallet" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bdk_wallet = { version = "=1.0.0-beta.5", features = ["keys-bip39"] } | ||
bdk_esplora = { version = "=0.19.0", features = ["blocking"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// detailed documentation for this code can be found at https://bitcoindevkit.github.io/book-of-bdk/cookbook/starter/ | ||
// --8<-- [start:file] | ||
use bdk_wallet::AddressInfo; | ||
use bdk_wallet::KeychainKind; | ||
use bdk_wallet::bitcoin::Network; | ||
use bdk_wallet::Wallet; | ||
use bdk_esplora::EsploraExt; | ||
use bdk_esplora::esplora_client::Builder; | ||
use bdk_esplora::esplora_client; | ||
use bdk_wallet::chain::spk_client::{FullScanRequestBuilder, FullScanResult}; | ||
use bdk_wallet::keys::bip39::{Language, Mnemonic, WordCount}; | ||
use bdk_wallet::keys::{GeneratedKey, GeneratableKey}; | ||
use bdk_wallet::miniscript::Tap; | ||
use bdk_wallet::bitcoin::bip32::Xpriv; | ||
use bdk_wallet::template::{Bip86, DescriptorTemplate}; | ||
|
||
const STOP_GAP: usize = 50; | ||
const PARALLEL_REQUESTS: usize = 1; | ||
|
||
|
||
fn main() -> () { | ||
|
||
let mnemonic: GeneratedKey<_, Tap> = | ||
Mnemonic::generate((WordCount::Words12, Language::English)) | ||
.expect("Failed to generate mnemonic"); | ||
println!("generated Seed Words:"); | ||
println!("{}", mnemonic.to_string()); | ||
println!("save these to recover your wallet later"); | ||
|
||
let seed = mnemonic.to_seed(""); | ||
let xprv: Xpriv = | ||
Xpriv::new_master(Network::Signet, &seed).expect("Failed to create master key"); | ||
println!("created Master Private Key:"); | ||
println!("{}", xprv); | ||
|
||
let (descriptor, _key_map, _) = Bip86(xprv, KeychainKind::External) | ||
.build(Network::Signet) | ||
.expect("Failed to build external descriptor"); | ||
println!("external descriptor: {}", descriptor); | ||
|
||
let (change_descriptor, _change_key_map, _) = Bip86(xprv, KeychainKind::Internal) | ||
.build(Network::Signet) | ||
.expect("Failed to build internal descriptor"); | ||
println!("internal descriptor: {}", change_descriptor); | ||
|
||
// Create the wallet | ||
let mut wallet: Wallet = Wallet::create(descriptor, change_descriptor) | ||
.network(Network::Signet) | ||
.create_wallet_no_persist() | ||
.unwrap(); | ||
|
||
// Reveal a new address from your external keychain | ||
// doing this just to show it is an HD wallet | ||
let address: AddressInfo = wallet.reveal_next_address(KeychainKind::External); | ||
println!("Generated address {} at index {}", address.address, address.index); | ||
|
||
// Sync the wallet | ||
// --8<-- [start:client] | ||
let client: esplora_client::BlockingClient = Builder::new("http://signet.bitcoindevkit.net").build_blocking(); | ||
// --8<-- [end:client] | ||
|
||
// --8<-- [start:scan] | ||
let full_scan_request: FullScanRequestBuilder<KeychainKind> = wallet.start_full_scan(); | ||
let update: FullScanResult<KeychainKind> = client.full_scan(full_scan_request, STOP_GAP, PARALLEL_REQUESTS).unwrap(); | ||
// Apply the update from the full scan to the wallet | ||
wallet.apply_update(update).unwrap(); | ||
let balance = wallet.balance(); | ||
println!("Wallet balance: {} sat", balance.total().to_sat()); | ||
// --8<-- [end:scan] | ||
|
||
// TODO: tx build + broadcast, recovery, storage, etc. | ||
} | ||
// --8<-- [end:file] |
Oops, something went wrong.