Skip to content

Commit

Permalink
Extract sdk-common crate (#1002)
Browse files Browse the repository at this point in the history
* Extract LnUrlError

* Extract sdk-lnurl/auth and sdk-utils

* Cargo fmt

* Create lnurl module

* Consolidate sdk-utils as module in sdk-lnurl

* Rename sdk-lnurl workspace member to sdk-common

* Move invoice module into sdk-common

* Move input_parser module into sdk-common

* Move pay module into sdk-common/lnurl

* Move withdraw module into sdk-common/lnurl

* Move auth structs into lnurl/auth/model

* Revert test methods to crate visibility

* Re-enable test-utils with FRB v1 workaround

* Fix tests, clippy

* Fix clippy for tests

* Re-generate RN bindings

* Fix tests, clippy, FRB

* Revert "Fix tests, clippy, FRB"

This reverts commit 1964f22.

* Consolidate pay/withdraw request data structs

* Move LnUrlPayError to sdk-common

* Make lnurl-pay model public

* Re-introduce payment in lnurl-pay result

* Move lnurl-pay tests from sdk-common to SDK

* Move LNURL-withdraw request, error into sdk-common

* Re-generate RN bindings

* Potential mockito server fix

* Move test_utils.rs in inner module of lib.rs

* Fix dart bridge mapping

* Fix cargo clippy

* Move UDL segments to minimize diff

* Remove unused LnUrlPayResult

* Potential fix for golang tests

* Potential fix for golang tests v2

* Move LnUrlError conversion to lnurl/error.rs

* Rename InputType::LnUrlEndpointError back to LnUrlError

* Fix tests

* Remove Wrapped prefix from LnUrlPaySuccessData, LnUrlPayResult

* LNURL-pay: move non-E2E tests to sdk-common

* LNURL-withdraw: move non-E2E tests to sdk-common

* LNURL-withdraw: move remaining tests to sdk-common (E2E tests, but only cover first portion of the flow, without payment)

* fix mirroring definitions

* remove test attribute

* Don't lint test_utils

* run cargo fmt

---------

Co-authored-by: Roei Erez <roeierez@gmail.com>
  • Loading branch information
ok300 and roeierez authored Jun 17, 2024
1 parent 2225617 commit eb75e48
Show file tree
Hide file tree
Showing 37 changed files with 2,137 additions and 1,614 deletions.
43 changes: 34 additions & 9 deletions libs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 29 additions & 2 deletions libs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,41 @@ rpath = true

[workspace]
members = [
"sdk-core",
"sdk-bindings",
"sdk-common",
"sdk-core",
]
resolver = "2"

[workspace.package]
version = "0.4.1"

[workspace.dependencies]
aes = "0.8"
anyhow = { version = "1.0.79", features = ["backtrace"] }
base64 = "0.13.0"
bitcoin = "=0.29.2" # Same version as used in gl-client
# Pin the reqwest dependency until macOS linker issue is fixed: https://github.com/seanmonstar/reqwest/issues/2006
hex = "0.4"
lightning = "=0.0.116" # Same version as used in gl-client
lightning-invoice = "=0.24.0" # Same version as used in gl-client
log = "0.4"
mockito = "1"
once_cell = "1"
regex = "1.8.1"
reqwest = { version = "=0.11.20", features = ["json"] }
rusqlite = { version = "0.29", features = [
"serde_json",
"bundled",
"backup",
"trace",
"hooks",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = "0.25"
strum_macros = "0.25"
thiserror = "1.0.56"
tokio = { version = "1", features = ["full"] }
uniffi = "0.23.0"
uniffi_macros = "0.23.0"
uniffi_macros = "0.23.0"
13 changes: 7 additions & 6 deletions libs/sdk-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ crate-type = ["staticlib", "cdylib", "lib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true }
breez-sdk-core = { path = "../sdk-core" }
anyhow = { version = "1.0.79", features = ["backtrace"] }
thiserror = "1.0.56"
tokio = { version = "1", features = ["full"] }
sdk-common = { path = "../sdk-common" }
thiserror = { workspace = true }
tokio = { workspace = true }
uniffi = { version = "0.23.0", features = ["bindgen-tests", "cli"] }
uniffi_bindgen = "0.23.0"
uniffi_macros = "0.23.0"
uniffi-kotlin-multiplatform = { git = "https://gitlab.com/trixnity/uniffi-kotlin-multiplatform-bindings", rev = "bf48c5fcb153856e3055025a3cbfa56fbf213188" }
camino = "1.1.1"
log = "*"
once_cell = "*"
log = { workspace = true }
once_cell = { workspace = true }
flutter_rust_bridge = "=1.82.6"
tiny-bip39 = "*"
tonic = { version = "^0.8", features = [
Expand All @@ -36,5 +37,5 @@ tonic = { version = "^0.8", features = [
[build-dependencies]
uniffi_build = { version = "0.23.0" }
uniffi_bindgen = "0.23.0"
anyhow = { version = "1.0.79", features = ["backtrace"] }
anyhow = { workspace = true }
glob = "0.3.1"
20 changes: 10 additions & 10 deletions libs/sdk-bindings/src/breez_sdk.udl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
dictionary RouteHintHop {
dictionary RouteHintHop {
string src_node_id;
u64 short_channel_id;
u32 fees_base_msat;
u32 fees_proportional_millionths;
u64 cltv_expiry_delta;
u64? htlc_minimum_msat;
u32 fees_proportional_millionths;
u64 cltv_expiry_delta;
u64? htlc_minimum_msat;
u64? htlc_maximum_msat;
};

Expand Down Expand Up @@ -187,7 +187,7 @@ dictionary NodeState {
u64 max_single_payment_amount_msat;
u64 max_chan_reserve_msats;
sequence<string> connected_peers;
u64 inbound_liquidity_msats;
u64 inbound_liquidity_msats;
};

dictionary ConfigureNodeRequest {
Expand Down Expand Up @@ -243,8 +243,8 @@ enum PaymentType {

dictionary Payment {
string id;
PaymentType payment_type;
i64 payment_time;
PaymentType payment_type;
i64 payment_time;
u64 amount_msat;
u64 fee_msat;
PaymentStatus status;
Expand Down Expand Up @@ -398,7 +398,7 @@ dictionary PaymentFailedData {
};

dictionary BackupFailedData {
string error;
string error;
};

[Enum]
Expand All @@ -409,7 +409,7 @@ interface BreezEvent {
PaymentSucceed(Payment details);
PaymentFailed(PaymentFailedData details);
BackupStarted();
BackupSucceeded();
BackupSucceeded();
BackupFailed(BackupFailedData details);
SwapUpdated(SwapInfo details);
};
Expand All @@ -423,7 +423,7 @@ callback interface LogStream {
void log(LogEntry l);
};

callback interface EventListener {
callback interface EventListener {
void on_event(BreezEvent e);
};

Expand Down
8 changes: 5 additions & 3 deletions libs/sdk-bindings/src/uniffi_binding.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::sync::Arc;

use anyhow::Result;
use breez_sdk_core::lnurl::pay::{LnUrlPayResult, LnUrlPaySuccessData};
use breez_sdk_core::{
error::*, mnemonic_to_seed as sdk_mnemonic_to_seed, parse as sdk_parse_input,
parse_invoice as sdk_parse_invoice, AesSuccessActionDataDecrypted, AesSuccessActionDataResult,
Expand All @@ -8,8 +11,8 @@ use breez_sdk_core::{
ConnectRequest, CurrencyInfo, EnvironmentType, EventListener, FeeratePreset, FiatCurrency,
GreenlightCredentials, GreenlightDeviceCredentials, GreenlightNodeConfig, HealthCheckStatus,
InputType, InvoicePaidDetails, LNInvoice, ListPaymentsRequest, LnPaymentDetails,
LnUrlAuthRequestData, LnUrlCallbackStatus, LnUrlErrorData, LnUrlPayErrorData, LnUrlPayRequest,
LnUrlPayRequestData, LnUrlPayResult, LnUrlPaySuccessData, LnUrlWithdrawRequest,
LnUrlAuthRequestData, LnUrlCallbackStatus, LnUrlErrorData, LnUrlPayError, LnUrlPayErrorData,
LnUrlPayRequest, LnUrlPayRequestData, LnUrlWithdrawError, LnUrlWithdrawRequest,
LnUrlWithdrawRequestData, LnUrlWithdrawResult, LnUrlWithdrawSuccessData, LocaleOverrides,
LocalizedName, LogEntry, LogStream, LspInformation, MaxReverseSwapAmountResponse,
MessageSuccessActionData, MetadataFilter, MetadataItem, Network, NodeConfig, NodeCredentials,
Expand All @@ -29,7 +32,6 @@ use breez_sdk_core::{
};
use log::{Level, LevelFilter, Metadata, Record};
use once_cell::sync::{Lazy, OnceCell};
use std::sync::Arc;

static RT: Lazy<tokio::runtime::Runtime> = Lazy::new(|| tokio::runtime::Runtime::new().unwrap());
static LOG_INIT: OnceCell<bool> = OnceCell::new();
Expand Down
30 changes: 30 additions & 0 deletions libs/sdk-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "sdk-common"
edition = "2021"
version.workspace = true

[dependencies]
aes = { workspace = true }
anyhow = { workspace = true }
base64 = { workspace = true }
bip21 = "0.2"
bitcoin = { workspace = true }
cbc = { version = "0.1", features = ["std"] }
hex = { workspace = true }
lightning = { workspace = true }
lightning-invoice = { workspace = true }
log = { workspace = true }
querystring = "1"
regex = { workspace = true }
reqwest = { workspace = true }
rusqlite = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
strum_macros = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
bitcoin = { workspace = true, features = ["rand"] }
mockito = { workspace = true }
tokio = { workspace = true }
once_cell = { workspace = true }
Loading

0 comments on commit eb75e48

Please sign in to comment.