From fa01549242a786f3fc9ccffa134e47ba462838db Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:44:44 +0100 Subject: [PATCH 01/12] Expand InputType with new variant: Bolt12 offer --- libs/sdk-bindings/src/breez_sdk.udl | 1 + libs/sdk-common/src/input_parser.rs | 23 ++ libs/sdk-core/src/binding.rs | 1 + libs/sdk-core/src/bridge_generated.rs | 16 +- libs/sdk-flutter/lib/bridge_generated.dart | 17 +- .../lib/bridge_generated.freezed.dart | 227 ++++++++++++++++++ .../main/java/com/breezsdk/BreezSDKMapper.kt | 7 + .../sdk-react-native/ios/BreezSDKMapper.swift | 14 ++ libs/sdk-react-native/src/index.ts | 4 + 9 files changed, 299 insertions(+), 11 deletions(-) diff --git a/libs/sdk-bindings/src/breez_sdk.udl b/libs/sdk-bindings/src/breez_sdk.udl index 07310ef7f..828324273 100644 --- a/libs/sdk-bindings/src/breez_sdk.udl +++ b/libs/sdk-bindings/src/breez_sdk.udl @@ -734,6 +734,7 @@ dictionary RecommendedFees { interface InputType { BitcoinAddress(BitcoinAddressData address); Bolt11(LNInvoice invoice); + Bolt12(string offer); NodeId(string node_id); Url(string url); LnUrlPay(LnUrlPayRequestData data); diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index fc8b8d3cb..6cdd6aa2a 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -4,6 +4,7 @@ use ::bip21::Uri; use anyhow::{anyhow, Result}; use bitcoin::bech32; use bitcoin::bech32::FromBase32; +use lightning::offers::offer::Offer; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use LnUrlRequestData::*; @@ -185,6 +186,12 @@ pub async fn parse(input: &str) -> Result { return Ok(InputType::Bolt11 { invoice }); } + if let Ok(offer) = input.parse::() { + return Ok(InputType::Bolt12 { + offer: offer.to_string(), + }); + } + // Public key serialized in compressed form (66 hex chars) if let Ok(_node_id) = bitcoin::secp256k1::PublicKey::from_str(input) { return Ok(InputType::NodeId { @@ -418,6 +425,9 @@ pub enum InputType { Bolt11 { invoice: LNInvoice, }, + Bolt12 { + offer: String, + }, NodeId { node_id: String, }, @@ -926,6 +936,19 @@ pub(crate) mod tests { Ok(()) } + #[tokio::test] + async fn test_bolt12_offer() -> Result<()> { + let bolt12_offer = "lno1pqpzwyq2p32x2um5ypmx2cm5dae8x93pqthvwfzadd7jejes8q9lhc4rvjxd022zv5l44g6qah82ru5rdpnpj"; + + assert!(matches!( + parse(bolt12_offer).await?, + InputType::Bolt12 { offer } + if offer == bolt12_offer + )); + + Ok(()) + } + #[tokio::test] async fn test_url() -> Result<()> { assert!(matches!( diff --git a/libs/sdk-core/src/binding.rs b/libs/sdk-core/src/binding.rs index d4636cce8..3d0b4409e 100644 --- a/libs/sdk-core/src/binding.rs +++ b/libs/sdk-core/src/binding.rs @@ -162,6 +162,7 @@ pub struct _LnUrlWithdrawRequestData { pub enum _InputType { BitcoinAddress { address: BitcoinAddressData }, Bolt11 { invoice: LNInvoice }, + Bolt12 { offer: String }, NodeId { node_id: String }, Url { url: String }, LnUrlPay { data: LnUrlPayRequestData }, diff --git a/libs/sdk-core/src/bridge_generated.rs b/libs/sdk-core/src/bridge_generated.rs index 5d6c32529..7f1a6b48e 100644 --- a/libs/sdk-core/src/bridge_generated.rs +++ b/libs/sdk-core/src/bridge_generated.rs @@ -1025,6 +1025,9 @@ const _: fn() = || { InputType::Bolt11 { invoice } => { let _: LNInvoice = invoice; } + InputType::Bolt12 { offer } => { + let _: String = offer; + } InputType::NodeId { node_id } => { let _: String = node_id; } @@ -1613,17 +1616,18 @@ impl support::IntoDart for mirror_InputType { InputType::Bolt11 { invoice } => { vec![1.into_dart(), invoice.into_into_dart().into_dart()] } + InputType::Bolt12 { offer } => vec![2.into_dart(), offer.into_into_dart().into_dart()], InputType::NodeId { node_id } => { - vec![2.into_dart(), node_id.into_into_dart().into_dart()] + vec![3.into_dart(), node_id.into_into_dart().into_dart()] } - InputType::Url { url } => vec![3.into_dart(), url.into_into_dart().into_dart()], - InputType::LnUrlPay { data } => vec![4.into_dart(), data.into_into_dart().into_dart()], + InputType::Url { url } => vec![4.into_dart(), url.into_into_dart().into_dart()], + InputType::LnUrlPay { data } => vec![5.into_dart(), data.into_into_dart().into_dart()], InputType::LnUrlWithdraw { data } => { - vec![5.into_dart(), data.into_into_dart().into_dart()] + vec![6.into_dart(), data.into_into_dart().into_dart()] } - InputType::LnUrlAuth { data } => vec![6.into_dart(), data.into_into_dart().into_dart()], + InputType::LnUrlAuth { data } => vec![7.into_dart(), data.into_into_dart().into_dart()], InputType::LnUrlError { data } => { - vec![7.into_dart(), data.into_into_dart().into_dart()] + vec![8.into_dart(), data.into_into_dart().into_dart()] } } .into_dart() diff --git a/libs/sdk-flutter/lib/bridge_generated.dart b/libs/sdk-flutter/lib/bridge_generated.dart index 7ac7d374a..427038d93 100644 --- a/libs/sdk-flutter/lib/bridge_generated.dart +++ b/libs/sdk-flutter/lib/bridge_generated.dart @@ -670,6 +670,9 @@ sealed class InputType with _$InputType { const factory InputType.bolt11({ required LNInvoice invoice, }) = InputType_Bolt11; + const factory InputType.bolt12({ + required String offer, + }) = InputType_Bolt12; const factory InputType.nodeId({ required String nodeId, }) = InputType_NodeId; @@ -3421,26 +3424,30 @@ class BreezSdkCoreImpl implements BreezSdkCore { invoice: _wire2api_box_autoadd_ln_invoice(raw[1]), ); case 2: + return InputType_Bolt12( + offer: _wire2api_String(raw[1]), + ); + case 3: return InputType_NodeId( nodeId: _wire2api_String(raw[1]), ); - case 3: + case 4: return InputType_Url( url: _wire2api_String(raw[1]), ); - case 4: + case 5: return InputType_LnUrlPay( data: _wire2api_box_autoadd_ln_url_pay_request_data(raw[1]), ); - case 5: + case 6: return InputType_LnUrlWithdraw( data: _wire2api_box_autoadd_ln_url_withdraw_request_data(raw[1]), ); - case 6: + case 7: return InputType_LnUrlAuth( data: _wire2api_box_autoadd_ln_url_auth_request_data(raw[1]), ); - case 7: + case 8: return InputType_LnUrlError( data: _wire2api_box_autoadd_ln_url_error_data(raw[1]), ); diff --git a/libs/sdk-flutter/lib/bridge_generated.freezed.dart b/libs/sdk-flutter/lib/bridge_generated.freezed.dart index 15ddfc256..3a169ac53 100644 --- a/libs/sdk-flutter/lib/bridge_generated.freezed.dart +++ b/libs/sdk-flutter/lib/bridge_generated.freezed.dart @@ -2180,6 +2180,7 @@ mixin _$InputType { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2192,6 +2193,7 @@ mixin _$InputType { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2204,6 +2206,7 @@ mixin _$InputType { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2217,6 +2220,7 @@ mixin _$InputType { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2229,6 +2233,7 @@ mixin _$InputType { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2241,6 +2246,7 @@ mixin _$InputType { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2334,6 +2340,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2349,6 +2356,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2364,6 +2372,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2383,6 +2392,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2398,6 +2408,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2413,6 +2424,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2503,6 +2515,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2518,6 +2531,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2533,6 +2547,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2552,6 +2567,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2567,6 +2583,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2582,6 +2599,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2605,6 +2623,179 @@ abstract class InputType_Bolt11 implements InputType { _$$InputType_Bolt11ImplCopyWith<_$InputType_Bolt11Impl> get copyWith => throw _privateConstructorUsedError; } +/// @nodoc +abstract class _$$InputType_Bolt12ImplCopyWith<$Res> { + factory _$$InputType_Bolt12ImplCopyWith( + _$InputType_Bolt12Impl value, $Res Function(_$InputType_Bolt12Impl) then) = + __$$InputType_Bolt12ImplCopyWithImpl<$Res>; + @useResult + $Res call({String offer}); +} + +/// @nodoc +class __$$InputType_Bolt12ImplCopyWithImpl<$Res> extends _$InputTypeCopyWithImpl<$Res, _$InputType_Bolt12Impl> + implements _$$InputType_Bolt12ImplCopyWith<$Res> { + __$$InputType_Bolt12ImplCopyWithImpl( + _$InputType_Bolt12Impl _value, $Res Function(_$InputType_Bolt12Impl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? offer = null, + }) { + return _then(_$InputType_Bolt12Impl( + offer: null == offer + ? _value.offer + : offer // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$InputType_Bolt12Impl implements InputType_Bolt12 { + const _$InputType_Bolt12Impl({required this.offer}); + + @override + final String offer; + + @override + String toString() { + return 'InputType.bolt12(offer: $offer)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$InputType_Bolt12Impl && + (identical(other.offer, offer) || other.offer == offer)); + } + + @override + int get hashCode => Object.hash(runtimeType, offer); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$InputType_Bolt12ImplCopyWith<_$InputType_Bolt12Impl> get copyWith => + __$$InputType_Bolt12ImplCopyWithImpl<_$InputType_Bolt12Impl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(BitcoinAddressData address) bitcoinAddress, + required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, + required TResult Function(String nodeId) nodeId, + required TResult Function(String url) url, + required TResult Function(LnUrlPayRequestData data) lnUrlPay, + required TResult Function(LnUrlWithdrawRequestData data) lnUrlWithdraw, + required TResult Function(LnUrlAuthRequestData data) lnUrlAuth, + required TResult Function(LnUrlErrorData data) lnUrlError, + }) { + return bolt12(offer); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(BitcoinAddressData address)? bitcoinAddress, + TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, + TResult? Function(String nodeId)? nodeId, + TResult? Function(String url)? url, + TResult? Function(LnUrlPayRequestData data)? lnUrlPay, + TResult? Function(LnUrlWithdrawRequestData data)? lnUrlWithdraw, + TResult? Function(LnUrlAuthRequestData data)? lnUrlAuth, + TResult? Function(LnUrlErrorData data)? lnUrlError, + }) { + return bolt12?.call(offer); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(BitcoinAddressData address)? bitcoinAddress, + TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, + TResult Function(String nodeId)? nodeId, + TResult Function(String url)? url, + TResult Function(LnUrlPayRequestData data)? lnUrlPay, + TResult Function(LnUrlWithdrawRequestData data)? lnUrlWithdraw, + TResult Function(LnUrlAuthRequestData data)? lnUrlAuth, + TResult Function(LnUrlErrorData data)? lnUrlError, + required TResult orElse(), + }) { + if (bolt12 != null) { + return bolt12(offer); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, + required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, + required TResult Function(InputType_NodeId value) nodeId, + required TResult Function(InputType_Url value) url, + required TResult Function(InputType_LnUrlPay value) lnUrlPay, + required TResult Function(InputType_LnUrlWithdraw value) lnUrlWithdraw, + required TResult Function(InputType_LnUrlAuth value) lnUrlAuth, + required TResult Function(InputType_LnUrlError value) lnUrlError, + }) { + return bolt12(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, + TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, + TResult? Function(InputType_NodeId value)? nodeId, + TResult? Function(InputType_Url value)? url, + TResult? Function(InputType_LnUrlPay value)? lnUrlPay, + TResult? Function(InputType_LnUrlWithdraw value)? lnUrlWithdraw, + TResult? Function(InputType_LnUrlAuth value)? lnUrlAuth, + TResult? Function(InputType_LnUrlError value)? lnUrlError, + }) { + return bolt12?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, + TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, + TResult Function(InputType_NodeId value)? nodeId, + TResult Function(InputType_Url value)? url, + TResult Function(InputType_LnUrlPay value)? lnUrlPay, + TResult Function(InputType_LnUrlWithdraw value)? lnUrlWithdraw, + TResult Function(InputType_LnUrlAuth value)? lnUrlAuth, + TResult Function(InputType_LnUrlError value)? lnUrlError, + required TResult orElse(), + }) { + if (bolt12 != null) { + return bolt12(this); + } + return orElse(); + } +} + +abstract class InputType_Bolt12 implements InputType { + const factory InputType_Bolt12({required final String offer}) = _$InputType_Bolt12Impl; + + String get offer; + @JsonKey(ignore: true) + _$$InputType_Bolt12ImplCopyWith<_$InputType_Bolt12Impl> get copyWith => throw _privateConstructorUsedError; +} + /// @nodoc abstract class _$$InputType_NodeIdImplCopyWith<$Res> { factory _$$InputType_NodeIdImplCopyWith( @@ -2670,6 +2861,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2685,6 +2877,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2700,6 +2893,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2719,6 +2913,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2734,6 +2929,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2749,6 +2945,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2835,6 +3032,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2850,6 +3048,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2865,6 +3064,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2884,6 +3084,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2899,6 +3100,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2914,6 +3116,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3003,6 +3206,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3018,6 +3222,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3033,6 +3238,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3052,6 +3258,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3067,6 +3274,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3082,6 +3290,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3172,6 +3381,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3187,6 +3397,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3202,6 +3413,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3221,6 +3433,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3236,6 +3449,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3251,6 +3465,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3342,6 +3557,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3357,6 +3573,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3372,6 +3589,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3391,6 +3609,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3406,6 +3625,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3421,6 +3641,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3511,6 +3732,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, + required TResult Function(String offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3526,6 +3748,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, + TResult? Function(String offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3541,6 +3764,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, + TResult Function(String offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3560,6 +3784,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, + required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3575,6 +3800,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, + TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3590,6 +3816,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, + TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, diff --git a/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt b/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt index 27f2a4945..c6fb8af6c 100644 --- a/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt +++ b/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt @@ -3987,6 +3987,9 @@ fun asInputType(inputType: ReadableMap): InputType? { if (type == "bolt11") { return InputType.Bolt11(inputType.getMap("invoice")?.let { asLnInvoice(it) }!!) } + if (type == "bolt12") { + return InputType.Bolt12(inputType.getString("offer")!!) + } if (type == "nodeId") { return InputType.NodeId(inputType.getString("nodeId")!!) } @@ -4019,6 +4022,10 @@ fun readableMapOf(inputType: InputType): ReadableMap? { pushToMap(map, "type", "bolt11") pushToMap(map, "invoice", readableMapOf(inputType.invoice)) } + is InputType.Bolt12 -> { + pushToMap(map, "type", "bolt12") + pushToMap(map, "offer", inputType.offer) + } is InputType.NodeId -> { pushToMap(map, "type", "nodeId") pushToMap(map, "nodeId", inputType.nodeId) diff --git a/libs/sdk-react-native/ios/BreezSDKMapper.swift b/libs/sdk-react-native/ios/BreezSDKMapper.swift index 012eecd30..4bfe0a79c 100644 --- a/libs/sdk-react-native/ios/BreezSDKMapper.swift +++ b/libs/sdk-react-native/ios/BreezSDKMapper.swift @@ -4722,6 +4722,12 @@ enum BreezSDKMapper { return InputType.bolt11(invoice: _invoice) } + if type == "bolt12" { + guard let _offer = inputType["offer"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "offer", typeName: "InputType")) + } + return InputType.bolt12(offer: _offer) + } if type == "nodeId" { guard let _nodeId = inputType["nodeId"] as? String else { throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "nodeId", typeName: "InputType")) @@ -4788,6 +4794,14 @@ enum BreezSDKMapper { "invoice": dictionaryOf(lnInvoice: invoice), ] + case let .bolt12( + offer + ): + return [ + "type": "bolt12", + "offer": offer, + ] + case let .nodeId( nodeId ): diff --git a/libs/sdk-react-native/src/index.ts b/libs/sdk-react-native/src/index.ts index 5225c062e..2bf4e885f 100644 --- a/libs/sdk-react-native/src/index.ts +++ b/libs/sdk-react-native/src/index.ts @@ -674,6 +674,7 @@ export enum HealthCheckStatus { export enum InputTypeVariant { BITCOIN_ADDRESS = "bitcoinAddress", BOLT11 = "bolt11", + BOLT12 = "bolt12", NODE_ID = "nodeId", URL = "url", LN_URL_PAY = "lnUrlPay", @@ -688,6 +689,9 @@ export type InputType = { } | { type: InputTypeVariant.BOLT11, invoice: LnInvoice +} | { + type: InputTypeVariant.BOLT12, + offer: string } | { type: InputTypeVariant.NODE_ID, nodeId: string From 36ce80ca776deb7f7bd97b6f4efd9a6089f6c0fc Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:32:56 +0100 Subject: [PATCH 02/12] Expand inner structure of InputType::Bolt12 --- libs/Cargo.toml | 2 +- libs/sdk-bindings/src/breez_sdk.udl | 18 +- libs/sdk-bindings/src/uniffi_binding.rs | 4 +- libs/sdk-common/src/input_parser.rs | 16 +- libs/sdk-common/src/invoice.rs | 42 ++ libs/sdk-core/src/binding.rs | 36 +- libs/sdk-core/src/bridge_generated.rs | 76 +++- libs/sdk-flutter/lib/bridge_generated.dart | 77 +++- .../lib/bridge_generated.freezed.dart | 399 ++++++++++++++++-- .../main/java/com/breezsdk/BreezSDKMapper.kt | 96 ++++- .../sdk-react-native/ios/BreezSDKMapper.swift | 135 +++++- libs/sdk-react-native/src/index.ts | 26 +- 12 files changed, 871 insertions(+), 56 deletions(-) diff --git a/libs/Cargo.toml b/libs/Cargo.toml index c27f40f3e..a782c38b2 100644 --- a/libs/Cargo.toml +++ b/libs/Cargo.toml @@ -21,7 +21,6 @@ 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.118" # Same version as used in gl-client lightning-invoice = "=0.26.0" # Same version as used in gl-client @@ -30,6 +29,7 @@ mockito = "1" once_cell = "1" prost = "^0.11" regex = "1.8.1" +# Pin the reqwest dependency until macOS linker issue is fixed: https://github.com/seanmonstar/reqwest/issues/2006 reqwest = { version = "=0.11.20", features = ["json"] } rusqlite = { version = "0.29", features = [ "serde_json", diff --git a/libs/sdk-bindings/src/breez_sdk.udl b/libs/sdk-bindings/src/breez_sdk.udl index 828324273..f89659def 100644 --- a/libs/sdk-bindings/src/breez_sdk.udl +++ b/libs/sdk-bindings/src/breez_sdk.udl @@ -730,11 +730,27 @@ dictionary RecommendedFees { u64 minimum_fee; }; +[Enum] +interface Amount { + Bitcoin(u64 amount_msat); + Currency(string iso4217_code, u64 fractional_amount); +}; + +dictionary LNOffer { + string bolt12; + sequence chains; + string description; + string signing_pubkey; + Amount? amount; + u64? absolute_expiry; + string? issuer; +}; + [Enum] interface InputType { BitcoinAddress(BitcoinAddressData address); Bolt11(LNInvoice invoice); - Bolt12(string offer); + Bolt12(LNOffer offer); NodeId(string node_id); Url(string url); LnUrlPay(LnUrlPayRequestData data); diff --git a/libs/sdk-bindings/src/uniffi_binding.rs b/libs/sdk-bindings/src/uniffi_binding.rs index 1de3ff14d..ccc4dcd7a 100644 --- a/libs/sdk-bindings/src/uniffi_binding.rs +++ b/libs/sdk-bindings/src/uniffi_binding.rs @@ -5,12 +5,12 @@ 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, - BackupFailedData, BackupStatus, BitcoinAddressData, BreezEvent, BreezServices, + Amount, BackupFailedData, BackupStatus, BitcoinAddressData, BreezEvent, BreezServices, BuyBitcoinProvider, BuyBitcoinRequest, BuyBitcoinResponse, ChannelState, CheckMessageRequest, CheckMessageResponse, ClosedChannelPaymentDetails, Config, ConfigureNodeRequest, ConnectRequest, CurrencyInfo, EnvironmentType, EventListener, FeeratePreset, FiatCurrency, GreenlightCredentials, GreenlightDeviceCredentials, GreenlightNodeConfig, HealthCheckStatus, - InputType, InvoicePaidDetails, LNInvoice, ListPaymentsRequest, LnPaymentDetails, + InputType, InvoicePaidDetails, LNInvoice, LNOffer, ListPaymentsRequest, LnPaymentDetails, LnUrlAuthError, LnUrlAuthRequestData, LnUrlCallbackStatus, LnUrlErrorData, LnUrlPayError, LnUrlPayErrorData, LnUrlPayRequest, LnUrlPayRequestData, LnUrlWithdrawError, LnUrlWithdrawRequest, LnUrlWithdrawRequestData, LnUrlWithdrawResult, LnUrlWithdrawSuccessData, diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index 6cdd6aa2a..5d2753eb9 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -188,7 +188,19 @@ pub async fn parse(input: &str) -> Result { if let Ok(offer) = input.parse::() { return Ok(InputType::Bolt12 { - offer: offer.to_string(), + offer: LNOffer { + bolt12: input.to_string(), + chains: offer + .chains() + .iter() + .map(|chain| chain.to_string()) + .collect(), + amount: offer.amount().map(|amount| amount.clone().into()), + description: offer.description().to_string(), + absolute_expiry: offer.absolute_expiry().map(|expiry| expiry.as_secs()), + issuer: offer.issuer().map(|s| s.to_string()), + signing_pubkey: offer.signing_pubkey().to_string(), + }, }); } @@ -426,7 +438,7 @@ pub enum InputType { invoice: LNInvoice, }, Bolt12 { - offer: String, + offer: LNOffer, }, NodeId { node_id: String, diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index fe6b4c390..c59a6de78 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -101,6 +101,48 @@ fn format_short_channel_id(id: u64) -> String { format!("{block_num}x{tx_num}x{tx_out}") } +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub enum Amount { + Bitcoin { + amount_msat: u64, + }, + Currency { + // Reference to [FiatCurrency.id] + iso4217_code: String, + fractional_amount: u64, + }, +} + +impl From for Amount { + fn from(amount: lightning::offers::offer::Amount) -> Self { + match amount { + lightning::offers::offer::Amount::Bitcoin { amount_msats } => Amount::Bitcoin { + amount_msat: amount_msats, + }, + lightning::offers::offer::Amount::Currency { + iso4217_code, + amount, + } => Amount::Currency { + iso4217_code: String::from_utf8(iso4217_code.to_vec()) + .expect("Expecting a valid ISO 4217 character sequence"), + fractional_amount: amount, + }, + } + } +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct LNOffer { + pub bolt12: String, + pub chains: Vec, + pub amount: Option, + pub description: String, + pub absolute_expiry: Option, + pub issuer: Option, + pub signing_pubkey: String, + // pub paths: Vec, +} + /// Wrapper for a BOLT11 LN invoice #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct LNInvoice { diff --git a/libs/sdk-core/src/binding.rs b/libs/sdk-core/src/binding.rs index 3d0b4409e..8c74cd0b2 100644 --- a/libs/sdk-core/src/binding.rs +++ b/libs/sdk-core/src/binding.rs @@ -19,12 +19,12 @@ use log::{Level, LevelFilter, Metadata, Record}; use once_cell::sync::{Lazy, OnceCell}; use sdk_common::invoice; pub use sdk_common::prelude::{ - parse, AesSuccessActionDataDecrypted, AesSuccessActionDataResult, BitcoinAddressData, - CurrencyInfo, FiatCurrency, InputType, LNInvoice, LnUrlAuthRequestData, LnUrlCallbackStatus, - LnUrlError, LnUrlErrorData, LnUrlPayErrorData, LnUrlPayRequest, LnUrlPayRequestData, - LnUrlWithdrawRequest, LnUrlWithdrawRequestData, LnUrlWithdrawResult, LnUrlWithdrawSuccessData, - LocaleOverrides, LocalizedName, MessageSuccessActionData, Network, Rate, RouteHint, - RouteHintHop, SuccessActionProcessed, Symbol, UrlSuccessActionData, + parse, AesSuccessActionDataDecrypted, AesSuccessActionDataResult, Amount, BitcoinAddressData, + CurrencyInfo, FiatCurrency, InputType, LNInvoice, LNOffer, LnUrlAuthRequestData, + LnUrlCallbackStatus, LnUrlError, LnUrlErrorData, LnUrlPayErrorData, LnUrlPayRequest, + LnUrlPayRequestData, LnUrlWithdrawRequest, LnUrlWithdrawRequestData, LnUrlWithdrawResult, + LnUrlWithdrawSuccessData, LocaleOverrides, LocalizedName, MessageSuccessActionData, Network, + Rate, RouteHint, RouteHintHop, SuccessActionProcessed, Symbol, UrlSuccessActionData, }; use tokio::sync::Mutex; @@ -158,11 +158,33 @@ pub struct _LnUrlWithdrawRequestData { pub max_withdrawable: u64, } +#[frb(mirror(Amount))] +pub enum _Amount { + Bitcoin { + amount_msat: u64, + }, + Currency { + iso4217_code: String, + fractional_amount: u64, + }, +} + +#[frb(mirror(LNOffer))] +pub struct _LNOffer { + pub bolt12: String, + pub chains: Vec, + pub amount: Option, + pub description: String, + pub absolute_expiry: Option, + pub issuer: Option, + pub signing_pubkey: String, +} + #[frb(mirror(InputType))] pub enum _InputType { BitcoinAddress { address: BitcoinAddressData }, Bolt11 { invoice: LNInvoice }, - Bolt12 { offer: String }, + Bolt12 { offer: LNOffer }, NodeId { node_id: String }, Url { url: String }, LnUrlPay { data: LnUrlPayRequestData }, diff --git a/libs/sdk-core/src/bridge_generated.rs b/libs/sdk-core/src/bridge_generated.rs index 7f1a6b48e..55680ab57 100644 --- a/libs/sdk-core/src/bridge_generated.rs +++ b/libs/sdk-core/src/bridge_generated.rs @@ -910,6 +910,9 @@ pub struct mirror_AesSuccessActionDataDecrypted(AesSuccessActionDataDecrypted); #[derive(Clone)] pub struct mirror_AesSuccessActionDataResult(AesSuccessActionDataResult); +#[derive(Clone)] +pub struct mirror_Amount(Amount); + #[derive(Clone)] pub struct mirror_BitcoinAddressData(BitcoinAddressData); @@ -925,6 +928,9 @@ pub struct mirror_InputType(InputType); #[derive(Clone)] pub struct mirror_LNInvoice(LNInvoice); +#[derive(Clone)] +pub struct mirror_LNOffer(LNOffer); + #[derive(Clone)] pub struct mirror_LnUrlAuthRequestData(LnUrlAuthRequestData); @@ -995,6 +1001,18 @@ const _: fn() = || { let _: String = reason; } } + match None::.unwrap() { + Amount::Bitcoin { amount_msat } => { + let _: u64 = amount_msat; + } + Amount::Currency { + iso4217_code, + fractional_amount, + } => { + let _: String = iso4217_code; + let _: u64 = fractional_amount; + } + } { let BitcoinAddressData = None::.unwrap(); let _: String = BitcoinAddressData.address; @@ -1026,7 +1044,7 @@ const _: fn() = || { let _: LNInvoice = invoice; } InputType::Bolt12 { offer } => { - let _: String = offer; + let _: LNOffer = offer; } InputType::NodeId { node_id } => { let _: String = node_id; @@ -1062,6 +1080,16 @@ const _: fn() = || { let _: Vec = LNInvoice.payment_secret; let _: u64 = LNInvoice.min_final_cltv_expiry_delta; } + { + let LNOffer = None::.unwrap(); + let _: String = LNOffer.bolt12; + let _: Vec = LNOffer.chains; + let _: Option = LNOffer.amount; + let _: String = LNOffer.description; + let _: Option = LNOffer.absolute_expiry; + let _: Option = LNOffer.issuer; + let _: String = LNOffer.signing_pubkey; + } { let LnUrlAuthRequestData = None::.unwrap(); let _: String = LnUrlAuthRequestData.k1; @@ -1337,6 +1365,31 @@ impl rust2dart::IntoIntoDart for AesSuccessAc } } +impl support::IntoDart for mirror_Amount { + fn into_dart(self) -> support::DartAbi { + match self.0 { + Amount::Bitcoin { amount_msat } => { + vec![0.into_dart(), amount_msat.into_into_dart().into_dart()] + } + Amount::Currency { + iso4217_code, + fractional_amount, + } => vec![ + 1.into_dart(), + iso4217_code.into_into_dart().into_dart(), + fractional_amount.into_into_dart().into_dart(), + ], + } + .into_dart() + } +} +impl support::IntoDartExceptPrimitive for mirror_Amount {} +impl rust2dart::IntoIntoDart for Amount { + fn into_into_dart(self) -> mirror_Amount { + mirror_Amount(self) + } +} + impl support::IntoDart for BackupFailedData { fn into_dart(self) -> support::DartAbi { vec![self.error.into_into_dart().into_dart()].into_dart() @@ -1686,6 +1739,27 @@ impl rust2dart::IntoIntoDart for LNInvoice { } } +impl support::IntoDart for mirror_LNOffer { + fn into_dart(self) -> support::DartAbi { + vec![ + self.0.bolt12.into_into_dart().into_dart(), + self.0.chains.into_into_dart().into_dart(), + self.0.amount.map(|v| mirror_Amount(v)).into_dart(), + self.0.description.into_into_dart().into_dart(), + self.0.absolute_expiry.into_dart(), + self.0.issuer.into_dart(), + self.0.signing_pubkey.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl support::IntoDartExceptPrimitive for mirror_LNOffer {} +impl rust2dart::IntoIntoDart for LNOffer { + fn into_into_dart(self) -> mirror_LNOffer { + mirror_LNOffer(self) + } +} + impl support::IntoDart for LnPaymentDetails { fn into_dart(self) -> support::DartAbi { vec![ diff --git a/libs/sdk-flutter/lib/bridge_generated.dart b/libs/sdk-flutter/lib/bridge_generated.dart index 427038d93..30d9cdb21 100644 --- a/libs/sdk-flutter/lib/bridge_generated.dart +++ b/libs/sdk-flutter/lib/bridge_generated.dart @@ -349,6 +349,17 @@ sealed class AesSuccessActionDataResult with _$AesSuccessActionDataResult { }) = AesSuccessActionDataResult_ErrorStatus; } +@freezed +sealed class Amount with _$Amount { + const factory Amount.bitcoin({ + required int amountMsat, + }) = Amount_Bitcoin; + const factory Amount.currency({ + required String iso4217Code, + required int fractionalAmount, + }) = Amount_Currency; +} + class BackupFailedData { final String error; @@ -671,7 +682,7 @@ sealed class InputType with _$InputType { required LNInvoice invoice, }) = InputType_Bolt11; const factory InputType.bolt12({ - required String offer, + required LNOffer offer, }) = InputType_Bolt12; const factory InputType.nodeId({ required String nodeId, @@ -761,6 +772,26 @@ class LNInvoice { }); } +class LNOffer { + final String bolt12; + final List chains; + final Amount? amount; + final String description; + final int? absoluteExpiry; + final String? issuer; + final String signingPubkey; + + const LNOffer({ + required this.bolt12, + required this.chains, + this.amount, + required this.description, + this.absoluteExpiry, + this.issuer, + required this.signingPubkey, + }); +} + /// Details of a LN payment, as included in a [Payment] class LnPaymentDetails { final String paymentHash; @@ -3096,6 +3127,22 @@ class BreezSdkCoreImpl implements BreezSdkCore { } } + Amount _wire2api_amount(dynamic raw) { + switch (raw[0]) { + case 0: + return Amount_Bitcoin( + amountMsat: _wire2api_u64(raw[1]), + ); + case 1: + return Amount_Currency( + iso4217Code: _wire2api_String(raw[1]), + fractionalAmount: _wire2api_u64(raw[2]), + ); + default: + throw Exception("unreachable"); + } + } + BackupFailedData _wire2api_backup_failed_data(dynamic raw) { final arr = raw as List; if (arr.length != 1) throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); @@ -3137,6 +3184,10 @@ class BreezSdkCoreImpl implements BreezSdkCore { return _wire2api_aes_success_action_data_result(raw); } + Amount _wire2api_box_autoadd_amount(dynamic raw) { + return _wire2api_amount(raw); + } + BackupFailedData _wire2api_box_autoadd_backup_failed_data(dynamic raw) { return _wire2api_backup_failed_data(raw); } @@ -3173,6 +3224,10 @@ class BreezSdkCoreImpl implements BreezSdkCore { return _wire2api_ln_invoice(raw); } + LNOffer _wire2api_box_autoadd_ln_offer(dynamic raw) { + return _wire2api_ln_offer(raw); + } + LnPaymentDetails _wire2api_box_autoadd_ln_payment_details(dynamic raw) { return _wire2api_ln_payment_details(raw); } @@ -3425,7 +3480,7 @@ class BreezSdkCoreImpl implements BreezSdkCore { ); case 2: return InputType_Bolt12( - offer: _wire2api_String(raw[1]), + offer: _wire2api_box_autoadd_ln_offer(raw[1]), ); case 3: return InputType_NodeId( @@ -3533,6 +3588,20 @@ class BreezSdkCoreImpl implements BreezSdkCore { ); } + LNOffer _wire2api_ln_offer(dynamic raw) { + final arr = raw as List; + if (arr.length != 7) throw Exception('unexpected arr length: expect 7 but see ${arr.length}'); + return LNOffer( + bolt12: _wire2api_String(arr[0]), + chains: _wire2api_StringList(arr[1]), + amount: _wire2api_opt_box_autoadd_amount(arr[2]), + description: _wire2api_String(arr[3]), + absoluteExpiry: _wire2api_opt_box_autoadd_u64(arr[4]), + issuer: _wire2api_opt_String(arr[5]), + signingPubkey: _wire2api_String(arr[6]), + ); + } + LnPaymentDetails _wire2api_ln_payment_details(dynamic raw) { final arr = raw as List; if (arr.length != 16) throw Exception('unexpected arr length: expect 16 but see ${arr.length}'); @@ -3836,6 +3905,10 @@ class BreezSdkCoreImpl implements BreezSdkCore { return raw == null ? null : _wire2api_StringList(raw); } + Amount? _wire2api_opt_box_autoadd_amount(dynamic raw) { + return raw == null ? null : _wire2api_box_autoadd_amount(raw); + } + bool? _wire2api_opt_box_autoadd_bool(dynamic raw) { return raw == null ? null : _wire2api_box_autoadd_bool(raw); } diff --git a/libs/sdk-flutter/lib/bridge_generated.freezed.dart b/libs/sdk-flutter/lib/bridge_generated.freezed.dart index 3a169ac53..e37ad2035 100644 --- a/libs/sdk-flutter/lib/bridge_generated.freezed.dart +++ b/libs/sdk-flutter/lib/bridge_generated.freezed.dart @@ -347,6 +347,335 @@ abstract class AesSuccessActionDataResult_ErrorStatus implements AesSuccessActio get copyWith => throw _privateConstructorUsedError; } +/// @nodoc +mixin _$Amount { + @optionalTypeArgs + TResult when({ + required TResult Function(int amountMsat) bitcoin, + required TResult Function(String iso4217Code, int fractionalAmount) currency, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(int amountMsat)? bitcoin, + TResult? Function(String iso4217Code, int fractionalAmount)? currency, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(int amountMsat)? bitcoin, + TResult Function(String iso4217Code, int fractionalAmount)? currency, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Amount_Bitcoin value) bitcoin, + required TResult Function(Amount_Currency value) currency, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Amount_Bitcoin value)? bitcoin, + TResult? Function(Amount_Currency value)? currency, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Amount_Bitcoin value)? bitcoin, + TResult Function(Amount_Currency value)? currency, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AmountCopyWith<$Res> { + factory $AmountCopyWith(Amount value, $Res Function(Amount) then) = _$AmountCopyWithImpl<$Res, Amount>; +} + +/// @nodoc +class _$AmountCopyWithImpl<$Res, $Val extends Amount> implements $AmountCopyWith<$Res> { + _$AmountCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; +} + +/// @nodoc +abstract class _$$Amount_BitcoinImplCopyWith<$Res> { + factory _$$Amount_BitcoinImplCopyWith( + _$Amount_BitcoinImpl value, $Res Function(_$Amount_BitcoinImpl) then) = + __$$Amount_BitcoinImplCopyWithImpl<$Res>; + @useResult + $Res call({int amountMsat}); +} + +/// @nodoc +class __$$Amount_BitcoinImplCopyWithImpl<$Res> extends _$AmountCopyWithImpl<$Res, _$Amount_BitcoinImpl> + implements _$$Amount_BitcoinImplCopyWith<$Res> { + __$$Amount_BitcoinImplCopyWithImpl(_$Amount_BitcoinImpl _value, $Res Function(_$Amount_BitcoinImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? amountMsat = null, + }) { + return _then(_$Amount_BitcoinImpl( + amountMsat: null == amountMsat + ? _value.amountMsat + : amountMsat // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +class _$Amount_BitcoinImpl implements Amount_Bitcoin { + const _$Amount_BitcoinImpl({required this.amountMsat}); + + @override + final int amountMsat; + + @override + String toString() { + return 'Amount.bitcoin(amountMsat: $amountMsat)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$Amount_BitcoinImpl && + (identical(other.amountMsat, amountMsat) || other.amountMsat == amountMsat)); + } + + @override + int get hashCode => Object.hash(runtimeType, amountMsat); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$Amount_BitcoinImplCopyWith<_$Amount_BitcoinImpl> get copyWith => + __$$Amount_BitcoinImplCopyWithImpl<_$Amount_BitcoinImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(int amountMsat) bitcoin, + required TResult Function(String iso4217Code, int fractionalAmount) currency, + }) { + return bitcoin(amountMsat); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(int amountMsat)? bitcoin, + TResult? Function(String iso4217Code, int fractionalAmount)? currency, + }) { + return bitcoin?.call(amountMsat); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(int amountMsat)? bitcoin, + TResult Function(String iso4217Code, int fractionalAmount)? currency, + required TResult orElse(), + }) { + if (bitcoin != null) { + return bitcoin(amountMsat); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Amount_Bitcoin value) bitcoin, + required TResult Function(Amount_Currency value) currency, + }) { + return bitcoin(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Amount_Bitcoin value)? bitcoin, + TResult? Function(Amount_Currency value)? currency, + }) { + return bitcoin?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Amount_Bitcoin value)? bitcoin, + TResult Function(Amount_Currency value)? currency, + required TResult orElse(), + }) { + if (bitcoin != null) { + return bitcoin(this); + } + return orElse(); + } +} + +abstract class Amount_Bitcoin implements Amount { + const factory Amount_Bitcoin({required final int amountMsat}) = _$Amount_BitcoinImpl; + + int get amountMsat; + @JsonKey(ignore: true) + _$$Amount_BitcoinImplCopyWith<_$Amount_BitcoinImpl> get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$Amount_CurrencyImplCopyWith<$Res> { + factory _$$Amount_CurrencyImplCopyWith( + _$Amount_CurrencyImpl value, $Res Function(_$Amount_CurrencyImpl) then) = + __$$Amount_CurrencyImplCopyWithImpl<$Res>; + @useResult + $Res call({String iso4217Code, int fractionalAmount}); +} + +/// @nodoc +class __$$Amount_CurrencyImplCopyWithImpl<$Res> extends _$AmountCopyWithImpl<$Res, _$Amount_CurrencyImpl> + implements _$$Amount_CurrencyImplCopyWith<$Res> { + __$$Amount_CurrencyImplCopyWithImpl( + _$Amount_CurrencyImpl _value, $Res Function(_$Amount_CurrencyImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? iso4217Code = null, + Object? fractionalAmount = null, + }) { + return _then(_$Amount_CurrencyImpl( + iso4217Code: null == iso4217Code + ? _value.iso4217Code + : iso4217Code // ignore: cast_nullable_to_non_nullable + as String, + fractionalAmount: null == fractionalAmount + ? _value.fractionalAmount + : fractionalAmount // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +class _$Amount_CurrencyImpl implements Amount_Currency { + const _$Amount_CurrencyImpl({required this.iso4217Code, required this.fractionalAmount}); + + @override + final String iso4217Code; + @override + final int fractionalAmount; + + @override + String toString() { + return 'Amount.currency(iso4217Code: $iso4217Code, fractionalAmount: $fractionalAmount)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$Amount_CurrencyImpl && + (identical(other.iso4217Code, iso4217Code) || other.iso4217Code == iso4217Code) && + (identical(other.fractionalAmount, fractionalAmount) || + other.fractionalAmount == fractionalAmount)); + } + + @override + int get hashCode => Object.hash(runtimeType, iso4217Code, fractionalAmount); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$Amount_CurrencyImplCopyWith<_$Amount_CurrencyImpl> get copyWith => + __$$Amount_CurrencyImplCopyWithImpl<_$Amount_CurrencyImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(int amountMsat) bitcoin, + required TResult Function(String iso4217Code, int fractionalAmount) currency, + }) { + return currency(iso4217Code, fractionalAmount); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(int amountMsat)? bitcoin, + TResult? Function(String iso4217Code, int fractionalAmount)? currency, + }) { + return currency?.call(iso4217Code, fractionalAmount); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(int amountMsat)? bitcoin, + TResult Function(String iso4217Code, int fractionalAmount)? currency, + required TResult orElse(), + }) { + if (currency != null) { + return currency(iso4217Code, fractionalAmount); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Amount_Bitcoin value) bitcoin, + required TResult Function(Amount_Currency value) currency, + }) { + return currency(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Amount_Bitcoin value)? bitcoin, + TResult? Function(Amount_Currency value)? currency, + }) { + return currency?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Amount_Bitcoin value)? bitcoin, + TResult Function(Amount_Currency value)? currency, + required TResult orElse(), + }) { + if (currency != null) { + return currency(this); + } + return orElse(); + } +} + +abstract class Amount_Currency implements Amount { + const factory Amount_Currency({required final String iso4217Code, required final int fractionalAmount}) = + _$Amount_CurrencyImpl; + + String get iso4217Code; + int get fractionalAmount; + @JsonKey(ignore: true) + _$$Amount_CurrencyImplCopyWith<_$Amount_CurrencyImpl> get copyWith => throw _privateConstructorUsedError; +} + /// @nodoc mixin _$BreezEvent { @optionalTypeArgs @@ -2180,7 +2509,7 @@ mixin _$InputType { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2193,7 +2522,7 @@ mixin _$InputType { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2206,7 +2535,7 @@ mixin _$InputType { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2340,7 +2669,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2356,7 +2685,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2372,7 +2701,7 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2515,7 +2844,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2531,7 +2860,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2547,7 +2876,7 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2629,7 +2958,7 @@ abstract class _$$InputType_Bolt12ImplCopyWith<$Res> { _$InputType_Bolt12Impl value, $Res Function(_$InputType_Bolt12Impl) then) = __$$InputType_Bolt12ImplCopyWithImpl<$Res>; @useResult - $Res call({String offer}); + $Res call({LNOffer offer}); } /// @nodoc @@ -2648,7 +2977,7 @@ class __$$InputType_Bolt12ImplCopyWithImpl<$Res> extends _$InputTypeCopyWithImpl offer: null == offer ? _value.offer : offer // ignore: cast_nullable_to_non_nullable - as String, + as LNOffer, )); } } @@ -2659,7 +2988,7 @@ class _$InputType_Bolt12Impl implements InputType_Bolt12 { const _$InputType_Bolt12Impl({required this.offer}); @override - final String offer; + final LNOffer offer; @override String toString() { @@ -2688,7 +3017,7 @@ class _$InputType_Bolt12Impl implements InputType_Bolt12 { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2704,7 +3033,7 @@ class _$InputType_Bolt12Impl implements InputType_Bolt12 { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2720,7 +3049,7 @@ class _$InputType_Bolt12Impl implements InputType_Bolt12 { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2789,9 +3118,9 @@ class _$InputType_Bolt12Impl implements InputType_Bolt12 { } abstract class InputType_Bolt12 implements InputType { - const factory InputType_Bolt12({required final String offer}) = _$InputType_Bolt12Impl; + const factory InputType_Bolt12({required final LNOffer offer}) = _$InputType_Bolt12Impl; - String get offer; + LNOffer get offer; @JsonKey(ignore: true) _$$InputType_Bolt12ImplCopyWith<_$InputType_Bolt12Impl> get copyWith => throw _privateConstructorUsedError; } @@ -2861,7 +3190,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2877,7 +3206,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2893,7 +3222,7 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3032,7 +3361,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3048,7 +3377,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3064,7 +3393,7 @@ class _$InputType_UrlImpl implements InputType_Url { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3206,7 +3535,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3222,7 +3551,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3238,7 +3567,7 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3381,7 +3710,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3397,7 +3726,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3413,7 +3742,7 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3557,7 +3886,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3573,7 +3902,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3589,7 +3918,7 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3732,7 +4061,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(String offer) bolt12, + required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3748,7 +4077,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(String offer)? bolt12, + TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3764,7 +4093,7 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(String offer)? bolt12, + TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, diff --git a/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt b/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt index c6fb8af6c..069f6a232 100644 --- a/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt +++ b/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt @@ -830,6 +830,59 @@ fun asLnInvoiceList(arr: ReadableArray): List { return list } +fun asLnOffer(lnOffer: ReadableMap): LnOffer? { + if (!validateMandatoryFields( + lnOffer, + arrayOf( + "bolt12", + "chains", + "description", + "signingPubkey", + ), + ) + ) { + return null + } + val bolt12 = lnOffer.getString("bolt12")!! + val chains = lnOffer.getArray("chains")?.let { asStringList(it) }!! + val description = lnOffer.getString("description")!! + val signingPubkey = lnOffer.getString("signingPubkey")!! + val amount = if (hasNonNullKey(lnOffer, "amount")) lnOffer.getMap("amount")?.let { asAmount(it) } else null + val absoluteExpiry = if (hasNonNullKey(lnOffer, "absoluteExpiry")) lnOffer.getDouble("absoluteExpiry").toULong() else null + val issuer = if (hasNonNullKey(lnOffer, "issuer")) lnOffer.getString("issuer") else null + return LnOffer( + bolt12, + chains, + description, + signingPubkey, + amount, + absoluteExpiry, + issuer, + ) +} + +fun readableMapOf(lnOffer: LnOffer): ReadableMap = + readableMapOf( + "bolt12" to lnOffer.bolt12, + "chains" to readableArrayOf(lnOffer.chains), + "description" to lnOffer.description, + "signingPubkey" to lnOffer.signingPubkey, + "amount" to lnOffer.amount?.let { readableMapOf(it) }, + "absoluteExpiry" to lnOffer.absoluteExpiry, + "issuer" to lnOffer.issuer, + ) + +fun asLnOfferList(arr: ReadableArray): List { + val list = ArrayList() + for (value in arr.toArrayList()) { + when (value) { + is ReadableMap -> list.add(asLnOffer(value)!!) + else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}")) + } + } + return list +} + fun asListPaymentsRequest(listPaymentsRequest: ReadableMap): ListPaymentsRequest? { if (!validateMandatoryFields( listPaymentsRequest, @@ -3822,6 +3875,45 @@ fun asAesSuccessActionDataResultList(arr: ReadableArray): List { + pushToMap(map, "type", "bitcoin") + pushToMap(map, "amountMsat", amount.amountMsat) + } + is Amount.Currency -> { + pushToMap(map, "type", "currency") + pushToMap(map, "iso4217Code", amount.iso4217Code) + pushToMap(map, "fractionalAmount", amount.fractionalAmount) + } + } + return map +} + +fun asAmountList(arr: ReadableArray): List { + val list = ArrayList() + for (value in arr.toArrayList()) { + when (value) { + is ReadableMap -> list.add(asAmount(value)!!) + else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}")) + } + } + return list +} + fun asBreezEvent(breezEvent: ReadableMap): BreezEvent? { val type = breezEvent.getString("type") @@ -3988,7 +4080,7 @@ fun asInputType(inputType: ReadableMap): InputType? { return InputType.Bolt11(inputType.getMap("invoice")?.let { asLnInvoice(it) }!!) } if (type == "bolt12") { - return InputType.Bolt12(inputType.getString("offer")!!) + return InputType.Bolt12(inputType.getMap("offer")?.let { asLnOffer(it) }!!) } if (type == "nodeId") { return InputType.NodeId(inputType.getString("nodeId")!!) @@ -4024,7 +4116,7 @@ fun readableMapOf(inputType: InputType): ReadableMap? { } is InputType.Bolt12 -> { pushToMap(map, "type", "bolt12") - pushToMap(map, "offer", inputType.offer) + pushToMap(map, "offer", readableMapOf(inputType.offer)) } is InputType.NodeId -> { pushToMap(map, "type", "nodeId") diff --git a/libs/sdk-react-native/ios/BreezSDKMapper.swift b/libs/sdk-react-native/ios/BreezSDKMapper.swift index 4bfe0a79c..2e72bb743 100644 --- a/libs/sdk-react-native/ios/BreezSDKMapper.swift +++ b/libs/sdk-react-native/ios/BreezSDKMapper.swift @@ -962,6 +962,79 @@ enum BreezSDKMapper { return lnInvoiceList.map { v -> [String: Any?] in return dictionaryOf(lnInvoice: v) } } + static func asLnOffer(lnOffer: [String: Any?]) throws -> LnOffer { + guard let bolt12 = lnOffer["bolt12"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bolt12", typeName: "LnOffer")) + } + guard let chains = lnOffer["chains"] as? [String] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "chains", typeName: "LnOffer")) + } + guard let description = lnOffer["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "LnOffer")) + } + guard let signingPubkey = lnOffer["signingPubkey"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signingPubkey", typeName: "LnOffer")) + } + var amount: Amount? + if let amountTmp = lnOffer["amount"] as? [String: Any?] { + amount = try asAmount(amount: amountTmp) + } + + var absoluteExpiry: UInt64? + if hasNonNilKey(data: lnOffer, key: "absoluteExpiry") { + guard let absoluteExpiryTmp = lnOffer["absoluteExpiry"] as? UInt64 else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "absoluteExpiry")) + } + absoluteExpiry = absoluteExpiryTmp + } + var issuer: String? + if hasNonNilKey(data: lnOffer, key: "issuer") { + guard let issuerTmp = lnOffer["issuer"] as? String else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "issuer")) + } + issuer = issuerTmp + } + + return LnOffer( + bolt12: bolt12, + chains: chains, + description: description, + signingPubkey: signingPubkey, + amount: amount, + absoluteExpiry: absoluteExpiry, + issuer: issuer + ) + } + + static func dictionaryOf(lnOffer: LnOffer) -> [String: Any?] { + return [ + "bolt12": lnOffer.bolt12, + "chains": lnOffer.chains, + "description": lnOffer.description, + "signingPubkey": lnOffer.signingPubkey, + "amount": lnOffer.amount == nil ? nil : dictionaryOf(amount: lnOffer.amount!), + "absoluteExpiry": lnOffer.absoluteExpiry == nil ? nil : lnOffer.absoluteExpiry, + "issuer": lnOffer.issuer == nil ? nil : lnOffer.issuer, + ] + } + + static func asLnOfferList(arr: [Any]) throws -> [LnOffer] { + var list = [LnOffer]() + for value in arr { + if let val = value as? [String: Any?] { + var lnOffer = try asLnOffer(lnOffer: val) + list.append(lnOffer) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnOffer")) + } + } + return list + } + + static func arrayOf(lnOfferList: [LnOffer]) -> [Any] { + return lnOfferList.map { v -> [String: Any?] in return dictionaryOf(lnOffer: v) } + } + static func asListPaymentsRequest(listPaymentsRequest: [String: Any?]) throws -> ListPaymentsRequest { var filters: [PaymentTypeFilter]? if let filtersTmp = listPaymentsRequest["filters"] as? [String] { @@ -4330,6 +4403,62 @@ enum BreezSDKMapper { return list } + static func asAmount(amount: [String: Any?]) throws -> Amount { + let type = amount["type"] as! String + if type == "bitcoin" { + guard let _amountMsat = amount["amountMsat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "Amount")) + } + return Amount.bitcoin(amountMsat: _amountMsat) + } + if type == "currency" { + guard let _iso4217Code = amount["iso4217Code"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "iso4217Code", typeName: "Amount")) + } + return Amount.currency(iso4217Code: _iso4217Code) + } + + throw SdkError.Generic(message: "Unexpected type \(type) for enum Amount") + } + + static func dictionaryOf(amount: Amount) -> [String: Any?] { + switch amount { + case let .bitcoin( + amountMsat + ): + return [ + "type": "bitcoin", + "amountMsat": amountMsat, + ] + + case let .currency( + iso4217Code, fractionalAmount + ): + return [ + "type": "currency", + "iso4217Code": iso4217Code, + "fractionalAmount": fractionalAmount, + ] + } + } + + static func arrayOf(amountList: [Amount]) -> [Any] { + return amountList.map { v -> [String: Any?] in return dictionaryOf(amount: v) } + } + + static func asAmountList(arr: [Any]) throws -> [Amount] { + var list = [Amount]() + for value in arr { + if let val = value as? [String: Any?] { + var amount = try asAmount(amount: val) + list.append(amount) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Amount")) + } + } + return list + } + static func asBreezEvent(breezEvent: [String: Any?]) throws -> BreezEvent { let type = breezEvent["type"] as! String if type == "newBlock" { @@ -4723,9 +4852,11 @@ enum BreezSDKMapper { return InputType.bolt11(invoice: _invoice) } if type == "bolt12" { - guard let _offer = inputType["offer"] as? String else { + guard let offerTmp = inputType["offer"] as? [String: Any?] else { throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "offer", typeName: "InputType")) } + let _offer = try asLnOffer(lnOffer: offerTmp) + return InputType.bolt12(offer: _offer) } if type == "nodeId" { @@ -4799,7 +4930,7 @@ enum BreezSDKMapper { ): return [ "type": "bolt12", - "offer": offer, + "offer": dictionaryOf(lnOffer: offer), ] case let .nodeId( diff --git a/libs/sdk-react-native/src/index.ts b/libs/sdk-react-native/src/index.ts index 2bf4e885f..f514c2177 100644 --- a/libs/sdk-react-native/src/index.ts +++ b/libs/sdk-react-native/src/index.ts @@ -143,6 +143,16 @@ export interface LnInvoice { minFinalCltvExpiryDelta: number } +export interface LnOffer { + bolt12: string + chains: string[] + description: string + signingPubkey: string + amount?: Amount + absoluteExpiry?: number + issuer?: string +} + export interface ListPaymentsRequest { filters?: PaymentTypeFilter[] metadataFilters?: MetadataFilter[] @@ -601,6 +611,20 @@ export type AesSuccessActionDataResult = { reason: string } +export enum AmountVariant { + BITCOIN = "bitcoin", + CURRENCY = "currency" +} + +export type Amount = { + type: AmountVariant.BITCOIN, + amountMsat: number +} | { + type: AmountVariant.CURRENCY, + iso4217Code: string + fractionalAmount: number +} + export enum BreezEventVariant { NEW_BLOCK = "newBlock", INVOICE_PAID = "invoicePaid", @@ -691,7 +715,7 @@ export type InputType = { invoice: LnInvoice } | { type: InputTypeVariant.BOLT12, - offer: string + offer: LnOffer } | { type: InputTypeVariant.NODE_ID, nodeId: string From c7abd3d4dcec1d8ac0fe05b844e7c75b9cd1d59a Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:12:44 +0100 Subject: [PATCH 03/12] Expose Bolt12Offer input type behind "liquid" feature --- libs/sdk-bindings/src/breez_sdk.udl | 17 - libs/sdk-bindings/src/uniffi_binding.rs | 4 +- libs/sdk-common/src/input_parser.rs | 35 +- libs/sdk-common/src/invoice.rs | 42 -- libs/sdk-core/src/binding.rs | 35 +- libs/sdk-core/src/bridge_generated.rs | 90 +-- libs/sdk-flutter/lib/bridge_generated.dart | 90 +-- .../lib/bridge_generated.freezed.dart | 556 ------------------ .../main/java/com/breezsdk/BreezSDKMapper.kt | 99 ---- .../sdk-react-native/ios/BreezSDKMapper.swift | 145 ----- libs/sdk-react-native/src/index.ts | 28 - 11 files changed, 21 insertions(+), 1120 deletions(-) diff --git a/libs/sdk-bindings/src/breez_sdk.udl b/libs/sdk-bindings/src/breez_sdk.udl index f89659def..07310ef7f 100644 --- a/libs/sdk-bindings/src/breez_sdk.udl +++ b/libs/sdk-bindings/src/breez_sdk.udl @@ -730,27 +730,10 @@ dictionary RecommendedFees { u64 minimum_fee; }; -[Enum] -interface Amount { - Bitcoin(u64 amount_msat); - Currency(string iso4217_code, u64 fractional_amount); -}; - -dictionary LNOffer { - string bolt12; - sequence chains; - string description; - string signing_pubkey; - Amount? amount; - u64? absolute_expiry; - string? issuer; -}; - [Enum] interface InputType { BitcoinAddress(BitcoinAddressData address); Bolt11(LNInvoice invoice); - Bolt12(LNOffer offer); NodeId(string node_id); Url(string url); LnUrlPay(LnUrlPayRequestData data); diff --git a/libs/sdk-bindings/src/uniffi_binding.rs b/libs/sdk-bindings/src/uniffi_binding.rs index ccc4dcd7a..1de3ff14d 100644 --- a/libs/sdk-bindings/src/uniffi_binding.rs +++ b/libs/sdk-bindings/src/uniffi_binding.rs @@ -5,12 +5,12 @@ 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, - Amount, BackupFailedData, BackupStatus, BitcoinAddressData, BreezEvent, BreezServices, + BackupFailedData, BackupStatus, BitcoinAddressData, BreezEvent, BreezServices, BuyBitcoinProvider, BuyBitcoinRequest, BuyBitcoinResponse, ChannelState, CheckMessageRequest, CheckMessageResponse, ClosedChannelPaymentDetails, Config, ConfigureNodeRequest, ConnectRequest, CurrencyInfo, EnvironmentType, EventListener, FeeratePreset, FiatCurrency, GreenlightCredentials, GreenlightDeviceCredentials, GreenlightNodeConfig, HealthCheckStatus, - InputType, InvoicePaidDetails, LNInvoice, LNOffer, ListPaymentsRequest, LnPaymentDetails, + InputType, InvoicePaidDetails, LNInvoice, ListPaymentsRequest, LnPaymentDetails, LnUrlAuthError, LnUrlAuthRequestData, LnUrlCallbackStatus, LnUrlErrorData, LnUrlPayError, LnUrlPayErrorData, LnUrlPayRequest, LnUrlPayRequestData, LnUrlWithdrawError, LnUrlWithdrawRequest, LnUrlWithdrawRequestData, LnUrlWithdrawResult, LnUrlWithdrawSuccessData, diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index 5d2753eb9..d642cc268 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -1,12 +1,11 @@ +use std::collections::HashMap; use std::str::FromStr; use ::bip21::Uri; use anyhow::{anyhow, Result}; use bitcoin::bech32; use bitcoin::bech32::FromBase32; -use lightning::offers::offer::Offer; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; use LnUrlRequestData::*; use crate::prelude::*; @@ -186,24 +185,6 @@ pub async fn parse(input: &str) -> Result { return Ok(InputType::Bolt11 { invoice }); } - if let Ok(offer) = input.parse::() { - return Ok(InputType::Bolt12 { - offer: LNOffer { - bolt12: input.to_string(), - chains: offer - .chains() - .iter() - .map(|chain| chain.to_string()) - .collect(), - amount: offer.amount().map(|amount| amount.clone().into()), - description: offer.description().to_string(), - absolute_expiry: offer.absolute_expiry().map(|expiry| expiry.as_secs()), - issuer: offer.issuer().map(|s| s.to_string()), - signing_pubkey: offer.signing_pubkey().to_string(), - }, - }); - } - // Public key serialized in compressed form (66 hex chars) if let Ok(_node_id) = bitcoin::secp256k1::PublicKey::from_str(input) { return Ok(InputType::NodeId { @@ -437,6 +418,7 @@ pub enum InputType { Bolt11 { invoice: LNInvoice, }, + #[cfg(feature = "liquid")] Bolt12 { offer: LNOffer, }, @@ -948,19 +930,6 @@ pub(crate) mod tests { Ok(()) } - #[tokio::test] - async fn test_bolt12_offer() -> Result<()> { - let bolt12_offer = "lno1pqpzwyq2p32x2um5ypmx2cm5dae8x93pqthvwfzadd7jejes8q9lhc4rvjxd022zv5l44g6qah82ru5rdpnpj"; - - assert!(matches!( - parse(bolt12_offer).await?, - InputType::Bolt12 { offer } - if offer == bolt12_offer - )); - - Ok(()) - } - #[tokio::test] async fn test_url() -> Result<()> { assert!(matches!( diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index c59a6de78..fe6b4c390 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -101,48 +101,6 @@ fn format_short_channel_id(id: u64) -> String { format!("{block_num}x{tx_num}x{tx_out}") } -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub enum Amount { - Bitcoin { - amount_msat: u64, - }, - Currency { - // Reference to [FiatCurrency.id] - iso4217_code: String, - fractional_amount: u64, - }, -} - -impl From for Amount { - fn from(amount: lightning::offers::offer::Amount) -> Self { - match amount { - lightning::offers::offer::Amount::Bitcoin { amount_msats } => Amount::Bitcoin { - amount_msat: amount_msats, - }, - lightning::offers::offer::Amount::Currency { - iso4217_code, - amount, - } => Amount::Currency { - iso4217_code: String::from_utf8(iso4217_code.to_vec()) - .expect("Expecting a valid ISO 4217 character sequence"), - fractional_amount: amount, - }, - } - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct LNOffer { - pub bolt12: String, - pub chains: Vec, - pub amount: Option, - pub description: String, - pub absolute_expiry: Option, - pub issuer: Option, - pub signing_pubkey: String, - // pub paths: Vec, -} - /// Wrapper for a BOLT11 LN invoice #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct LNInvoice { diff --git a/libs/sdk-core/src/binding.rs b/libs/sdk-core/src/binding.rs index 8c74cd0b2..d4636cce8 100644 --- a/libs/sdk-core/src/binding.rs +++ b/libs/sdk-core/src/binding.rs @@ -19,12 +19,12 @@ use log::{Level, LevelFilter, Metadata, Record}; use once_cell::sync::{Lazy, OnceCell}; use sdk_common::invoice; pub use sdk_common::prelude::{ - parse, AesSuccessActionDataDecrypted, AesSuccessActionDataResult, Amount, BitcoinAddressData, - CurrencyInfo, FiatCurrency, InputType, LNInvoice, LNOffer, LnUrlAuthRequestData, - LnUrlCallbackStatus, LnUrlError, LnUrlErrorData, LnUrlPayErrorData, LnUrlPayRequest, - LnUrlPayRequestData, LnUrlWithdrawRequest, LnUrlWithdrawRequestData, LnUrlWithdrawResult, - LnUrlWithdrawSuccessData, LocaleOverrides, LocalizedName, MessageSuccessActionData, Network, - Rate, RouteHint, RouteHintHop, SuccessActionProcessed, Symbol, UrlSuccessActionData, + parse, AesSuccessActionDataDecrypted, AesSuccessActionDataResult, BitcoinAddressData, + CurrencyInfo, FiatCurrency, InputType, LNInvoice, LnUrlAuthRequestData, LnUrlCallbackStatus, + LnUrlError, LnUrlErrorData, LnUrlPayErrorData, LnUrlPayRequest, LnUrlPayRequestData, + LnUrlWithdrawRequest, LnUrlWithdrawRequestData, LnUrlWithdrawResult, LnUrlWithdrawSuccessData, + LocaleOverrides, LocalizedName, MessageSuccessActionData, Network, Rate, RouteHint, + RouteHintHop, SuccessActionProcessed, Symbol, UrlSuccessActionData, }; use tokio::sync::Mutex; @@ -158,33 +158,10 @@ pub struct _LnUrlWithdrawRequestData { pub max_withdrawable: u64, } -#[frb(mirror(Amount))] -pub enum _Amount { - Bitcoin { - amount_msat: u64, - }, - Currency { - iso4217_code: String, - fractional_amount: u64, - }, -} - -#[frb(mirror(LNOffer))] -pub struct _LNOffer { - pub bolt12: String, - pub chains: Vec, - pub amount: Option, - pub description: String, - pub absolute_expiry: Option, - pub issuer: Option, - pub signing_pubkey: String, -} - #[frb(mirror(InputType))] pub enum _InputType { BitcoinAddress { address: BitcoinAddressData }, Bolt11 { invoice: LNInvoice }, - Bolt12 { offer: LNOffer }, NodeId { node_id: String }, Url { url: String }, LnUrlPay { data: LnUrlPayRequestData }, diff --git a/libs/sdk-core/src/bridge_generated.rs b/libs/sdk-core/src/bridge_generated.rs index 55680ab57..5d6c32529 100644 --- a/libs/sdk-core/src/bridge_generated.rs +++ b/libs/sdk-core/src/bridge_generated.rs @@ -910,9 +910,6 @@ pub struct mirror_AesSuccessActionDataDecrypted(AesSuccessActionDataDecrypted); #[derive(Clone)] pub struct mirror_AesSuccessActionDataResult(AesSuccessActionDataResult); -#[derive(Clone)] -pub struct mirror_Amount(Amount); - #[derive(Clone)] pub struct mirror_BitcoinAddressData(BitcoinAddressData); @@ -928,9 +925,6 @@ pub struct mirror_InputType(InputType); #[derive(Clone)] pub struct mirror_LNInvoice(LNInvoice); -#[derive(Clone)] -pub struct mirror_LNOffer(LNOffer); - #[derive(Clone)] pub struct mirror_LnUrlAuthRequestData(LnUrlAuthRequestData); @@ -1001,18 +995,6 @@ const _: fn() = || { let _: String = reason; } } - match None::.unwrap() { - Amount::Bitcoin { amount_msat } => { - let _: u64 = amount_msat; - } - Amount::Currency { - iso4217_code, - fractional_amount, - } => { - let _: String = iso4217_code; - let _: u64 = fractional_amount; - } - } { let BitcoinAddressData = None::.unwrap(); let _: String = BitcoinAddressData.address; @@ -1043,9 +1025,6 @@ const _: fn() = || { InputType::Bolt11 { invoice } => { let _: LNInvoice = invoice; } - InputType::Bolt12 { offer } => { - let _: LNOffer = offer; - } InputType::NodeId { node_id } => { let _: String = node_id; } @@ -1080,16 +1059,6 @@ const _: fn() = || { let _: Vec = LNInvoice.payment_secret; let _: u64 = LNInvoice.min_final_cltv_expiry_delta; } - { - let LNOffer = None::.unwrap(); - let _: String = LNOffer.bolt12; - let _: Vec = LNOffer.chains; - let _: Option = LNOffer.amount; - let _: String = LNOffer.description; - let _: Option = LNOffer.absolute_expiry; - let _: Option = LNOffer.issuer; - let _: String = LNOffer.signing_pubkey; - } { let LnUrlAuthRequestData = None::.unwrap(); let _: String = LnUrlAuthRequestData.k1; @@ -1365,31 +1334,6 @@ impl rust2dart::IntoIntoDart for AesSuccessAc } } -impl support::IntoDart for mirror_Amount { - fn into_dart(self) -> support::DartAbi { - match self.0 { - Amount::Bitcoin { amount_msat } => { - vec![0.into_dart(), amount_msat.into_into_dart().into_dart()] - } - Amount::Currency { - iso4217_code, - fractional_amount, - } => vec![ - 1.into_dart(), - iso4217_code.into_into_dart().into_dart(), - fractional_amount.into_into_dart().into_dart(), - ], - } - .into_dart() - } -} -impl support::IntoDartExceptPrimitive for mirror_Amount {} -impl rust2dart::IntoIntoDart for Amount { - fn into_into_dart(self) -> mirror_Amount { - mirror_Amount(self) - } -} - impl support::IntoDart for BackupFailedData { fn into_dart(self) -> support::DartAbi { vec![self.error.into_into_dart().into_dart()].into_dart() @@ -1669,18 +1613,17 @@ impl support::IntoDart for mirror_InputType { InputType::Bolt11 { invoice } => { vec![1.into_dart(), invoice.into_into_dart().into_dart()] } - InputType::Bolt12 { offer } => vec![2.into_dart(), offer.into_into_dart().into_dart()], InputType::NodeId { node_id } => { - vec![3.into_dart(), node_id.into_into_dart().into_dart()] + vec![2.into_dart(), node_id.into_into_dart().into_dart()] } - InputType::Url { url } => vec![4.into_dart(), url.into_into_dart().into_dart()], - InputType::LnUrlPay { data } => vec![5.into_dart(), data.into_into_dart().into_dart()], + InputType::Url { url } => vec![3.into_dart(), url.into_into_dart().into_dart()], + InputType::LnUrlPay { data } => vec![4.into_dart(), data.into_into_dart().into_dart()], InputType::LnUrlWithdraw { data } => { - vec![6.into_dart(), data.into_into_dart().into_dart()] + vec![5.into_dart(), data.into_into_dart().into_dart()] } - InputType::LnUrlAuth { data } => vec![7.into_dart(), data.into_into_dart().into_dart()], + InputType::LnUrlAuth { data } => vec![6.into_dart(), data.into_into_dart().into_dart()], InputType::LnUrlError { data } => { - vec![8.into_dart(), data.into_into_dart().into_dart()] + vec![7.into_dart(), data.into_into_dart().into_dart()] } } .into_dart() @@ -1739,27 +1682,6 @@ impl rust2dart::IntoIntoDart for LNInvoice { } } -impl support::IntoDart for mirror_LNOffer { - fn into_dart(self) -> support::DartAbi { - vec![ - self.0.bolt12.into_into_dart().into_dart(), - self.0.chains.into_into_dart().into_dart(), - self.0.amount.map(|v| mirror_Amount(v)).into_dart(), - self.0.description.into_into_dart().into_dart(), - self.0.absolute_expiry.into_dart(), - self.0.issuer.into_dart(), - self.0.signing_pubkey.into_into_dart().into_dart(), - ] - .into_dart() - } -} -impl support::IntoDartExceptPrimitive for mirror_LNOffer {} -impl rust2dart::IntoIntoDart for LNOffer { - fn into_into_dart(self) -> mirror_LNOffer { - mirror_LNOffer(self) - } -} - impl support::IntoDart for LnPaymentDetails { fn into_dart(self) -> support::DartAbi { vec![ diff --git a/libs/sdk-flutter/lib/bridge_generated.dart b/libs/sdk-flutter/lib/bridge_generated.dart index 30d9cdb21..7ac7d374a 100644 --- a/libs/sdk-flutter/lib/bridge_generated.dart +++ b/libs/sdk-flutter/lib/bridge_generated.dart @@ -349,17 +349,6 @@ sealed class AesSuccessActionDataResult with _$AesSuccessActionDataResult { }) = AesSuccessActionDataResult_ErrorStatus; } -@freezed -sealed class Amount with _$Amount { - const factory Amount.bitcoin({ - required int amountMsat, - }) = Amount_Bitcoin; - const factory Amount.currency({ - required String iso4217Code, - required int fractionalAmount, - }) = Amount_Currency; -} - class BackupFailedData { final String error; @@ -681,9 +670,6 @@ sealed class InputType with _$InputType { const factory InputType.bolt11({ required LNInvoice invoice, }) = InputType_Bolt11; - const factory InputType.bolt12({ - required LNOffer offer, - }) = InputType_Bolt12; const factory InputType.nodeId({ required String nodeId, }) = InputType_NodeId; @@ -772,26 +758,6 @@ class LNInvoice { }); } -class LNOffer { - final String bolt12; - final List chains; - final Amount? amount; - final String description; - final int? absoluteExpiry; - final String? issuer; - final String signingPubkey; - - const LNOffer({ - required this.bolt12, - required this.chains, - this.amount, - required this.description, - this.absoluteExpiry, - this.issuer, - required this.signingPubkey, - }); -} - /// Details of a LN payment, as included in a [Payment] class LnPaymentDetails { final String paymentHash; @@ -3127,22 +3093,6 @@ class BreezSdkCoreImpl implements BreezSdkCore { } } - Amount _wire2api_amount(dynamic raw) { - switch (raw[0]) { - case 0: - return Amount_Bitcoin( - amountMsat: _wire2api_u64(raw[1]), - ); - case 1: - return Amount_Currency( - iso4217Code: _wire2api_String(raw[1]), - fractionalAmount: _wire2api_u64(raw[2]), - ); - default: - throw Exception("unreachable"); - } - } - BackupFailedData _wire2api_backup_failed_data(dynamic raw) { final arr = raw as List; if (arr.length != 1) throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); @@ -3184,10 +3134,6 @@ class BreezSdkCoreImpl implements BreezSdkCore { return _wire2api_aes_success_action_data_result(raw); } - Amount _wire2api_box_autoadd_amount(dynamic raw) { - return _wire2api_amount(raw); - } - BackupFailedData _wire2api_box_autoadd_backup_failed_data(dynamic raw) { return _wire2api_backup_failed_data(raw); } @@ -3224,10 +3170,6 @@ class BreezSdkCoreImpl implements BreezSdkCore { return _wire2api_ln_invoice(raw); } - LNOffer _wire2api_box_autoadd_ln_offer(dynamic raw) { - return _wire2api_ln_offer(raw); - } - LnPaymentDetails _wire2api_box_autoadd_ln_payment_details(dynamic raw) { return _wire2api_ln_payment_details(raw); } @@ -3479,30 +3421,26 @@ class BreezSdkCoreImpl implements BreezSdkCore { invoice: _wire2api_box_autoadd_ln_invoice(raw[1]), ); case 2: - return InputType_Bolt12( - offer: _wire2api_box_autoadd_ln_offer(raw[1]), - ); - case 3: return InputType_NodeId( nodeId: _wire2api_String(raw[1]), ); - case 4: + case 3: return InputType_Url( url: _wire2api_String(raw[1]), ); - case 5: + case 4: return InputType_LnUrlPay( data: _wire2api_box_autoadd_ln_url_pay_request_data(raw[1]), ); - case 6: + case 5: return InputType_LnUrlWithdraw( data: _wire2api_box_autoadd_ln_url_withdraw_request_data(raw[1]), ); - case 7: + case 6: return InputType_LnUrlAuth( data: _wire2api_box_autoadd_ln_url_auth_request_data(raw[1]), ); - case 8: + case 7: return InputType_LnUrlError( data: _wire2api_box_autoadd_ln_url_error_data(raw[1]), ); @@ -3588,20 +3526,6 @@ class BreezSdkCoreImpl implements BreezSdkCore { ); } - LNOffer _wire2api_ln_offer(dynamic raw) { - final arr = raw as List; - if (arr.length != 7) throw Exception('unexpected arr length: expect 7 but see ${arr.length}'); - return LNOffer( - bolt12: _wire2api_String(arr[0]), - chains: _wire2api_StringList(arr[1]), - amount: _wire2api_opt_box_autoadd_amount(arr[2]), - description: _wire2api_String(arr[3]), - absoluteExpiry: _wire2api_opt_box_autoadd_u64(arr[4]), - issuer: _wire2api_opt_String(arr[5]), - signingPubkey: _wire2api_String(arr[6]), - ); - } - LnPaymentDetails _wire2api_ln_payment_details(dynamic raw) { final arr = raw as List; if (arr.length != 16) throw Exception('unexpected arr length: expect 16 but see ${arr.length}'); @@ -3905,10 +3829,6 @@ class BreezSdkCoreImpl implements BreezSdkCore { return raw == null ? null : _wire2api_StringList(raw); } - Amount? _wire2api_opt_box_autoadd_amount(dynamic raw) { - return raw == null ? null : _wire2api_box_autoadd_amount(raw); - } - bool? _wire2api_opt_box_autoadd_bool(dynamic raw) { return raw == null ? null : _wire2api_box_autoadd_bool(raw); } diff --git a/libs/sdk-flutter/lib/bridge_generated.freezed.dart b/libs/sdk-flutter/lib/bridge_generated.freezed.dart index e37ad2035..15ddfc256 100644 --- a/libs/sdk-flutter/lib/bridge_generated.freezed.dart +++ b/libs/sdk-flutter/lib/bridge_generated.freezed.dart @@ -347,335 +347,6 @@ abstract class AesSuccessActionDataResult_ErrorStatus implements AesSuccessActio get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -mixin _$Amount { - @optionalTypeArgs - TResult when({ - required TResult Function(int amountMsat) bitcoin, - required TResult Function(String iso4217Code, int fractionalAmount) currency, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(int amountMsat)? bitcoin, - TResult? Function(String iso4217Code, int fractionalAmount)? currency, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(int amountMsat)? bitcoin, - TResult Function(String iso4217Code, int fractionalAmount)? currency, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(Amount_Bitcoin value) bitcoin, - required TResult Function(Amount_Currency value) currency, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Amount_Bitcoin value)? bitcoin, - TResult? Function(Amount_Currency value)? currency, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Amount_Bitcoin value)? bitcoin, - TResult Function(Amount_Currency value)? currency, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $AmountCopyWith<$Res> { - factory $AmountCopyWith(Amount value, $Res Function(Amount) then) = _$AmountCopyWithImpl<$Res, Amount>; -} - -/// @nodoc -class _$AmountCopyWithImpl<$Res, $Val extends Amount> implements $AmountCopyWith<$Res> { - _$AmountCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; -} - -/// @nodoc -abstract class _$$Amount_BitcoinImplCopyWith<$Res> { - factory _$$Amount_BitcoinImplCopyWith( - _$Amount_BitcoinImpl value, $Res Function(_$Amount_BitcoinImpl) then) = - __$$Amount_BitcoinImplCopyWithImpl<$Res>; - @useResult - $Res call({int amountMsat}); -} - -/// @nodoc -class __$$Amount_BitcoinImplCopyWithImpl<$Res> extends _$AmountCopyWithImpl<$Res, _$Amount_BitcoinImpl> - implements _$$Amount_BitcoinImplCopyWith<$Res> { - __$$Amount_BitcoinImplCopyWithImpl(_$Amount_BitcoinImpl _value, $Res Function(_$Amount_BitcoinImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? amountMsat = null, - }) { - return _then(_$Amount_BitcoinImpl( - amountMsat: null == amountMsat - ? _value.amountMsat - : amountMsat // ignore: cast_nullable_to_non_nullable - as int, - )); - } -} - -/// @nodoc - -class _$Amount_BitcoinImpl implements Amount_Bitcoin { - const _$Amount_BitcoinImpl({required this.amountMsat}); - - @override - final int amountMsat; - - @override - String toString() { - return 'Amount.bitcoin(amountMsat: $amountMsat)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$Amount_BitcoinImpl && - (identical(other.amountMsat, amountMsat) || other.amountMsat == amountMsat)); - } - - @override - int get hashCode => Object.hash(runtimeType, amountMsat); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$Amount_BitcoinImplCopyWith<_$Amount_BitcoinImpl> get copyWith => - __$$Amount_BitcoinImplCopyWithImpl<_$Amount_BitcoinImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(int amountMsat) bitcoin, - required TResult Function(String iso4217Code, int fractionalAmount) currency, - }) { - return bitcoin(amountMsat); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(int amountMsat)? bitcoin, - TResult? Function(String iso4217Code, int fractionalAmount)? currency, - }) { - return bitcoin?.call(amountMsat); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(int amountMsat)? bitcoin, - TResult Function(String iso4217Code, int fractionalAmount)? currency, - required TResult orElse(), - }) { - if (bitcoin != null) { - return bitcoin(amountMsat); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(Amount_Bitcoin value) bitcoin, - required TResult Function(Amount_Currency value) currency, - }) { - return bitcoin(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Amount_Bitcoin value)? bitcoin, - TResult? Function(Amount_Currency value)? currency, - }) { - return bitcoin?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Amount_Bitcoin value)? bitcoin, - TResult Function(Amount_Currency value)? currency, - required TResult orElse(), - }) { - if (bitcoin != null) { - return bitcoin(this); - } - return orElse(); - } -} - -abstract class Amount_Bitcoin implements Amount { - const factory Amount_Bitcoin({required final int amountMsat}) = _$Amount_BitcoinImpl; - - int get amountMsat; - @JsonKey(ignore: true) - _$$Amount_BitcoinImplCopyWith<_$Amount_BitcoinImpl> get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$Amount_CurrencyImplCopyWith<$Res> { - factory _$$Amount_CurrencyImplCopyWith( - _$Amount_CurrencyImpl value, $Res Function(_$Amount_CurrencyImpl) then) = - __$$Amount_CurrencyImplCopyWithImpl<$Res>; - @useResult - $Res call({String iso4217Code, int fractionalAmount}); -} - -/// @nodoc -class __$$Amount_CurrencyImplCopyWithImpl<$Res> extends _$AmountCopyWithImpl<$Res, _$Amount_CurrencyImpl> - implements _$$Amount_CurrencyImplCopyWith<$Res> { - __$$Amount_CurrencyImplCopyWithImpl( - _$Amount_CurrencyImpl _value, $Res Function(_$Amount_CurrencyImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? iso4217Code = null, - Object? fractionalAmount = null, - }) { - return _then(_$Amount_CurrencyImpl( - iso4217Code: null == iso4217Code - ? _value.iso4217Code - : iso4217Code // ignore: cast_nullable_to_non_nullable - as String, - fractionalAmount: null == fractionalAmount - ? _value.fractionalAmount - : fractionalAmount // ignore: cast_nullable_to_non_nullable - as int, - )); - } -} - -/// @nodoc - -class _$Amount_CurrencyImpl implements Amount_Currency { - const _$Amount_CurrencyImpl({required this.iso4217Code, required this.fractionalAmount}); - - @override - final String iso4217Code; - @override - final int fractionalAmount; - - @override - String toString() { - return 'Amount.currency(iso4217Code: $iso4217Code, fractionalAmount: $fractionalAmount)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$Amount_CurrencyImpl && - (identical(other.iso4217Code, iso4217Code) || other.iso4217Code == iso4217Code) && - (identical(other.fractionalAmount, fractionalAmount) || - other.fractionalAmount == fractionalAmount)); - } - - @override - int get hashCode => Object.hash(runtimeType, iso4217Code, fractionalAmount); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$Amount_CurrencyImplCopyWith<_$Amount_CurrencyImpl> get copyWith => - __$$Amount_CurrencyImplCopyWithImpl<_$Amount_CurrencyImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(int amountMsat) bitcoin, - required TResult Function(String iso4217Code, int fractionalAmount) currency, - }) { - return currency(iso4217Code, fractionalAmount); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(int amountMsat)? bitcoin, - TResult? Function(String iso4217Code, int fractionalAmount)? currency, - }) { - return currency?.call(iso4217Code, fractionalAmount); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(int amountMsat)? bitcoin, - TResult Function(String iso4217Code, int fractionalAmount)? currency, - required TResult orElse(), - }) { - if (currency != null) { - return currency(iso4217Code, fractionalAmount); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(Amount_Bitcoin value) bitcoin, - required TResult Function(Amount_Currency value) currency, - }) { - return currency(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Amount_Bitcoin value)? bitcoin, - TResult? Function(Amount_Currency value)? currency, - }) { - return currency?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Amount_Bitcoin value)? bitcoin, - TResult Function(Amount_Currency value)? currency, - required TResult orElse(), - }) { - if (currency != null) { - return currency(this); - } - return orElse(); - } -} - -abstract class Amount_Currency implements Amount { - const factory Amount_Currency({required final String iso4217Code, required final int fractionalAmount}) = - _$Amount_CurrencyImpl; - - String get iso4217Code; - int get fractionalAmount; - @JsonKey(ignore: true) - _$$Amount_CurrencyImplCopyWith<_$Amount_CurrencyImpl> get copyWith => throw _privateConstructorUsedError; -} - /// @nodoc mixin _$BreezEvent { @optionalTypeArgs @@ -2509,7 +2180,6 @@ mixin _$InputType { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2522,7 +2192,6 @@ mixin _$InputType { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2535,7 +2204,6 @@ mixin _$InputType { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2549,7 +2217,6 @@ mixin _$InputType { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2562,7 +2229,6 @@ mixin _$InputType { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2575,7 +2241,6 @@ mixin _$InputType { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2669,7 +2334,6 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2685,7 +2349,6 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2701,7 +2364,6 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2721,7 +2383,6 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2737,7 +2398,6 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2753,7 +2413,6 @@ class _$InputType_BitcoinAddressImpl implements InputType_BitcoinAddress { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2844,7 +2503,6 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -2860,7 +2518,6 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2876,7 +2533,6 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -2896,7 +2552,6 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -2912,7 +2567,6 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2928,7 +2582,6 @@ class _$InputType_Bolt11Impl implements InputType_Bolt11 { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -2952,179 +2605,6 @@ abstract class InputType_Bolt11 implements InputType { _$$InputType_Bolt11ImplCopyWith<_$InputType_Bolt11Impl> get copyWith => throw _privateConstructorUsedError; } -/// @nodoc -abstract class _$$InputType_Bolt12ImplCopyWith<$Res> { - factory _$$InputType_Bolt12ImplCopyWith( - _$InputType_Bolt12Impl value, $Res Function(_$InputType_Bolt12Impl) then) = - __$$InputType_Bolt12ImplCopyWithImpl<$Res>; - @useResult - $Res call({LNOffer offer}); -} - -/// @nodoc -class __$$InputType_Bolt12ImplCopyWithImpl<$Res> extends _$InputTypeCopyWithImpl<$Res, _$InputType_Bolt12Impl> - implements _$$InputType_Bolt12ImplCopyWith<$Res> { - __$$InputType_Bolt12ImplCopyWithImpl( - _$InputType_Bolt12Impl _value, $Res Function(_$InputType_Bolt12Impl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? offer = null, - }) { - return _then(_$InputType_Bolt12Impl( - offer: null == offer - ? _value.offer - : offer // ignore: cast_nullable_to_non_nullable - as LNOffer, - )); - } -} - -/// @nodoc - -class _$InputType_Bolt12Impl implements InputType_Bolt12 { - const _$InputType_Bolt12Impl({required this.offer}); - - @override - final LNOffer offer; - - @override - String toString() { - return 'InputType.bolt12(offer: $offer)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$InputType_Bolt12Impl && - (identical(other.offer, offer) || other.offer == offer)); - } - - @override - int get hashCode => Object.hash(runtimeType, offer); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$InputType_Bolt12ImplCopyWith<_$InputType_Bolt12Impl> get copyWith => - __$$InputType_Bolt12ImplCopyWithImpl<_$InputType_Bolt12Impl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function(BitcoinAddressData address) bitcoinAddress, - required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, - required TResult Function(String nodeId) nodeId, - required TResult Function(String url) url, - required TResult Function(LnUrlPayRequestData data) lnUrlPay, - required TResult Function(LnUrlWithdrawRequestData data) lnUrlWithdraw, - required TResult Function(LnUrlAuthRequestData data) lnUrlAuth, - required TResult Function(LnUrlErrorData data) lnUrlError, - }) { - return bolt12(offer); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(BitcoinAddressData address)? bitcoinAddress, - TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, - TResult? Function(String nodeId)? nodeId, - TResult? Function(String url)? url, - TResult? Function(LnUrlPayRequestData data)? lnUrlPay, - TResult? Function(LnUrlWithdrawRequestData data)? lnUrlWithdraw, - TResult? Function(LnUrlAuthRequestData data)? lnUrlAuth, - TResult? Function(LnUrlErrorData data)? lnUrlError, - }) { - return bolt12?.call(offer); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(BitcoinAddressData address)? bitcoinAddress, - TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, - TResult Function(String nodeId)? nodeId, - TResult Function(String url)? url, - TResult Function(LnUrlPayRequestData data)? lnUrlPay, - TResult Function(LnUrlWithdrawRequestData data)? lnUrlWithdraw, - TResult Function(LnUrlAuthRequestData data)? lnUrlAuth, - TResult Function(LnUrlErrorData data)? lnUrlError, - required TResult orElse(), - }) { - if (bolt12 != null) { - return bolt12(offer); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, - required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, - required TResult Function(InputType_NodeId value) nodeId, - required TResult Function(InputType_Url value) url, - required TResult Function(InputType_LnUrlPay value) lnUrlPay, - required TResult Function(InputType_LnUrlWithdraw value) lnUrlWithdraw, - required TResult Function(InputType_LnUrlAuth value) lnUrlAuth, - required TResult Function(InputType_LnUrlError value) lnUrlError, - }) { - return bolt12(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, - TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, - TResult? Function(InputType_NodeId value)? nodeId, - TResult? Function(InputType_Url value)? url, - TResult? Function(InputType_LnUrlPay value)? lnUrlPay, - TResult? Function(InputType_LnUrlWithdraw value)? lnUrlWithdraw, - TResult? Function(InputType_LnUrlAuth value)? lnUrlAuth, - TResult? Function(InputType_LnUrlError value)? lnUrlError, - }) { - return bolt12?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, - TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, - TResult Function(InputType_NodeId value)? nodeId, - TResult Function(InputType_Url value)? url, - TResult Function(InputType_LnUrlPay value)? lnUrlPay, - TResult Function(InputType_LnUrlWithdraw value)? lnUrlWithdraw, - TResult Function(InputType_LnUrlAuth value)? lnUrlAuth, - TResult Function(InputType_LnUrlError value)? lnUrlError, - required TResult orElse(), - }) { - if (bolt12 != null) { - return bolt12(this); - } - return orElse(); - } -} - -abstract class InputType_Bolt12 implements InputType { - const factory InputType_Bolt12({required final LNOffer offer}) = _$InputType_Bolt12Impl; - - LNOffer get offer; - @JsonKey(ignore: true) - _$$InputType_Bolt12ImplCopyWith<_$InputType_Bolt12Impl> get copyWith => throw _privateConstructorUsedError; -} - /// @nodoc abstract class _$$InputType_NodeIdImplCopyWith<$Res> { factory _$$InputType_NodeIdImplCopyWith( @@ -3190,7 +2670,6 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3206,7 +2685,6 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3222,7 +2700,6 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3242,7 +2719,6 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3258,7 +2734,6 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3274,7 +2749,6 @@ class _$InputType_NodeIdImpl implements InputType_NodeId { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3361,7 +2835,6 @@ class _$InputType_UrlImpl implements InputType_Url { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3377,7 +2850,6 @@ class _$InputType_UrlImpl implements InputType_Url { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3393,7 +2865,6 @@ class _$InputType_UrlImpl implements InputType_Url { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3413,7 +2884,6 @@ class _$InputType_UrlImpl implements InputType_Url { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3429,7 +2899,6 @@ class _$InputType_UrlImpl implements InputType_Url { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3445,7 +2914,6 @@ class _$InputType_UrlImpl implements InputType_Url { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3535,7 +3003,6 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3551,7 +3018,6 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3567,7 +3033,6 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3587,7 +3052,6 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3603,7 +3067,6 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3619,7 +3082,6 @@ class _$InputType_LnUrlPayImpl implements InputType_LnUrlPay { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3710,7 +3172,6 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3726,7 +3187,6 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3742,7 +3202,6 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3762,7 +3221,6 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3778,7 +3236,6 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3794,7 +3251,6 @@ class _$InputType_LnUrlWithdrawImpl implements InputType_LnUrlWithdraw { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3886,7 +3342,6 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -3902,7 +3357,6 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3918,7 +3372,6 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -3938,7 +3391,6 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -3954,7 +3406,6 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -3970,7 +3421,6 @@ class _$InputType_LnUrlAuthImpl implements InputType_LnUrlAuth { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, @@ -4061,7 +3511,6 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult when({ required TResult Function(BitcoinAddressData address) bitcoinAddress, required TResult Function(LNInvoice invoice) bolt11, - required TResult Function(LNOffer offer) bolt12, required TResult Function(String nodeId) nodeId, required TResult Function(String url) url, required TResult Function(LnUrlPayRequestData data) lnUrlPay, @@ -4077,7 +3526,6 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult? whenOrNull({ TResult? Function(BitcoinAddressData address)? bitcoinAddress, TResult? Function(LNInvoice invoice)? bolt11, - TResult? Function(LNOffer offer)? bolt12, TResult? Function(String nodeId)? nodeId, TResult? Function(String url)? url, TResult? Function(LnUrlPayRequestData data)? lnUrlPay, @@ -4093,7 +3541,6 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult maybeWhen({ TResult Function(BitcoinAddressData address)? bitcoinAddress, TResult Function(LNInvoice invoice)? bolt11, - TResult Function(LNOffer offer)? bolt12, TResult Function(String nodeId)? nodeId, TResult Function(String url)? url, TResult Function(LnUrlPayRequestData data)? lnUrlPay, @@ -4113,7 +3560,6 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult map({ required TResult Function(InputType_BitcoinAddress value) bitcoinAddress, required TResult Function(InputType_Bolt11 value) bolt11, - required TResult Function(InputType_Bolt12 value) bolt12, required TResult Function(InputType_NodeId value) nodeId, required TResult Function(InputType_Url value) url, required TResult Function(InputType_LnUrlPay value) lnUrlPay, @@ -4129,7 +3575,6 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult? mapOrNull({ TResult? Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult? Function(InputType_Bolt11 value)? bolt11, - TResult? Function(InputType_Bolt12 value)? bolt12, TResult? Function(InputType_NodeId value)? nodeId, TResult? Function(InputType_Url value)? url, TResult? Function(InputType_LnUrlPay value)? lnUrlPay, @@ -4145,7 +3590,6 @@ class _$InputType_LnUrlErrorImpl implements InputType_LnUrlError { TResult maybeMap({ TResult Function(InputType_BitcoinAddress value)? bitcoinAddress, TResult Function(InputType_Bolt11 value)? bolt11, - TResult Function(InputType_Bolt12 value)? bolt12, TResult Function(InputType_NodeId value)? nodeId, TResult Function(InputType_Url value)? url, TResult Function(InputType_LnUrlPay value)? lnUrlPay, diff --git a/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt b/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt index 069f6a232..27f2a4945 100644 --- a/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt +++ b/libs/sdk-react-native/android/src/main/java/com/breezsdk/BreezSDKMapper.kt @@ -830,59 +830,6 @@ fun asLnInvoiceList(arr: ReadableArray): List { return list } -fun asLnOffer(lnOffer: ReadableMap): LnOffer? { - if (!validateMandatoryFields( - lnOffer, - arrayOf( - "bolt12", - "chains", - "description", - "signingPubkey", - ), - ) - ) { - return null - } - val bolt12 = lnOffer.getString("bolt12")!! - val chains = lnOffer.getArray("chains")?.let { asStringList(it) }!! - val description = lnOffer.getString("description")!! - val signingPubkey = lnOffer.getString("signingPubkey")!! - val amount = if (hasNonNullKey(lnOffer, "amount")) lnOffer.getMap("amount")?.let { asAmount(it) } else null - val absoluteExpiry = if (hasNonNullKey(lnOffer, "absoluteExpiry")) lnOffer.getDouble("absoluteExpiry").toULong() else null - val issuer = if (hasNonNullKey(lnOffer, "issuer")) lnOffer.getString("issuer") else null - return LnOffer( - bolt12, - chains, - description, - signingPubkey, - amount, - absoluteExpiry, - issuer, - ) -} - -fun readableMapOf(lnOffer: LnOffer): ReadableMap = - readableMapOf( - "bolt12" to lnOffer.bolt12, - "chains" to readableArrayOf(lnOffer.chains), - "description" to lnOffer.description, - "signingPubkey" to lnOffer.signingPubkey, - "amount" to lnOffer.amount?.let { readableMapOf(it) }, - "absoluteExpiry" to lnOffer.absoluteExpiry, - "issuer" to lnOffer.issuer, - ) - -fun asLnOfferList(arr: ReadableArray): List { - val list = ArrayList() - for (value in arr.toArrayList()) { - when (value) { - is ReadableMap -> list.add(asLnOffer(value)!!) - else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}")) - } - } - return list -} - fun asListPaymentsRequest(listPaymentsRequest: ReadableMap): ListPaymentsRequest? { if (!validateMandatoryFields( listPaymentsRequest, @@ -3875,45 +3822,6 @@ fun asAesSuccessActionDataResultList(arr: ReadableArray): List { - pushToMap(map, "type", "bitcoin") - pushToMap(map, "amountMsat", amount.amountMsat) - } - is Amount.Currency -> { - pushToMap(map, "type", "currency") - pushToMap(map, "iso4217Code", amount.iso4217Code) - pushToMap(map, "fractionalAmount", amount.fractionalAmount) - } - } - return map -} - -fun asAmountList(arr: ReadableArray): List { - val list = ArrayList() - for (value in arr.toArrayList()) { - when (value) { - is ReadableMap -> list.add(asAmount(value)!!) - else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}")) - } - } - return list -} - fun asBreezEvent(breezEvent: ReadableMap): BreezEvent? { val type = breezEvent.getString("type") @@ -4079,9 +3987,6 @@ fun asInputType(inputType: ReadableMap): InputType? { if (type == "bolt11") { return InputType.Bolt11(inputType.getMap("invoice")?.let { asLnInvoice(it) }!!) } - if (type == "bolt12") { - return InputType.Bolt12(inputType.getMap("offer")?.let { asLnOffer(it) }!!) - } if (type == "nodeId") { return InputType.NodeId(inputType.getString("nodeId")!!) } @@ -4114,10 +4019,6 @@ fun readableMapOf(inputType: InputType): ReadableMap? { pushToMap(map, "type", "bolt11") pushToMap(map, "invoice", readableMapOf(inputType.invoice)) } - is InputType.Bolt12 -> { - pushToMap(map, "type", "bolt12") - pushToMap(map, "offer", readableMapOf(inputType.offer)) - } is InputType.NodeId -> { pushToMap(map, "type", "nodeId") pushToMap(map, "nodeId", inputType.nodeId) diff --git a/libs/sdk-react-native/ios/BreezSDKMapper.swift b/libs/sdk-react-native/ios/BreezSDKMapper.swift index 2e72bb743..012eecd30 100644 --- a/libs/sdk-react-native/ios/BreezSDKMapper.swift +++ b/libs/sdk-react-native/ios/BreezSDKMapper.swift @@ -962,79 +962,6 @@ enum BreezSDKMapper { return lnInvoiceList.map { v -> [String: Any?] in return dictionaryOf(lnInvoice: v) } } - static func asLnOffer(lnOffer: [String: Any?]) throws -> LnOffer { - guard let bolt12 = lnOffer["bolt12"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bolt12", typeName: "LnOffer")) - } - guard let chains = lnOffer["chains"] as? [String] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "chains", typeName: "LnOffer")) - } - guard let description = lnOffer["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "LnOffer")) - } - guard let signingPubkey = lnOffer["signingPubkey"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signingPubkey", typeName: "LnOffer")) - } - var amount: Amount? - if let amountTmp = lnOffer["amount"] as? [String: Any?] { - amount = try asAmount(amount: amountTmp) - } - - var absoluteExpiry: UInt64? - if hasNonNilKey(data: lnOffer, key: "absoluteExpiry") { - guard let absoluteExpiryTmp = lnOffer["absoluteExpiry"] as? UInt64 else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "absoluteExpiry")) - } - absoluteExpiry = absoluteExpiryTmp - } - var issuer: String? - if hasNonNilKey(data: lnOffer, key: "issuer") { - guard let issuerTmp = lnOffer["issuer"] as? String else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "issuer")) - } - issuer = issuerTmp - } - - return LnOffer( - bolt12: bolt12, - chains: chains, - description: description, - signingPubkey: signingPubkey, - amount: amount, - absoluteExpiry: absoluteExpiry, - issuer: issuer - ) - } - - static func dictionaryOf(lnOffer: LnOffer) -> [String: Any?] { - return [ - "bolt12": lnOffer.bolt12, - "chains": lnOffer.chains, - "description": lnOffer.description, - "signingPubkey": lnOffer.signingPubkey, - "amount": lnOffer.amount == nil ? nil : dictionaryOf(amount: lnOffer.amount!), - "absoluteExpiry": lnOffer.absoluteExpiry == nil ? nil : lnOffer.absoluteExpiry, - "issuer": lnOffer.issuer == nil ? nil : lnOffer.issuer, - ] - } - - static func asLnOfferList(arr: [Any]) throws -> [LnOffer] { - var list = [LnOffer]() - for value in arr { - if let val = value as? [String: Any?] { - var lnOffer = try asLnOffer(lnOffer: val) - list.append(lnOffer) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnOffer")) - } - } - return list - } - - static func arrayOf(lnOfferList: [LnOffer]) -> [Any] { - return lnOfferList.map { v -> [String: Any?] in return dictionaryOf(lnOffer: v) } - } - static func asListPaymentsRequest(listPaymentsRequest: [String: Any?]) throws -> ListPaymentsRequest { var filters: [PaymentTypeFilter]? if let filtersTmp = listPaymentsRequest["filters"] as? [String] { @@ -4403,62 +4330,6 @@ enum BreezSDKMapper { return list } - static func asAmount(amount: [String: Any?]) throws -> Amount { - let type = amount["type"] as! String - if type == "bitcoin" { - guard let _amountMsat = amount["amountMsat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "Amount")) - } - return Amount.bitcoin(amountMsat: _amountMsat) - } - if type == "currency" { - guard let _iso4217Code = amount["iso4217Code"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "iso4217Code", typeName: "Amount")) - } - return Amount.currency(iso4217Code: _iso4217Code) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum Amount") - } - - static func dictionaryOf(amount: Amount) -> [String: Any?] { - switch amount { - case let .bitcoin( - amountMsat - ): - return [ - "type": "bitcoin", - "amountMsat": amountMsat, - ] - - case let .currency( - iso4217Code, fractionalAmount - ): - return [ - "type": "currency", - "iso4217Code": iso4217Code, - "fractionalAmount": fractionalAmount, - ] - } - } - - static func arrayOf(amountList: [Amount]) -> [Any] { - return amountList.map { v -> [String: Any?] in return dictionaryOf(amount: v) } - } - - static func asAmountList(arr: [Any]) throws -> [Amount] { - var list = [Amount]() - for value in arr { - if let val = value as? [String: Any?] { - var amount = try asAmount(amount: val) - list.append(amount) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Amount")) - } - } - return list - } - static func asBreezEvent(breezEvent: [String: Any?]) throws -> BreezEvent { let type = breezEvent["type"] as! String if type == "newBlock" { @@ -4851,14 +4722,6 @@ enum BreezSDKMapper { return InputType.bolt11(invoice: _invoice) } - if type == "bolt12" { - guard let offerTmp = inputType["offer"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "offer", typeName: "InputType")) - } - let _offer = try asLnOffer(lnOffer: offerTmp) - - return InputType.bolt12(offer: _offer) - } if type == "nodeId" { guard let _nodeId = inputType["nodeId"] as? String else { throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "nodeId", typeName: "InputType")) @@ -4925,14 +4788,6 @@ enum BreezSDKMapper { "invoice": dictionaryOf(lnInvoice: invoice), ] - case let .bolt12( - offer - ): - return [ - "type": "bolt12", - "offer": dictionaryOf(lnOffer: offer), - ] - case let .nodeId( nodeId ): diff --git a/libs/sdk-react-native/src/index.ts b/libs/sdk-react-native/src/index.ts index f514c2177..5225c062e 100644 --- a/libs/sdk-react-native/src/index.ts +++ b/libs/sdk-react-native/src/index.ts @@ -143,16 +143,6 @@ export interface LnInvoice { minFinalCltvExpiryDelta: number } -export interface LnOffer { - bolt12: string - chains: string[] - description: string - signingPubkey: string - amount?: Amount - absoluteExpiry?: number - issuer?: string -} - export interface ListPaymentsRequest { filters?: PaymentTypeFilter[] metadataFilters?: MetadataFilter[] @@ -611,20 +601,6 @@ export type AesSuccessActionDataResult = { reason: string } -export enum AmountVariant { - BITCOIN = "bitcoin", - CURRENCY = "currency" -} - -export type Amount = { - type: AmountVariant.BITCOIN, - amountMsat: number -} | { - type: AmountVariant.CURRENCY, - iso4217Code: string - fractionalAmount: number -} - export enum BreezEventVariant { NEW_BLOCK = "newBlock", INVOICE_PAID = "invoicePaid", @@ -698,7 +674,6 @@ export enum HealthCheckStatus { export enum InputTypeVariant { BITCOIN_ADDRESS = "bitcoinAddress", BOLT11 = "bolt11", - BOLT12 = "bolt12", NODE_ID = "nodeId", URL = "url", LN_URL_PAY = "lnUrlPay", @@ -713,9 +688,6 @@ export type InputType = { } | { type: InputTypeVariant.BOLT11, invoice: LnInvoice -} | { - type: InputTypeVariant.BOLT12, - offer: LnOffer } | { type: InputTypeVariant.NODE_ID, nodeId: string From 6fc830ea2b9a859733f555c6eb4d451639313911 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:17:43 +0100 Subject: [PATCH 04/12] Add LNOffer struct --- libs/sdk-common/src/invoice.rs | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index fe6b4c390..087e32b7f 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -101,6 +101,48 @@ fn format_short_channel_id(id: u64) -> String { format!("{block_num}x{tx_num}x{tx_out}") } +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub enum Amount { + Bitcoin { + amount_msat: u64, + }, + Currency { + // Reference to [FiatCurrency.id] + iso4217_code: String, + fractional_amount: u64, + }, +} + +impl From for Amount { + fn from(amount: lightning::offers::offer::Amount) -> Self { + match amount { + lightning::offers::offer::Amount::Bitcoin { amount_msats } => Amount::Bitcoin { + amount_msat: amount_msats, + }, + lightning::offers::offer::Amount::Currency { + iso4217_code, + amount, + } => Amount::Currency { + iso4217_code: String::from_utf8(iso4217_code.to_vec()) + .expect("Expecting a valid ISO 4217 character sequence"), + fractional_amount: amount, + }, + } + } +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct LNOffer { + pub bolt12: String, + pub chains: Vec, + pub amount: Option, + pub description: Option, + pub absolute_expiry: Option, + pub issuer: Option, + pub signing_pubkey: Option, + // pub paths: Vec, +} + /// Wrapper for a BOLT11 LN invoice #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct LNInvoice { From 11c6812c81407881a014390cb3da68cea169bcf1 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:08:20 +0100 Subject: [PATCH 05/12] Fix new type naming --- libs/sdk-common/src/input_parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sdk-common/src/input_parser.rs b/libs/sdk-common/src/input_parser.rs index d642cc268..f595bad13 100644 --- a/libs/sdk-common/src/input_parser.rs +++ b/libs/sdk-common/src/input_parser.rs @@ -419,7 +419,7 @@ pub enum InputType { invoice: LNInvoice, }, #[cfg(feature = "liquid")] - Bolt12 { + Bolt12Offer { offer: LNOffer, }, NodeId { From 8da4455e4a5a077e40c440d6c875236d666fffb0 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:07:36 +0100 Subject: [PATCH 06/12] Add docs for new fields --- libs/sdk-common/src/invoice.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index 087e32b7f..73963bd06 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -133,8 +133,10 @@ impl From for Amount { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct LNOffer { + /// String representation of the Bolt12 offer pub bolt12: String, pub chains: Vec, + /// If set, it represents the minimum amount that an invoice must have to be valid for this offer pub amount: Option, pub description: Option, pub absolute_expiry: Option, From 3ffe4458d81e4d8f9c5d287e1b5dacf9735ec3d3 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:29:37 +0100 Subject: [PATCH 07/12] Rename offer min_amount, add docs --- libs/sdk-common/src/invoice.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index 73963bd06..0cae0adfb 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -137,10 +137,12 @@ pub struct LNOffer { pub bolt12: String, pub chains: Vec, /// If set, it represents the minimum amount that an invoice must have to be valid for this offer - pub amount: Option, + pub min_amount: Option, pub description: Option, + /// Epoch time from which an invoice should no longer be requested. If None, the offer does not expire. pub absolute_expiry: Option, pub issuer: Option, + /// The public key used by the recipient to sign invoices. pub signing_pubkey: Option, // pub paths: Vec, } From 643928e4cab2aa0a77f9df5b1c202706181fe293 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:27:07 +0100 Subject: [PATCH 08/12] Rename LNOffer field --- libs/sdk-common/src/invoice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index 0cae0adfb..6b7db73c8 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -134,7 +134,7 @@ impl From for Amount { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct LNOffer { /// String representation of the Bolt12 offer - pub bolt12: String, + pub offer: String, pub chains: Vec, /// If set, it represents the minimum amount that an invoice must have to be valid for this offer pub min_amount: Option, From 02e5741f38345ba9ceb70cdb73546d8f9d25bafc Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:39:47 +0100 Subject: [PATCH 09/12] Add more docs to Amount::Currency fields --- libs/sdk-common/src/invoice.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index 6b7db73c8..d987854eb 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -106,9 +106,11 @@ pub enum Amount { Bitcoin { amount_msat: u64, }, + /// An amount of currency specified using ISO 4712. Currency { - // Reference to [FiatCurrency.id] + /// The currency that the amount is denominated in. iso4217_code: String, + /// The amount in the currency unit adjusted by the ISO 4712 exponent (e.g., USD cents). fractional_amount: u64, }, } From caf483b6eebf860e079c239858f2900c82302955 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:55:16 +0100 Subject: [PATCH 10/12] Use TryFrom when converting between amounts --- libs/sdk-common/src/invoice.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index d987854eb..b45eb1dd2 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -2,6 +2,7 @@ use std::num::ParseIntError; use std::str::FromStr; use std::time::{SystemTimeError, UNIX_EPOCH}; +use anyhow::anyhow; use bitcoin::secp256k1::{self, PublicKey}; use hex::ToHex; use lightning::routing::gossip::RoutingFees; @@ -115,20 +116,22 @@ pub enum Amount { }, } -impl From for Amount { - fn from(amount: lightning::offers::offer::Amount) -> Self { +impl TryFrom for Amount { + type Error = anyhow::Error; + + fn try_from(amount: lightning::offers::offer::Amount) -> Result { match amount { - lightning::offers::offer::Amount::Bitcoin { amount_msats } => Amount::Bitcoin { + lightning::offers::offer::Amount::Bitcoin { amount_msats } => Ok(Amount::Bitcoin { amount_msat: amount_msats, - }, + }), lightning::offers::offer::Amount::Currency { iso4217_code, amount, - } => Amount::Currency { + } => Ok(Amount::Currency { iso4217_code: String::from_utf8(iso4217_code.to_vec()) - .expect("Expecting a valid ISO 4217 character sequence"), + .map_err(|_| anyhow!("Expecting a valid ISO 4217 character sequence"))?, fractional_amount: amount, - }, + }), } } } From 53ba77bce27b49a5c9b47698b5ce3cbded975572 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:11:21 +0100 Subject: [PATCH 11/12] Bolt12 LNOffer: add field for blinded paths --- libs/sdk-common/src/invoice.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index b45eb1dd2..ca52e1209 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -149,7 +149,13 @@ pub struct LNOffer { pub issuer: Option, /// The public key used by the recipient to sign invoices. pub signing_pubkey: Option, - // pub paths: Vec, + pub paths: Vec, +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct LNOfferBlindedPath { + /// For each blinded hop, we store the node ID (pubkey as hex). + pub blinded_hops: Vec, } /// Wrapper for a BOLT11 LN invoice From 12dea61af7b74be972a957aa53402d9eccc6530f Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:01:40 +0100 Subject: [PATCH 12/12] Rename LNOfferBlindedPath to LnOfferBlindedPath This helps circumvent an uniffi issue where sequence fails to parse but sequence is fine. --- libs/sdk-common/src/invoice.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index ca52e1209..f7790adb5 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -149,11 +149,11 @@ pub struct LNOffer { pub issuer: Option, /// The public key used by the recipient to sign invoices. pub signing_pubkey: Option, - pub paths: Vec, + pub paths: Vec, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct LNOfferBlindedPath { +pub struct LnOfferBlindedPath { /// For each blinded hop, we store the node ID (pubkey as hex). pub blinded_hops: Vec, }