Skip to content

Commit

Permalink
Add use_trampoline to LnUrlPayRequest and generate bindings
Browse files Browse the repository at this point in the history
Changes introduced in: breez/breez-sdk-greenlight#1034
  • Loading branch information
erdemyerebasmaz committed Aug 20, 2024
1 parent c0393b6 commit 97d6099
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ pub(crate) async fn handle_command(
.lnurl_pay(LnUrlPayRequest {
data: pd,
amount_msat: amount_msat.parse::<u64>()?,
use_trampoline: false,
comment: None,
payment_label: None,
validate_success_action_url: validate_success_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/core/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ pub struct _LnUrlPayRequestData {
pub struct _LnUrlPayRequest {
pub data: LnUrlPayRequestData,
pub amount_msat: u64,
pub use_trampoline: bool,
pub comment: Option<String>,
pub payment_label: Option<String>,
pub validate_success_action_url: Option<bool>,
Expand Down
8 changes: 8 additions & 0 deletions lib/core/src/frb_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,7 @@ const _: fn() = || {
let LnUrlPayRequest = None::<crate::bindings::LnUrlPayRequest>.unwrap();
let _: crate::bindings::LnUrlPayRequestData = LnUrlPayRequest.data;
let _: u64 = LnUrlPayRequest.amount_msat;
let _: bool = LnUrlPayRequest.use_trampoline;
let _: Option<String> = LnUrlPayRequest.comment;
let _: Option<String> = LnUrlPayRequest.payment_label;
let _: Option<bool> = LnUrlPayRequest.validate_success_action_url;
Expand Down Expand Up @@ -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 = <crate::bindings::LnUrlPayRequestData>::sse_decode(deserializer);
let mut var_amountMsat = <u64>::sse_decode(deserializer);
let mut var_useTrampoline = <bool>::sse_decode(deserializer);
let mut var_comment = <Option<String>>::sse_decode(deserializer);
let mut var_paymentLabel = <Option<String>>::sse_decode(deserializer);
let mut var_validateSuccessActionUrl = <Option<bool>>::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,
Expand Down Expand Up @@ -4175,6 +4178,7 @@ impl flutter_rust_bridge::IntoDart for FrbWrapper<crate::bindings::LnUrlPayReque
[
self.0.data.into_into_dart().into_dart(),
self.0.amount_msat.into_into_dart().into_dart(),
self.0.use_trampoline.into_into_dart().into_dart(),
self.0.comment.into_into_dart().into_dart(),
self.0.payment_label.into_into_dart().into_dart(),
self.0
Expand Down Expand Up @@ -5812,6 +5816,7 @@ impl SseEncode for crate::bindings::LnUrlPayRequest {
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<crate::bindings::LnUrlPayRequestData>::sse_encode(self.data, serializer);
<u64>::sse_encode(self.amount_msat, serializer);
<bool>::sse_encode(self.use_trampoline, serializer);
<Option<String>>::sse_encode(self.comment, serializer);
<Option<String>>::sse_encode(self.payment_label, serializer);
<Option<bool>>::sse_encode(self.validate_success_action_url, serializer);
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions packages/dart/lib/src/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,15 @@ class LnUrlPayErrorData {
class LnUrlPayRequest {
final LnUrlPayRequestData data;
final BigInt amountMsat;
final bool useTrampoline;
final String? comment;
final String? paymentLabel;
final bool? validateSuccessActionUrl;

const LnUrlPayRequest({
required this.data,
required this.amountMsat,
required this.useTrampoline,
this.comment,
this.paymentLabel,
this.validateSuccessActionUrl,
Expand All @@ -412,6 +414,7 @@ class LnUrlPayRequest {
int get hashCode =>
data.hashCode ^
amountMsat.hashCode ^
useTrampoline.hashCode ^
comment.hashCode ^
paymentLabel.hashCode ^
validateSuccessActionUrl.hashCode;
Expand All @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions packages/dart/lib/src/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>;
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]),
);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions packages/dart/lib/src/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
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);
Expand Down Expand Up @@ -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<wire_cst_list_prim_u_8_strict> comment;

external ffi.Pointer<wire_cst_list_prim_u_8_strict> payment_label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<wire_cst_list_prim_u_8_strict> comment;

external ffi.Pointer<wire_cst_list_prim_u_8_strict> payment_label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,15 @@ fun asLnUrlPayRequest(lnUrlPayRequest: ReadableMap): LnUrlPayRequest? {
arrayOf(
"data",
"amountMsat",
"useTrampoline",
),
)
) {
return null
}
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 =
Expand All @@ -732,6 +734,7 @@ fun asLnUrlPayRequest(lnUrlPayRequest: ReadableMap): LnUrlPayRequest? {
return LnUrlPayRequest(
data,
amountMsat,
useTrampoline,
comment,
paymentLabel,
validateSuccessActionUrl,
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native/ios/BreezSDKLiquidMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -877,6 +880,7 @@ enum BreezSDKLiquidMapper {
return LnUrlPayRequest(
data: data,
amountMsat: amountMsat,
useTrampoline: useTrampoline,
comment: comment,
paymentLabel: paymentLabel,
validateSuccessActionUrl: validateSuccessActionUrl
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface LnUrlPayErrorData {
export interface LnUrlPayRequest {
data: LnUrlPayRequestData
amountMsat: number
useTrampoline: boolean
comment?: string
paymentLabel?: string
validateSuccessActionUrl?: boolean
Expand Down

0 comments on commit 97d6099

Please sign in to comment.