Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM: Interface #757

Draft
wants to merge 5 commits into
base: wasm
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
393 changes: 124 additions & 269 deletions cli/Cargo.lock

Large diffs are not rendered by default.

179 changes: 99 additions & 80 deletions lib/Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ unexpected_cfgs = { level = "allow", check-cfg = ['cfg(frb_expand)'] }
anyhow = "1.0"
log = "0.4.20"
once_cell = "1.19"
serde = { version = "1.0", features = ["derive"] }
sdk-common = { git = "https://github.com/breez/breez-sdk", rev = "24e29929f495f113158f2f9db11c098cc1493bee", features = ["liquid"] }
sdk-macros = { git = "https://github.com/breez/breez-sdk", rev = "24e29929f495f113158f2f9db11c098cc1493bee" }
thiserror = "1.0"
# Version must match that used by uniffi-bindgen-go
uniffi = "0.25.0"
Expand Down
3 changes: 2 additions & 1 deletion lib/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lwk_signer = { version = "0.8.0", default-features = false }
rusqlite = { version = "0.31", features = ["backup", "bundled"] }
tokio = { version = "1", default-features = false, features = ["rt", "macros"] }
# TODO: Change on top of main once PR is merged
sdk-common = { git = "https://github.com/breez/breez-sdk", rev = "19ed955c6fa854ad6cd2beb2eca9127d8099c506", features = ["liquid"] }
sdk-common = { workspace = true }
rusqlite_migration = "1.0"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.116"
Expand Down Expand Up @@ -68,6 +68,7 @@ lwk_wollet = { git = "https://github.com/breez/lwk", branch = "breez-sdk-liquid-
lwk_wollet = { git = "https://github.com/breez/lwk", branch = "breez-sdk-liquid-0.6.3", default-features = false, features = [ "esplora" ] }

[dev-dependencies]
sdk-common = { workspace = true, features = ["test-utils"] }
paste = "1.0.15"
tempdir = "0.3.7"

Expand Down
21 changes: 13 additions & 8 deletions lib/core/src/chain/bitcoin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
collections::HashMap,
sync::{Mutex, OnceLock},
sync::{Arc, Mutex, OnceLock},
time::Duration,
};

Expand All @@ -16,7 +16,10 @@ use electrum_client::{
};
use log::info;
use lwk_wollet::{bitcoin::ScriptBuf, ElectrumOptions, ElectrumUrl, Error, History};
use sdk_common::{bitcoin::hashes::hex::ToHex, prelude::get_parse_and_log_response};
use sdk_common::{
bitcoin::hashes::hex::ToHex,
prelude::{get_and_check_success, parse_json, RestClient},
};

use crate::{
model::{Config, LiquidNetwork, RecommendedFees},
Expand Down Expand Up @@ -82,14 +85,16 @@ pub trait BitcoinChainService: Send + Sync {
}

pub(crate) struct HybridBitcoinChainService {
client: OnceLock<Client>,
config: Config,
rest_client: Arc<dyn RestClient>,
client: OnceLock<Client>,
last_known_tip: Mutex<Option<HeaderNotification>>,
}
impl HybridBitcoinChainService {
pub fn new(config: Config) -> Result<Self, Error> {
pub fn new(config: Config, rest_client: Arc<dyn RestClient>) -> Result<Self, Error> {
Ok(Self {
config,
rest_client,
client: OnceLock::new(),
last_known_tip: Mutex::new(None),
})
Expand Down Expand Up @@ -364,11 +369,11 @@ impl BitcoinChainService for HybridBitcoinChainService {
}

async fn recommended_fees(&self) -> Result<RecommendedFees> {
get_parse_and_log_response(
let (response, _) = get_and_check_success(
self.rest_client.as_ref(),
&format!("{}/v1/fees/recommended", self.config.mempoolspace_url),
true,
)
.await
.map_err(Into::into)
.await?;
Ok(parse_json(&response)?)
}
}
Loading
Loading