-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temp 20: Add blocking esplora client with scan method
- Loading branch information
1 parent
6589695
commit 4c8818c
Showing
8 changed files
with
1,231 additions
and
94 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "bdk-ffi" | ||
version = "1.0.0-alpha.1" | ||
version = "1.0.0-alpha.2" | ||
authors = ["Steve Myers <[email protected]>", "Sudarsan Balaji <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -17,9 +17,9 @@ path = "uniffi-bindgen.rs" | |
default = ["uniffi/cli"] | ||
|
||
[dependencies] | ||
bdk = { git = "https://github.com/bitcoindevkit/bdk.git", rev = "59fc1b341ba94212b2ea3e888e51fb6fcd00589f", features = ["all-keys", "keys-bip39"] } | ||
bdk_file_store = { git = "https://github.com/bitcoindevkit/bdk.git", rev = "59fc1b341ba94212b2ea3e888e51fb6fcd00589f" } | ||
# bdk_chain = { git = "https://github.com/bitcoindevkit/bdk.git", rev = "59fc1b341ba94212b2ea3e888e51fb6fcd00589f" } | ||
bdk = { version = "1.0.0-alpha.2", features = ["all-keys", "keys-bip39"] } | ||
bdk_file_store = { version = "0.2.0" } | ||
bdk_esplora = { version = "0.4.0" } | ||
uniffi = { version = "=0.23.0" } | ||
|
||
[build-dependencies] | ||
|
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,59 @@ | ||
use crate::wallet::Update; | ||
use crate::wallet::Wallet; | ||
use bdk::wallet::Update as BdkUpdate; | ||
use bdk::Error as BdkError; | ||
use bdk_esplora::esplora_client::{BlockingClient, Builder}; | ||
use bdk_esplora::EsploraExt; | ||
use std::sync::Arc; | ||
|
||
pub struct EsploraClient(BlockingClient); | ||
|
||
impl EsploraClient { | ||
pub fn new(url: String) -> Self { | ||
let client = Builder::new(url.as_str()).build_blocking().unwrap(); | ||
Self(client) | ||
} | ||
|
||
pub fn scan( | ||
&self, | ||
wallet: Arc<Wallet>, | ||
stop_gap: u64, | ||
parallel_requests: u64, | ||
) -> Result<Arc<Update>, BdkError> { | ||
let wallet = wallet.get_wallet(); | ||
|
||
let previous_tip = wallet.latest_checkpoint(); | ||
let keychain_spks = wallet.spks_of_all_keychains().into_iter().collect(); | ||
|
||
let (update_graph, last_active_indices) = self | ||
.0 | ||
.scan_txs_with_keychains( | ||
keychain_spks, | ||
None, | ||
None, | ||
stop_gap as usize, | ||
parallel_requests as usize, | ||
) | ||
.unwrap(); | ||
|
||
let missing_heights = update_graph.missing_heights(wallet.local_chain()); | ||
let chain_update = self | ||
.0 | ||
.update_local_chain(previous_tip, missing_heights) | ||
.unwrap(); | ||
|
||
let update = BdkUpdate { | ||
last_active_indices, | ||
graph: update_graph, | ||
chain: Some(chain_update), | ||
}; | ||
|
||
Ok(Arc::new(Update(update))) | ||
} | ||
|
||
// pub fn sync(); | ||
|
||
// pub fn broadcast(); | ||
|
||
// pub fn estimate_fee(); | ||
} |
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