mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-20 06:24:19 +01:00
WASM: sync grpc client (#790)
This commit is contained in:
88
cli/Cargo.lock
generated
88
cli/Cargo.lock
generated
@@ -349,7 +349,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum-core 0.3.4",
|
||||
"axum-core",
|
||||
"bitflags 1.3.2",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
@@ -370,33 +370,6 @@ dependencies = [
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum"
|
||||
version = "0.7.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum-core 0.4.5",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"http-body-util",
|
||||
"itoa",
|
||||
"matchit",
|
||||
"memchr",
|
||||
"mime",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"serde",
|
||||
"sync_wrapper 1.0.2",
|
||||
"tower 0.5.2",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-core"
|
||||
version = "0.3.4"
|
||||
@@ -414,26 +387,6 @@ dependencies = [
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-core"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"http-body-util",
|
||||
"mime",
|
||||
"pin-project-lite",
|
||||
"rustversion",
|
||||
"sync_wrapper 1.0.2",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.74"
|
||||
@@ -743,7 +696,7 @@ dependencies = [
|
||||
"lwk_wollet",
|
||||
"maybe-sync",
|
||||
"mockall",
|
||||
"prost 0.13.5",
|
||||
"prost 0.11.9",
|
||||
"reqwest 0.12.13",
|
||||
"rusqlite",
|
||||
"rusqlite_migration",
|
||||
@@ -761,7 +714,8 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tonic 0.12.3",
|
||||
"tonic-build 0.12.3",
|
||||
"tonic 0.8.3",
|
||||
"tonic-build 0.8.4",
|
||||
"url",
|
||||
"uuid",
|
||||
"web-time",
|
||||
@@ -2018,7 +1972,6 @@ dependencies = [
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project-lite",
|
||||
"smallvec",
|
||||
@@ -2056,19 +2009,6 @@ dependencies = [
|
||||
"tokio-io-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-timeout"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0"
|
||||
dependencies = [
|
||||
"hyper 1.6.0",
|
||||
"hyper-util",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.6.0"
|
||||
@@ -4054,7 +3994,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sdk-common"
|
||||
version = "0.6.2"
|
||||
source = "git+https://github.com/breez/breez-sdk?rev=6c0cf15425f2ef83ade52976dbd88e8a75e73cf9#6c0cf15425f2ef83ade52976dbd88e8a75e73cf9"
|
||||
source = "git+https://github.com/breez/breez-sdk?rev=3a46e2acdf935884c7d1a3f6296b20973c9e4cce#3a46e2acdf935884c7d1a3f6296b20973c9e4cce"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"anyhow",
|
||||
@@ -4098,7 +4038,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sdk-macros"
|
||||
version = "0.6.2"
|
||||
source = "git+https://github.com/breez/breez-sdk?rev=6c0cf15425f2ef83ade52976dbd88e8a75e73cf9#6c0cf15425f2ef83ade52976dbd88e8a75e73cf9"
|
||||
source = "git+https://github.com/breez/breez-sdk?rev=3a46e2acdf935884c7d1a3f6296b20973c9e4cce#3a46e2acdf935884c7d1a3f6296b20973c9e4cce"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -4724,7 +4664,7 @@ checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb"
|
||||
dependencies = [
|
||||
"async-stream",
|
||||
"async-trait",
|
||||
"axum 0.6.20",
|
||||
"axum",
|
||||
"base64 0.13.1",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
@@ -4733,7 +4673,7 @@ dependencies = [
|
||||
"http 0.2.12",
|
||||
"http-body 0.4.6",
|
||||
"hyper 0.14.32",
|
||||
"hyper-timeout 0.4.1",
|
||||
"hyper-timeout",
|
||||
"percent-encoding",
|
||||
"pin-project",
|
||||
"prost 0.11.9",
|
||||
@@ -4758,31 +4698,19 @@ version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52"
|
||||
dependencies = [
|
||||
"async-stream",
|
||||
"async-trait",
|
||||
"axum 0.7.9",
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"h2 0.4.8",
|
||||
"http 1.3.1",
|
||||
"http-body 1.0.1",
|
||||
"http-body-util",
|
||||
"hyper 1.6.0",
|
||||
"hyper-timeout 0.5.2",
|
||||
"hyper-util",
|
||||
"percent-encoding",
|
||||
"pin-project",
|
||||
"prost 0.13.5",
|
||||
"rustls-pemfile 2.2.0",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tokio-rustls 0.26.2",
|
||||
"tokio-stream",
|
||||
"tower 0.4.13",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
"webpki-roots 0.26.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
1374
lib/Cargo.lock
generated
1374
lib/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -37,8 +37,8 @@ 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 = "6c0cf15425f2ef83ade52976dbd88e8a75e73cf9", features = ["liquid"] }
|
||||
sdk-macros = { git = "https://github.com/breez/breez-sdk", rev = "6c0cf15425f2ef83ade52976dbd88e8a75e73cf9" }
|
||||
sdk-common = { git = "https://github.com/breez/breez-sdk", rev = "3a46e2acdf935884c7d1a3f6296b20973c9e4cce", features = ["liquid"] }
|
||||
sdk-macros = { git = "https://github.com/breez/breez-sdk", rev = "3a46e2acdf935884c7d1a3f6296b20973c9e4cce" }
|
||||
thiserror = "1.0"
|
||||
|
||||
[patch.crates-io]
|
||||
|
||||
@@ -56,7 +56,7 @@ reqwest = { version = "0.12", features = ["json"] }
|
||||
zbase32 = "0.1.2"
|
||||
x509-parser = { version = "0.16.0" }
|
||||
tempfile = "3"
|
||||
prost = "0.13.3"
|
||||
prost = "^0.11"
|
||||
ecies = { version = "0.2.7", default-features = false, features = ["pure"] }
|
||||
semver = "1.0.23"
|
||||
lazy_static = "1.5.0"
|
||||
@@ -70,7 +70,7 @@ electrum-client = { version = "0.21.0", default-features = false, features = [
|
||||
lwk_wollet = { version = "0.9.0" }
|
||||
maybe-sync = { version = "0.1.1", features = ["sync"] }
|
||||
tokio-stream = { version = "0.1.14", features = ["sync"] }
|
||||
tonic = { version = "0.12.3", features = ["tls", "tls-webpki-roots"] }
|
||||
tonic = { version = "^0.8", features = ["tls", "tls-webpki-roots"] }
|
||||
uuid = { version = "1.8.0", features = ["v4"] }
|
||||
|
||||
# WASM dependencies
|
||||
@@ -81,6 +81,10 @@ lwk_wollet = { version = "0.9.0", default-features = false, features = [
|
||||
] }
|
||||
maybe-sync = "0.1.1"
|
||||
uuid = { version = "1.8.0", features = ["v4", "js"] }
|
||||
tonic = { version = "0.12", default-features = false, features = [
|
||||
"codegen",
|
||||
"prost",
|
||||
] }
|
||||
|
||||
[dev-dependencies]
|
||||
sdk-common = { workspace = true, features = ["test-utils"] }
|
||||
@@ -99,7 +103,7 @@ getrandom = { version = "0.2", features = ["js"] }
|
||||
[build-dependencies]
|
||||
anyhow = { version = "1.0.79", features = ["backtrace"] }
|
||||
glob = "0.3.1"
|
||||
tonic-build = "0.12.3"
|
||||
tonic-build = "^0.8"
|
||||
|
||||
# Pin these versions to fix iOS build issues
|
||||
[target.'cfg(target_os = "ios")'.build-dependencies]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use anyhow::*;
|
||||
use glob::glob;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::result::Result::Ok;
|
||||
use std::{env, io};
|
||||
|
||||
/// Adds a temporary workaround for an issue with the Rust compiler and Android
|
||||
/// in x86_64 devices: https://github.com/rust-lang/rust/issues/109717.
|
||||
@@ -32,8 +33,26 @@ fn setup_x86_64_android_workaround() {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
setup_x86_64_android_workaround();
|
||||
tonic_build::compile_protos("src/sync/proto/sync.proto")?;
|
||||
pub fn compile_protos(proto: impl AsRef<Path>) -> io::Result<()> {
|
||||
let proto_path: &Path = proto.as_ref();
|
||||
let proto_dir = proto_path
|
||||
.parent()
|
||||
.expect("proto file should reside in a directory");
|
||||
let target_family =
|
||||
env::var("CARGO_CFG_TARGET_FAMILY").expect("CARGO_CFG_TARGET_FAMILY not set");
|
||||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
|
||||
let is_wasm = target_family == "wasm" && target_os == "unknown";
|
||||
|
||||
tonic_build::configure()
|
||||
.build_server(false)
|
||||
.build_client(true)
|
||||
.build_transport(!is_wasm)
|
||||
.compile(&[proto_path], &[proto_dir])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
setup_x86_64_android_workaround();
|
||||
compile_protos("src/sync/proto/sync.proto")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
|
||||
use log::debug;
|
||||
@@ -7,7 +5,6 @@ use tokio::sync::Mutex;
|
||||
use tonic::{
|
||||
metadata::{errors::InvalidMetadataValue, Ascii, MetadataValue},
|
||||
service::{interceptor::InterceptedService, Interceptor},
|
||||
transport::{Channel, ClientTlsConfig, Endpoint},
|
||||
Request, Status, Streaming,
|
||||
};
|
||||
|
||||
@@ -15,6 +12,7 @@ use super::model::{
|
||||
syncer_client::SyncerClient as ProtoSyncerClient, ListChangesReply, ListChangesRequest,
|
||||
ListenChangesRequest, Notification, SetRecordReply, SetRecordRequest,
|
||||
};
|
||||
use sdk_common::grpc::transport::{GrpcClient, Transport};
|
||||
|
||||
#[sdk_macros::async_trait]
|
||||
pub(crate) trait SyncerClient: Send + Sync {
|
||||
@@ -26,7 +24,7 @@ pub(crate) trait SyncerClient: Send + Sync {
|
||||
}
|
||||
|
||||
pub(crate) struct BreezSyncerClient {
|
||||
grpc_channel: Mutex<Option<Channel>>,
|
||||
grpc_channel: Mutex<Option<Transport>>,
|
||||
api_key: Option<String>,
|
||||
}
|
||||
|
||||
@@ -38,15 +36,6 @@ impl BreezSyncerClient {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_endpoint(server_url: &str) -> Result<Endpoint> {
|
||||
Ok(Endpoint::from_shared(server_url.to_string())?
|
||||
.http2_keep_alive_interval(Duration::new(10, 0))
|
||||
.tcp_keepalive(Some(Duration::from_secs(10)))
|
||||
.keep_alive_timeout(Duration::from_secs(5))
|
||||
.keep_alive_while_idle(true)
|
||||
.tls_config(ClientTlsConfig::new().with_enabled_roots())?)
|
||||
}
|
||||
|
||||
fn api_key_metadata(&self) -> Result<Option<MetadataValue<Ascii>>, Error> {
|
||||
match &self.api_key {
|
||||
Some(key) => Ok(Some(format!("Bearer {key}").parse().map_err(
|
||||
@@ -65,7 +54,7 @@ impl BreezSyncerClient {
|
||||
impl BreezSyncerClient {
|
||||
async fn get_client(
|
||||
&self,
|
||||
) -> Result<ProtoSyncerClient<InterceptedService<Channel, ApiKeyInterceptor>>, Error> {
|
||||
) -> Result<ProtoSyncerClient<InterceptedService<Transport, ApiKeyInterceptor>>, Error> {
|
||||
let Some(channel) = self.grpc_channel.lock().await.clone() else {
|
||||
return Err(anyhow!("Cannot get sync client: not connected"));
|
||||
};
|
||||
@@ -81,7 +70,7 @@ impl BreezSyncerClient {
|
||||
impl SyncerClient for BreezSyncerClient {
|
||||
async fn connect(&self, connect_url: String) -> Result<()> {
|
||||
let mut grpc_channel = self.grpc_channel.lock().await;
|
||||
*grpc_channel = Some(Self::create_endpoint(&connect_url)?.connect_lazy());
|
||||
*grpc_channel = Some(GrpcClient::new(connect_url.clone())?.into_inner());
|
||||
debug!("Successfully connected to {connect_url}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user