-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b434c9
commit c8fe44a
Showing
2 changed files
with
148 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use bdk_kyoto::builder::LightClientBuilder; | ||
use bdk_kyoto::{Event, LogLevel}; | ||
use bdk_wallet::bitcoin::Network; | ||
use bdk_wallet::Wallet; | ||
|
||
/* Sync a bdk wallet using events*/ | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let desc = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/0/*)"; | ||
let change_desc = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)"; | ||
|
||
let mut wallet = Wallet::create(desc, change_desc) | ||
.network(Network::Signet) | ||
.lookahead(30) | ||
.create_wallet_no_persist()?; | ||
|
||
// The light client builder handles the logic of inserting the SPKs | ||
let (node, mut client) = LightClientBuilder::new(&wallet) | ||
.scan_after(170_000) | ||
.build() | ||
.unwrap(); | ||
|
||
tokio::task::spawn(async move { node.run().await }); | ||
|
||
loop { | ||
if let Some(event) = client.next_event(LogLevel::Debug).await { | ||
match event { | ||
Event::Log(l) => println!("{l}"), | ||
Event::Warning(warning) => println!("{warning}"), | ||
Event::ScanResult(full_scan_result) => { | ||
wallet.apply_update(full_scan_result).unwrap(); | ||
println!("balance in BTC: {}", wallet.balance().total().to_sat()); | ||
} | ||
Event::PeersFound => println!("Connected to all necessary peers."), | ||
Event::TxSent(txid) => println!("Broadcast a transaction: {txid}"), | ||
Event::TxFailed(failure_payload) => { | ||
println!("Transaction failed to broadcast: {failure_payload:?}") | ||
} | ||
Event::StateChange(_node_state) => (), | ||
} | ||
} | ||
} | ||
} |
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