-
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: add code examples for persistence pages
- Loading branch information
1 parent
2199444
commit 419944b
Showing
13 changed files
with
91 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
@default: | ||
just --list | ||
|
||
# build all rust examples | ||
build-rust: | ||
cd rust && cargo build | ||
|
||
# format all rust examples | ||
fmt-rust: | ||
cd rust && cargo fmt | ||
# Rust examples: fmt, clippy check, and build | ||
rust: | ||
cd rust && cargo fmt && cargo clippy && cargo build |
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
File renamed without changes.
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
File renamed without changes.
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 @@ | ||
target/ |
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 @@ | ||
[package] | ||
name = "sqlite-wallet" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# --8<-- [start:deps] | ||
[dependencies] | ||
bdk_wallet = { version = "1.0.0", features = ["rusqlite"] } | ||
# --8<-- [end:deps] | ||
anyhow = "1" |
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,52 @@ | ||
use bdk_wallet::bitcoin::Network; | ||
use bdk_wallet::rusqlite; | ||
use bdk_wallet::KeychainKind; | ||
use bdk_wallet::Wallet; | ||
|
||
// --8<-- [start:descriptors] | ||
// const EXTERNAL_DESCRIPTOR: &str = "[your external descriptor here ...]"; | ||
// const INTERNAL_DESCRIPTOR: &str = "[your internal descriptor here ...]"; | ||
// Example private descriptors | ||
const EXTERNAL_DESCRIPTOR: &str = "tr(tprv8ZgxMBicQKsPdJuLWWArdBsWjqDA3W5WoREnfdgKEcCQB1FMKfSoaFz9JHZU71HwXAqTsjHripkLM62kUQar14SDD8brsmhFKqVUPXGrZLc/86'/1'/0'/0/*)#fv8tutn2"; | ||
const INTERNAL_DESCRIPTOR: &str = "tr(tprv8ZgxMBicQKsPdJuLWWArdBsWjqDA3W5WoREnfdgKEcCQB1FMKfSoaFz9JHZU71HwXAqTsjHripkLM62kUQar14SDD8brsmhFKqVUPXGrZLc/86'/1'/0'/1/*)#ccz2p7rj"; | ||
// --8<-- [end:descriptors] | ||
|
||
fn main() -> Result<(), anyhow::Error> { | ||
// --8<-- [start:load] | ||
let network = Network::Signet; | ||
let file_path = "test_wallet.sqlite3"; | ||
let mut conn = rusqlite::Connection::open(file_path)?; | ||
|
||
let wallet_opt = Wallet::load() | ||
.descriptor(KeychainKind::External, Some(EXTERNAL_DESCRIPTOR)) | ||
.descriptor(KeychainKind::Internal, Some(INTERNAL_DESCRIPTOR)) | ||
.extract_keys() // only needed if using private key descriptors | ||
.check_network(network) | ||
.load_wallet(&mut conn)?; | ||
// --8<-- [end:load] | ||
|
||
// --8<-- [start:create] | ||
let mut wallet = match wallet_opt { | ||
Some(wallet) => { | ||
println!("Loaded existing wallet database."); | ||
wallet | ||
} | ||
None => { | ||
println!("Creating new wallet database."); | ||
Wallet::create(EXTERNAL_DESCRIPTOR, INTERNAL_DESCRIPTOR) | ||
.network(network) | ||
.create_wallet(&mut conn)? | ||
} | ||
}; | ||
// --8<-- [end:create] | ||
|
||
// --8<-- [start:address] | ||
// Reveal a new address from your external keychain | ||
let address = wallet.reveal_next_address(KeychainKind::External); | ||
wallet.persist(&mut conn)?; | ||
// Only share new address with user after successfully persisting wallet | ||
println!("Wallet address[{}]: {}", address.index, address.address); | ||
// --8<-- [end:address] | ||
|
||
Ok(()) | ||
} |
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,8 +1,10 @@ | ||
default: | ||
just --list | ||
|
||
rust: | ||
cd examples/rust && cargo build | ||
# Build mkdocs | ||
build: | ||
mkdocs build | ||
|
||
# Serve mkdocs | ||
serve: | ||
mkdocs serve |
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