Skip to content

Commit

Permalink
Add config param for payment request yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Apr 23, 2024
1 parent eb2ed33 commit 772e7f7
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions libs/sdk-bindings/src/breez_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ dictionary Config {
string working_dir;
Network network;
u32 payment_timeout_sec;
u64 payment_request_yield_sec;
string? default_lsp_id;
string? api_key;
f64 maxfee_percent;
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl BreezServices {
})
.await?;

let timeout = Duration::from_secs(self.config.payment_timeout_sec as u64);
let timeout = Duration::from_secs(self.config.payment_request_yield_sec);
let (tx, rx) = std::sync::mpsc::channel();
let cloned = self.clone();
tokio::spawn(async move {
Expand Down
3 changes: 3 additions & 0 deletions libs/sdk-core/src/bridge_generated.io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ impl Wire2Api<Config> for wire_Config {
working_dir: self.working_dir.wire2api(),
network: self.network.wire2api(),
payment_timeout_sec: self.payment_timeout_sec.wire2api(),
payment_request_yield_sec: self.payment_request_yield_sec.wire2api(),
default_lsp_id: self.default_lsp_id.wire2api(),
api_key: self.api_key.wire2api(),
maxfee_percent: self.maxfee_percent.wire2api(),
Expand Down Expand Up @@ -1143,6 +1144,7 @@ pub struct wire_Config {
working_dir: *mut wire_uint_8_list,
network: i32,
payment_timeout_sec: u32,
payment_request_yield_sec: u64,
default_lsp_id: *mut wire_uint_8_list,
api_key: *mut wire_uint_8_list,
maxfee_percent: f64,
Expand Down Expand Up @@ -1515,6 +1517,7 @@ impl NewWithNullPtr for wire_Config {
working_dir: core::ptr::null_mut(),
network: Default::default(),
payment_timeout_sec: Default::default(),
payment_request_yield_sec: Default::default(),
default_lsp_id: core::ptr::null_mut(),
api_key: core::ptr::null_mut(),
maxfee_percent: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-core/src/bridge_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ impl support::IntoDart for Config {
self.working_dir.into_into_dart().into_dart(),
self.network.into_into_dart().into_dart(),
self.payment_timeout_sec.into_into_dart().into_dart(),
self.payment_request_yield_sec.into_into_dart().into_dart(),
self.default_lsp_id.into_dart(),
self.api_key.into_dart(),
self.maxfee_percent.into_into_dart().into_dart(),
Expand Down
6 changes: 6 additions & 0 deletions libs/sdk-core/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,11 @@ pub struct Config {
/// the folder should exist before starting the SDK.
pub working_dir: String,
pub network: Network,
/// Maps to the CLN `retry_for` config when paying invoices (`lightning-pay`)
pub payment_timeout_sec: u32,
/// The duration, in seconds, in which to return from a [crate::BreezServices::send_payment]
/// request with a pending payment if not already finished.
pub payment_request_yield_sec: u64,
pub default_lsp_id: Option<String>,
pub api_key: Option<String>,
/// Maps to the CLN `maxfeepercent` config when paying invoices (`lightning-pay`)
Expand All @@ -498,6 +502,7 @@ impl Config {
working_dir: ".".to_string(),
network: Bitcoin,
payment_timeout_sec: 60,
payment_request_yield_sec: 30,
default_lsp_id: None,
api_key: Some(api_key),
maxfee_percent: 1.0,
Expand All @@ -514,6 +519,7 @@ impl Config {
working_dir: ".".to_string(),
network: Bitcoin,
payment_timeout_sec: 60,
payment_request_yield_sec: 30,
default_lsp_id: None,
api_key: Some(api_key),
maxfee_percent: 0.5,
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-flutter/ios/Classes/bridge_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef struct wire_Config {
struct wire_uint_8_list *working_dir;
int32_t network;
uint32_t payment_timeout_sec;
uint64_t payment_request_yield_sec;
struct wire_uint_8_list *default_lsp_id;
struct wire_uint_8_list *api_key;
double maxfee_percent;
Expand Down
24 changes: 18 additions & 6 deletions libs/sdk-flutter/lib/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,13 @@ class Config {
/// the folder should exist before starting the SDK.
final String workingDir;
final Network network;

/// Maps to the CLN `retry_for` config when paying invoices (`lightning-pay`)
final int paymentTimeoutSec;

/// The duration, in seconds, in which to return from a [crate::BreezServices::send_payment]
/// request with a pending payment if not already finished.
final int paymentRequestYieldSec;
final String? defaultLspId;
final String? apiKey;

Expand All @@ -543,6 +549,7 @@ class Config {
required this.workingDir,
required this.network,
required this.paymentTimeoutSec,
required this.paymentRequestYieldSec,
this.defaultLspId,
this.apiKey,
required this.maxfeePercent,
Expand Down Expand Up @@ -3380,19 +3387,20 @@ class BreezSdkCoreImpl implements BreezSdkCore {

Config _wire2api_config(dynamic raw) {
final arr = raw as List<dynamic>;
if (arr.length != 11) throw Exception('unexpected arr length: expect 11 but see ${arr.length}');
if (arr.length != 12) throw Exception('unexpected arr length: expect 12 but see ${arr.length}');
return Config(
breezserver: _wire2api_String(arr[0]),
chainnotifierUrl: _wire2api_String(arr[1]),
mempoolspaceUrl: _wire2api_opt_String(arr[2]),
workingDir: _wire2api_String(arr[3]),
network: _wire2api_network(arr[4]),
paymentTimeoutSec: _wire2api_u32(arr[5]),
defaultLspId: _wire2api_opt_String(arr[6]),
apiKey: _wire2api_opt_String(arr[7]),
maxfeePercent: _wire2api_f64(arr[8]),
exemptfeeMsat: _wire2api_u64(arr[9]),
nodeConfig: _wire2api_node_config(arr[10]),
paymentRequestYieldSec: _wire2api_u64(arr[6]),
defaultLspId: _wire2api_opt_String(arr[7]),
apiKey: _wire2api_opt_String(arr[8]),
maxfeePercent: _wire2api_f64(arr[9]),
exemptfeeMsat: _wire2api_u64(arr[10]),
nodeConfig: _wire2api_node_config(arr[11]),
);
}

Expand Down Expand Up @@ -4839,6 +4847,7 @@ class BreezSdkCorePlatform extends FlutterRustBridgeBase<BreezSdkCoreWire> {
wireObj.working_dir = api2wire_String(apiObj.workingDir);
wireObj.network = api2wire_network(apiObj.network);
wireObj.payment_timeout_sec = api2wire_u32(apiObj.paymentTimeoutSec);
wireObj.payment_request_yield_sec = api2wire_u64(apiObj.paymentRequestYieldSec);
wireObj.default_lsp_id = api2wire_opt_String(apiObj.defaultLspId);
wireObj.api_key = api2wire_opt_String(apiObj.apiKey);
wireObj.maxfee_percent = api2wire_f64(apiObj.maxfeePercent);
Expand Down Expand Up @@ -6513,6 +6522,9 @@ final class wire_Config extends ffi.Struct {
@ffi.Uint32()
external int payment_timeout_sec;

@ffi.Uint64()
external int payment_request_yield_sec;

external ffi.Pointer<wire_uint_8_list> default_lsp_id;

external ffi.Pointer<wire_uint_8_list> api_key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ fun asConfig(config: ReadableMap): Config? {
"workingDir",
"network",
"paymentTimeoutSec",
"paymentRequestYieldSec",
"maxfeePercent",
"exemptfeeMsat",
"nodeConfig",
Expand All @@ -399,6 +400,7 @@ fun asConfig(config: ReadableMap): Config? {
val workingDir = config.getString("workingDir")!!
val network = config.getString("network")?.let { asNetwork(it) }!!
val paymentTimeoutSec = config.getInt("paymentTimeoutSec").toUInt()
val paymentRequestYieldSec = config.getDouble("paymentRequestYieldSec").toULong()
val defaultLspId = if (hasNonNullKey(config, "defaultLspId")) config.getString("defaultLspId") else null
val apiKey = if (hasNonNullKey(config, "apiKey")) config.getString("apiKey") else null
val maxfeePercent = config.getDouble("maxfeePercent")
Expand All @@ -411,6 +413,7 @@ fun asConfig(config: ReadableMap): Config? {
workingDir,
network,
paymentTimeoutSec,
paymentRequestYieldSec,
defaultLspId,
apiKey,
maxfeePercent,
Expand All @@ -427,6 +430,7 @@ fun readableMapOf(config: Config): ReadableMap {
"workingDir" to config.workingDir,
"network" to config.network.name.lowercase(),
"paymentTimeoutSec" to config.paymentTimeoutSec,
"paymentRequestYieldSec" to config.paymentRequestYieldSec,
"defaultLspId" to config.defaultLspId,
"apiKey" to config.apiKey,
"maxfeePercent" to config.maxfeePercent,
Expand Down
5 changes: 5 additions & 0 deletions libs/sdk-react-native/ios/BreezSDKMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ enum BreezSDKMapper {
guard let paymentTimeoutSec = config["paymentTimeoutSec"] as? UInt32 else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentTimeoutSec", typeName: "Config"))
}
guard let paymentRequestYieldSec = config["paymentRequestYieldSec"] as? UInt64 else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentRequestYieldSec", typeName: "Config"))
}
var defaultLspId: String?
if hasNonNilKey(data: config, key: "defaultLspId") {
guard let defaultLspIdTmp = config["defaultLspId"] as? String else {
Expand Down Expand Up @@ -451,6 +454,7 @@ enum BreezSDKMapper {
workingDir: workingDir,
network: network,
paymentTimeoutSec: paymentTimeoutSec,
paymentRequestYieldSec: paymentRequestYieldSec,
defaultLspId: defaultLspId,
apiKey: apiKey,
maxfeePercent: maxfeePercent,
Expand All @@ -467,6 +471,7 @@ enum BreezSDKMapper {
"workingDir": config.workingDir,
"network": valueOf(network: config.network),
"paymentTimeoutSec": config.paymentTimeoutSec,
"paymentRequestYieldSec": config.paymentRequestYieldSec,
"defaultLspId": config.defaultLspId == nil ? nil : config.defaultLspId,
"apiKey": config.apiKey == nil ? nil : config.apiKey,
"maxfeePercent": config.maxfeePercent,
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type Config = {
workingDir: string
network: Network
paymentTimeoutSec: number
paymentRequestYieldSec: number
defaultLspId?: string
apiKey?: string
maxfeePercent: number
Expand Down

0 comments on commit 772e7f7

Please sign in to comment.