From 97d60999a044021c6995d4afd097d88a9ff6c398 Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Tue, 20 Aug 2024 14:16:41 +0300 Subject: [PATCH] Add `use_trampoline` to `LnUrlPayRequest` and generate bindings Changes introduced in: https://github.com/breez/breez-sdk-greenlight/pull/1034 --- cli/src/commands.rs | 1 + .../breez_sdk_liquid/include/breez_sdk_liquid.h | 1 + lib/bindings/src/breez_sdk_liquid.udl | 1 + lib/core/src/bindings.rs | 1 + lib/core/src/frb_generated.rs | 8 ++++++++ packages/dart/lib/src/bindings.dart | 4 ++++ packages/dart/lib/src/frb_generated.dart | 12 ++++++++---- packages/dart/lib/src/frb_generated.io.dart | 4 ++++ .../lib/flutter_breez_liquid_bindings_generated.dart | 3 +++ .../java/com/breezsdkliquid/BreezSDKLiquidMapper.kt | 4 ++++ packages/react-native/ios/BreezSDKLiquidMapper.swift | 5 +++++ packages/react-native/src/index.ts | 1 + 12 files changed, 41 insertions(+), 4 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 71b7ba2a1..0bc9803cb 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -444,6 +444,7 @@ pub(crate) async fn handle_command( .lnurl_pay(LnUrlPayRequest { data: pd, amount_msat: amount_msat.parse::()?, + use_trampoline: false, comment: None, payment_label: None, validate_success_action_url: validate_success_url, diff --git a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h index 06c61d545..4acde7523 100644 --- a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h +++ b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h @@ -92,6 +92,7 @@ typedef struct wire_cst_ln_url_pay_request_data { typedef struct wire_cst_ln_url_pay_request { struct wire_cst_ln_url_pay_request_data data; uint64_t amount_msat; + bool use_trampoline; struct wire_cst_list_prim_u_8_strict *comment; struct wire_cst_list_prim_u_8_strict *payment_label; bool *validate_success_action_url; diff --git a/lib/bindings/src/breez_sdk_liquid.udl b/lib/bindings/src/breez_sdk_liquid.udl index 3c007e071..8a1c8f4fd 100644 --- a/lib/bindings/src/breez_sdk_liquid.udl +++ b/lib/bindings/src/breez_sdk_liquid.udl @@ -125,6 +125,7 @@ dictionary LnUrlPayErrorData { dictionary LnUrlPayRequest { LnUrlPayRequestData data; u64 amount_msat; + boolean use_trampoline; string? comment = null; string? payment_label = null; boolean? validate_success_action_url = null; diff --git a/lib/core/src/bindings.rs b/lib/core/src/bindings.rs index 6e50cd72e..4a018222d 100644 --- a/lib/core/src/bindings.rs +++ b/lib/core/src/bindings.rs @@ -351,6 +351,7 @@ pub struct _LnUrlPayRequestData { pub struct _LnUrlPayRequest { pub data: LnUrlPayRequestData, pub amount_msat: u64, + pub use_trampoline: bool, pub comment: Option, pub payment_label: Option, pub validate_success_action_url: Option, diff --git a/lib/core/src/frb_generated.rs b/lib/core/src/frb_generated.rs index ed748b788..447727e78 100644 --- a/lib/core/src/frb_generated.rs +++ b/lib/core/src/frb_generated.rs @@ -1673,6 +1673,7 @@ const _: fn() = || { let LnUrlPayRequest = None::.unwrap(); let _: crate::bindings::LnUrlPayRequestData = LnUrlPayRequest.data; let _: u64 = LnUrlPayRequest.amount_msat; + let _: bool = LnUrlPayRequest.use_trampoline; let _: Option = LnUrlPayRequest.comment; let _: Option = LnUrlPayRequest.payment_label; let _: Option = LnUrlPayRequest.validate_success_action_url; @@ -2556,12 +2557,14 @@ impl SseDecode for crate::bindings::LnUrlPayRequest { fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { let mut var_data = ::sse_decode(deserializer); let mut var_amountMsat = ::sse_decode(deserializer); + let mut var_useTrampoline = ::sse_decode(deserializer); let mut var_comment = >::sse_decode(deserializer); let mut var_paymentLabel = >::sse_decode(deserializer); let mut var_validateSuccessActionUrl = >::sse_decode(deserializer); return crate::bindings::LnUrlPayRequest { data: var_data, amount_msat: var_amountMsat, + use_trampoline: var_useTrampoline, comment: var_comment, payment_label: var_paymentLabel, validate_success_action_url: var_validateSuccessActionUrl, @@ -4175,6 +4178,7 @@ impl flutter_rust_bridge::IntoDart for FrbWrapper::sse_encode(self.data, serializer); ::sse_encode(self.amount_msat, serializer); + ::sse_encode(self.use_trampoline, serializer); >::sse_encode(self.comment, serializer); >::sse_encode(self.payment_label, serializer); >::sse_encode(self.validate_success_action_url, serializer); @@ -7449,6 +7454,7 @@ mod io { crate::bindings::LnUrlPayRequest { data: self.data.cst_decode(), amount_msat: self.amount_msat.cst_decode(), + use_trampoline: self.use_trampoline.cst_decode(), comment: self.comment.cst_decode(), payment_label: self.payment_label.cst_decode(), validate_success_action_url: self.validate_success_action_url.cst_decode(), @@ -8414,6 +8420,7 @@ mod io { Self { data: Default::default(), amount_msat: Default::default(), + use_trampoline: Default::default(), comment: core::ptr::null_mut(), payment_label: core::ptr::null_mut(), validate_success_action_url: core::ptr::null_mut(), @@ -10195,6 +10202,7 @@ mod io { pub struct wire_cst_ln_url_pay_request { data: wire_cst_ln_url_pay_request_data, amount_msat: u64, + use_trampoline: bool, comment: *mut wire_cst_list_prim_u_8_strict, payment_label: *mut wire_cst_list_prim_u_8_strict, validate_success_action_url: *mut bool, diff --git a/packages/dart/lib/src/bindings.dart b/packages/dart/lib/src/bindings.dart index b8cbc9a07..467d40243 100644 --- a/packages/dart/lib/src/bindings.dart +++ b/packages/dart/lib/src/bindings.dart @@ -396,6 +396,7 @@ class LnUrlPayErrorData { class LnUrlPayRequest { final LnUrlPayRequestData data; final BigInt amountMsat; + final bool useTrampoline; final String? comment; final String? paymentLabel; final bool? validateSuccessActionUrl; @@ -403,6 +404,7 @@ class LnUrlPayRequest { const LnUrlPayRequest({ required this.data, required this.amountMsat, + required this.useTrampoline, this.comment, this.paymentLabel, this.validateSuccessActionUrl, @@ -412,6 +414,7 @@ class LnUrlPayRequest { int get hashCode => data.hashCode ^ amountMsat.hashCode ^ + useTrampoline.hashCode ^ comment.hashCode ^ paymentLabel.hashCode ^ validateSuccessActionUrl.hashCode; @@ -423,6 +426,7 @@ class LnUrlPayRequest { runtimeType == other.runtimeType && data == other.data && amountMsat == other.amountMsat && + useTrampoline == other.useTrampoline && comment == other.comment && paymentLabel == other.paymentLabel && validateSuccessActionUrl == other.validateSuccessActionUrl; diff --git a/packages/dart/lib/src/frb_generated.dart b/packages/dart/lib/src/frb_generated.dart index 17e38c2a9..eb841f226 100644 --- a/packages/dart/lib/src/frb_generated.dart +++ b/packages/dart/lib/src/frb_generated.dart @@ -1828,13 +1828,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { LnUrlPayRequest dco_decode_ln_url_pay_request(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 5) throw Exception('unexpected arr length: expect 5 but see ${arr.length}'); + if (arr.length != 6) throw Exception('unexpected arr length: expect 6 but see ${arr.length}'); return LnUrlPayRequest( data: dco_decode_ln_url_pay_request_data(arr[0]), amountMsat: dco_decode_u_64(arr[1]), - comment: dco_decode_opt_String(arr[2]), - paymentLabel: dco_decode_opt_String(arr[3]), - validateSuccessActionUrl: dco_decode_opt_box_autoadd_bool(arr[4]), + useTrampoline: dco_decode_bool(arr[2]), + comment: dco_decode_opt_String(arr[3]), + paymentLabel: dco_decode_opt_String(arr[4]), + validateSuccessActionUrl: dco_decode_opt_box_autoadd_bool(arr[5]), ); } @@ -3395,12 +3396,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { // Codec=Sse (Serialization based), see doc to use other codecs var var_data = sse_decode_ln_url_pay_request_data(deserializer); var var_amountMsat = sse_decode_u_64(deserializer); + var var_useTrampoline = sse_decode_bool(deserializer); var var_comment = sse_decode_opt_String(deserializer); var var_paymentLabel = sse_decode_opt_String(deserializer); var var_validateSuccessActionUrl = sse_decode_opt_box_autoadd_bool(deserializer); return LnUrlPayRequest( data: var_data, amountMsat: var_amountMsat, + useTrampoline: var_useTrampoline, comment: var_comment, paymentLabel: var_paymentLabel, validateSuccessActionUrl: var_validateSuccessActionUrl); @@ -4931,6 +4934,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { // Codec=Sse (Serialization based), see doc to use other codecs sse_encode_ln_url_pay_request_data(self.data, serializer); sse_encode_u_64(self.amountMsat, serializer); + sse_encode_bool(self.useTrampoline, serializer); sse_encode_opt_String(self.comment, serializer); sse_encode_opt_String(self.paymentLabel, serializer); sse_encode_opt_box_autoadd_bool(self.validateSuccessActionUrl, serializer); diff --git a/packages/dart/lib/src/frb_generated.io.dart b/packages/dart/lib/src/frb_generated.io.dart index 60885844f..0539dbed0 100644 --- a/packages/dart/lib/src/frb_generated.io.dart +++ b/packages/dart/lib/src/frb_generated.io.dart @@ -2000,6 +2000,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void cst_api_fill_to_wire_ln_url_pay_request(LnUrlPayRequest apiObj, wire_cst_ln_url_pay_request wireObj) { cst_api_fill_to_wire_ln_url_pay_request_data(apiObj.data, wireObj.data); wireObj.amount_msat = cst_encode_u_64(apiObj.amountMsat); + wireObj.use_trampoline = cst_encode_bool(apiObj.useTrampoline); wireObj.comment = cst_encode_opt_String(apiObj.comment); wireObj.payment_label = cst_encode_opt_String(apiObj.paymentLabel); wireObj.validate_success_action_url = cst_encode_opt_box_autoadd_bool(apiObj.validateSuccessActionUrl); @@ -4465,6 +4466,9 @@ final class wire_cst_ln_url_pay_request extends ffi.Struct { @ffi.Uint64() external int amount_msat; + @ffi.Bool() + external bool use_trampoline; + external ffi.Pointer comment; external ffi.Pointer payment_label; diff --git a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart index 86d65de05..4b48d2221 100644 --- a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart +++ b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart @@ -1474,6 +1474,9 @@ final class wire_cst_ln_url_pay_request extends ffi.Struct { @ffi.Uint64() external int amount_msat; + @ffi.Bool() + external bool use_trampoline; + external ffi.Pointer comment; external ffi.Pointer payment_label; diff --git a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt index a1bc60514..ed68bc1ae 100644 --- a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt +++ b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt @@ -710,6 +710,7 @@ fun asLnUrlPayRequest(lnUrlPayRequest: ReadableMap): LnUrlPayRequest? { arrayOf( "data", "amountMsat", + "useTrampoline", ), ) ) { @@ -717,6 +718,7 @@ fun asLnUrlPayRequest(lnUrlPayRequest: ReadableMap): LnUrlPayRequest? { } val data = lnUrlPayRequest.getMap("data")?.let { asLnUrlPayRequestData(it) }!! val amountMsat = lnUrlPayRequest.getDouble("amountMsat").toULong() + val useTrampoline = lnUrlPayRequest.getBoolean("useTrampoline") val comment = if (hasNonNullKey(lnUrlPayRequest, "comment")) lnUrlPayRequest.getString("comment") else null val paymentLabel = if (hasNonNullKey(lnUrlPayRequest, "paymentLabel")) lnUrlPayRequest.getString("paymentLabel") else null val validateSuccessActionUrl = @@ -732,6 +734,7 @@ fun asLnUrlPayRequest(lnUrlPayRequest: ReadableMap): LnUrlPayRequest? { return LnUrlPayRequest( data, amountMsat, + useTrampoline, comment, paymentLabel, validateSuccessActionUrl, @@ -742,6 +745,7 @@ fun readableMapOf(lnUrlPayRequest: LnUrlPayRequest): ReadableMap = readableMapOf( "data" to readableMapOf(lnUrlPayRequest.data), "amountMsat" to lnUrlPayRequest.amountMsat, + "useTrampoline" to lnUrlPayRequest.useTrampoline, "comment" to lnUrlPayRequest.comment, "paymentLabel" to lnUrlPayRequest.paymentLabel, "validateSuccessActionUrl" to lnUrlPayRequest.validateSuccessActionUrl, diff --git a/packages/react-native/ios/BreezSDKLiquidMapper.swift b/packages/react-native/ios/BreezSDKLiquidMapper.swift index 0927447e7..273559503 100644 --- a/packages/react-native/ios/BreezSDKLiquidMapper.swift +++ b/packages/react-native/ios/BreezSDKLiquidMapper.swift @@ -852,6 +852,9 @@ enum BreezSDKLiquidMapper { guard let amountMsat = lnUrlPayRequest["amountMsat"] as? UInt64 else { throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "LnUrlPayRequest")) } + guard let useTrampoline = lnUrlPayRequest["useTrampoline"] as? Bool else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "useTrampoline", typeName: "LnUrlPayRequest")) + } var comment: String? if hasNonNilKey(data: lnUrlPayRequest, key: "comment") { guard let commentTmp = lnUrlPayRequest["comment"] as? String else { @@ -877,6 +880,7 @@ enum BreezSDKLiquidMapper { return LnUrlPayRequest( data: data, amountMsat: amountMsat, + useTrampoline: useTrampoline, comment: comment, paymentLabel: paymentLabel, validateSuccessActionUrl: validateSuccessActionUrl @@ -887,6 +891,7 @@ enum BreezSDKLiquidMapper { return [ "data": dictionaryOf(lnUrlPayRequestData: lnUrlPayRequest.data), "amountMsat": lnUrlPayRequest.amountMsat, + "useTrampoline": lnUrlPayRequest.useTrampoline, "comment": lnUrlPayRequest.comment == nil ? nil : lnUrlPayRequest.comment, "paymentLabel": lnUrlPayRequest.paymentLabel == nil ? nil : lnUrlPayRequest.paymentLabel, "validateSuccessActionUrl": lnUrlPayRequest.validateSuccessActionUrl == nil ? nil : lnUrlPayRequest.validateSuccessActionUrl, diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 171270528..cd7171111 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -132,6 +132,7 @@ export interface LnUrlPayErrorData { export interface LnUrlPayRequest { data: LnUrlPayRequestData amountMsat: number + useTrampoline: boolean comment?: string paymentLabel?: string validateSuccessActionUrl?: boolean