From 89e20d4d1d61220aca4472fca931b7f48856448c Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:58:24 +0200 Subject: [PATCH 01/22] Add zero-amount Receive Chain Swap --- lib/core/src/sdk.rs | 60 +++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index c5e992238..4ef187a53 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -633,10 +633,12 @@ impl LiquidSdk { fn get_and_validate_chain_pair( &self, direction: Direction, - user_lockup_amount_sat: u64, + user_lockup_amount_sat: Option, ) -> Result { let pair = self.get_chain_pair(direction)?; - self.validate_user_lockup_amount_for_chain_pair(&pair, user_lockup_amount_sat)?; + if let Some(user_lockup_amount_sat) = user_lockup_amount_sat { + self.validate_user_lockup_amount_for_chain_pair(&pair, user_lockup_amount_sat)?; + } Ok(pair) } @@ -1442,24 +1444,22 @@ impl LiquidSdk { ); } PaymentMethod::BitcoinAddress => { - let Some(payer_amount_sat) = req.payer_amount_sat else { - return Err(PaymentError::AmountMissing { err: "`payer_amount_sat` must be specified when `PaymentMethod::BitcoinAddress` is used.".to_string() }); - }; + let payer_amount_sat = req.payer_amount_sat; let pair = self.get_and_validate_chain_pair(Direction::Incoming, payer_amount_sat)?; let claim_fees_sat = pair.fees.claim_estimate(); let server_fees_sat = pair.fees.server(); - fees_sat = pair.fees.boltz(payer_amount_sat) + claim_fees_sat + server_fees_sat; - debug!( - "Preparing Chain Receive Swap with: payer_amount_sat {payer_amount_sat} sat, fees_sat {fees_sat} sat" - ); + let service_fees_sat = payer_amount_sat + .map(|user_lockup_amount_sat| pair.fees.boltz(user_lockup_amount_sat)) + .unwrap_or_default(); + + fees_sat = service_fees_sat + claim_fees_sat + server_fees_sat; + debug!("Preparing Chain Receive Swap with: payer_amount_sat {payer_amount_sat:?}, fees_sat {fees_sat}"); } PaymentMethod::LiquidAddress => { fees_sat = 0; - debug!( - "Preparing Liquid Receive Swap with: amount_sat {:?} sat, fees_sat {fees_sat} sat", - req.payer_amount_sat - ); + let payer_amount_sat = req.payer_amount_sat; + debug!("Preparing Liquid Receive Swap with: amount_sat {payer_amount_sat:?}, fees_sat {fees_sat}"); } }; @@ -1519,12 +1519,7 @@ impl LiquidSdk { self.create_receive_swap(*amount_sat, *fees_sat, description, description_hash) .await } - PaymentMethod::BitcoinAddress => { - let Some(amount_sat) = amount_sat else { - return Err(PaymentError::AmountMissing { err: "`amount_sat` must be specified when `PaymentMethod::BitcoinAddress` is used.".to_string() }); - }; - self.receive_onchain(*amount_sat, *fees_sat).await - } + PaymentMethod::BitcoinAddress => self.receive_onchain(*amount_sat, *fees_sat).await, PaymentMethod::LiquidAddress => { let address = self.onchain_wallet.next_unused_address().await?.to_string(); @@ -1671,15 +1666,19 @@ impl LiquidSdk { async fn create_receive_chain_swap( &self, - user_lockup_amount_sat: u64, + user_lockup_amount_sat: Option, fees_sat: u64, ) -> Result { let pair = self.get_and_validate_chain_pair(Direction::Incoming, user_lockup_amount_sat)?; let claim_fees_sat = pair.fees.claim_estimate(); let server_fees_sat = pair.fees.server(); + // Service fees are 0 if this is a zero-amount swap + let service_fees_sat = user_lockup_amount_sat + .map(|user_lockup_amount_sat| pair.fees.boltz(user_lockup_amount_sat)) + .unwrap_or_default(); ensure_sdk!( - fees_sat == pair.fees.boltz(user_lockup_amount_sat) + claim_fees_sat + server_fees_sat, + fees_sat == service_fees_sat + claim_fees_sat + server_fees_sat, PaymentError::InvalidOrExpiredFees ); @@ -1711,7 +1710,7 @@ impl LiquidSdk { preimage_hash: preimage.sha256, claim_public_key: Some(claim_public_key), refund_public_key: Some(refund_public_key), - user_lock_amount: Some(user_lockup_amount_sat), + user_lock_amount: user_lockup_amount_sat, server_lock_amount: None, pair_hash: Some(pair.hash), referral_id: None, @@ -1722,8 +1721,12 @@ impl LiquidSdk { let create_response_json = ChainSwap::from_boltz_struct_to_json(&create_response, &swap_id)?; - let accept_zero_conf = user_lockup_amount_sat <= pair.limits.maximal_zero_conf; - let receiver_amount_sat = user_lockup_amount_sat - fees_sat; + let accept_zero_conf = user_lockup_amount_sat + .map(|user_lockup_amount_sat| user_lockup_amount_sat <= pair.limits.maximal_zero_conf) + .unwrap_or(false); + let receiver_amount_sat = user_lockup_amount_sat + .map(|user_lockup_amount_sat| user_lockup_amount_sat - fees_sat) + .unwrap_or(0); let claim_address = self.onchain_wallet.next_unused_address().await?.to_string(); let swap = ChainSwap { @@ -1734,7 +1737,7 @@ impl LiquidSdk { timeout_block_height: create_response.lockup_details.timeout_block_height, preimage: preimage_str, description: Some("Bitcoin transfer".to_string()), - payer_amount_sat: user_lockup_amount_sat, + payer_amount_sat: user_lockup_amount_sat.unwrap_or(0), receiver_amount_sat, claim_fees_sat, accept_zero_conf, @@ -1754,9 +1757,12 @@ impl LiquidSdk { } /// Receive from a Bitcoin transaction via a chain swap. + /// + /// If no `user_lockup_amount_sat` is specified, this is an amountless swap and `fees_sat` exclude + /// the service fees. async fn receive_onchain( &self, - payer_amount_sat: u64, + payer_amount_sat: Option, fees_sat: u64, ) -> Result { self.ensure_is_started().await?; @@ -1924,7 +1930,7 @@ impl LiquidSdk { pub async fn buy_bitcoin(&self, req: &BuyBitcoinRequest) -> Result { let swap = self .create_receive_chain_swap( - req.prepare_response.amount_sat, + Some(req.prepare_response.amount_sat), req.prepare_response.fees_sat, ) .await?; From bedc05d2c7d9efd63d1bd95084a6d5be9d4ba92b Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:41:50 +0100 Subject: [PATCH 02/22] prep-receive-payment: Add min/max fields for zero-amount swaps --- cli/src/commands.rs | 17 +- .../include/breez_sdk_liquid.h | 2 + lib/bindings/src/breez_sdk_liquid.udl | 4 +- lib/core/src/frb_generated.rs | 14 + lib/core/src/model.rs | 8 + lib/core/src/sdk.rs | 10 + packages/dart/lib/src/frb_generated.dart | 14 +- packages/dart/lib/src/frb_generated.io.dart | 6 + packages/dart/lib/src/model.dart | 23 +- .../breezsdkliquid/BreezSDKLiquidMapper.kt | 30 +- .../ios/BreezSDKLiquidMapper.swift | 5841 +++++++++-------- .../react-native/ios/RNBreezSDKLiquid.swift | 233 +- packages/react-native/src/index.ts | 132 +- 13 files changed, 3219 insertions(+), 3115 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 39ff2d6e9..2d3422d84 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -263,13 +263,16 @@ pub(crate) async fn handle_command( }) .await?; - wait_confirmation!( - format!( - "Fees: {} sat. Are the fees acceptable? (y/N) ", - prepare_response.fees_sat - ), - "Payment receive halted" - ); + let fees = prepare_response.fees_sat; + let confirmation_msg = match payer_amount_sat { + Some(_) => format!("Fees: {fees} sat. Are the fees acceptable? (y/N)"), + None => { + let min = prepare_response.min_payer_amount_sat.unwrap(); + let max = prepare_response.max_payer_amount_sat.unwrap(); + format!("Fees: {fees} sat. Sender should send between {min} sat - {max} sat. Are the fees acceptable? (y/N)") + } + }; + wait_confirmation!(confirmation_msg, "Payment receive halted"); let response = sdk .receive_payment(&ReceivePaymentRequest { diff --git a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h index d02b1bd78..a62868a61 100644 --- a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h +++ b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h @@ -317,6 +317,8 @@ typedef struct wire_cst_prepare_receive_response { int32_t payment_method; uint64_t *payer_amount_sat; uint64_t fees_sat; + uint64_t *min_payer_amount_sat; + uint64_t *max_payer_amount_sat; } wire_cst_prepare_receive_response; typedef struct wire_cst_receive_payment_request { diff --git a/lib/bindings/src/breez_sdk_liquid.udl b/lib/bindings/src/breez_sdk_liquid.udl index 290267558..227dfe4ee 100644 --- a/lib/bindings/src/breez_sdk_liquid.udl +++ b/lib/bindings/src/breez_sdk_liquid.udl @@ -407,9 +407,11 @@ dictionary PrepareReceiveRequest { }; dictionary PrepareReceiveResponse { - u64? payer_amount_sat; PaymentMethod payment_method; u64 fees_sat; + u64? payer_amount_sat; + u64? min_payer_amount_sat; + u64? max_payer_amount_sat; }; dictionary ReceivePaymentRequest { diff --git a/lib/core/src/frb_generated.rs b/lib/core/src/frb_generated.rs index 54c3f65aa..f22d2275e 100644 --- a/lib/core/src/frb_generated.rs +++ b/lib/core/src/frb_generated.rs @@ -3599,10 +3599,14 @@ impl SseDecode for crate::model::PrepareReceiveResponse { let mut var_paymentMethod = ::sse_decode(deserializer); let mut var_payerAmountSat = >::sse_decode(deserializer); let mut var_feesSat = ::sse_decode(deserializer); + let mut var_minPayerAmountSat = >::sse_decode(deserializer); + let mut var_maxPayerAmountSat = >::sse_decode(deserializer); return crate::model::PrepareReceiveResponse { payment_method: var_paymentMethod, payer_amount_sat: var_payerAmountSat, fees_sat: var_feesSat, + min_payer_amount_sat: var_minPayerAmountSat, + max_payer_amount_sat: var_maxPayerAmountSat, }; } } @@ -5572,6 +5576,8 @@ impl flutter_rust_bridge::IntoDart for crate::model::PrepareReceiveResponse { self.payment_method.into_into_dart().into_dart(), self.payer_amount_sat.into_into_dart().into_dart(), self.fees_sat.into_into_dart().into_dart(), + self.min_payer_amount_sat.into_into_dart().into_dart(), + self.max_payer_amount_sat.into_into_dart().into_dart(), ] .into_dart() } @@ -7344,6 +7350,8 @@ impl SseEncode for crate::model::PrepareReceiveResponse { ::sse_encode(self.payment_method, serializer); >::sse_encode(self.payer_amount_sat, serializer); ::sse_encode(self.fees_sat, serializer); + >::sse_encode(self.min_payer_amount_sat, serializer); + >::sse_encode(self.max_payer_amount_sat, serializer); } } @@ -9114,6 +9122,8 @@ mod io { payment_method: self.payment_method.cst_decode(), payer_amount_sat: self.payer_amount_sat.cst_decode(), fees_sat: self.fees_sat.cst_decode(), + min_payer_amount_sat: self.min_payer_amount_sat.cst_decode(), + max_payer_amount_sat: self.max_payer_amount_sat.cst_decode(), } } } @@ -10209,6 +10219,8 @@ mod io { payment_method: Default::default(), payer_amount_sat: core::ptr::null_mut(), fees_sat: Default::default(), + min_payer_amount_sat: core::ptr::null_mut(), + max_payer_amount_sat: core::ptr::null_mut(), } } } @@ -12239,6 +12251,8 @@ mod io { payment_method: i32, payer_amount_sat: *mut u64, fees_sat: u64, + min_payer_amount_sat: *mut u64, + max_payer_amount_sat: *mut u64, } #[repr(C)] #[derive(Clone, Copy)] diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index a4a4acba3..b69512ee4 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -284,6 +284,14 @@ pub struct PrepareReceiveResponse { pub payment_method: PaymentMethod, pub payer_amount_sat: Option, pub fees_sat: u64, + /// The minimum amount the payer can send for this swap to succeed. + /// + /// Only applicable to Zero-Amount Receive Chain Swaps. + pub min_payer_amount_sat: Option, + /// The maximum amount the payer can send for this swap to succeed. + /// + /// Only applicable to Zero-Amount Receive Chain Swaps. + pub max_payer_amount_sat: Option, } /// An argument when calling [crate::sdk::LiquidSdk::receive_payment]. diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index 4ef187a53..db38df10d 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -1419,6 +1419,8 @@ impl LiquidSdk { ) -> Result { self.ensure_is_started().await?; + let mut min_payer_amount_sat = None; + let mut max_payer_amount_sat = None; let fees_sat; match req.payment_method { PaymentMethod::Lightning => { @@ -1453,6 +1455,11 @@ impl LiquidSdk { .map(|user_lockup_amount_sat| pair.fees.boltz(user_lockup_amount_sat)) .unwrap_or_default(); + if payer_amount_sat.is_none() { + min_payer_amount_sat = Some(pair.limits.minimal); + max_payer_amount_sat = Some(pair.limits.maximal); + } + fees_sat = service_fees_sat + claim_fees_sat + server_fees_sat; debug!("Preparing Chain Receive Swap with: payer_amount_sat {payer_amount_sat:?}, fees_sat {fees_sat}"); } @@ -1467,6 +1474,8 @@ impl LiquidSdk { payer_amount_sat: req.payer_amount_sat, fees_sat, payment_method: req.payment_method.clone(), + min_payer_amount_sat, + max_payer_amount_sat, }) } @@ -1494,6 +1503,7 @@ impl LiquidSdk { payment_method, payer_amount_sat: amount_sat, fees_sat, + .. } = &req.prepare_response; match payment_method { diff --git a/packages/dart/lib/src/frb_generated.dart b/packages/dart/lib/src/frb_generated.dart index a382c9dbb..6848f40ba 100644 --- a/packages/dart/lib/src/frb_generated.dart +++ b/packages/dart/lib/src/frb_generated.dart @@ -2597,11 +2597,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { PrepareReceiveResponse dco_decode_prepare_receive_response(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 3) throw Exception('unexpected arr length: expect 3 but see ${arr.length}'); + if (arr.length != 5) throw Exception('unexpected arr length: expect 5 but see ${arr.length}'); return PrepareReceiveResponse( paymentMethod: dco_decode_payment_method(arr[0]), payerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[1]), feesSat: dco_decode_u_64(arr[2]), + minPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[3]), + maxPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[4]), ); } @@ -4445,8 +4447,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_paymentMethod = sse_decode_payment_method(deserializer); var var_payerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); var var_feesSat = sse_decode_u_64(deserializer); + var var_minPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); + var var_maxPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); return PrepareReceiveResponse( - paymentMethod: var_paymentMethod, payerAmountSat: var_payerAmountSat, feesSat: var_feesSat); + paymentMethod: var_paymentMethod, + payerAmountSat: var_payerAmountSat, + feesSat: var_feesSat, + minPayerAmountSat: var_minPayerAmountSat, + maxPayerAmountSat: var_maxPayerAmountSat); } @protected @@ -6173,6 +6181,8 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_payment_method(self.paymentMethod, serializer); sse_encode_opt_box_autoadd_u_64(self.payerAmountSat, serializer); sse_encode_u_64(self.feesSat, serializer); + sse_encode_opt_box_autoadd_u_64(self.minPayerAmountSat, serializer); + sse_encode_opt_box_autoadd_u_64(self.maxPayerAmountSat, serializer); } @protected diff --git a/packages/dart/lib/src/frb_generated.io.dart b/packages/dart/lib/src/frb_generated.io.dart index d5f2bf4b6..b9ae06b6d 100644 --- a/packages/dart/lib/src/frb_generated.io.dart +++ b/packages/dart/lib/src/frb_generated.io.dart @@ -2716,6 +2716,8 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { wireObj.payment_method = cst_encode_payment_method(apiObj.paymentMethod); wireObj.payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.payerAmountSat); wireObj.fees_sat = cst_encode_u_64(apiObj.feesSat); + wireObj.min_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.minPayerAmountSat); + wireObj.max_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.maxPayerAmountSat); } @protected @@ -5399,6 +5401,10 @@ final class wire_cst_prepare_receive_response extends ffi.Struct { @ffi.Uint64() external int fees_sat; + + external ffi.Pointer min_payer_amount_sat; + + external ffi.Pointer max_payer_amount_sat; } final class wire_cst_receive_payment_request extends ffi.Struct { diff --git a/packages/dart/lib/src/model.dart b/packages/dart/lib/src/model.dart index bc2ea5cb8..9c6b6cd87 100644 --- a/packages/dart/lib/src/model.dart +++ b/packages/dart/lib/src/model.dart @@ -924,14 +924,31 @@ class PrepareReceiveResponse { final BigInt? payerAmountSat; final BigInt feesSat; + /// The minimum amount the payer can send for this swap to succeed. + /// + /// Only applicable to Zero-Amount Receive Chain Swaps. + final BigInt? minPayerAmountSat; + + /// The maximum amount the payer can send for this swap to succeed. + /// + /// Only applicable to Zero-Amount Receive Chain Swaps. + final BigInt? maxPayerAmountSat; + const PrepareReceiveResponse({ required this.paymentMethod, this.payerAmountSat, required this.feesSat, + this.minPayerAmountSat, + this.maxPayerAmountSat, }); @override - int get hashCode => paymentMethod.hashCode ^ payerAmountSat.hashCode ^ feesSat.hashCode; + int get hashCode => + paymentMethod.hashCode ^ + payerAmountSat.hashCode ^ + feesSat.hashCode ^ + minPayerAmountSat.hashCode ^ + maxPayerAmountSat.hashCode; @override bool operator ==(Object other) => @@ -940,7 +957,9 @@ class PrepareReceiveResponse { runtimeType == other.runtimeType && paymentMethod == other.paymentMethod && payerAmountSat == other.payerAmountSat && - feesSat == other.feesSat; + feesSat == other.feesSat && + minPayerAmountSat == other.minPayerAmountSat && + maxPayerAmountSat == other.maxPayerAmountSat; } /// An argument when calling [crate::sdk::LiquidSdk::prepare_refund]. diff --git a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt index b9c340314..27bb19d83 100644 --- a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt +++ b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt @@ -1606,6 +1606,8 @@ fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiv ) { return null } + val paymentMethod = prepareReceiveResponse.getString("paymentMethod")?.let { asPaymentMethod(it) }!! + val feesSat = prepareReceiveResponse.getDouble("feesSat").toULong() val payerAmountSat = if (hasNonNullKey( prepareReceiveResponse, @@ -1616,16 +1618,36 @@ fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiv } else { null } - val paymentMethod = prepareReceiveResponse.getString("paymentMethod")?.let { asPaymentMethod(it) }!! - val feesSat = prepareReceiveResponse.getDouble("feesSat").toULong() - return PrepareReceiveResponse(payerAmountSat, paymentMethod, feesSat) + val minPayerAmountSat = + if (hasNonNullKey( + prepareReceiveResponse, + "minPayerAmountSat", + ) + ) { + prepareReceiveResponse.getDouble("minPayerAmountSat").toULong() + } else { + null + } + val maxPayerAmountSat = + if (hasNonNullKey( + prepareReceiveResponse, + "maxPayerAmountSat", + ) + ) { + prepareReceiveResponse.getDouble("maxPayerAmountSat").toULong() + } else { + null + } + return PrepareReceiveResponse(paymentMethod, feesSat, payerAmountSat, minPayerAmountSat, maxPayerAmountSat) } fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap = readableMapOf( - "payerAmountSat" to prepareReceiveResponse.payerAmountSat, "paymentMethod" to prepareReceiveResponse.paymentMethod.name.lowercase(), "feesSat" to prepareReceiveResponse.feesSat, + "payerAmountSat" to prepareReceiveResponse.payerAmountSat, + "minPayerAmountSat" to prepareReceiveResponse.minPayerAmountSat, + "maxPayerAmountSat" to prepareReceiveResponse.maxPayerAmountSat, ) fun asPrepareReceiveResponseList(arr: ReadableArray): List { diff --git a/packages/react-native/ios/BreezSDKLiquidMapper.swift b/packages/react-native/ios/BreezSDKLiquidMapper.swift index 2efdbb4e7..c01edec79 100644 --- a/packages/react-native/ios/BreezSDKLiquidMapper.swift +++ b/packages/react-native/ios/BreezSDKLiquidMapper.swift @@ -1,82 +1,80 @@ -import BreezSDKLiquid import Foundation +import BreezSDKLiquid enum BreezSDKLiquidMapper { - static func asAesSuccessActionData(aesSuccessActionData: [String: Any?]) throws -> AesSuccessActionData { - guard let description = aesSuccessActionData["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionData")) - } - guard let ciphertext = aesSuccessActionData["ciphertext"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "ciphertext", typeName: "AesSuccessActionData")) - } - guard let iv = aesSuccessActionData["iv"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "iv", typeName: "AesSuccessActionData")) - } - - return AesSuccessActionData(description: description, ciphertext: ciphertext, iv: iv) +static func asAesSuccessActionData(aesSuccessActionData: [String: Any?]) throws -> AesSuccessActionData { + guard let description = aesSuccessActionData["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionData")) + } + guard let ciphertext = aesSuccessActionData["ciphertext"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "ciphertext", typeName: "AesSuccessActionData")) + } + guard let iv = aesSuccessActionData["iv"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "iv", typeName: "AesSuccessActionData")) } + + return AesSuccessActionData(description: description, ciphertext: ciphertext, iv: iv) +} - static func dictionaryOf(aesSuccessActionData: AesSuccessActionData) -> [String: Any?] { - return [ +static func dictionaryOf(aesSuccessActionData: AesSuccessActionData) -> [String: Any?] { + return [ "description": aesSuccessActionData.description, "ciphertext": aesSuccessActionData.ciphertext, - "iv": aesSuccessActionData.iv, - ] - } + "iv": aesSuccessActionData.iv, + ] +} - static func asAesSuccessActionDataList(arr: [Any]) throws -> [AesSuccessActionData] { - var list = [AesSuccessActionData]() - for value in arr { - if let val = value as? [String: Any?] { - var aesSuccessActionData = try asAesSuccessActionData(aesSuccessActionData: val) - list.append(aesSuccessActionData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionData")) - } +static func asAesSuccessActionDataList(arr: [Any]) throws -> [AesSuccessActionData] { + var list = [AesSuccessActionData]() + for value in arr { + if let val = value as? [String: Any?] { + var aesSuccessActionData = try asAesSuccessActionData(aesSuccessActionData: val) + list.append(aesSuccessActionData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionData")) } - return list } + return list +} - static func arrayOf(aesSuccessActionDataList: [AesSuccessActionData]) -> [Any] { - return aesSuccessActionDataList.map { v -> [String: Any?] in return dictionaryOf(aesSuccessActionData: v) } +static func arrayOf(`aesSuccessActionDataList`: [AesSuccessActionData]) -> [Any] { + return `aesSuccessActionDataList`.map { (v) -> [String: Any?] in return dictionaryOf(aesSuccessActionData: v) } +} +static func asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: [String: Any?]) throws -> AesSuccessActionDataDecrypted { + guard let description = aesSuccessActionDataDecrypted["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionDataDecrypted")) } - - static func asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: [String: Any?]) throws -> AesSuccessActionDataDecrypted { - guard let description = aesSuccessActionDataDecrypted["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionDataDecrypted")) - } - guard let plaintext = aesSuccessActionDataDecrypted["plaintext"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "plaintext", typeName: "AesSuccessActionDataDecrypted")) - } - - return AesSuccessActionDataDecrypted(description: description, plaintext: plaintext) + guard let plaintext = aesSuccessActionDataDecrypted["plaintext"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "plaintext", typeName: "AesSuccessActionDataDecrypted")) } + + return AesSuccessActionDataDecrypted(description: description, plaintext: plaintext) +} - static func dictionaryOf(aesSuccessActionDataDecrypted: AesSuccessActionDataDecrypted) -> [String: Any?] { - return [ +static func dictionaryOf(aesSuccessActionDataDecrypted: AesSuccessActionDataDecrypted) -> [String: Any?] { + return [ "description": aesSuccessActionDataDecrypted.description, - "plaintext": aesSuccessActionDataDecrypted.plaintext, - ] - } + "plaintext": aesSuccessActionDataDecrypted.plaintext, + ] +} - static func asAesSuccessActionDataDecryptedList(arr: [Any]) throws -> [AesSuccessActionDataDecrypted] { - var list = [AesSuccessActionDataDecrypted]() - for value in arr { - if let val = value as? [String: Any?] { - var aesSuccessActionDataDecrypted = try asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: val) - list.append(aesSuccessActionDataDecrypted) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataDecrypted")) - } +static func asAesSuccessActionDataDecryptedList(arr: [Any]) throws -> [AesSuccessActionDataDecrypted] { + var list = [AesSuccessActionDataDecrypted]() + for value in arr { + if let val = value as? [String: Any?] { + var aesSuccessActionDataDecrypted = try asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: val) + list.append(aesSuccessActionDataDecrypted) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataDecrypted")) } - return list - } - - static func arrayOf(aesSuccessActionDataDecryptedList: [AesSuccessActionDataDecrypted]) -> [Any] { - return aesSuccessActionDataDecryptedList.map { v -> [String: Any?] in return dictionaryOf(aesSuccessActionDataDecrypted: v) } } + return list +} - static func asBackupRequest(backupRequest: [String: Any?]) throws -> BackupRequest { +static func arrayOf(`aesSuccessActionDataDecryptedList`: [AesSuccessActionDataDecrypted]) -> [Any] { + return `aesSuccessActionDataDecryptedList`.map { (v) -> [String: Any?] in return dictionaryOf(aesSuccessActionDataDecrypted: v) } +} +static func asBackupRequest(backupRequest: [String: Any?]) throws -> BackupRequest { var backupPath: String? if hasNonNilKey(data: backupRequest, key: "backupPath") { guard let backupPathTmp = backupRequest["backupPath"] as? String else { @@ -84,42 +82,41 @@ enum BreezSDKLiquidMapper { } backupPath = backupPathTmp } + + return BackupRequest(backupPath: backupPath) +} - return BackupRequest(backupPath: backupPath) - } - - static func dictionaryOf(backupRequest: BackupRequest) -> [String: Any?] { - return [ - "backupPath": backupRequest.backupPath == nil ? nil : backupRequest.backupPath, - ] - } +static func dictionaryOf(backupRequest: BackupRequest) -> [String: Any?] { + return [ + "backupPath": backupRequest.backupPath == nil ? nil : backupRequest.backupPath, + ] +} - static func asBackupRequestList(arr: [Any]) throws -> [BackupRequest] { - var list = [BackupRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var backupRequest = try asBackupRequest(backupRequest: val) - list.append(backupRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BackupRequest")) - } +static func asBackupRequestList(arr: [Any]) throws -> [BackupRequest] { + var list = [BackupRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var backupRequest = try asBackupRequest(backupRequest: val) + list.append(backupRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BackupRequest")) } - return list } + return list +} - static func arrayOf(backupRequestList: [BackupRequest]) -> [Any] { - return backupRequestList.map { v -> [String: Any?] in return dictionaryOf(backupRequest: v) } +static func arrayOf(`backupRequestList`: [BackupRequest]) -> [Any] { + return `backupRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(backupRequest: v) } +} +static func asBitcoinAddressData(bitcoinAddressData: [String: Any?]) throws -> BitcoinAddressData { + guard let address = bitcoinAddressData["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "BitcoinAddressData")) } - - static func asBitcoinAddressData(bitcoinAddressData: [String: Any?]) throws -> BitcoinAddressData { - guard let address = bitcoinAddressData["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "BitcoinAddressData")) - } - guard let networkTmp = bitcoinAddressData["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "BitcoinAddressData")) - } - let network = try asNetwork(network: networkTmp) - + guard let networkTmp = bitcoinAddressData["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "BitcoinAddressData")) + } + let network = try asNetwork(network: networkTmp) + var amountSat: UInt64? if hasNonNilKey(data: bitcoinAddressData, key: "amountSat") { guard let amountSatTmp = bitcoinAddressData["amountSat"] as? UInt64 else { @@ -141,43 +138,42 @@ enum BreezSDKLiquidMapper { } message = messageTmp } + + return BitcoinAddressData(address: address, network: network, amountSat: amountSat, label: label, message: message) +} - return BitcoinAddressData(address: address, network: network, amountSat: amountSat, label: label, message: message) - } - - static func dictionaryOf(bitcoinAddressData: BitcoinAddressData) -> [String: Any?] { - return [ +static func dictionaryOf(bitcoinAddressData: BitcoinAddressData) -> [String: Any?] { + return [ "address": bitcoinAddressData.address, - "network": valueOf(network: bitcoinAddressData.network), + "network": valueOf( network: bitcoinAddressData.network), "amountSat": bitcoinAddressData.amountSat == nil ? nil : bitcoinAddressData.amountSat, "label": bitcoinAddressData.label == nil ? nil : bitcoinAddressData.label, - "message": bitcoinAddressData.message == nil ? nil : bitcoinAddressData.message, - ] - } + "message": bitcoinAddressData.message == nil ? nil : bitcoinAddressData.message, + ] +} - static func asBitcoinAddressDataList(arr: [Any]) throws -> [BitcoinAddressData] { - var list = [BitcoinAddressData]() - for value in arr { - if let val = value as? [String: Any?] { - var bitcoinAddressData = try asBitcoinAddressData(bitcoinAddressData: val) - list.append(bitcoinAddressData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BitcoinAddressData")) - } +static func asBitcoinAddressDataList(arr: [Any]) throws -> [BitcoinAddressData] { + var list = [BitcoinAddressData]() + for value in arr { + if let val = value as? [String: Any?] { + var bitcoinAddressData = try asBitcoinAddressData(bitcoinAddressData: val) + list.append(bitcoinAddressData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BitcoinAddressData")) } - return list } + return list +} - static func arrayOf(bitcoinAddressDataList: [BitcoinAddressData]) -> [Any] { - return bitcoinAddressDataList.map { v -> [String: Any?] in return dictionaryOf(bitcoinAddressData: v) } +static func arrayOf(`bitcoinAddressDataList`: [BitcoinAddressData]) -> [Any] { + return `bitcoinAddressDataList`.map { (v) -> [String: Any?] in return dictionaryOf(bitcoinAddressData: v) } +} +static func asBuyBitcoinRequest(buyBitcoinRequest: [String: Any?]) throws -> BuyBitcoinRequest { + guard let prepareResponseTmp = buyBitcoinRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "BuyBitcoinRequest")) } - - static func asBuyBitcoinRequest(buyBitcoinRequest: [String: Any?]) throws -> BuyBitcoinRequest { - guard let prepareResponseTmp = buyBitcoinRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "BuyBitcoinRequest")) - } - let prepareResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: prepareResponseTmp) - + let prepareResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: prepareResponseTmp) + var redirectUrl: String? if hasNonNilKey(data: buyBitcoinRequest, key: "redirectUrl") { guard let redirectUrlTmp = buyBitcoinRequest["redirectUrl"] as? String else { @@ -185,128 +181,125 @@ enum BreezSDKLiquidMapper { } redirectUrl = redirectUrlTmp } + + return BuyBitcoinRequest(prepareResponse: prepareResponse, redirectUrl: redirectUrl) +} - return BuyBitcoinRequest(prepareResponse: prepareResponse, redirectUrl: redirectUrl) - } - - static func dictionaryOf(buyBitcoinRequest: BuyBitcoinRequest) -> [String: Any?] { - return [ +static func dictionaryOf(buyBitcoinRequest: BuyBitcoinRequest) -> [String: Any?] { + return [ "prepareResponse": dictionaryOf(prepareBuyBitcoinResponse: buyBitcoinRequest.prepareResponse), - "redirectUrl": buyBitcoinRequest.redirectUrl == nil ? nil : buyBitcoinRequest.redirectUrl, - ] - } + "redirectUrl": buyBitcoinRequest.redirectUrl == nil ? nil : buyBitcoinRequest.redirectUrl, + ] +} - static func asBuyBitcoinRequestList(arr: [Any]) throws -> [BuyBitcoinRequest] { - var list = [BuyBitcoinRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var buyBitcoinRequest = try asBuyBitcoinRequest(buyBitcoinRequest: val) - list.append(buyBitcoinRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinRequest")) - } +static func asBuyBitcoinRequestList(arr: [Any]) throws -> [BuyBitcoinRequest] { + var list = [BuyBitcoinRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var buyBitcoinRequest = try asBuyBitcoinRequest(buyBitcoinRequest: val) + list.append(buyBitcoinRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinRequest")) } - return list } + return list +} - static func arrayOf(buyBitcoinRequestList: [BuyBitcoinRequest]) -> [Any] { - return buyBitcoinRequestList.map { v -> [String: Any?] in return dictionaryOf(buyBitcoinRequest: v) } +static func arrayOf(`buyBitcoinRequestList`: [BuyBitcoinRequest]) -> [Any] { + return `buyBitcoinRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(buyBitcoinRequest: v) } +} +static func asCheckMessageRequest(checkMessageRequest: [String: Any?]) throws -> CheckMessageRequest { + guard let message = checkMessageRequest["message"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "CheckMessageRequest")) } - - static func asCheckMessageRequest(checkMessageRequest: [String: Any?]) throws -> CheckMessageRequest { - guard let message = checkMessageRequest["message"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "CheckMessageRequest")) - } - guard let pubkey = checkMessageRequest["pubkey"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "CheckMessageRequest")) - } - guard let signature = checkMessageRequest["signature"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "CheckMessageRequest")) - } - - return CheckMessageRequest(message: message, pubkey: pubkey, signature: signature) + guard let pubkey = checkMessageRequest["pubkey"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "CheckMessageRequest")) } + guard let signature = checkMessageRequest["signature"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "CheckMessageRequest")) + } + + return CheckMessageRequest(message: message, pubkey: pubkey, signature: signature) +} - static func dictionaryOf(checkMessageRequest: CheckMessageRequest) -> [String: Any?] { - return [ +static func dictionaryOf(checkMessageRequest: CheckMessageRequest) -> [String: Any?] { + return [ "message": checkMessageRequest.message, "pubkey": checkMessageRequest.pubkey, - "signature": checkMessageRequest.signature, - ] - } + "signature": checkMessageRequest.signature, + ] +} - static func asCheckMessageRequestList(arr: [Any]) throws -> [CheckMessageRequest] { - var list = [CheckMessageRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var checkMessageRequest = try asCheckMessageRequest(checkMessageRequest: val) - list.append(checkMessageRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageRequest")) - } +static func asCheckMessageRequestList(arr: [Any]) throws -> [CheckMessageRequest] { + var list = [CheckMessageRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var checkMessageRequest = try asCheckMessageRequest(checkMessageRequest: val) + list.append(checkMessageRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageRequest")) } - return list } + return list +} - static func arrayOf(checkMessageRequestList: [CheckMessageRequest]) -> [Any] { - return checkMessageRequestList.map { v -> [String: Any?] in return dictionaryOf(checkMessageRequest: v) } +static func arrayOf(`checkMessageRequestList`: [CheckMessageRequest]) -> [Any] { + return `checkMessageRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(checkMessageRequest: v) } +} +static func asCheckMessageResponse(checkMessageResponse: [String: Any?]) throws -> CheckMessageResponse { + guard let isValid = checkMessageResponse["isValid"] as? Bool else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "isValid", typeName: "CheckMessageResponse")) } + + return CheckMessageResponse(isValid: isValid) +} - static func asCheckMessageResponse(checkMessageResponse: [String: Any?]) throws -> CheckMessageResponse { - guard let isValid = checkMessageResponse["isValid"] as? Bool else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "isValid", typeName: "CheckMessageResponse")) - } +static func dictionaryOf(checkMessageResponse: CheckMessageResponse) -> [String: Any?] { + return [ + "isValid": checkMessageResponse.isValid, + ] +} - return CheckMessageResponse(isValid: isValid) +static func asCheckMessageResponseList(arr: [Any]) throws -> [CheckMessageResponse] { + var list = [CheckMessageResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var checkMessageResponse = try asCheckMessageResponse(checkMessageResponse: val) + list.append(checkMessageResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageResponse")) + } } + return list +} - static func dictionaryOf(checkMessageResponse: CheckMessageResponse) -> [String: Any?] { - return [ - "isValid": checkMessageResponse.isValid, - ] +static func arrayOf(`checkMessageResponseList`: [CheckMessageResponse]) -> [Any] { + return `checkMessageResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(checkMessageResponse: v) } +} +static func asConfig(config: [String: Any?]) throws -> Config { + guard let liquidElectrumUrl = config["liquidElectrumUrl"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "liquidElectrumUrl", typeName: "Config")) } - - static func asCheckMessageResponseList(arr: [Any]) throws -> [CheckMessageResponse] { - var list = [CheckMessageResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var checkMessageResponse = try asCheckMessageResponse(checkMessageResponse: val) - list.append(checkMessageResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageResponse")) - } - } - return list + guard let bitcoinElectrumUrl = config["bitcoinElectrumUrl"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bitcoinElectrumUrl", typeName: "Config")) } - - static func arrayOf(checkMessageResponseList: [CheckMessageResponse]) -> [Any] { - return checkMessageResponseList.map { v -> [String: Any?] in return dictionaryOf(checkMessageResponse: v) } + guard let mempoolspaceUrl = config["mempoolspaceUrl"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mempoolspaceUrl", typeName: "Config")) + } + guard let workingDir = config["workingDir"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "workingDir", typeName: "Config")) + } + guard let networkTmp = config["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "Config")) + } + let network = try asLiquidNetwork(liquidNetwork: networkTmp) + + guard let paymentTimeoutSec = config["paymentTimeoutSec"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentTimeoutSec", typeName: "Config")) + } + guard let zeroConfMinFeeRateMsat = config["zeroConfMinFeeRateMsat"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "zeroConfMinFeeRateMsat", typeName: "Config")) } - - static func asConfig(config: [String: Any?]) throws -> Config { - guard let liquidElectrumUrl = config["liquidElectrumUrl"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "liquidElectrumUrl", typeName: "Config")) - } - guard let bitcoinElectrumUrl = config["bitcoinElectrumUrl"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bitcoinElectrumUrl", typeName: "Config")) - } - guard let mempoolspaceUrl = config["mempoolspaceUrl"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mempoolspaceUrl", typeName: "Config")) - } - guard let workingDir = config["workingDir"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "workingDir", typeName: "Config")) - } - guard let networkTmp = config["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "Config")) - } - let network = try asLiquidNetwork(liquidNetwork: networkTmp) - - guard let paymentTimeoutSec = config["paymentTimeoutSec"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentTimeoutSec", typeName: "Config")) - } - guard let zeroConfMinFeeRateMsat = config["zeroConfMinFeeRateMsat"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "zeroConfMinFeeRateMsat", typeName: "Config")) - } var breezApiKey: String? if hasNonNilKey(data: config, key: "breezApiKey") { guard let breezApiKeyTmp = config["breezApiKey"] as? String else { @@ -321,117 +314,115 @@ enum BreezSDKLiquidMapper { } zeroConfMaxAmountSat = zeroConfMaxAmountSatTmp } + + return Config(liquidElectrumUrl: liquidElectrumUrl, bitcoinElectrumUrl: bitcoinElectrumUrl, mempoolspaceUrl: mempoolspaceUrl, workingDir: workingDir, network: network, paymentTimeoutSec: paymentTimeoutSec, zeroConfMinFeeRateMsat: zeroConfMinFeeRateMsat, breezApiKey: breezApiKey, zeroConfMaxAmountSat: zeroConfMaxAmountSat) +} - return Config(liquidElectrumUrl: liquidElectrumUrl, bitcoinElectrumUrl: bitcoinElectrumUrl, mempoolspaceUrl: mempoolspaceUrl, workingDir: workingDir, network: network, paymentTimeoutSec: paymentTimeoutSec, zeroConfMinFeeRateMsat: zeroConfMinFeeRateMsat, breezApiKey: breezApiKey, zeroConfMaxAmountSat: zeroConfMaxAmountSat) - } - - static func dictionaryOf(config: Config) -> [String: Any?] { - return [ +static func dictionaryOf(config: Config) -> [String: Any?] { + return [ "liquidElectrumUrl": config.liquidElectrumUrl, "bitcoinElectrumUrl": config.bitcoinElectrumUrl, "mempoolspaceUrl": config.mempoolspaceUrl, "workingDir": config.workingDir, - "network": valueOf(liquidNetwork: config.network), + "network": valueOf( liquidNetwork: config.network), "paymentTimeoutSec": config.paymentTimeoutSec, "zeroConfMinFeeRateMsat": config.zeroConfMinFeeRateMsat, "breezApiKey": config.breezApiKey == nil ? nil : config.breezApiKey, - "zeroConfMaxAmountSat": config.zeroConfMaxAmountSat == nil ? nil : config.zeroConfMaxAmountSat, - ] - } + "zeroConfMaxAmountSat": config.zeroConfMaxAmountSat == nil ? nil : config.zeroConfMaxAmountSat, + ] +} - static func asConfigList(arr: [Any]) throws -> [Config] { - var list = [Config]() - for value in arr { - if let val = value as? [String: Any?] { - var config = try asConfig(config: val) - list.append(config) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Config")) - } +static func asConfigList(arr: [Any]) throws -> [Config] { + var list = [Config]() + for value in arr { + if let val = value as? [String: Any?] { + var config = try asConfig(config: val) + list.append(config) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Config")) } - return list } + return list +} - static func arrayOf(configList: [Config]) -> [Any] { - return configList.map { v -> [String: Any?] in return dictionaryOf(config: v) } +static func arrayOf(`configList`: [Config]) -> [Any] { + return `configList`.map { (v) -> [String: Any?] in return dictionaryOf(config: v) } +} +static func asConnectRequest(connectRequest: [String: Any?]) throws -> ConnectRequest { + guard let configTmp = connectRequest["config"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectRequest")) } - - static func asConnectRequest(connectRequest: [String: Any?]) throws -> ConnectRequest { - guard let configTmp = connectRequest["config"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectRequest")) - } - let config = try asConfig(config: configTmp) - - guard let mnemonic = connectRequest["mnemonic"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mnemonic", typeName: "ConnectRequest")) - } - - return ConnectRequest(config: config, mnemonic: mnemonic) + let config = try asConfig(config: configTmp) + + guard let mnemonic = connectRequest["mnemonic"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mnemonic", typeName: "ConnectRequest")) } + + return ConnectRequest(config: config, mnemonic: mnemonic) +} - static func dictionaryOf(connectRequest: ConnectRequest) -> [String: Any?] { - return [ +static func dictionaryOf(connectRequest: ConnectRequest) -> [String: Any?] { + return [ "config": dictionaryOf(config: connectRequest.config), - "mnemonic": connectRequest.mnemonic, - ] - } + "mnemonic": connectRequest.mnemonic, + ] +} - static func asConnectRequestList(arr: [Any]) throws -> [ConnectRequest] { - var list = [ConnectRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var connectRequest = try asConnectRequest(connectRequest: val) - list.append(connectRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectRequest")) - } +static func asConnectRequestList(arr: [Any]) throws -> [ConnectRequest] { + var list = [ConnectRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var connectRequest = try asConnectRequest(connectRequest: val) + list.append(connectRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectRequest")) } - return list - } - - static func arrayOf(connectRequestList: [ConnectRequest]) -> [Any] { - return connectRequestList.map { v -> [String: Any?] in return dictionaryOf(connectRequest: v) } } + return list +} - static func asConnectWithSignerRequest(connectWithSignerRequest: [String: Any?]) throws -> ConnectWithSignerRequest { - guard let configTmp = connectWithSignerRequest["config"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectWithSignerRequest")) - } - let config = try asConfig(config: configTmp) - - return ConnectWithSignerRequest(config: config) - } +static func arrayOf(`connectRequestList`: [ConnectRequest]) -> [Any] { + return `connectRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(connectRequest: v) } +} +static func asConnectWithSignerRequest(connectWithSignerRequest: [String: Any?]) throws -> ConnectWithSignerRequest { + guard let configTmp = connectWithSignerRequest["config"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectWithSignerRequest")) + } + let config = try asConfig(config: configTmp) + + + return ConnectWithSignerRequest(config: config) +} - static func dictionaryOf(connectWithSignerRequest: ConnectWithSignerRequest) -> [String: Any?] { - return [ - "config": dictionaryOf(config: connectWithSignerRequest.config), - ] - } +static func dictionaryOf(connectWithSignerRequest: ConnectWithSignerRequest) -> [String: Any?] { + return [ + "config": dictionaryOf(config: connectWithSignerRequest.config), + ] +} - static func asConnectWithSignerRequestList(arr: [Any]) throws -> [ConnectWithSignerRequest] { - var list = [ConnectWithSignerRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var connectWithSignerRequest = try asConnectWithSignerRequest(connectWithSignerRequest: val) - list.append(connectWithSignerRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectWithSignerRequest")) - } +static func asConnectWithSignerRequestList(arr: [Any]) throws -> [ConnectWithSignerRequest] { + var list = [ConnectWithSignerRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var connectWithSignerRequest = try asConnectWithSignerRequest(connectWithSignerRequest: val) + list.append(connectWithSignerRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectWithSignerRequest")) } - return list } + return list +} - static func arrayOf(connectWithSignerRequestList: [ConnectWithSignerRequest]) -> [Any] { - return connectWithSignerRequestList.map { v -> [String: Any?] in return dictionaryOf(connectWithSignerRequest: v) } +static func arrayOf(`connectWithSignerRequestList`: [ConnectWithSignerRequest]) -> [Any] { + return `connectWithSignerRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(connectWithSignerRequest: v) } +} +static func asCurrencyInfo(currencyInfo: [String: Any?]) throws -> CurrencyInfo { + guard let name = currencyInfo["name"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "CurrencyInfo")) + } + guard let fractionSize = currencyInfo["fractionSize"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fractionSize", typeName: "CurrencyInfo")) } - - static func asCurrencyInfo(currencyInfo: [String: Any?]) throws -> CurrencyInfo { - guard let name = currencyInfo["name"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "CurrencyInfo")) - } - guard let fractionSize = currencyInfo["fractionSize"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fractionSize", typeName: "CurrencyInfo")) - } var spacing: UInt32? if hasNonNilKey(data: currencyInfo, key: "spacing") { guard let spacingTmp = currencyInfo["spacing"] as? UInt32 else { @@ -443,152 +434,151 @@ enum BreezSDKLiquidMapper { if let symbolTmp = currencyInfo["symbol"] as? [String: Any?] { symbol = try asSymbol(symbol: symbolTmp) } - + var uniqSymbol: Symbol? if let uniqSymbolTmp = currencyInfo["uniqSymbol"] as? [String: Any?] { uniqSymbol = try asSymbol(symbol: uniqSymbolTmp) } - - guard let localizedNameTmp = currencyInfo["localizedName"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localizedName", typeName: "CurrencyInfo")) - } - let localizedName = try asLocalizedNameList(arr: localizedNameTmp) - - guard let localeOverridesTmp = currencyInfo["localeOverrides"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localeOverrides", typeName: "CurrencyInfo")) - } - let localeOverrides = try asLocaleOverridesList(arr: localeOverridesTmp) - - return CurrencyInfo(name: name, fractionSize: fractionSize, spacing: spacing, symbol: symbol, uniqSymbol: uniqSymbol, localizedName: localizedName, localeOverrides: localeOverrides) + + guard let localizedNameTmp = currencyInfo["localizedName"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localizedName", typeName: "CurrencyInfo")) + } + let localizedName = try asLocalizedNameList(arr: localizedNameTmp) + + guard let localeOverridesTmp = currencyInfo["localeOverrides"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localeOverrides", typeName: "CurrencyInfo")) } + let localeOverrides = try asLocaleOverridesList(arr: localeOverridesTmp) + + + return CurrencyInfo(name: name, fractionSize: fractionSize, spacing: spacing, symbol: symbol, uniqSymbol: uniqSymbol, localizedName: localizedName, localeOverrides: localeOverrides) +} - static func dictionaryOf(currencyInfo: CurrencyInfo) -> [String: Any?] { - return [ +static func dictionaryOf(currencyInfo: CurrencyInfo) -> [String: Any?] { + return [ "name": currencyInfo.name, "fractionSize": currencyInfo.fractionSize, "spacing": currencyInfo.spacing == nil ? nil : currencyInfo.spacing, "symbol": currencyInfo.symbol == nil ? nil : dictionaryOf(symbol: currencyInfo.symbol!), "uniqSymbol": currencyInfo.uniqSymbol == nil ? nil : dictionaryOf(symbol: currencyInfo.uniqSymbol!), "localizedName": arrayOf(localizedNameList: currencyInfo.localizedName), - "localeOverrides": arrayOf(localeOverridesList: currencyInfo.localeOverrides), - ] - } + "localeOverrides": arrayOf(localeOverridesList: currencyInfo.localeOverrides), + ] +} - static func asCurrencyInfoList(arr: [Any]) throws -> [CurrencyInfo] { - var list = [CurrencyInfo]() - for value in arr { - if let val = value as? [String: Any?] { - var currencyInfo = try asCurrencyInfo(currencyInfo: val) - list.append(currencyInfo) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "CurrencyInfo")) - } +static func asCurrencyInfoList(arr: [Any]) throws -> [CurrencyInfo] { + var list = [CurrencyInfo]() + for value in arr { + if let val = value as? [String: Any?] { + var currencyInfo = try asCurrencyInfo(currencyInfo: val) + list.append(currencyInfo) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "CurrencyInfo")) } - return list } + return list +} - static func arrayOf(currencyInfoList: [CurrencyInfo]) -> [Any] { - return currencyInfoList.map { v -> [String: Any?] in return dictionaryOf(currencyInfo: v) } +static func arrayOf(`currencyInfoList`: [CurrencyInfo]) -> [Any] { + return `currencyInfoList`.map { (v) -> [String: Any?] in return dictionaryOf(currencyInfo: v) } +} +static func asFiatCurrency(fiatCurrency: [String: Any?]) throws -> FiatCurrency { + guard let id = fiatCurrency["id"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "id", typeName: "FiatCurrency")) } - - static func asFiatCurrency(fiatCurrency: [String: Any?]) throws -> FiatCurrency { - guard let id = fiatCurrency["id"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "id", typeName: "FiatCurrency")) - } - guard let infoTmp = fiatCurrency["info"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "info", typeName: "FiatCurrency")) - } - let info = try asCurrencyInfo(currencyInfo: infoTmp) - - return FiatCurrency(id: id, info: info) + guard let infoTmp = fiatCurrency["info"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "info", typeName: "FiatCurrency")) } + let info = try asCurrencyInfo(currencyInfo: infoTmp) + + + return FiatCurrency(id: id, info: info) +} - static func dictionaryOf(fiatCurrency: FiatCurrency) -> [String: Any?] { - return [ +static func dictionaryOf(fiatCurrency: FiatCurrency) -> [String: Any?] { + return [ "id": fiatCurrency.id, - "info": dictionaryOf(currencyInfo: fiatCurrency.info), - ] - } + "info": dictionaryOf(currencyInfo: fiatCurrency.info), + ] +} - static func asFiatCurrencyList(arr: [Any]) throws -> [FiatCurrency] { - var list = [FiatCurrency]() - for value in arr { - if let val = value as? [String: Any?] { - var fiatCurrency = try asFiatCurrency(fiatCurrency: val) - list.append(fiatCurrency) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "FiatCurrency")) - } +static func asFiatCurrencyList(arr: [Any]) throws -> [FiatCurrency] { + var list = [FiatCurrency]() + for value in arr { + if let val = value as? [String: Any?] { + var fiatCurrency = try asFiatCurrency(fiatCurrency: val) + list.append(fiatCurrency) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "FiatCurrency")) } - return list } + return list +} - static func arrayOf(fiatCurrencyList: [FiatCurrency]) -> [Any] { - return fiatCurrencyList.map { v -> [String: Any?] in return dictionaryOf(fiatCurrency: v) } +static func arrayOf(`fiatCurrencyList`: [FiatCurrency]) -> [Any] { + return `fiatCurrencyList`.map { (v) -> [String: Any?] in return dictionaryOf(fiatCurrency: v) } +} +static func asGetInfoResponse(getInfoResponse: [String: Any?]) throws -> GetInfoResponse { + guard let balanceSat = getInfoResponse["balanceSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "balanceSat", typeName: "GetInfoResponse")) } - - static func asGetInfoResponse(getInfoResponse: [String: Any?]) throws -> GetInfoResponse { - guard let balanceSat = getInfoResponse["balanceSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "balanceSat", typeName: "GetInfoResponse")) - } - guard let pendingSendSat = getInfoResponse["pendingSendSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingSendSat", typeName: "GetInfoResponse")) - } - guard let pendingReceiveSat = getInfoResponse["pendingReceiveSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingReceiveSat", typeName: "GetInfoResponse")) - } - guard let fingerprint = getInfoResponse["fingerprint"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fingerprint", typeName: "GetInfoResponse")) - } - guard let pubkey = getInfoResponse["pubkey"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "GetInfoResponse")) - } - - return GetInfoResponse(balanceSat: balanceSat, pendingSendSat: pendingSendSat, pendingReceiveSat: pendingReceiveSat, fingerprint: fingerprint, pubkey: pubkey) + guard let pendingSendSat = getInfoResponse["pendingSendSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingSendSat", typeName: "GetInfoResponse")) + } + guard let pendingReceiveSat = getInfoResponse["pendingReceiveSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingReceiveSat", typeName: "GetInfoResponse")) + } + guard let fingerprint = getInfoResponse["fingerprint"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fingerprint", typeName: "GetInfoResponse")) + } + guard let pubkey = getInfoResponse["pubkey"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "GetInfoResponse")) } + + return GetInfoResponse(balanceSat: balanceSat, pendingSendSat: pendingSendSat, pendingReceiveSat: pendingReceiveSat, fingerprint: fingerprint, pubkey: pubkey) +} - static func dictionaryOf(getInfoResponse: GetInfoResponse) -> [String: Any?] { - return [ +static func dictionaryOf(getInfoResponse: GetInfoResponse) -> [String: Any?] { + return [ "balanceSat": getInfoResponse.balanceSat, "pendingSendSat": getInfoResponse.pendingSendSat, "pendingReceiveSat": getInfoResponse.pendingReceiveSat, "fingerprint": getInfoResponse.fingerprint, - "pubkey": getInfoResponse.pubkey, - ] - } + "pubkey": getInfoResponse.pubkey, + ] +} - static func asGetInfoResponseList(arr: [Any]) throws -> [GetInfoResponse] { - var list = [GetInfoResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var getInfoResponse = try asGetInfoResponse(getInfoResponse: val) - list.append(getInfoResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "GetInfoResponse")) - } +static func asGetInfoResponseList(arr: [Any]) throws -> [GetInfoResponse] { + var list = [GetInfoResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var getInfoResponse = try asGetInfoResponse(getInfoResponse: val) + list.append(getInfoResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "GetInfoResponse")) } - return list } + return list +} - static func arrayOf(getInfoResponseList: [GetInfoResponse]) -> [Any] { - return getInfoResponseList.map { v -> [String: Any?] in return dictionaryOf(getInfoResponse: v) } +static func arrayOf(`getInfoResponseList`: [GetInfoResponse]) -> [Any] { + return `getInfoResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(getInfoResponse: v) } +} +static func asLnInvoice(lnInvoice: [String: Any?]) throws -> LnInvoice { + guard let bolt11 = lnInvoice["bolt11"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bolt11", typeName: "LnInvoice")) + } + guard let networkTmp = lnInvoice["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LnInvoice")) + } + let network = try asNetwork(network: networkTmp) + + guard let payeePubkey = lnInvoice["payeePubkey"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payeePubkey", typeName: "LnInvoice")) + } + guard let paymentHash = lnInvoice["paymentHash"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnInvoice")) } - - static func asLnInvoice(lnInvoice: [String: Any?]) throws -> LnInvoice { - guard let bolt11 = lnInvoice["bolt11"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bolt11", typeName: "LnInvoice")) - } - guard let networkTmp = lnInvoice["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LnInvoice")) - } - let network = try asNetwork(network: networkTmp) - - guard let payeePubkey = lnInvoice["payeePubkey"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payeePubkey", typeName: "LnInvoice")) - } - guard let paymentHash = lnInvoice["paymentHash"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnInvoice")) - } var description: String? if hasNonNilKey(data: lnInvoice, key: "description") { guard let descriptionTmp = lnInvoice["description"] as? String else { @@ -610,31 +600,31 @@ enum BreezSDKLiquidMapper { } amountMsat = amountMsatTmp } - guard let timestamp = lnInvoice["timestamp"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "LnInvoice")) - } - guard let expiry = lnInvoice["expiry"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "expiry", typeName: "LnInvoice")) - } - guard let routingHintsTmp = lnInvoice["routingHints"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "routingHints", typeName: "LnInvoice")) - } - let routingHints = try asRouteHintList(arr: routingHintsTmp) - - guard let paymentSecret = lnInvoice["paymentSecret"] as? [UInt8] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentSecret", typeName: "LnInvoice")) - } - guard let minFinalCltvExpiryDelta = lnInvoice["minFinalCltvExpiryDelta"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minFinalCltvExpiryDelta", typeName: "LnInvoice")) - } - - return LnInvoice(bolt11: bolt11, network: network, payeePubkey: payeePubkey, paymentHash: paymentHash, description: description, descriptionHash: descriptionHash, amountMsat: amountMsat, timestamp: timestamp, expiry: expiry, routingHints: routingHints, paymentSecret: paymentSecret, minFinalCltvExpiryDelta: minFinalCltvExpiryDelta) + guard let timestamp = lnInvoice["timestamp"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "LnInvoice")) + } + guard let expiry = lnInvoice["expiry"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "expiry", typeName: "LnInvoice")) } + guard let routingHintsTmp = lnInvoice["routingHints"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "routingHints", typeName: "LnInvoice")) + } + let routingHints = try asRouteHintList(arr: routingHintsTmp) + + guard let paymentSecret = lnInvoice["paymentSecret"] as? [UInt8] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentSecret", typeName: "LnInvoice")) + } + guard let minFinalCltvExpiryDelta = lnInvoice["minFinalCltvExpiryDelta"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minFinalCltvExpiryDelta", typeName: "LnInvoice")) + } + + return LnInvoice(bolt11: bolt11, network: network, payeePubkey: payeePubkey, paymentHash: paymentHash, description: description, descriptionHash: descriptionHash, amountMsat: amountMsat, timestamp: timestamp, expiry: expiry, routingHints: routingHints, paymentSecret: paymentSecret, minFinalCltvExpiryDelta: minFinalCltvExpiryDelta) +} - static func dictionaryOf(lnInvoice: LnInvoice) -> [String: Any?] { - return [ +static func dictionaryOf(lnInvoice: LnInvoice) -> [String: Any?] { + return [ "bolt11": lnInvoice.bolt11, - "network": valueOf(network: lnInvoice.network), + "network": valueOf( network: lnInvoice.network), "payeePubkey": lnInvoice.payeePubkey, "paymentHash": lnInvoice.paymentHash, "description": lnInvoice.description == nil ? nil : lnInvoice.description, @@ -644,113 +634,111 @@ enum BreezSDKLiquidMapper { "expiry": lnInvoice.expiry, "routingHints": arrayOf(routeHintList: lnInvoice.routingHints), "paymentSecret": lnInvoice.paymentSecret, - "minFinalCltvExpiryDelta": lnInvoice.minFinalCltvExpiryDelta, - ] - } + "minFinalCltvExpiryDelta": lnInvoice.minFinalCltvExpiryDelta, + ] +} - static func asLnInvoiceList(arr: [Any]) throws -> [LnInvoice] { - var list = [LnInvoice]() - for value in arr { - if let val = value as? [String: Any?] { - var lnInvoice = try asLnInvoice(lnInvoice: val) - list.append(lnInvoice) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnInvoice")) - } +static func asLnInvoiceList(arr: [Any]) throws -> [LnInvoice] { + var list = [LnInvoice]() + for value in arr { + if let val = value as? [String: Any?] { + var lnInvoice = try asLnInvoice(lnInvoice: val) + list.append(lnInvoice) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnInvoice")) } - return list } + return list +} - static func arrayOf(lnInvoiceList: [LnInvoice]) -> [Any] { - return lnInvoiceList.map { v -> [String: Any?] in return dictionaryOf(lnInvoice: v) } - } - - static func asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: [String: Any?]) throws -> LightningPaymentLimitsResponse { - guard let sendTmp = lightningPaymentLimitsResponse["send"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "LightningPaymentLimitsResponse")) - } - let send = try asLimits(limits: sendTmp) - - guard let receiveTmp = lightningPaymentLimitsResponse["receive"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "LightningPaymentLimitsResponse")) - } - let receive = try asLimits(limits: receiveTmp) - - return LightningPaymentLimitsResponse(send: send, receive: receive) - } +static func arrayOf(`lnInvoiceList`: [LnInvoice]) -> [Any] { + return `lnInvoiceList`.map { (v) -> [String: Any?] in return dictionaryOf(lnInvoice: v) } +} +static func asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: [String: Any?]) throws -> LightningPaymentLimitsResponse { + guard let sendTmp = lightningPaymentLimitsResponse["send"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "LightningPaymentLimitsResponse")) + } + let send = try asLimits(limits: sendTmp) + + guard let receiveTmp = lightningPaymentLimitsResponse["receive"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "LightningPaymentLimitsResponse")) + } + let receive = try asLimits(limits: receiveTmp) + + + return LightningPaymentLimitsResponse(send: send, receive: receive) +} - static func dictionaryOf(lightningPaymentLimitsResponse: LightningPaymentLimitsResponse) -> [String: Any?] { - return [ +static func dictionaryOf(lightningPaymentLimitsResponse: LightningPaymentLimitsResponse) -> [String: Any?] { + return [ "send": dictionaryOf(limits: lightningPaymentLimitsResponse.send), - "receive": dictionaryOf(limits: lightningPaymentLimitsResponse.receive), - ] - } + "receive": dictionaryOf(limits: lightningPaymentLimitsResponse.receive), + ] +} - static func asLightningPaymentLimitsResponseList(arr: [Any]) throws -> [LightningPaymentLimitsResponse] { - var list = [LightningPaymentLimitsResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var lightningPaymentLimitsResponse = try asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: val) - list.append(lightningPaymentLimitsResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LightningPaymentLimitsResponse")) - } +static func asLightningPaymentLimitsResponseList(arr: [Any]) throws -> [LightningPaymentLimitsResponse] { + var list = [LightningPaymentLimitsResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var lightningPaymentLimitsResponse = try asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: val) + list.append(lightningPaymentLimitsResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LightningPaymentLimitsResponse")) } - return list } + return list +} - static func arrayOf(lightningPaymentLimitsResponseList: [LightningPaymentLimitsResponse]) -> [Any] { - return lightningPaymentLimitsResponseList.map { v -> [String: Any?] in return dictionaryOf(lightningPaymentLimitsResponse: v) } +static func arrayOf(`lightningPaymentLimitsResponseList`: [LightningPaymentLimitsResponse]) -> [Any] { + return `lightningPaymentLimitsResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(lightningPaymentLimitsResponse: v) } +} +static func asLimits(limits: [String: Any?]) throws -> Limits { + guard let minSat = limits["minSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSat", typeName: "Limits")) } - - static func asLimits(limits: [String: Any?]) throws -> Limits { - guard let minSat = limits["minSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSat", typeName: "Limits")) - } - guard let maxSat = limits["maxSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSat", typeName: "Limits")) - } - guard let maxZeroConfSat = limits["maxZeroConfSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxZeroConfSat", typeName: "Limits")) - } - - return Limits(minSat: minSat, maxSat: maxSat, maxZeroConfSat: maxZeroConfSat) + guard let maxSat = limits["maxSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSat", typeName: "Limits")) + } + guard let maxZeroConfSat = limits["maxZeroConfSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxZeroConfSat", typeName: "Limits")) } + + return Limits(minSat: minSat, maxSat: maxSat, maxZeroConfSat: maxZeroConfSat) +} - static func dictionaryOf(limits: Limits) -> [String: Any?] { - return [ +static func dictionaryOf(limits: Limits) -> [String: Any?] { + return [ "minSat": limits.minSat, "maxSat": limits.maxSat, - "maxZeroConfSat": limits.maxZeroConfSat, - ] - } + "maxZeroConfSat": limits.maxZeroConfSat, + ] +} - static func asLimitsList(arr: [Any]) throws -> [Limits] { - var list = [Limits]() - for value in arr { - if let val = value as? [String: Any?] { - var limits = try asLimits(limits: val) - list.append(limits) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Limits")) - } +static func asLimitsList(arr: [Any]) throws -> [Limits] { + var list = [Limits]() + for value in arr { + if let val = value as? [String: Any?] { + var limits = try asLimits(limits: val) + list.append(limits) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Limits")) } - return list } + return list +} - static func arrayOf(limitsList: [Limits]) -> [Any] { - return limitsList.map { v -> [String: Any?] in return dictionaryOf(limits: v) } +static func arrayOf(`limitsList`: [Limits]) -> [Any] { + return `limitsList`.map { (v) -> [String: Any?] in return dictionaryOf(limits: v) } +} +static func asLiquidAddressData(liquidAddressData: [String: Any?]) throws -> LiquidAddressData { + guard let address = liquidAddressData["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "LiquidAddressData")) } - - static func asLiquidAddressData(liquidAddressData: [String: Any?]) throws -> LiquidAddressData { - guard let address = liquidAddressData["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "LiquidAddressData")) - } - guard let networkTmp = liquidAddressData["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LiquidAddressData")) - } - let network = try asNetwork(network: networkTmp) - + guard let networkTmp = liquidAddressData["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LiquidAddressData")) + } + let network = try asNetwork(network: networkTmp) + var assetId: String? if hasNonNilKey(data: liquidAddressData, key: "assetId") { guard let assetIdTmp = liquidAddressData["assetId"] as? String else { @@ -779,44 +767,43 @@ enum BreezSDKLiquidMapper { } message = messageTmp } + + return LiquidAddressData(address: address, network: network, assetId: assetId, amountSat: amountSat, label: label, message: message) +} - return LiquidAddressData(address: address, network: network, assetId: assetId, amountSat: amountSat, label: label, message: message) - } - - static func dictionaryOf(liquidAddressData: LiquidAddressData) -> [String: Any?] { - return [ +static func dictionaryOf(liquidAddressData: LiquidAddressData) -> [String: Any?] { + return [ "address": liquidAddressData.address, - "network": valueOf(network: liquidAddressData.network), + "network": valueOf( network: liquidAddressData.network), "assetId": liquidAddressData.assetId == nil ? nil : liquidAddressData.assetId, "amountSat": liquidAddressData.amountSat == nil ? nil : liquidAddressData.amountSat, "label": liquidAddressData.label == nil ? nil : liquidAddressData.label, - "message": liquidAddressData.message == nil ? nil : liquidAddressData.message, - ] - } + "message": liquidAddressData.message == nil ? nil : liquidAddressData.message, + ] +} - static func asLiquidAddressDataList(arr: [Any]) throws -> [LiquidAddressData] { - var list = [LiquidAddressData]() - for value in arr { - if let val = value as? [String: Any?] { - var liquidAddressData = try asLiquidAddressData(liquidAddressData: val) - list.append(liquidAddressData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidAddressData")) - } +static func asLiquidAddressDataList(arr: [Any]) throws -> [LiquidAddressData] { + var list = [LiquidAddressData]() + for value in arr { + if let val = value as? [String: Any?] { + var liquidAddressData = try asLiquidAddressData(liquidAddressData: val) + list.append(liquidAddressData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidAddressData")) } - return list - } - - static func arrayOf(liquidAddressDataList: [LiquidAddressData]) -> [Any] { - return liquidAddressDataList.map { v -> [String: Any?] in return dictionaryOf(liquidAddressData: v) } } + return list +} - static func asListPaymentsRequest(listPaymentsRequest: [String: Any?]) throws -> ListPaymentsRequest { +static func arrayOf(`liquidAddressDataList`: [LiquidAddressData]) -> [Any] { + return `liquidAddressDataList`.map { (v) -> [String: Any?] in return dictionaryOf(liquidAddressData: v) } +} +static func asListPaymentsRequest(listPaymentsRequest: [String: Any?]) throws -> ListPaymentsRequest { var filters: [PaymentType]? if let filtersTmp = listPaymentsRequest["filters"] as? [String] { filters = try asPaymentTypeList(arr: filtersTmp) } - + var fromTimestamp: Int64? if hasNonNilKey(data: listPaymentsRequest, key: "fromTimestamp") { guard let fromTimestampTmp = listPaymentsRequest["fromTimestamp"] as? Int64 else { @@ -849,48 +836,48 @@ enum BreezSDKLiquidMapper { if let detailsTmp = listPaymentsRequest["details"] as? [String: Any?] { details = try asListPaymentDetails(listPaymentDetails: detailsTmp) } + + + return ListPaymentsRequest(filters: filters, fromTimestamp: fromTimestamp, toTimestamp: toTimestamp, offset: offset, limit: limit, details: details) +} - return ListPaymentsRequest(filters: filters, fromTimestamp: fromTimestamp, toTimestamp: toTimestamp, offset: offset, limit: limit, details: details) - } - - static func dictionaryOf(listPaymentsRequest: ListPaymentsRequest) -> [String: Any?] { - return [ +static func dictionaryOf(listPaymentsRequest: ListPaymentsRequest) -> [String: Any?] { + return [ "filters": listPaymentsRequest.filters == nil ? nil : arrayOf(paymentTypeList: listPaymentsRequest.filters!), "fromTimestamp": listPaymentsRequest.fromTimestamp == nil ? nil : listPaymentsRequest.fromTimestamp, "toTimestamp": listPaymentsRequest.toTimestamp == nil ? nil : listPaymentsRequest.toTimestamp, "offset": listPaymentsRequest.offset == nil ? nil : listPaymentsRequest.offset, "limit": listPaymentsRequest.limit == nil ? nil : listPaymentsRequest.limit, - "details": listPaymentsRequest.details == nil ? nil : dictionaryOf(listPaymentDetails: listPaymentsRequest.details!), - ] - } + "details": listPaymentsRequest.details == nil ? nil : dictionaryOf(listPaymentDetails: listPaymentsRequest.details!), + ] +} - static func asListPaymentsRequestList(arr: [Any]) throws -> [ListPaymentsRequest] { - var list = [ListPaymentsRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var listPaymentsRequest = try asListPaymentsRequest(listPaymentsRequest: val) - list.append(listPaymentsRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentsRequest")) - } +static func asListPaymentsRequestList(arr: [Any]) throws -> [ListPaymentsRequest] { + var list = [ListPaymentsRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var listPaymentsRequest = try asListPaymentsRequest(listPaymentsRequest: val) + list.append(listPaymentsRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentsRequest")) } - return list } + return list +} - static func arrayOf(listPaymentsRequestList: [ListPaymentsRequest]) -> [Any] { - return listPaymentsRequestList.map { v -> [String: Any?] in return dictionaryOf(listPaymentsRequest: v) } +static func arrayOf(`listPaymentsRequestList`: [ListPaymentsRequest]) -> [Any] { + return `listPaymentsRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(listPaymentsRequest: v) } +} +static func asLnUrlAuthRequestData(lnUrlAuthRequestData: [String: Any?]) throws -> LnUrlAuthRequestData { + guard let k1 = lnUrlAuthRequestData["k1"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlAuthRequestData")) + } + guard let domain = lnUrlAuthRequestData["domain"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlAuthRequestData")) + } + guard let url = lnUrlAuthRequestData["url"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "LnUrlAuthRequestData")) } - - static func asLnUrlAuthRequestData(lnUrlAuthRequestData: [String: Any?]) throws -> LnUrlAuthRequestData { - guard let k1 = lnUrlAuthRequestData["k1"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlAuthRequestData")) - } - guard let domain = lnUrlAuthRequestData["domain"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlAuthRequestData")) - } - guard let url = lnUrlAuthRequestData["url"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "LnUrlAuthRequestData")) - } var action: String? if hasNonNilKey(data: lnUrlAuthRequestData, key: "action") { guard let actionTmp = lnUrlAuthRequestData["action"] as? String else { @@ -898,156 +885,153 @@ enum BreezSDKLiquidMapper { } action = actionTmp } + + return LnUrlAuthRequestData(k1: k1, domain: domain, url: url, action: action) +} - return LnUrlAuthRequestData(k1: k1, domain: domain, url: url, action: action) - } - - static func dictionaryOf(lnUrlAuthRequestData: LnUrlAuthRequestData) -> [String: Any?] { - return [ +static func dictionaryOf(lnUrlAuthRequestData: LnUrlAuthRequestData) -> [String: Any?] { + return [ "k1": lnUrlAuthRequestData.k1, "domain": lnUrlAuthRequestData.domain, "url": lnUrlAuthRequestData.url, - "action": lnUrlAuthRequestData.action == nil ? nil : lnUrlAuthRequestData.action, - ] - } + "action": lnUrlAuthRequestData.action == nil ? nil : lnUrlAuthRequestData.action, + ] +} - static func asLnUrlAuthRequestDataList(arr: [Any]) throws -> [LnUrlAuthRequestData] { - var list = [LnUrlAuthRequestData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlAuthRequestData = try asLnUrlAuthRequestData(lnUrlAuthRequestData: val) - list.append(lnUrlAuthRequestData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlAuthRequestData")) - } +static func asLnUrlAuthRequestDataList(arr: [Any]) throws -> [LnUrlAuthRequestData] { + var list = [LnUrlAuthRequestData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlAuthRequestData = try asLnUrlAuthRequestData(lnUrlAuthRequestData: val) + list.append(lnUrlAuthRequestData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlAuthRequestData")) } - return list } + return list +} - static func arrayOf(lnUrlAuthRequestDataList: [LnUrlAuthRequestData]) -> [Any] { - return lnUrlAuthRequestDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlAuthRequestData: v) } - } - - static func asLnUrlErrorData(lnUrlErrorData: [String: Any?]) throws -> LnUrlErrorData { - guard let reason = lnUrlErrorData["reason"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlErrorData")) - } - - return LnUrlErrorData(reason: reason) +static func arrayOf(`lnUrlAuthRequestDataList`: [LnUrlAuthRequestData]) -> [Any] { + return `lnUrlAuthRequestDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlAuthRequestData: v) } +} +static func asLnUrlErrorData(lnUrlErrorData: [String: Any?]) throws -> LnUrlErrorData { + guard let reason = lnUrlErrorData["reason"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlErrorData")) } + + return LnUrlErrorData(reason: reason) +} - static func dictionaryOf(lnUrlErrorData: LnUrlErrorData) -> [String: Any?] { - return [ - "reason": lnUrlErrorData.reason, - ] - } +static func dictionaryOf(lnUrlErrorData: LnUrlErrorData) -> [String: Any?] { + return [ + "reason": lnUrlErrorData.reason, + ] +} - static func asLnUrlErrorDataList(arr: [Any]) throws -> [LnUrlErrorData] { - var list = [LnUrlErrorData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlErrorData = try asLnUrlErrorData(lnUrlErrorData: val) - list.append(lnUrlErrorData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlErrorData")) - } +static func asLnUrlErrorDataList(arr: [Any]) throws -> [LnUrlErrorData] { + var list = [LnUrlErrorData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlErrorData = try asLnUrlErrorData(lnUrlErrorData: val) + list.append(lnUrlErrorData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlErrorData")) } - return list } + return list +} - static func arrayOf(lnUrlErrorDataList: [LnUrlErrorData]) -> [Any] { - return lnUrlErrorDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlErrorData: v) } +static func arrayOf(`lnUrlErrorDataList`: [LnUrlErrorData]) -> [Any] { + return `lnUrlErrorDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlErrorData: v) } +} +static func asLnUrlPayErrorData(lnUrlPayErrorData: [String: Any?]) throws -> LnUrlPayErrorData { + guard let paymentHash = lnUrlPayErrorData["paymentHash"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnUrlPayErrorData")) } - - static func asLnUrlPayErrorData(lnUrlPayErrorData: [String: Any?]) throws -> LnUrlPayErrorData { - guard let paymentHash = lnUrlPayErrorData["paymentHash"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnUrlPayErrorData")) - } - guard let reason = lnUrlPayErrorData["reason"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlPayErrorData")) - } - - return LnUrlPayErrorData(paymentHash: paymentHash, reason: reason) + guard let reason = lnUrlPayErrorData["reason"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlPayErrorData")) } + + return LnUrlPayErrorData(paymentHash: paymentHash, reason: reason) +} - static func dictionaryOf(lnUrlPayErrorData: LnUrlPayErrorData) -> [String: Any?] { - return [ +static func dictionaryOf(lnUrlPayErrorData: LnUrlPayErrorData) -> [String: Any?] { + return [ "paymentHash": lnUrlPayErrorData.paymentHash, - "reason": lnUrlPayErrorData.reason, - ] - } + "reason": lnUrlPayErrorData.reason, + ] +} - static func asLnUrlPayErrorDataList(arr: [Any]) throws -> [LnUrlPayErrorData] { - var list = [LnUrlPayErrorData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayErrorData = try asLnUrlPayErrorData(lnUrlPayErrorData: val) - list.append(lnUrlPayErrorData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayErrorData")) - } +static func asLnUrlPayErrorDataList(arr: [Any]) throws -> [LnUrlPayErrorData] { + var list = [LnUrlPayErrorData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayErrorData = try asLnUrlPayErrorData(lnUrlPayErrorData: val) + list.append(lnUrlPayErrorData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayErrorData")) } - return list } + return list +} - static func arrayOf(lnUrlPayErrorDataList: [LnUrlPayErrorData]) -> [Any] { - return lnUrlPayErrorDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayErrorData: v) } - } +static func arrayOf(`lnUrlPayErrorDataList`: [LnUrlPayErrorData]) -> [Any] { + return `lnUrlPayErrorDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayErrorData: v) } +} +static func asLnUrlPayRequest(lnUrlPayRequest: [String: Any?]) throws -> LnUrlPayRequest { + guard let prepareResponseTmp = lnUrlPayRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "LnUrlPayRequest")) + } + let prepareResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: prepareResponseTmp) + + + return LnUrlPayRequest(prepareResponse: prepareResponse) +} - static func asLnUrlPayRequest(lnUrlPayRequest: [String: Any?]) throws -> LnUrlPayRequest { - guard let prepareResponseTmp = lnUrlPayRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "LnUrlPayRequest")) - } - let prepareResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: prepareResponseTmp) +static func dictionaryOf(lnUrlPayRequest: LnUrlPayRequest) -> [String: Any?] { + return [ + "prepareResponse": dictionaryOf(prepareLnUrlPayResponse: lnUrlPayRequest.prepareResponse), + ] +} - return LnUrlPayRequest(prepareResponse: prepareResponse) +static func asLnUrlPayRequestList(arr: [Any]) throws -> [LnUrlPayRequest] { + var list = [LnUrlPayRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayRequest = try asLnUrlPayRequest(lnUrlPayRequest: val) + list.append(lnUrlPayRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequest")) + } } + return list +} - static func dictionaryOf(lnUrlPayRequest: LnUrlPayRequest) -> [String: Any?] { - return [ - "prepareResponse": dictionaryOf(prepareLnUrlPayResponse: lnUrlPayRequest.prepareResponse), - ] +static func arrayOf(`lnUrlPayRequestList`: [LnUrlPayRequest]) -> [Any] { + return `lnUrlPayRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayRequest: v) } +} +static func asLnUrlPayRequestData(lnUrlPayRequestData: [String: Any?]) throws -> LnUrlPayRequestData { + guard let callback = lnUrlPayRequestData["callback"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlPayRequestData")) } - - static func asLnUrlPayRequestList(arr: [Any]) throws -> [LnUrlPayRequest] { - var list = [LnUrlPayRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayRequest = try asLnUrlPayRequest(lnUrlPayRequest: val) - list.append(lnUrlPayRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequest")) - } - } - return list + guard let minSendable = lnUrlPayRequestData["minSendable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSendable", typeName: "LnUrlPayRequestData")) } - - static func arrayOf(lnUrlPayRequestList: [LnUrlPayRequest]) -> [Any] { - return lnUrlPayRequestList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayRequest: v) } + guard let maxSendable = lnUrlPayRequestData["maxSendable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSendable", typeName: "LnUrlPayRequestData")) + } + guard let metadataStr = lnUrlPayRequestData["metadataStr"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "metadataStr", typeName: "LnUrlPayRequestData")) + } + guard let commentAllowed = lnUrlPayRequestData["commentAllowed"] as? UInt16 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "commentAllowed", typeName: "LnUrlPayRequestData")) + } + guard let domain = lnUrlPayRequestData["domain"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlPayRequestData")) + } + guard let allowsNostr = lnUrlPayRequestData["allowsNostr"] as? Bool else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "allowsNostr", typeName: "LnUrlPayRequestData")) } - - static func asLnUrlPayRequestData(lnUrlPayRequestData: [String: Any?]) throws -> LnUrlPayRequestData { - guard let callback = lnUrlPayRequestData["callback"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlPayRequestData")) - } - guard let minSendable = lnUrlPayRequestData["minSendable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSendable", typeName: "LnUrlPayRequestData")) - } - guard let maxSendable = lnUrlPayRequestData["maxSendable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSendable", typeName: "LnUrlPayRequestData")) - } - guard let metadataStr = lnUrlPayRequestData["metadataStr"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "metadataStr", typeName: "LnUrlPayRequestData")) - } - guard let commentAllowed = lnUrlPayRequestData["commentAllowed"] as? UInt16 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "commentAllowed", typeName: "LnUrlPayRequestData")) - } - guard let domain = lnUrlPayRequestData["domain"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlPayRequestData")) - } - guard let allowsNostr = lnUrlPayRequestData["allowsNostr"] as? Bool else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "allowsNostr", typeName: "LnUrlPayRequestData")) - } var nostrPubkey: String? if hasNonNilKey(data: lnUrlPayRequestData, key: "nostrPubkey") { guard let nostrPubkeyTmp = lnUrlPayRequestData["nostrPubkey"] as? String else { @@ -1062,12 +1046,12 @@ enum BreezSDKLiquidMapper { } lnAddress = lnAddressTmp } + + return LnUrlPayRequestData(callback: callback, minSendable: minSendable, maxSendable: maxSendable, metadataStr: metadataStr, commentAllowed: commentAllowed, domain: domain, allowsNostr: allowsNostr, nostrPubkey: nostrPubkey, lnAddress: lnAddress) +} - return LnUrlPayRequestData(callback: callback, minSendable: minSendable, maxSendable: maxSendable, metadataStr: metadataStr, commentAllowed: commentAllowed, domain: domain, allowsNostr: allowsNostr, nostrPubkey: nostrPubkey, lnAddress: lnAddress) - } - - static func dictionaryOf(lnUrlPayRequestData: LnUrlPayRequestData) -> [String: Any?] { - return [ +static func dictionaryOf(lnUrlPayRequestData: LnUrlPayRequestData) -> [String: Any?] { + return [ "callback": lnUrlPayRequestData.callback, "minSendable": lnUrlPayRequestData.minSendable, "maxSendable": lnUrlPayRequestData.maxSendable, @@ -1076,74 +1060,73 @@ enum BreezSDKLiquidMapper { "domain": lnUrlPayRequestData.domain, "allowsNostr": lnUrlPayRequestData.allowsNostr, "nostrPubkey": lnUrlPayRequestData.nostrPubkey == nil ? nil : lnUrlPayRequestData.nostrPubkey, - "lnAddress": lnUrlPayRequestData.lnAddress == nil ? nil : lnUrlPayRequestData.lnAddress, - ] - } + "lnAddress": lnUrlPayRequestData.lnAddress == nil ? nil : lnUrlPayRequestData.lnAddress, + ] +} - static func asLnUrlPayRequestDataList(arr: [Any]) throws -> [LnUrlPayRequestData] { - var list = [LnUrlPayRequestData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayRequestData = try asLnUrlPayRequestData(lnUrlPayRequestData: val) - list.append(lnUrlPayRequestData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequestData")) - } +static func asLnUrlPayRequestDataList(arr: [Any]) throws -> [LnUrlPayRequestData] { + var list = [LnUrlPayRequestData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayRequestData = try asLnUrlPayRequestData(lnUrlPayRequestData: val) + list.append(lnUrlPayRequestData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequestData")) } - return list - } - - static func arrayOf(lnUrlPayRequestDataList: [LnUrlPayRequestData]) -> [Any] { - return lnUrlPayRequestDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayRequestData: v) } } + return list +} - static func asLnUrlPaySuccessData(lnUrlPaySuccessData: [String: Any?]) throws -> LnUrlPaySuccessData { +static func arrayOf(`lnUrlPayRequestDataList`: [LnUrlPayRequestData]) -> [Any] { + return `lnUrlPayRequestDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayRequestData: v) } +} +static func asLnUrlPaySuccessData(lnUrlPaySuccessData: [String: Any?]) throws -> LnUrlPaySuccessData { var successAction: SuccessActionProcessed? if let successActionTmp = lnUrlPaySuccessData["successAction"] as? [String: Any?] { successAction = try asSuccessActionProcessed(successActionProcessed: successActionTmp) } - - guard let paymentTmp = lnUrlPaySuccessData["payment"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "LnUrlPaySuccessData")) - } - let payment = try asPayment(payment: paymentTmp) - - return LnUrlPaySuccessData(successAction: successAction, payment: payment) + + guard let paymentTmp = lnUrlPaySuccessData["payment"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "LnUrlPaySuccessData")) } + let payment = try asPayment(payment: paymentTmp) + + + return LnUrlPaySuccessData(successAction: successAction, payment: payment) +} - static func dictionaryOf(lnUrlPaySuccessData: LnUrlPaySuccessData) -> [String: Any?] { - return [ +static func dictionaryOf(lnUrlPaySuccessData: LnUrlPaySuccessData) -> [String: Any?] { + return [ "successAction": lnUrlPaySuccessData.successAction == nil ? nil : dictionaryOf(successActionProcessed: lnUrlPaySuccessData.successAction!), - "payment": dictionaryOf(payment: lnUrlPaySuccessData.payment), - ] - } + "payment": dictionaryOf(payment: lnUrlPaySuccessData.payment), + ] +} - static func asLnUrlPaySuccessDataList(arr: [Any]) throws -> [LnUrlPaySuccessData] { - var list = [LnUrlPaySuccessData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPaySuccessData = try asLnUrlPaySuccessData(lnUrlPaySuccessData: val) - list.append(lnUrlPaySuccessData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPaySuccessData")) - } +static func asLnUrlPaySuccessDataList(arr: [Any]) throws -> [LnUrlPaySuccessData] { + var list = [LnUrlPaySuccessData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPaySuccessData = try asLnUrlPaySuccessData(lnUrlPaySuccessData: val) + list.append(lnUrlPaySuccessData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPaySuccessData")) } - return list } + return list +} - static func arrayOf(lnUrlPaySuccessDataList: [LnUrlPaySuccessData]) -> [Any] { - return lnUrlPaySuccessDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPaySuccessData: v) } +static func arrayOf(`lnUrlPaySuccessDataList`: [LnUrlPaySuccessData]) -> [Any] { + return `lnUrlPaySuccessDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPaySuccessData: v) } +} +static func asLnUrlWithdrawRequest(lnUrlWithdrawRequest: [String: Any?]) throws -> LnUrlWithdrawRequest { + guard let dataTmp = lnUrlWithdrawRequest["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawRequest")) + } + let data = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: dataTmp) + + guard let amountMsat = lnUrlWithdrawRequest["amountMsat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "LnUrlWithdrawRequest")) } - - static func asLnUrlWithdrawRequest(lnUrlWithdrawRequest: [String: Any?]) throws -> LnUrlWithdrawRequest { - guard let dataTmp = lnUrlWithdrawRequest["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawRequest")) - } - let data = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: dataTmp) - - guard let amountMsat = lnUrlWithdrawRequest["amountMsat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "LnUrlWithdrawRequest")) - } var description: String? if hasNonNilKey(data: lnUrlWithdrawRequest, key: "description") { guard let descriptionTmp = lnUrlWithdrawRequest["description"] as? String else { @@ -1151,118 +1134,116 @@ enum BreezSDKLiquidMapper { } description = descriptionTmp } + + return LnUrlWithdrawRequest(data: data, amountMsat: amountMsat, description: description) +} - return LnUrlWithdrawRequest(data: data, amountMsat: amountMsat, description: description) - } - - static func dictionaryOf(lnUrlWithdrawRequest: LnUrlWithdrawRequest) -> [String: Any?] { - return [ +static func dictionaryOf(lnUrlWithdrawRequest: LnUrlWithdrawRequest) -> [String: Any?] { + return [ "data": dictionaryOf(lnUrlWithdrawRequestData: lnUrlWithdrawRequest.data), "amountMsat": lnUrlWithdrawRequest.amountMsat, - "description": lnUrlWithdrawRequest.description == nil ? nil : lnUrlWithdrawRequest.description, - ] - } + "description": lnUrlWithdrawRequest.description == nil ? nil : lnUrlWithdrawRequest.description, + ] +} - static func asLnUrlWithdrawRequestList(arr: [Any]) throws -> [LnUrlWithdrawRequest] { - var list = [LnUrlWithdrawRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawRequest = try asLnUrlWithdrawRequest(lnUrlWithdrawRequest: val) - list.append(lnUrlWithdrawRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequest")) - } +static func asLnUrlWithdrawRequestList(arr: [Any]) throws -> [LnUrlWithdrawRequest] { + var list = [LnUrlWithdrawRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawRequest = try asLnUrlWithdrawRequest(lnUrlWithdrawRequest: val) + list.append(lnUrlWithdrawRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequest")) } - return list } + return list +} - static func arrayOf(lnUrlWithdrawRequestList: [LnUrlWithdrawRequest]) -> [Any] { - return lnUrlWithdrawRequestList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequest: v) } +static func arrayOf(`lnUrlWithdrawRequestList`: [LnUrlWithdrawRequest]) -> [Any] { + return `lnUrlWithdrawRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequest: v) } +} +static func asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: [String: Any?]) throws -> LnUrlWithdrawRequestData { + guard let callback = lnUrlWithdrawRequestData["callback"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlWithdrawRequestData")) } - - static func asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: [String: Any?]) throws -> LnUrlWithdrawRequestData { - guard let callback = lnUrlWithdrawRequestData["callback"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlWithdrawRequestData")) - } - guard let k1 = lnUrlWithdrawRequestData["k1"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlWithdrawRequestData")) - } - guard let defaultDescription = lnUrlWithdrawRequestData["defaultDescription"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "defaultDescription", typeName: "LnUrlWithdrawRequestData")) - } - guard let minWithdrawable = lnUrlWithdrawRequestData["minWithdrawable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minWithdrawable", typeName: "LnUrlWithdrawRequestData")) - } - guard let maxWithdrawable = lnUrlWithdrawRequestData["maxWithdrawable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxWithdrawable", typeName: "LnUrlWithdrawRequestData")) - } - - return LnUrlWithdrawRequestData(callback: callback, k1: k1, defaultDescription: defaultDescription, minWithdrawable: minWithdrawable, maxWithdrawable: maxWithdrawable) + guard let k1 = lnUrlWithdrawRequestData["k1"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlWithdrawRequestData")) + } + guard let defaultDescription = lnUrlWithdrawRequestData["defaultDescription"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "defaultDescription", typeName: "LnUrlWithdrawRequestData")) + } + guard let minWithdrawable = lnUrlWithdrawRequestData["minWithdrawable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minWithdrawable", typeName: "LnUrlWithdrawRequestData")) } + guard let maxWithdrawable = lnUrlWithdrawRequestData["maxWithdrawable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxWithdrawable", typeName: "LnUrlWithdrawRequestData")) + } + + return LnUrlWithdrawRequestData(callback: callback, k1: k1, defaultDescription: defaultDescription, minWithdrawable: minWithdrawable, maxWithdrawable: maxWithdrawable) +} - static func dictionaryOf(lnUrlWithdrawRequestData: LnUrlWithdrawRequestData) -> [String: Any?] { - return [ +static func dictionaryOf(lnUrlWithdrawRequestData: LnUrlWithdrawRequestData) -> [String: Any?] { + return [ "callback": lnUrlWithdrawRequestData.callback, "k1": lnUrlWithdrawRequestData.k1, "defaultDescription": lnUrlWithdrawRequestData.defaultDescription, "minWithdrawable": lnUrlWithdrawRequestData.minWithdrawable, - "maxWithdrawable": lnUrlWithdrawRequestData.maxWithdrawable, - ] - } + "maxWithdrawable": lnUrlWithdrawRequestData.maxWithdrawable, + ] +} - static func asLnUrlWithdrawRequestDataList(arr: [Any]) throws -> [LnUrlWithdrawRequestData] { - var list = [LnUrlWithdrawRequestData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawRequestData = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: val) - list.append(lnUrlWithdrawRequestData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequestData")) - } +static func asLnUrlWithdrawRequestDataList(arr: [Any]) throws -> [LnUrlWithdrawRequestData] { + var list = [LnUrlWithdrawRequestData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawRequestData = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: val) + list.append(lnUrlWithdrawRequestData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequestData")) } - return list - } - - static func arrayOf(lnUrlWithdrawRequestDataList: [LnUrlWithdrawRequestData]) -> [Any] { - return lnUrlWithdrawRequestDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequestData: v) } } + return list +} - static func asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: [String: Any?]) throws -> LnUrlWithdrawSuccessData { - guard let invoiceTmp = lnUrlWithdrawSuccessData["invoice"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "LnUrlWithdrawSuccessData")) - } - let invoice = try asLnInvoice(lnInvoice: invoiceTmp) - - return LnUrlWithdrawSuccessData(invoice: invoice) - } +static func arrayOf(`lnUrlWithdrawRequestDataList`: [LnUrlWithdrawRequestData]) -> [Any] { + return `lnUrlWithdrawRequestDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequestData: v) } +} +static func asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: [String: Any?]) throws -> LnUrlWithdrawSuccessData { + guard let invoiceTmp = lnUrlWithdrawSuccessData["invoice"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "LnUrlWithdrawSuccessData")) + } + let invoice = try asLnInvoice(lnInvoice: invoiceTmp) + + + return LnUrlWithdrawSuccessData(invoice: invoice) +} - static func dictionaryOf(lnUrlWithdrawSuccessData: LnUrlWithdrawSuccessData) -> [String: Any?] { - return [ - "invoice": dictionaryOf(lnInvoice: lnUrlWithdrawSuccessData.invoice), - ] - } +static func dictionaryOf(lnUrlWithdrawSuccessData: LnUrlWithdrawSuccessData) -> [String: Any?] { + return [ + "invoice": dictionaryOf(lnInvoice: lnUrlWithdrawSuccessData.invoice), + ] +} - static func asLnUrlWithdrawSuccessDataList(arr: [Any]) throws -> [LnUrlWithdrawSuccessData] { - var list = [LnUrlWithdrawSuccessData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawSuccessData = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: val) - list.append(lnUrlWithdrawSuccessData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawSuccessData")) - } +static func asLnUrlWithdrawSuccessDataList(arr: [Any]) throws -> [LnUrlWithdrawSuccessData] { + var list = [LnUrlWithdrawSuccessData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawSuccessData = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: val) + list.append(lnUrlWithdrawSuccessData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawSuccessData")) } - return list } + return list +} - static func arrayOf(lnUrlWithdrawSuccessDataList: [LnUrlWithdrawSuccessData]) -> [Any] { - return lnUrlWithdrawSuccessDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawSuccessData: v) } +static func arrayOf(`lnUrlWithdrawSuccessDataList`: [LnUrlWithdrawSuccessData]) -> [Any] { + return `lnUrlWithdrawSuccessDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawSuccessData: v) } +} +static func asLocaleOverrides(localeOverrides: [String: Any?]) throws -> LocaleOverrides { + guard let locale = localeOverrides["locale"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocaleOverrides")) } - - static func asLocaleOverrides(localeOverrides: [String: Any?]) throws -> LocaleOverrides { - guard let locale = localeOverrides["locale"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocaleOverrides")) - } var spacing: UInt32? if hasNonNilKey(data: localeOverrides, key: "spacing") { guard let spacingTmp = localeOverrides["spacing"] as? UInt32 else { @@ -1270,239 +1251,236 @@ enum BreezSDKLiquidMapper { } spacing = spacingTmp } - guard let symbolTmp = localeOverrides["symbol"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "symbol", typeName: "LocaleOverrides")) - } - let symbol = try asSymbol(symbol: symbolTmp) - - return LocaleOverrides(locale: locale, spacing: spacing, symbol: symbol) + guard let symbolTmp = localeOverrides["symbol"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "symbol", typeName: "LocaleOverrides")) } + let symbol = try asSymbol(symbol: symbolTmp) + + + return LocaleOverrides(locale: locale, spacing: spacing, symbol: symbol) +} - static func dictionaryOf(localeOverrides: LocaleOverrides) -> [String: Any?] { - return [ +static func dictionaryOf(localeOverrides: LocaleOverrides) -> [String: Any?] { + return [ "locale": localeOverrides.locale, "spacing": localeOverrides.spacing == nil ? nil : localeOverrides.spacing, - "symbol": dictionaryOf(symbol: localeOverrides.symbol), - ] - } + "symbol": dictionaryOf(symbol: localeOverrides.symbol), + ] +} - static func asLocaleOverridesList(arr: [Any]) throws -> [LocaleOverrides] { - var list = [LocaleOverrides]() - for value in arr { - if let val = value as? [String: Any?] { - var localeOverrides = try asLocaleOverrides(localeOverrides: val) - list.append(localeOverrides) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LocaleOverrides")) - } +static func asLocaleOverridesList(arr: [Any]) throws -> [LocaleOverrides] { + var list = [LocaleOverrides]() + for value in arr { + if let val = value as? [String: Any?] { + var localeOverrides = try asLocaleOverrides(localeOverrides: val) + list.append(localeOverrides) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LocaleOverrides")) } - return list } + return list +} - static func arrayOf(localeOverridesList: [LocaleOverrides]) -> [Any] { - return localeOverridesList.map { v -> [String: Any?] in return dictionaryOf(localeOverrides: v) } +static func arrayOf(`localeOverridesList`: [LocaleOverrides]) -> [Any] { + return `localeOverridesList`.map { (v) -> [String: Any?] in return dictionaryOf(localeOverrides: v) } +} +static func asLocalizedName(localizedName: [String: Any?]) throws -> LocalizedName { + guard let locale = localizedName["locale"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocalizedName")) } - - static func asLocalizedName(localizedName: [String: Any?]) throws -> LocalizedName { - guard let locale = localizedName["locale"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocalizedName")) - } - guard let name = localizedName["name"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "LocalizedName")) - } - - return LocalizedName(locale: locale, name: name) + guard let name = localizedName["name"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "LocalizedName")) } + + return LocalizedName(locale: locale, name: name) +} - static func dictionaryOf(localizedName: LocalizedName) -> [String: Any?] { - return [ +static func dictionaryOf(localizedName: LocalizedName) -> [String: Any?] { + return [ "locale": localizedName.locale, - "name": localizedName.name, - ] - } + "name": localizedName.name, + ] +} - static func asLocalizedNameList(arr: [Any]) throws -> [LocalizedName] { - var list = [LocalizedName]() - for value in arr { - if let val = value as? [String: Any?] { - var localizedName = try asLocalizedName(localizedName: val) - list.append(localizedName) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LocalizedName")) - } +static func asLocalizedNameList(arr: [Any]) throws -> [LocalizedName] { + var list = [LocalizedName]() + for value in arr { + if let val = value as? [String: Any?] { + var localizedName = try asLocalizedName(localizedName: val) + list.append(localizedName) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LocalizedName")) } - return list } + return list +} - static func arrayOf(localizedNameList: [LocalizedName]) -> [Any] { - return localizedNameList.map { v -> [String: Any?] in return dictionaryOf(localizedName: v) } +static func arrayOf(`localizedNameList`: [LocalizedName]) -> [Any] { + return `localizedNameList`.map { (v) -> [String: Any?] in return dictionaryOf(localizedName: v) } +} +static func asLogEntry(logEntry: [String: Any?]) throws -> LogEntry { + guard let line = logEntry["line"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "line", typeName: "LogEntry")) } - - static func asLogEntry(logEntry: [String: Any?]) throws -> LogEntry { - guard let line = logEntry["line"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "line", typeName: "LogEntry")) - } - guard let level = logEntry["level"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "level", typeName: "LogEntry")) - } - - return LogEntry(line: line, level: level) + guard let level = logEntry["level"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "level", typeName: "LogEntry")) } + + return LogEntry(line: line, level: level) +} - static func dictionaryOf(logEntry: LogEntry) -> [String: Any?] { - return [ +static func dictionaryOf(logEntry: LogEntry) -> [String: Any?] { + return [ "line": logEntry.line, - "level": logEntry.level, - ] - } + "level": logEntry.level, + ] +} - static func asLogEntryList(arr: [Any]) throws -> [LogEntry] { - var list = [LogEntry]() - for value in arr { - if let val = value as? [String: Any?] { - var logEntry = try asLogEntry(logEntry: val) - list.append(logEntry) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LogEntry")) - } +static func asLogEntryList(arr: [Any]) throws -> [LogEntry] { + var list = [LogEntry]() + for value in arr { + if let val = value as? [String: Any?] { + var logEntry = try asLogEntry(logEntry: val) + list.append(logEntry) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LogEntry")) } - return list - } - - static func arrayOf(logEntryList: [LogEntry]) -> [Any] { - return logEntryList.map { v -> [String: Any?] in return dictionaryOf(logEntry: v) } } + return list +} - static func asMessageSuccessActionData(messageSuccessActionData: [String: Any?]) throws -> MessageSuccessActionData { - guard let message = messageSuccessActionData["message"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "MessageSuccessActionData")) - } - - return MessageSuccessActionData(message: message) +static func arrayOf(`logEntryList`: [LogEntry]) -> [Any] { + return `logEntryList`.map { (v) -> [String: Any?] in return dictionaryOf(logEntry: v) } +} +static func asMessageSuccessActionData(messageSuccessActionData: [String: Any?]) throws -> MessageSuccessActionData { + guard let message = messageSuccessActionData["message"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "MessageSuccessActionData")) } + + return MessageSuccessActionData(message: message) +} - static func dictionaryOf(messageSuccessActionData: MessageSuccessActionData) -> [String: Any?] { - return [ - "message": messageSuccessActionData.message, - ] - } +static func dictionaryOf(messageSuccessActionData: MessageSuccessActionData) -> [String: Any?] { + return [ + "message": messageSuccessActionData.message, + ] +} - static func asMessageSuccessActionDataList(arr: [Any]) throws -> [MessageSuccessActionData] { - var list = [MessageSuccessActionData]() - for value in arr { - if let val = value as? [String: Any?] { - var messageSuccessActionData = try asMessageSuccessActionData(messageSuccessActionData: val) - list.append(messageSuccessActionData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "MessageSuccessActionData")) - } +static func asMessageSuccessActionDataList(arr: [Any]) throws -> [MessageSuccessActionData] { + var list = [MessageSuccessActionData]() + for value in arr { + if let val = value as? [String: Any?] { + var messageSuccessActionData = try asMessageSuccessActionData(messageSuccessActionData: val) + list.append(messageSuccessActionData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "MessageSuccessActionData")) } - return list - } - - static func arrayOf(messageSuccessActionDataList: [MessageSuccessActionData]) -> [Any] { - return messageSuccessActionDataList.map { v -> [String: Any?] in return dictionaryOf(messageSuccessActionData: v) } } + return list +} - static func asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: [String: Any?]) throws -> OnchainPaymentLimitsResponse { - guard let sendTmp = onchainPaymentLimitsResponse["send"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "OnchainPaymentLimitsResponse")) - } - let send = try asLimits(limits: sendTmp) - - guard let receiveTmp = onchainPaymentLimitsResponse["receive"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "OnchainPaymentLimitsResponse")) - } - let receive = try asLimits(limits: receiveTmp) - - return OnchainPaymentLimitsResponse(send: send, receive: receive) - } +static func arrayOf(`messageSuccessActionDataList`: [MessageSuccessActionData]) -> [Any] { + return `messageSuccessActionDataList`.map { (v) -> [String: Any?] in return dictionaryOf(messageSuccessActionData: v) } +} +static func asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: [String: Any?]) throws -> OnchainPaymentLimitsResponse { + guard let sendTmp = onchainPaymentLimitsResponse["send"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "OnchainPaymentLimitsResponse")) + } + let send = try asLimits(limits: sendTmp) + + guard let receiveTmp = onchainPaymentLimitsResponse["receive"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "OnchainPaymentLimitsResponse")) + } + let receive = try asLimits(limits: receiveTmp) + + + return OnchainPaymentLimitsResponse(send: send, receive: receive) +} - static func dictionaryOf(onchainPaymentLimitsResponse: OnchainPaymentLimitsResponse) -> [String: Any?] { - return [ +static func dictionaryOf(onchainPaymentLimitsResponse: OnchainPaymentLimitsResponse) -> [String: Any?] { + return [ "send": dictionaryOf(limits: onchainPaymentLimitsResponse.send), - "receive": dictionaryOf(limits: onchainPaymentLimitsResponse.receive), - ] - } + "receive": dictionaryOf(limits: onchainPaymentLimitsResponse.receive), + ] +} - static func asOnchainPaymentLimitsResponseList(arr: [Any]) throws -> [OnchainPaymentLimitsResponse] { - var list = [OnchainPaymentLimitsResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var onchainPaymentLimitsResponse = try asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: val) - list.append(onchainPaymentLimitsResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "OnchainPaymentLimitsResponse")) - } +static func asOnchainPaymentLimitsResponseList(arr: [Any]) throws -> [OnchainPaymentLimitsResponse] { + var list = [OnchainPaymentLimitsResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var onchainPaymentLimitsResponse = try asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: val) + list.append(onchainPaymentLimitsResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "OnchainPaymentLimitsResponse")) } - return list } + return list +} - static func arrayOf(onchainPaymentLimitsResponseList: [OnchainPaymentLimitsResponse]) -> [Any] { - return onchainPaymentLimitsResponseList.map { v -> [String: Any?] in return dictionaryOf(onchainPaymentLimitsResponse: v) } +static func arrayOf(`onchainPaymentLimitsResponseList`: [OnchainPaymentLimitsResponse]) -> [Any] { + return `onchainPaymentLimitsResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(onchainPaymentLimitsResponse: v) } +} +static func asPayOnchainRequest(payOnchainRequest: [String: Any?]) throws -> PayOnchainRequest { + guard let address = payOnchainRequest["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "PayOnchainRequest")) } - - static func asPayOnchainRequest(payOnchainRequest: [String: Any?]) throws -> PayOnchainRequest { - guard let address = payOnchainRequest["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "PayOnchainRequest")) - } - guard let prepareResponseTmp = payOnchainRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "PayOnchainRequest")) - } - let prepareResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: prepareResponseTmp) - - return PayOnchainRequest(address: address, prepareResponse: prepareResponse) + guard let prepareResponseTmp = payOnchainRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "PayOnchainRequest")) } + let prepareResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: prepareResponseTmp) + + + return PayOnchainRequest(address: address, prepareResponse: prepareResponse) +} - static func dictionaryOf(payOnchainRequest: PayOnchainRequest) -> [String: Any?] { - return [ +static func dictionaryOf(payOnchainRequest: PayOnchainRequest) -> [String: Any?] { + return [ "address": payOnchainRequest.address, - "prepareResponse": dictionaryOf(preparePayOnchainResponse: payOnchainRequest.prepareResponse), - ] - } + "prepareResponse": dictionaryOf(preparePayOnchainResponse: payOnchainRequest.prepareResponse), + ] +} - static func asPayOnchainRequestList(arr: [Any]) throws -> [PayOnchainRequest] { - var list = [PayOnchainRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var payOnchainRequest = try asPayOnchainRequest(payOnchainRequest: val) - list.append(payOnchainRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainRequest")) - } +static func asPayOnchainRequestList(arr: [Any]) throws -> [PayOnchainRequest] { + var list = [PayOnchainRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var payOnchainRequest = try asPayOnchainRequest(payOnchainRequest: val) + list.append(payOnchainRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainRequest")) } - return list } + return list +} - static func arrayOf(payOnchainRequestList: [PayOnchainRequest]) -> [Any] { - return payOnchainRequestList.map { v -> [String: Any?] in return dictionaryOf(payOnchainRequest: v) } +static func arrayOf(`payOnchainRequestList`: [PayOnchainRequest]) -> [Any] { + return `payOnchainRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(payOnchainRequest: v) } +} +static func asPayment(payment: [String: Any?]) throws -> Payment { + guard let timestamp = payment["timestamp"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "Payment")) } - - static func asPayment(payment: [String: Any?]) throws -> Payment { - guard let timestamp = payment["timestamp"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "Payment")) - } - guard let amountSat = payment["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "Payment")) - } - guard let feesSat = payment["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "Payment")) - } - guard let paymentTypeTmp = payment["paymentType"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentType", typeName: "Payment")) - } - let paymentType = try asPaymentType(paymentType: paymentTypeTmp) - - guard let statusTmp = payment["status"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "status", typeName: "Payment")) - } - let status = try asPaymentState(paymentState: statusTmp) - - guard let detailsTmp = payment["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "Payment")) - } - let details = try asPaymentDetails(paymentDetails: detailsTmp) - + guard let amountSat = payment["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "Payment")) + } + guard let feesSat = payment["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "Payment")) + } + guard let paymentTypeTmp = payment["paymentType"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentType", typeName: "Payment")) + } + let paymentType = try asPaymentType(paymentType: paymentTypeTmp) + + guard let statusTmp = payment["status"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "status", typeName: "Payment")) + } + let status = try asPaymentState(paymentState: statusTmp) + + guard let detailsTmp = payment["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "Payment")) + } + let details = try asPaymentDetails(paymentDetails: detailsTmp) + var destination: String? if hasNonNilKey(data: payment, key: "destination") { guard let destinationTmp = payment["destination"] as? String else { @@ -1517,127 +1495,124 @@ enum BreezSDKLiquidMapper { } txId = txIdTmp } + + return Payment(timestamp: timestamp, amountSat: amountSat, feesSat: feesSat, paymentType: paymentType, status: status, details: details, destination: destination, txId: txId) +} - return Payment(timestamp: timestamp, amountSat: amountSat, feesSat: feesSat, paymentType: paymentType, status: status, details: details, destination: destination, txId: txId) - } - - static func dictionaryOf(payment: Payment) -> [String: Any?] { - return [ +static func dictionaryOf(payment: Payment) -> [String: Any?] { + return [ "timestamp": payment.timestamp, "amountSat": payment.amountSat, "feesSat": payment.feesSat, - "paymentType": valueOf(paymentType: payment.paymentType), - "status": valueOf(paymentState: payment.status), + "paymentType": valueOf( paymentType: payment.paymentType), + "status": valueOf( paymentState: payment.status), "details": dictionaryOf(paymentDetails: payment.details), "destination": payment.destination == nil ? nil : payment.destination, - "txId": payment.txId == nil ? nil : payment.txId, - ] - } + "txId": payment.txId == nil ? nil : payment.txId, + ] +} - static func asPaymentList(arr: [Any]) throws -> [Payment] { - var list = [Payment]() - for value in arr { - if let val = value as? [String: Any?] { - var payment = try asPayment(payment: val) - list.append(payment) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Payment")) - } +static func asPaymentList(arr: [Any]) throws -> [Payment] { + var list = [Payment]() + for value in arr { + if let val = value as? [String: Any?] { + var payment = try asPayment(payment: val) + list.append(payment) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Payment")) } - return list } + return list +} - static func arrayOf(paymentList: [Payment]) -> [Any] { - return paymentList.map { v -> [String: Any?] in return dictionaryOf(payment: v) } +static func arrayOf(`paymentList`: [Payment]) -> [Any] { + return `paymentList`.map { (v) -> [String: Any?] in return dictionaryOf(payment: v) } +} +static func asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: [String: Any?]) throws -> PrepareBuyBitcoinRequest { + guard let providerTmp = prepareBuyBitcoinRequest["provider"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinRequest")) } - - static func asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: [String: Any?]) throws -> PrepareBuyBitcoinRequest { - guard let providerTmp = prepareBuyBitcoinRequest["provider"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinRequest")) - } - let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) - - guard let amountSat = prepareBuyBitcoinRequest["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinRequest")) - } - - return PrepareBuyBitcoinRequest(provider: provider, amountSat: amountSat) + let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) + + guard let amountSat = prepareBuyBitcoinRequest["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinRequest")) } + + return PrepareBuyBitcoinRequest(provider: provider, amountSat: amountSat) +} - static func dictionaryOf(prepareBuyBitcoinRequest: PrepareBuyBitcoinRequest) -> [String: Any?] { - return [ - "provider": valueOf(buyBitcoinProvider: prepareBuyBitcoinRequest.provider), - "amountSat": prepareBuyBitcoinRequest.amountSat, - ] - } +static func dictionaryOf(prepareBuyBitcoinRequest: PrepareBuyBitcoinRequest) -> [String: Any?] { + return [ + "provider": valueOf( buyBitcoinProvider: prepareBuyBitcoinRequest.provider), + "amountSat": prepareBuyBitcoinRequest.amountSat, + ] +} - static func asPrepareBuyBitcoinRequestList(arr: [Any]) throws -> [PrepareBuyBitcoinRequest] { - var list = [PrepareBuyBitcoinRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareBuyBitcoinRequest = try asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: val) - list.append(prepareBuyBitcoinRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinRequest")) - } +static func asPrepareBuyBitcoinRequestList(arr: [Any]) throws -> [PrepareBuyBitcoinRequest] { + var list = [PrepareBuyBitcoinRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareBuyBitcoinRequest = try asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: val) + list.append(prepareBuyBitcoinRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinRequest")) } - return list } + return list +} - static func arrayOf(prepareBuyBitcoinRequestList: [PrepareBuyBitcoinRequest]) -> [Any] { - return prepareBuyBitcoinRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinRequest: v) } +static func arrayOf(`prepareBuyBitcoinRequestList`: [PrepareBuyBitcoinRequest]) -> [Any] { + return `prepareBuyBitcoinRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinRequest: v) } +} +static func asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: [String: Any?]) throws -> PrepareBuyBitcoinResponse { + guard let providerTmp = prepareBuyBitcoinResponse["provider"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinResponse")) } - - static func asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: [String: Any?]) throws -> PrepareBuyBitcoinResponse { - guard let providerTmp = prepareBuyBitcoinResponse["provider"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinResponse")) - } - let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) - - guard let amountSat = prepareBuyBitcoinResponse["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinResponse")) - } - guard let feesSat = prepareBuyBitcoinResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareBuyBitcoinResponse")) - } - - return PrepareBuyBitcoinResponse(provider: provider, amountSat: amountSat, feesSat: feesSat) + let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) + + guard let amountSat = prepareBuyBitcoinResponse["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinResponse")) + } + guard let feesSat = prepareBuyBitcoinResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareBuyBitcoinResponse")) } + + return PrepareBuyBitcoinResponse(provider: provider, amountSat: amountSat, feesSat: feesSat) +} - static func dictionaryOf(prepareBuyBitcoinResponse: PrepareBuyBitcoinResponse) -> [String: Any?] { - return [ - "provider": valueOf(buyBitcoinProvider: prepareBuyBitcoinResponse.provider), +static func dictionaryOf(prepareBuyBitcoinResponse: PrepareBuyBitcoinResponse) -> [String: Any?] { + return [ + "provider": valueOf( buyBitcoinProvider: prepareBuyBitcoinResponse.provider), "amountSat": prepareBuyBitcoinResponse.amountSat, - "feesSat": prepareBuyBitcoinResponse.feesSat, - ] - } + "feesSat": prepareBuyBitcoinResponse.feesSat, + ] +} - static func asPrepareBuyBitcoinResponseList(arr: [Any]) throws -> [PrepareBuyBitcoinResponse] { - var list = [PrepareBuyBitcoinResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareBuyBitcoinResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: val) - list.append(prepareBuyBitcoinResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinResponse")) - } +static func asPrepareBuyBitcoinResponseList(arr: [Any]) throws -> [PrepareBuyBitcoinResponse] { + var list = [PrepareBuyBitcoinResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareBuyBitcoinResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: val) + list.append(prepareBuyBitcoinResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinResponse")) } - return list } + return list +} - static func arrayOf(prepareBuyBitcoinResponseList: [PrepareBuyBitcoinResponse]) -> [Any] { - return prepareBuyBitcoinResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinResponse: v) } +static func arrayOf(`prepareBuyBitcoinResponseList`: [PrepareBuyBitcoinResponse]) -> [Any] { + return `prepareBuyBitcoinResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinResponse: v) } +} +static func asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: [String: Any?]) throws -> PrepareLnUrlPayRequest { + guard let dataTmp = prepareLnUrlPayRequest["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "PrepareLnUrlPayRequest")) + } + let data = try asLnUrlPayRequestData(lnUrlPayRequestData: dataTmp) + + guard let amountMsat = prepareLnUrlPayRequest["amountMsat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "PrepareLnUrlPayRequest")) } - - static func asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: [String: Any?]) throws -> PrepareLnUrlPayRequest { - guard let dataTmp = prepareLnUrlPayRequest["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "PrepareLnUrlPayRequest")) - } - let data = try asLnUrlPayRequestData(lnUrlPayRequestData: dataTmp) - - guard let amountMsat = prepareLnUrlPayRequest["amountMsat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "PrepareLnUrlPayRequest")) - } var comment: String? if hasNonNilKey(data: prepareLnUrlPayRequest, key: "comment") { guard let commentTmp = prepareLnUrlPayRequest["comment"] as? String else { @@ -1652,84 +1627,83 @@ enum BreezSDKLiquidMapper { } validateSuccessActionUrl = validateSuccessActionUrlTmp } + + return PrepareLnUrlPayRequest(data: data, amountMsat: amountMsat, comment: comment, validateSuccessActionUrl: validateSuccessActionUrl) +} - return PrepareLnUrlPayRequest(data: data, amountMsat: amountMsat, comment: comment, validateSuccessActionUrl: validateSuccessActionUrl) - } - - static func dictionaryOf(prepareLnUrlPayRequest: PrepareLnUrlPayRequest) -> [String: Any?] { - return [ +static func dictionaryOf(prepareLnUrlPayRequest: PrepareLnUrlPayRequest) -> [String: Any?] { + return [ "data": dictionaryOf(lnUrlPayRequestData: prepareLnUrlPayRequest.data), "amountMsat": prepareLnUrlPayRequest.amountMsat, "comment": prepareLnUrlPayRequest.comment == nil ? nil : prepareLnUrlPayRequest.comment, - "validateSuccessActionUrl": prepareLnUrlPayRequest.validateSuccessActionUrl == nil ? nil : prepareLnUrlPayRequest.validateSuccessActionUrl, - ] - } + "validateSuccessActionUrl": prepareLnUrlPayRequest.validateSuccessActionUrl == nil ? nil : prepareLnUrlPayRequest.validateSuccessActionUrl, + ] +} - static func asPrepareLnUrlPayRequestList(arr: [Any]) throws -> [PrepareLnUrlPayRequest] { - var list = [PrepareLnUrlPayRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareLnUrlPayRequest = try asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: val) - list.append(prepareLnUrlPayRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayRequest")) - } +static func asPrepareLnUrlPayRequestList(arr: [Any]) throws -> [PrepareLnUrlPayRequest] { + var list = [PrepareLnUrlPayRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareLnUrlPayRequest = try asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: val) + list.append(prepareLnUrlPayRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayRequest")) } - return list } + return list +} - static func arrayOf(prepareLnUrlPayRequestList: [PrepareLnUrlPayRequest]) -> [Any] { - return prepareLnUrlPayRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareLnUrlPayRequest: v) } +static func arrayOf(`prepareLnUrlPayRequestList`: [PrepareLnUrlPayRequest]) -> [Any] { + return `prepareLnUrlPayRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareLnUrlPayRequest: v) } +} +static func asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: [String: Any?]) throws -> PrepareLnUrlPayResponse { + guard let destinationTmp = prepareLnUrlPayResponse["destination"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareLnUrlPayResponse")) + } + let destination = try asSendDestination(sendDestination: destinationTmp) + + guard let feesSat = prepareLnUrlPayResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareLnUrlPayResponse")) } - - static func asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: [String: Any?]) throws -> PrepareLnUrlPayResponse { - guard let destinationTmp = prepareLnUrlPayResponse["destination"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareLnUrlPayResponse")) - } - let destination = try asSendDestination(sendDestination: destinationTmp) - - guard let feesSat = prepareLnUrlPayResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareLnUrlPayResponse")) - } var successAction: SuccessAction? if let successActionTmp = prepareLnUrlPayResponse["successAction"] as? [String: Any?] { successAction = try asSuccessAction(successAction: successActionTmp) } + + + return PrepareLnUrlPayResponse(destination: destination, feesSat: feesSat, successAction: successAction) +} - return PrepareLnUrlPayResponse(destination: destination, feesSat: feesSat, successAction: successAction) - } - - static func dictionaryOf(prepareLnUrlPayResponse: PrepareLnUrlPayResponse) -> [String: Any?] { - return [ +static func dictionaryOf(prepareLnUrlPayResponse: PrepareLnUrlPayResponse) -> [String: Any?] { + return [ "destination": dictionaryOf(sendDestination: prepareLnUrlPayResponse.destination), "feesSat": prepareLnUrlPayResponse.feesSat, - "successAction": prepareLnUrlPayResponse.successAction == nil ? nil : dictionaryOf(successAction: prepareLnUrlPayResponse.successAction!), - ] - } + "successAction": prepareLnUrlPayResponse.successAction == nil ? nil : dictionaryOf(successAction: prepareLnUrlPayResponse.successAction!), + ] +} - static func asPrepareLnUrlPayResponseList(arr: [Any]) throws -> [PrepareLnUrlPayResponse] { - var list = [PrepareLnUrlPayResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareLnUrlPayResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: val) - list.append(prepareLnUrlPayResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayResponse")) - } +static func asPrepareLnUrlPayResponseList(arr: [Any]) throws -> [PrepareLnUrlPayResponse] { + var list = [PrepareLnUrlPayResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareLnUrlPayResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: val) + list.append(prepareLnUrlPayResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayResponse")) } - return list } + return list +} - static func arrayOf(prepareLnUrlPayResponseList: [PrepareLnUrlPayResponse]) -> [Any] { - return prepareLnUrlPayResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareLnUrlPayResponse: v) } +static func arrayOf(`prepareLnUrlPayResponseList`: [PrepareLnUrlPayResponse]) -> [Any] { + return `prepareLnUrlPayResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareLnUrlPayResponse: v) } +} +static func asPreparePayOnchainRequest(preparePayOnchainRequest: [String: Any?]) throws -> PreparePayOnchainRequest { + guard let amountTmp = preparePayOnchainRequest["amount"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amount", typeName: "PreparePayOnchainRequest")) } - - static func asPreparePayOnchainRequest(preparePayOnchainRequest: [String: Any?]) throws -> PreparePayOnchainRequest { - guard let amountTmp = preparePayOnchainRequest["amount"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amount", typeName: "PreparePayOnchainRequest")) - } - let amount = try asPayOnchainAmount(payOnchainAmount: amountTmp) - + let amount = try asPayOnchainAmount(payOnchainAmount: amountTmp) + var feeRateSatPerVbyte: UInt32? if hasNonNilKey(data: preparePayOnchainRequest, key: "feeRateSatPerVbyte") { guard let feeRateSatPerVbyteTmp = preparePayOnchainRequest["feeRateSatPerVbyte"] as? UInt32 else { @@ -1737,79 +1711,77 @@ enum BreezSDKLiquidMapper { } feeRateSatPerVbyte = feeRateSatPerVbyteTmp } + + return PreparePayOnchainRequest(amount: amount, feeRateSatPerVbyte: feeRateSatPerVbyte) +} - return PreparePayOnchainRequest(amount: amount, feeRateSatPerVbyte: feeRateSatPerVbyte) - } - - static func dictionaryOf(preparePayOnchainRequest: PreparePayOnchainRequest) -> [String: Any?] { - return [ +static func dictionaryOf(preparePayOnchainRequest: PreparePayOnchainRequest) -> [String: Any?] { + return [ "amount": dictionaryOf(payOnchainAmount: preparePayOnchainRequest.amount), - "feeRateSatPerVbyte": preparePayOnchainRequest.feeRateSatPerVbyte == nil ? nil : preparePayOnchainRequest.feeRateSatPerVbyte, - ] - } + "feeRateSatPerVbyte": preparePayOnchainRequest.feeRateSatPerVbyte == nil ? nil : preparePayOnchainRequest.feeRateSatPerVbyte, + ] +} - static func asPreparePayOnchainRequestList(arr: [Any]) throws -> [PreparePayOnchainRequest] { - var list = [PreparePayOnchainRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var preparePayOnchainRequest = try asPreparePayOnchainRequest(preparePayOnchainRequest: val) - list.append(preparePayOnchainRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainRequest")) - } +static func asPreparePayOnchainRequestList(arr: [Any]) throws -> [PreparePayOnchainRequest] { + var list = [PreparePayOnchainRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var preparePayOnchainRequest = try asPreparePayOnchainRequest(preparePayOnchainRequest: val) + list.append(preparePayOnchainRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainRequest")) } - return list } + return list +} - static func arrayOf(preparePayOnchainRequestList: [PreparePayOnchainRequest]) -> [Any] { - return preparePayOnchainRequestList.map { v -> [String: Any?] in return dictionaryOf(preparePayOnchainRequest: v) } +static func arrayOf(`preparePayOnchainRequestList`: [PreparePayOnchainRequest]) -> [Any] { + return `preparePayOnchainRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(preparePayOnchainRequest: v) } +} +static func asPreparePayOnchainResponse(preparePayOnchainResponse: [String: Any?]) throws -> PreparePayOnchainResponse { + guard let receiverAmountSat = preparePayOnchainResponse["receiverAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receiverAmountSat", typeName: "PreparePayOnchainResponse")) } - - static func asPreparePayOnchainResponse(preparePayOnchainResponse: [String: Any?]) throws -> PreparePayOnchainResponse { - guard let receiverAmountSat = preparePayOnchainResponse["receiverAmountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receiverAmountSat", typeName: "PreparePayOnchainResponse")) - } - guard let claimFeesSat = preparePayOnchainResponse["claimFeesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "claimFeesSat", typeName: "PreparePayOnchainResponse")) - } - guard let totalFeesSat = preparePayOnchainResponse["totalFeesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "totalFeesSat", typeName: "PreparePayOnchainResponse")) - } - - return PreparePayOnchainResponse(receiverAmountSat: receiverAmountSat, claimFeesSat: claimFeesSat, totalFeesSat: totalFeesSat) + guard let claimFeesSat = preparePayOnchainResponse["claimFeesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "claimFeesSat", typeName: "PreparePayOnchainResponse")) } + guard let totalFeesSat = preparePayOnchainResponse["totalFeesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "totalFeesSat", typeName: "PreparePayOnchainResponse")) + } + + return PreparePayOnchainResponse(receiverAmountSat: receiverAmountSat, claimFeesSat: claimFeesSat, totalFeesSat: totalFeesSat) +} - static func dictionaryOf(preparePayOnchainResponse: PreparePayOnchainResponse) -> [String: Any?] { - return [ +static func dictionaryOf(preparePayOnchainResponse: PreparePayOnchainResponse) -> [String: Any?] { + return [ "receiverAmountSat": preparePayOnchainResponse.receiverAmountSat, "claimFeesSat": preparePayOnchainResponse.claimFeesSat, - "totalFeesSat": preparePayOnchainResponse.totalFeesSat, - ] - } + "totalFeesSat": preparePayOnchainResponse.totalFeesSat, + ] +} - static func asPreparePayOnchainResponseList(arr: [Any]) throws -> [PreparePayOnchainResponse] { - var list = [PreparePayOnchainResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var preparePayOnchainResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: val) - list.append(preparePayOnchainResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainResponse")) - } +static func asPreparePayOnchainResponseList(arr: [Any]) throws -> [PreparePayOnchainResponse] { + var list = [PreparePayOnchainResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var preparePayOnchainResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: val) + list.append(preparePayOnchainResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainResponse")) } - return list } + return list +} - static func arrayOf(preparePayOnchainResponseList: [PreparePayOnchainResponse]) -> [Any] { - return preparePayOnchainResponseList.map { v -> [String: Any?] in return dictionaryOf(preparePayOnchainResponse: v) } +static func arrayOf(`preparePayOnchainResponseList`: [PreparePayOnchainResponse]) -> [Any] { + return `preparePayOnchainResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(preparePayOnchainResponse: v) } +} +static func asPrepareReceiveRequest(prepareReceiveRequest: [String: Any?]) throws -> PrepareReceiveRequest { + guard let paymentMethodTmp = prepareReceiveRequest["paymentMethod"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveRequest")) } - - static func asPrepareReceiveRequest(prepareReceiveRequest: [String: Any?]) throws -> PrepareReceiveRequest { - guard let paymentMethodTmp = prepareReceiveRequest["paymentMethod"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveRequest")) - } - let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) - + let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) + var payerAmountSat: UInt64? if hasNonNilKey(data: prepareReceiveRequest, key: "payerAmountSat") { guard let payerAmountSatTmp = prepareReceiveRequest["payerAmountSat"] as? UInt64 else { @@ -1817,35 +1789,42 @@ enum BreezSDKLiquidMapper { } payerAmountSat = payerAmountSatTmp } + + return PrepareReceiveRequest(paymentMethod: paymentMethod, payerAmountSat: payerAmountSat) +} - return PrepareReceiveRequest(paymentMethod: paymentMethod, payerAmountSat: payerAmountSat) - } - - static func dictionaryOf(prepareReceiveRequest: PrepareReceiveRequest) -> [String: Any?] { - return [ - "paymentMethod": valueOf(paymentMethod: prepareReceiveRequest.paymentMethod), - "payerAmountSat": prepareReceiveRequest.payerAmountSat == nil ? nil : prepareReceiveRequest.payerAmountSat, - ] - } +static func dictionaryOf(prepareReceiveRequest: PrepareReceiveRequest) -> [String: Any?] { + return [ + "paymentMethod": valueOf( paymentMethod: prepareReceiveRequest.paymentMethod), + "payerAmountSat": prepareReceiveRequest.payerAmountSat == nil ? nil : prepareReceiveRequest.payerAmountSat, + ] +} - static func asPrepareReceiveRequestList(arr: [Any]) throws -> [PrepareReceiveRequest] { - var list = [PrepareReceiveRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareReceiveRequest = try asPrepareReceiveRequest(prepareReceiveRequest: val) - list.append(prepareReceiveRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveRequest")) - } +static func asPrepareReceiveRequestList(arr: [Any]) throws -> [PrepareReceiveRequest] { + var list = [PrepareReceiveRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareReceiveRequest = try asPrepareReceiveRequest(prepareReceiveRequest: val) + list.append(prepareReceiveRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveRequest")) } - return list } + return list +} - static func arrayOf(prepareReceiveRequestList: [PrepareReceiveRequest]) -> [Any] { - return prepareReceiveRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareReceiveRequest: v) } +static func arrayOf(`prepareReceiveRequestList`: [PrepareReceiveRequest]) -> [Any] { + return `prepareReceiveRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareReceiveRequest: v) } +} +static func asPrepareReceiveResponse(prepareReceiveResponse: [String: Any?]) throws -> PrepareReceiveResponse { + guard let paymentMethodTmp = prepareReceiveResponse["paymentMethod"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveResponse")) + } + let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) + + guard let feesSat = prepareReceiveResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareReceiveResponse")) } - - static func asPrepareReceiveResponse(prepareReceiveResponse: [String: Any?]) throws -> PrepareReceiveResponse { var payerAmountSat: UInt64? if hasNonNilKey(data: prepareReceiveResponse, key: "payerAmountSat") { guard let payerAmountSatTmp = prepareReceiveResponse["payerAmountSat"] as? UInt64 else { @@ -1853,89 +1832,95 @@ enum BreezSDKLiquidMapper { } payerAmountSat = payerAmountSatTmp } - guard let paymentMethodTmp = prepareReceiveResponse["paymentMethod"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveResponse")) + var minPayerAmountSat: UInt64? + if hasNonNilKey(data: prepareReceiveResponse, key: "minPayerAmountSat") { + guard let minPayerAmountSatTmp = prepareReceiveResponse["minPayerAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "minPayerAmountSat")) + } + minPayerAmountSat = minPayerAmountSatTmp } - let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) - - guard let feesSat = prepareReceiveResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareReceiveResponse")) + var maxPayerAmountSat: UInt64? + if hasNonNilKey(data: prepareReceiveResponse, key: "maxPayerAmountSat") { + guard let maxPayerAmountSatTmp = prepareReceiveResponse["maxPayerAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "maxPayerAmountSat")) + } + maxPayerAmountSat = maxPayerAmountSatTmp } + + return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, minPayerAmountSat: minPayerAmountSat, maxPayerAmountSat: maxPayerAmountSat) +} - return PrepareReceiveResponse(payerAmountSat: payerAmountSat, paymentMethod: paymentMethod, feesSat: feesSat) - } - - static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [String: Any?] { - return [ - "payerAmountSat": prepareReceiveResponse.payerAmountSat == nil ? nil : prepareReceiveResponse.payerAmountSat, - "paymentMethod": valueOf(paymentMethod: prepareReceiveResponse.paymentMethod), +static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [String: Any?] { + return [ + "paymentMethod": valueOf( paymentMethod: prepareReceiveResponse.paymentMethod), "feesSat": prepareReceiveResponse.feesSat, - ] - } + "payerAmountSat": prepareReceiveResponse.payerAmountSat == nil ? nil : prepareReceiveResponse.payerAmountSat, + "minPayerAmountSat": prepareReceiveResponse.minPayerAmountSat == nil ? nil : prepareReceiveResponse.minPayerAmountSat, + "maxPayerAmountSat": prepareReceiveResponse.maxPayerAmountSat == nil ? nil : prepareReceiveResponse.maxPayerAmountSat, + ] +} - static func asPrepareReceiveResponseList(arr: [Any]) throws -> [PrepareReceiveResponse] { - var list = [PrepareReceiveResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareReceiveResponse = try asPrepareReceiveResponse(prepareReceiveResponse: val) - list.append(prepareReceiveResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveResponse")) - } +static func asPrepareReceiveResponseList(arr: [Any]) throws -> [PrepareReceiveResponse] { + var list = [PrepareReceiveResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareReceiveResponse = try asPrepareReceiveResponse(prepareReceiveResponse: val) + list.append(prepareReceiveResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveResponse")) } - return list } + return list +} - static func arrayOf(prepareReceiveResponseList: [PrepareReceiveResponse]) -> [Any] { - return prepareReceiveResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareReceiveResponse: v) } +static func arrayOf(`prepareReceiveResponseList`: [PrepareReceiveResponse]) -> [Any] { + return `prepareReceiveResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareReceiveResponse: v) } +} +static func asPrepareRefundRequest(prepareRefundRequest: [String: Any?]) throws -> PrepareRefundRequest { + guard let swapAddress = prepareRefundRequest["swapAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "PrepareRefundRequest")) } - - static func asPrepareRefundRequest(prepareRefundRequest: [String: Any?]) throws -> PrepareRefundRequest { - guard let swapAddress = prepareRefundRequest["swapAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "PrepareRefundRequest")) - } - guard let refundAddress = prepareRefundRequest["refundAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "PrepareRefundRequest")) - } - guard let feeRateSatPerVbyte = prepareRefundRequest["feeRateSatPerVbyte"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "PrepareRefundRequest")) - } - - return PrepareRefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) + guard let refundAddress = prepareRefundRequest["refundAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "PrepareRefundRequest")) + } + guard let feeRateSatPerVbyte = prepareRefundRequest["feeRateSatPerVbyte"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "PrepareRefundRequest")) } + + return PrepareRefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) +} - static func dictionaryOf(prepareRefundRequest: PrepareRefundRequest) -> [String: Any?] { - return [ +static func dictionaryOf(prepareRefundRequest: PrepareRefundRequest) -> [String: Any?] { + return [ "swapAddress": prepareRefundRequest.swapAddress, "refundAddress": prepareRefundRequest.refundAddress, - "feeRateSatPerVbyte": prepareRefundRequest.feeRateSatPerVbyte, - ] - } + "feeRateSatPerVbyte": prepareRefundRequest.feeRateSatPerVbyte, + ] +} - static func asPrepareRefundRequestList(arr: [Any]) throws -> [PrepareRefundRequest] { - var list = [PrepareRefundRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareRefundRequest = try asPrepareRefundRequest(prepareRefundRequest: val) - list.append(prepareRefundRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundRequest")) - } +static func asPrepareRefundRequestList(arr: [Any]) throws -> [PrepareRefundRequest] { + var list = [PrepareRefundRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareRefundRequest = try asPrepareRefundRequest(prepareRefundRequest: val) + list.append(prepareRefundRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundRequest")) } - return list } + return list +} - static func arrayOf(prepareRefundRequestList: [PrepareRefundRequest]) -> [Any] { - return prepareRefundRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareRefundRequest: v) } +static func arrayOf(`prepareRefundRequestList`: [PrepareRefundRequest]) -> [Any] { + return `prepareRefundRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareRefundRequest: v) } +} +static func asPrepareRefundResponse(prepareRefundResponse: [String: Any?]) throws -> PrepareRefundResponse { + guard let txVsize = prepareRefundResponse["txVsize"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txVsize", typeName: "PrepareRefundResponse")) + } + guard let txFeeSat = prepareRefundResponse["txFeeSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txFeeSat", typeName: "PrepareRefundResponse")) } - - static func asPrepareRefundResponse(prepareRefundResponse: [String: Any?]) throws -> PrepareRefundResponse { - guard let txVsize = prepareRefundResponse["txVsize"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txVsize", typeName: "PrepareRefundResponse")) - } - guard let txFeeSat = prepareRefundResponse["txFeeSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txFeeSat", typeName: "PrepareRefundResponse")) - } var refundTxId: String? if hasNonNilKey(data: prepareRefundResponse, key: "refundTxId") { guard let refundTxIdTmp = prepareRefundResponse["refundTxId"] as? String else { @@ -1943,39 +1928,38 @@ enum BreezSDKLiquidMapper { } refundTxId = refundTxIdTmp } + + return PrepareRefundResponse(txVsize: txVsize, txFeeSat: txFeeSat, refundTxId: refundTxId) +} - return PrepareRefundResponse(txVsize: txVsize, txFeeSat: txFeeSat, refundTxId: refundTxId) - } - - static func dictionaryOf(prepareRefundResponse: PrepareRefundResponse) -> [String: Any?] { - return [ +static func dictionaryOf(prepareRefundResponse: PrepareRefundResponse) -> [String: Any?] { + return [ "txVsize": prepareRefundResponse.txVsize, "txFeeSat": prepareRefundResponse.txFeeSat, - "refundTxId": prepareRefundResponse.refundTxId == nil ? nil : prepareRefundResponse.refundTxId, - ] - } + "refundTxId": prepareRefundResponse.refundTxId == nil ? nil : prepareRefundResponse.refundTxId, + ] +} - static func asPrepareRefundResponseList(arr: [Any]) throws -> [PrepareRefundResponse] { - var list = [PrepareRefundResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareRefundResponse = try asPrepareRefundResponse(prepareRefundResponse: val) - list.append(prepareRefundResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundResponse")) - } +static func asPrepareRefundResponseList(arr: [Any]) throws -> [PrepareRefundResponse] { + var list = [PrepareRefundResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareRefundResponse = try asPrepareRefundResponse(prepareRefundResponse: val) + list.append(prepareRefundResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundResponse")) } - return list } + return list +} - static func arrayOf(prepareRefundResponseList: [PrepareRefundResponse]) -> [Any] { - return prepareRefundResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareRefundResponse: v) } +static func arrayOf(`prepareRefundResponseList`: [PrepareRefundResponse]) -> [Any] { + return `prepareRefundResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareRefundResponse: v) } +} +static func asPrepareSendRequest(prepareSendRequest: [String: Any?]) throws -> PrepareSendRequest { + guard let destination = prepareSendRequest["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendRequest")) } - - static func asPrepareSendRequest(prepareSendRequest: [String: Any?]) throws -> PrepareSendRequest { - guard let destination = prepareSendRequest["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendRequest")) - } var amountSat: UInt64? if hasNonNilKey(data: prepareSendRequest, key: "amountSat") { guard let amountSatTmp = prepareSendRequest["amountSat"] as? UInt64 else { @@ -1983,112 +1967,109 @@ enum BreezSDKLiquidMapper { } amountSat = amountSatTmp } + + return PrepareSendRequest(destination: destination, amountSat: amountSat) +} - return PrepareSendRequest(destination: destination, amountSat: amountSat) - } - - static func dictionaryOf(prepareSendRequest: PrepareSendRequest) -> [String: Any?] { - return [ +static func dictionaryOf(prepareSendRequest: PrepareSendRequest) -> [String: Any?] { + return [ "destination": prepareSendRequest.destination, - "amountSat": prepareSendRequest.amountSat == nil ? nil : prepareSendRequest.amountSat, - ] - } + "amountSat": prepareSendRequest.amountSat == nil ? nil : prepareSendRequest.amountSat, + ] +} - static func asPrepareSendRequestList(arr: [Any]) throws -> [PrepareSendRequest] { - var list = [PrepareSendRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareSendRequest = try asPrepareSendRequest(prepareSendRequest: val) - list.append(prepareSendRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendRequest")) - } +static func asPrepareSendRequestList(arr: [Any]) throws -> [PrepareSendRequest] { + var list = [PrepareSendRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareSendRequest = try asPrepareSendRequest(prepareSendRequest: val) + list.append(prepareSendRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendRequest")) } - return list } + return list +} - static func arrayOf(prepareSendRequestList: [PrepareSendRequest]) -> [Any] { - return prepareSendRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareSendRequest: v) } +static func arrayOf(`prepareSendRequestList`: [PrepareSendRequest]) -> [Any] { + return `prepareSendRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareSendRequest: v) } +} +static func asPrepareSendResponse(prepareSendResponse: [String: Any?]) throws -> PrepareSendResponse { + guard let destinationTmp = prepareSendResponse["destination"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendResponse")) } - - static func asPrepareSendResponse(prepareSendResponse: [String: Any?]) throws -> PrepareSendResponse { - guard let destinationTmp = prepareSendResponse["destination"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendResponse")) - } - let destination = try asSendDestination(sendDestination: destinationTmp) - - guard let feesSat = prepareSendResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareSendResponse")) - } - - return PrepareSendResponse(destination: destination, feesSat: feesSat) + let destination = try asSendDestination(sendDestination: destinationTmp) + + guard let feesSat = prepareSendResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareSendResponse")) } + + return PrepareSendResponse(destination: destination, feesSat: feesSat) +} - static func dictionaryOf(prepareSendResponse: PrepareSendResponse) -> [String: Any?] { - return [ +static func dictionaryOf(prepareSendResponse: PrepareSendResponse) -> [String: Any?] { + return [ "destination": dictionaryOf(sendDestination: prepareSendResponse.destination), - "feesSat": prepareSendResponse.feesSat, - ] - } + "feesSat": prepareSendResponse.feesSat, + ] +} - static func asPrepareSendResponseList(arr: [Any]) throws -> [PrepareSendResponse] { - var list = [PrepareSendResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareSendResponse = try asPrepareSendResponse(prepareSendResponse: val) - list.append(prepareSendResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendResponse")) - } +static func asPrepareSendResponseList(arr: [Any]) throws -> [PrepareSendResponse] { + var list = [PrepareSendResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareSendResponse = try asPrepareSendResponse(prepareSendResponse: val) + list.append(prepareSendResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendResponse")) } - return list } + return list +} - static func arrayOf(prepareSendResponseList: [PrepareSendResponse]) -> [Any] { - return prepareSendResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareSendResponse: v) } +static func arrayOf(`prepareSendResponseList`: [PrepareSendResponse]) -> [Any] { + return `prepareSendResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareSendResponse: v) } +} +static func asRate(rate: [String: Any?]) throws -> Rate { + guard let coin = rate["coin"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "coin", typeName: "Rate")) } - - static func asRate(rate: [String: Any?]) throws -> Rate { - guard let coin = rate["coin"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "coin", typeName: "Rate")) - } - guard let value = rate["value"] as? Double else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "value", typeName: "Rate")) - } - - return Rate(coin: coin, value: value) + guard let value = rate["value"] as? Double else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "value", typeName: "Rate")) } + + return Rate(coin: coin, value: value) +} - static func dictionaryOf(rate: Rate) -> [String: Any?] { - return [ +static func dictionaryOf(rate: Rate) -> [String: Any?] { + return [ "coin": rate.coin, - "value": rate.value, - ] - } + "value": rate.value, + ] +} - static func asRateList(arr: [Any]) throws -> [Rate] { - var list = [Rate]() - for value in arr { - if let val = value as? [String: Any?] { - var rate = try asRate(rate: val) - list.append(rate) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Rate")) - } +static func asRateList(arr: [Any]) throws -> [Rate] { + var list = [Rate]() + for value in arr { + if let val = value as? [String: Any?] { + var rate = try asRate(rate: val) + list.append(rate) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Rate")) } - return list } + return list +} - static func arrayOf(rateList: [Rate]) -> [Any] { - return rateList.map { v -> [String: Any?] in return dictionaryOf(rate: v) } +static func arrayOf(`rateList`: [Rate]) -> [Any] { + return `rateList`.map { (v) -> [String: Any?] in return dictionaryOf(rate: v) } +} +static func asReceivePaymentRequest(receivePaymentRequest: [String: Any?]) throws -> ReceivePaymentRequest { + guard let prepareResponseTmp = receivePaymentRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "ReceivePaymentRequest")) } - - static func asReceivePaymentRequest(receivePaymentRequest: [String: Any?]) throws -> ReceivePaymentRequest { - guard let prepareResponseTmp = receivePaymentRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "ReceivePaymentRequest")) - } - let prepareResponse = try asPrepareReceiveResponse(prepareReceiveResponse: prepareResponseTmp) - + let prepareResponse = try asPrepareReceiveResponse(prepareReceiveResponse: prepareResponseTmp) + var description: String? if hasNonNilKey(data: receivePaymentRequest, key: "description") { guard let descriptionTmp = receivePaymentRequest["description"] as? String else { @@ -2103,223 +2084,217 @@ enum BreezSDKLiquidMapper { } useDescriptionHash = useDescriptionHashTmp } + + return ReceivePaymentRequest(prepareResponse: prepareResponse, description: description, useDescriptionHash: useDescriptionHash) +} - return ReceivePaymentRequest(prepareResponse: prepareResponse, description: description, useDescriptionHash: useDescriptionHash) - } - - static func dictionaryOf(receivePaymentRequest: ReceivePaymentRequest) -> [String: Any?] { - return [ +static func dictionaryOf(receivePaymentRequest: ReceivePaymentRequest) -> [String: Any?] { + return [ "prepareResponse": dictionaryOf(prepareReceiveResponse: receivePaymentRequest.prepareResponse), "description": receivePaymentRequest.description == nil ? nil : receivePaymentRequest.description, - "useDescriptionHash": receivePaymentRequest.useDescriptionHash == nil ? nil : receivePaymentRequest.useDescriptionHash, - ] - } + "useDescriptionHash": receivePaymentRequest.useDescriptionHash == nil ? nil : receivePaymentRequest.useDescriptionHash, + ] +} - static func asReceivePaymentRequestList(arr: [Any]) throws -> [ReceivePaymentRequest] { - var list = [ReceivePaymentRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var receivePaymentRequest = try asReceivePaymentRequest(receivePaymentRequest: val) - list.append(receivePaymentRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentRequest")) - } +static func asReceivePaymentRequestList(arr: [Any]) throws -> [ReceivePaymentRequest] { + var list = [ReceivePaymentRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var receivePaymentRequest = try asReceivePaymentRequest(receivePaymentRequest: val) + list.append(receivePaymentRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentRequest")) } - return list } + return list +} - static func arrayOf(receivePaymentRequestList: [ReceivePaymentRequest]) -> [Any] { - return receivePaymentRequestList.map { v -> [String: Any?] in return dictionaryOf(receivePaymentRequest: v) } +static func arrayOf(`receivePaymentRequestList`: [ReceivePaymentRequest]) -> [Any] { + return `receivePaymentRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(receivePaymentRequest: v) } +} +static func asReceivePaymentResponse(receivePaymentResponse: [String: Any?]) throws -> ReceivePaymentResponse { + guard let destination = receivePaymentResponse["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ReceivePaymentResponse")) } + + return ReceivePaymentResponse(destination: destination) +} - static func asReceivePaymentResponse(receivePaymentResponse: [String: Any?]) throws -> ReceivePaymentResponse { - guard let destination = receivePaymentResponse["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ReceivePaymentResponse")) - } +static func dictionaryOf(receivePaymentResponse: ReceivePaymentResponse) -> [String: Any?] { + return [ + "destination": receivePaymentResponse.destination, + ] +} - return ReceivePaymentResponse(destination: destination) +static func asReceivePaymentResponseList(arr: [Any]) throws -> [ReceivePaymentResponse] { + var list = [ReceivePaymentResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var receivePaymentResponse = try asReceivePaymentResponse(receivePaymentResponse: val) + list.append(receivePaymentResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentResponse")) + } } + return list +} - static func dictionaryOf(receivePaymentResponse: ReceivePaymentResponse) -> [String: Any?] { - return [ - "destination": receivePaymentResponse.destination, - ] +static func arrayOf(`receivePaymentResponseList`: [ReceivePaymentResponse]) -> [Any] { + return `receivePaymentResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(receivePaymentResponse: v) } +} +static func asRecommendedFees(recommendedFees: [String: Any?]) throws -> RecommendedFees { + guard let fastestFee = recommendedFees["fastestFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fastestFee", typeName: "RecommendedFees")) } - - static func asReceivePaymentResponseList(arr: [Any]) throws -> [ReceivePaymentResponse] { - var list = [ReceivePaymentResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var receivePaymentResponse = try asReceivePaymentResponse(receivePaymentResponse: val) - list.append(receivePaymentResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentResponse")) - } - } - return list + guard let halfHourFee = recommendedFees["halfHourFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "halfHourFee", typeName: "RecommendedFees")) } - - static func arrayOf(receivePaymentResponseList: [ReceivePaymentResponse]) -> [Any] { - return receivePaymentResponseList.map { v -> [String: Any?] in return dictionaryOf(receivePaymentResponse: v) } + guard let hourFee = recommendedFees["hourFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hourFee", typeName: "RecommendedFees")) } - - static func asRecommendedFees(recommendedFees: [String: Any?]) throws -> RecommendedFees { - guard let fastestFee = recommendedFees["fastestFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fastestFee", typeName: "RecommendedFees")) - } - guard let halfHourFee = recommendedFees["halfHourFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "halfHourFee", typeName: "RecommendedFees")) - } - guard let hourFee = recommendedFees["hourFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hourFee", typeName: "RecommendedFees")) - } - guard let economyFee = recommendedFees["economyFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "economyFee", typeName: "RecommendedFees")) - } - guard let minimumFee = recommendedFees["minimumFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minimumFee", typeName: "RecommendedFees")) - } - - return RecommendedFees(fastestFee: fastestFee, halfHourFee: halfHourFee, hourFee: hourFee, economyFee: economyFee, minimumFee: minimumFee) + guard let economyFee = recommendedFees["economyFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "economyFee", typeName: "RecommendedFees")) } + guard let minimumFee = recommendedFees["minimumFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minimumFee", typeName: "RecommendedFees")) + } + + return RecommendedFees(fastestFee: fastestFee, halfHourFee: halfHourFee, hourFee: hourFee, economyFee: economyFee, minimumFee: minimumFee) +} - static func dictionaryOf(recommendedFees: RecommendedFees) -> [String: Any?] { - return [ +static func dictionaryOf(recommendedFees: RecommendedFees) -> [String: Any?] { + return [ "fastestFee": recommendedFees.fastestFee, "halfHourFee": recommendedFees.halfHourFee, "hourFee": recommendedFees.hourFee, "economyFee": recommendedFees.economyFee, - "minimumFee": recommendedFees.minimumFee, - ] - } + "minimumFee": recommendedFees.minimumFee, + ] +} - static func asRecommendedFeesList(arr: [Any]) throws -> [RecommendedFees] { - var list = [RecommendedFees]() - for value in arr { - if let val = value as? [String: Any?] { - var recommendedFees = try asRecommendedFees(recommendedFees: val) - list.append(recommendedFees) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RecommendedFees")) - } +static func asRecommendedFeesList(arr: [Any]) throws -> [RecommendedFees] { + var list = [RecommendedFees]() + for value in arr { + if let val = value as? [String: Any?] { + var recommendedFees = try asRecommendedFees(recommendedFees: val) + list.append(recommendedFees) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RecommendedFees")) } - return list } + return list +} - static func arrayOf(recommendedFeesList: [RecommendedFees]) -> [Any] { - return recommendedFeesList.map { v -> [String: Any?] in return dictionaryOf(recommendedFees: v) } +static func arrayOf(`recommendedFeesList`: [RecommendedFees]) -> [Any] { + return `recommendedFeesList`.map { (v) -> [String: Any?] in return dictionaryOf(recommendedFees: v) } +} +static func asRefundRequest(refundRequest: [String: Any?]) throws -> RefundRequest { + guard let swapAddress = refundRequest["swapAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundRequest")) } - - static func asRefundRequest(refundRequest: [String: Any?]) throws -> RefundRequest { - guard let swapAddress = refundRequest["swapAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundRequest")) - } - guard let refundAddress = refundRequest["refundAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "RefundRequest")) - } - guard let feeRateSatPerVbyte = refundRequest["feeRateSatPerVbyte"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "RefundRequest")) - } - - return RefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) + guard let refundAddress = refundRequest["refundAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "RefundRequest")) + } + guard let feeRateSatPerVbyte = refundRequest["feeRateSatPerVbyte"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "RefundRequest")) } + + return RefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) +} - static func dictionaryOf(refundRequest: RefundRequest) -> [String: Any?] { - return [ +static func dictionaryOf(refundRequest: RefundRequest) -> [String: Any?] { + return [ "swapAddress": refundRequest.swapAddress, "refundAddress": refundRequest.refundAddress, - "feeRateSatPerVbyte": refundRequest.feeRateSatPerVbyte, - ] - } + "feeRateSatPerVbyte": refundRequest.feeRateSatPerVbyte, + ] +} - static func asRefundRequestList(arr: [Any]) throws -> [RefundRequest] { - var list = [RefundRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var refundRequest = try asRefundRequest(refundRequest: val) - list.append(refundRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundRequest")) - } +static func asRefundRequestList(arr: [Any]) throws -> [RefundRequest] { + var list = [RefundRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var refundRequest = try asRefundRequest(refundRequest: val) + list.append(refundRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundRequest")) } - return list - } - - static func arrayOf(refundRequestList: [RefundRequest]) -> [Any] { - return refundRequestList.map { v -> [String: Any?] in return dictionaryOf(refundRequest: v) } } + return list +} - static func asRefundResponse(refundResponse: [String: Any?]) throws -> RefundResponse { - guard let refundTxId = refundResponse["refundTxId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundTxId", typeName: "RefundResponse")) - } - - return RefundResponse(refundTxId: refundTxId) +static func arrayOf(`refundRequestList`: [RefundRequest]) -> [Any] { + return `refundRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(refundRequest: v) } +} +static func asRefundResponse(refundResponse: [String: Any?]) throws -> RefundResponse { + guard let refundTxId = refundResponse["refundTxId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundTxId", typeName: "RefundResponse")) } + + return RefundResponse(refundTxId: refundTxId) +} - static func dictionaryOf(refundResponse: RefundResponse) -> [String: Any?] { - return [ - "refundTxId": refundResponse.refundTxId, - ] - } +static func dictionaryOf(refundResponse: RefundResponse) -> [String: Any?] { + return [ + "refundTxId": refundResponse.refundTxId, + ] +} - static func asRefundResponseList(arr: [Any]) throws -> [RefundResponse] { - var list = [RefundResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var refundResponse = try asRefundResponse(refundResponse: val) - list.append(refundResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundResponse")) - } +static func asRefundResponseList(arr: [Any]) throws -> [RefundResponse] { + var list = [RefundResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var refundResponse = try asRefundResponse(refundResponse: val) + list.append(refundResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundResponse")) } - return list } + return list +} - static func arrayOf(refundResponseList: [RefundResponse]) -> [Any] { - return refundResponseList.map { v -> [String: Any?] in return dictionaryOf(refundResponse: v) } +static func arrayOf(`refundResponseList`: [RefundResponse]) -> [Any] { + return `refundResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(refundResponse: v) } +} +static func asRefundableSwap(refundableSwap: [String: Any?]) throws -> RefundableSwap { + guard let swapAddress = refundableSwap["swapAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundableSwap")) } - - static func asRefundableSwap(refundableSwap: [String: Any?]) throws -> RefundableSwap { - guard let swapAddress = refundableSwap["swapAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundableSwap")) - } - guard let timestamp = refundableSwap["timestamp"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "RefundableSwap")) - } - guard let amountSat = refundableSwap["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "RefundableSwap")) - } - - return RefundableSwap(swapAddress: swapAddress, timestamp: timestamp, amountSat: amountSat) + guard let timestamp = refundableSwap["timestamp"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "RefundableSwap")) + } + guard let amountSat = refundableSwap["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "RefundableSwap")) } + + return RefundableSwap(swapAddress: swapAddress, timestamp: timestamp, amountSat: amountSat) +} - static func dictionaryOf(refundableSwap: RefundableSwap) -> [String: Any?] { - return [ +static func dictionaryOf(refundableSwap: RefundableSwap) -> [String: Any?] { + return [ "swapAddress": refundableSwap.swapAddress, "timestamp": refundableSwap.timestamp, - "amountSat": refundableSwap.amountSat, - ] - } + "amountSat": refundableSwap.amountSat, + ] +} - static func asRefundableSwapList(arr: [Any]) throws -> [RefundableSwap] { - var list = [RefundableSwap]() - for value in arr { - if let val = value as? [String: Any?] { - var refundableSwap = try asRefundableSwap(refundableSwap: val) - list.append(refundableSwap) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundableSwap")) - } +static func asRefundableSwapList(arr: [Any]) throws -> [RefundableSwap] { + var list = [RefundableSwap]() + for value in arr { + if let val = value as? [String: Any?] { + var refundableSwap = try asRefundableSwap(refundableSwap: val) + list.append(refundableSwap) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundableSwap")) } - return list - } - - static func arrayOf(refundableSwapList: [RefundableSwap]) -> [Any] { - return refundableSwapList.map { v -> [String: Any?] in return dictionaryOf(refundableSwap: v) } } + return list +} - static func asRestoreRequest(restoreRequest: [String: Any?]) throws -> RestoreRequest { +static func arrayOf(`refundableSwapList`: [RefundableSwap]) -> [Any] { + return `refundableSwapList`.map { (v) -> [String: Any?] in return dictionaryOf(refundableSwap: v) } +} +static func asRestoreRequest(restoreRequest: [String: Any?]) throws -> RestoreRequest { var backupPath: String? if hasNonNilKey(data: restoreRequest, key: "backupPath") { guard let backupPathTmp = restoreRequest["backupPath"] as? String else { @@ -2327,81 +2302,80 @@ enum BreezSDKLiquidMapper { } backupPath = backupPathTmp } + + return RestoreRequest(backupPath: backupPath) +} - return RestoreRequest(backupPath: backupPath) - } - - static func dictionaryOf(restoreRequest: RestoreRequest) -> [String: Any?] { - return [ - "backupPath": restoreRequest.backupPath == nil ? nil : restoreRequest.backupPath, - ] - } +static func dictionaryOf(restoreRequest: RestoreRequest) -> [String: Any?] { + return [ + "backupPath": restoreRequest.backupPath == nil ? nil : restoreRequest.backupPath, + ] +} - static func asRestoreRequestList(arr: [Any]) throws -> [RestoreRequest] { - var list = [RestoreRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var restoreRequest = try asRestoreRequest(restoreRequest: val) - list.append(restoreRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RestoreRequest")) - } +static func asRestoreRequestList(arr: [Any]) throws -> [RestoreRequest] { + var list = [RestoreRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var restoreRequest = try asRestoreRequest(restoreRequest: val) + list.append(restoreRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RestoreRequest")) } - return list } + return list +} - static func arrayOf(restoreRequestList: [RestoreRequest]) -> [Any] { - return restoreRequestList.map { v -> [String: Any?] in return dictionaryOf(restoreRequest: v) } - } +static func arrayOf(`restoreRequestList`: [RestoreRequest]) -> [Any] { + return `restoreRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(restoreRequest: v) } +} +static func asRouteHint(routeHint: [String: Any?]) throws -> RouteHint { + guard let hopsTmp = routeHint["hops"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hops", typeName: "RouteHint")) + } + let hops = try asRouteHintHopList(arr: hopsTmp) + + + return RouteHint(hops: hops) +} - static func asRouteHint(routeHint: [String: Any?]) throws -> RouteHint { - guard let hopsTmp = routeHint["hops"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hops", typeName: "RouteHint")) - } - let hops = try asRouteHintHopList(arr: hopsTmp) +static func dictionaryOf(routeHint: RouteHint) -> [String: Any?] { + return [ + "hops": arrayOf(routeHintHopList: routeHint.hops), + ] +} - return RouteHint(hops: hops) +static func asRouteHintList(arr: [Any]) throws -> [RouteHint] { + var list = [RouteHint]() + for value in arr { + if let val = value as? [String: Any?] { + var routeHint = try asRouteHint(routeHint: val) + list.append(routeHint) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHint")) + } } + return list +} - static func dictionaryOf(routeHint: RouteHint) -> [String: Any?] { - return [ - "hops": arrayOf(routeHintHopList: routeHint.hops), - ] +static func arrayOf(`routeHintList`: [RouteHint]) -> [Any] { + return `routeHintList`.map { (v) -> [String: Any?] in return dictionaryOf(routeHint: v) } +} +static func asRouteHintHop(routeHintHop: [String: Any?]) throws -> RouteHintHop { + guard let srcNodeId = routeHintHop["srcNodeId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "srcNodeId", typeName: "RouteHintHop")) } - - static func asRouteHintList(arr: [Any]) throws -> [RouteHint] { - var list = [RouteHint]() - for value in arr { - if let val = value as? [String: Any?] { - var routeHint = try asRouteHint(routeHint: val) - list.append(routeHint) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHint")) - } - } - return list + guard let shortChannelId = routeHintHop["shortChannelId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "shortChannelId", typeName: "RouteHintHop")) } - - static func arrayOf(routeHintList: [RouteHint]) -> [Any] { - return routeHintList.map { v -> [String: Any?] in return dictionaryOf(routeHint: v) } + guard let feesBaseMsat = routeHintHop["feesBaseMsat"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesBaseMsat", typeName: "RouteHintHop")) + } + guard let feesProportionalMillionths = routeHintHop["feesProportionalMillionths"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesProportionalMillionths", typeName: "RouteHintHop")) + } + guard let cltvExpiryDelta = routeHintHop["cltvExpiryDelta"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "cltvExpiryDelta", typeName: "RouteHintHop")) } - - static func asRouteHintHop(routeHintHop: [String: Any?]) throws -> RouteHintHop { - guard let srcNodeId = routeHintHop["srcNodeId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "srcNodeId", typeName: "RouteHintHop")) - } - guard let shortChannelId = routeHintHop["shortChannelId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "shortChannelId", typeName: "RouteHintHop")) - } - guard let feesBaseMsat = routeHintHop["feesBaseMsat"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesBaseMsat", typeName: "RouteHintHop")) - } - guard let feesProportionalMillionths = routeHintHop["feesProportionalMillionths"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesProportionalMillionths", typeName: "RouteHintHop")) - } - guard let cltvExpiryDelta = routeHintHop["cltvExpiryDelta"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "cltvExpiryDelta", typeName: "RouteHintHop")) - } var htlcMinimumMsat: UInt64? if hasNonNilKey(data: routeHintHop, key: "htlcMinimumMsat") { guard let htlcMinimumMsatTmp = routeHintHop["htlcMinimumMsat"] as? UInt64 else { @@ -2416,166 +2390,163 @@ enum BreezSDKLiquidMapper { } htlcMaximumMsat = htlcMaximumMsatTmp } + + return RouteHintHop(srcNodeId: srcNodeId, shortChannelId: shortChannelId, feesBaseMsat: feesBaseMsat, feesProportionalMillionths: feesProportionalMillionths, cltvExpiryDelta: cltvExpiryDelta, htlcMinimumMsat: htlcMinimumMsat, htlcMaximumMsat: htlcMaximumMsat) +} - return RouteHintHop(srcNodeId: srcNodeId, shortChannelId: shortChannelId, feesBaseMsat: feesBaseMsat, feesProportionalMillionths: feesProportionalMillionths, cltvExpiryDelta: cltvExpiryDelta, htlcMinimumMsat: htlcMinimumMsat, htlcMaximumMsat: htlcMaximumMsat) - } - - static func dictionaryOf(routeHintHop: RouteHintHop) -> [String: Any?] { - return [ +static func dictionaryOf(routeHintHop: RouteHintHop) -> [String: Any?] { + return [ "srcNodeId": routeHintHop.srcNodeId, "shortChannelId": routeHintHop.shortChannelId, "feesBaseMsat": routeHintHop.feesBaseMsat, "feesProportionalMillionths": routeHintHop.feesProportionalMillionths, "cltvExpiryDelta": routeHintHop.cltvExpiryDelta, "htlcMinimumMsat": routeHintHop.htlcMinimumMsat == nil ? nil : routeHintHop.htlcMinimumMsat, - "htlcMaximumMsat": routeHintHop.htlcMaximumMsat == nil ? nil : routeHintHop.htlcMaximumMsat, - ] - } + "htlcMaximumMsat": routeHintHop.htlcMaximumMsat == nil ? nil : routeHintHop.htlcMaximumMsat, + ] +} - static func asRouteHintHopList(arr: [Any]) throws -> [RouteHintHop] { - var list = [RouteHintHop]() - for value in arr { - if let val = value as? [String: Any?] { - var routeHintHop = try asRouteHintHop(routeHintHop: val) - list.append(routeHintHop) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHintHop")) - } +static func asRouteHintHopList(arr: [Any]) throws -> [RouteHintHop] { + var list = [RouteHintHop]() + for value in arr { + if let val = value as? [String: Any?] { + var routeHintHop = try asRouteHintHop(routeHintHop: val) + list.append(routeHintHop) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHintHop")) } - return list - } - - static func arrayOf(routeHintHopList: [RouteHintHop]) -> [Any] { - return routeHintHopList.map { v -> [String: Any?] in return dictionaryOf(routeHintHop: v) } } + return list +} - static func asSendPaymentRequest(sendPaymentRequest: [String: Any?]) throws -> SendPaymentRequest { - guard let prepareResponseTmp = sendPaymentRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "SendPaymentRequest")) - } - let prepareResponse = try asPrepareSendResponse(prepareSendResponse: prepareResponseTmp) +static func arrayOf(`routeHintHopList`: [RouteHintHop]) -> [Any] { + return `routeHintHopList`.map { (v) -> [String: Any?] in return dictionaryOf(routeHintHop: v) } +} +static func asSendPaymentRequest(sendPaymentRequest: [String: Any?]) throws -> SendPaymentRequest { + guard let prepareResponseTmp = sendPaymentRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "SendPaymentRequest")) + } + let prepareResponse = try asPrepareSendResponse(prepareSendResponse: prepareResponseTmp) + + + return SendPaymentRequest(prepareResponse: prepareResponse) +} - return SendPaymentRequest(prepareResponse: prepareResponse) - } +static func dictionaryOf(sendPaymentRequest: SendPaymentRequest) -> [String: Any?] { + return [ + "prepareResponse": dictionaryOf(prepareSendResponse: sendPaymentRequest.prepareResponse), + ] +} - static func dictionaryOf(sendPaymentRequest: SendPaymentRequest) -> [String: Any?] { - return [ - "prepareResponse": dictionaryOf(prepareSendResponse: sendPaymentRequest.prepareResponse), - ] +static func asSendPaymentRequestList(arr: [Any]) throws -> [SendPaymentRequest] { + var list = [SendPaymentRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var sendPaymentRequest = try asSendPaymentRequest(sendPaymentRequest: val) + list.append(sendPaymentRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentRequest")) + } } + return list +} - static func asSendPaymentRequestList(arr: [Any]) throws -> [SendPaymentRequest] { - var list = [SendPaymentRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var sendPaymentRequest = try asSendPaymentRequest(sendPaymentRequest: val) - list.append(sendPaymentRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentRequest")) - } - } - return list - } - - static func arrayOf(sendPaymentRequestList: [SendPaymentRequest]) -> [Any] { - return sendPaymentRequestList.map { v -> [String: Any?] in return dictionaryOf(sendPaymentRequest: v) } - } - - static func asSendPaymentResponse(sendPaymentResponse: [String: Any?]) throws -> SendPaymentResponse { - guard let paymentTmp = sendPaymentResponse["payment"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "SendPaymentResponse")) - } - let payment = try asPayment(payment: paymentTmp) - - return SendPaymentResponse(payment: payment) - } +static func arrayOf(`sendPaymentRequestList`: [SendPaymentRequest]) -> [Any] { + return `sendPaymentRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(sendPaymentRequest: v) } +} +static func asSendPaymentResponse(sendPaymentResponse: [String: Any?]) throws -> SendPaymentResponse { + guard let paymentTmp = sendPaymentResponse["payment"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "SendPaymentResponse")) + } + let payment = try asPayment(payment: paymentTmp) + + + return SendPaymentResponse(payment: payment) +} - static func dictionaryOf(sendPaymentResponse: SendPaymentResponse) -> [String: Any?] { - return [ - "payment": dictionaryOf(payment: sendPaymentResponse.payment), - ] - } +static func dictionaryOf(sendPaymentResponse: SendPaymentResponse) -> [String: Any?] { + return [ + "payment": dictionaryOf(payment: sendPaymentResponse.payment), + ] +} - static func asSendPaymentResponseList(arr: [Any]) throws -> [SendPaymentResponse] { - var list = [SendPaymentResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var sendPaymentResponse = try asSendPaymentResponse(sendPaymentResponse: val) - list.append(sendPaymentResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentResponse")) - } +static func asSendPaymentResponseList(arr: [Any]) throws -> [SendPaymentResponse] { + var list = [SendPaymentResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var sendPaymentResponse = try asSendPaymentResponse(sendPaymentResponse: val) + list.append(sendPaymentResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentResponse")) } - return list } + return list +} - static func arrayOf(sendPaymentResponseList: [SendPaymentResponse]) -> [Any] { - return sendPaymentResponseList.map { v -> [String: Any?] in return dictionaryOf(sendPaymentResponse: v) } - } - - static func asSignMessageRequest(signMessageRequest: [String: Any?]) throws -> SignMessageRequest { - guard let message = signMessageRequest["message"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "SignMessageRequest")) - } - - return SignMessageRequest(message: message) +static func arrayOf(`sendPaymentResponseList`: [SendPaymentResponse]) -> [Any] { + return `sendPaymentResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(sendPaymentResponse: v) } +} +static func asSignMessageRequest(signMessageRequest: [String: Any?]) throws -> SignMessageRequest { + guard let message = signMessageRequest["message"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "SignMessageRequest")) } + + return SignMessageRequest(message: message) +} - static func dictionaryOf(signMessageRequest: SignMessageRequest) -> [String: Any?] { - return [ - "message": signMessageRequest.message, - ] - } +static func dictionaryOf(signMessageRequest: SignMessageRequest) -> [String: Any?] { + return [ + "message": signMessageRequest.message, + ] +} - static func asSignMessageRequestList(arr: [Any]) throws -> [SignMessageRequest] { - var list = [SignMessageRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var signMessageRequest = try asSignMessageRequest(signMessageRequest: val) - list.append(signMessageRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageRequest")) - } +static func asSignMessageRequestList(arr: [Any]) throws -> [SignMessageRequest] { + var list = [SignMessageRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var signMessageRequest = try asSignMessageRequest(signMessageRequest: val) + list.append(signMessageRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageRequest")) } - return list } + return list +} - static func arrayOf(signMessageRequestList: [SignMessageRequest]) -> [Any] { - return signMessageRequestList.map { v -> [String: Any?] in return dictionaryOf(signMessageRequest: v) } - } - - static func asSignMessageResponse(signMessageResponse: [String: Any?]) throws -> SignMessageResponse { - guard let signature = signMessageResponse["signature"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "SignMessageResponse")) - } - - return SignMessageResponse(signature: signature) +static func arrayOf(`signMessageRequestList`: [SignMessageRequest]) -> [Any] { + return `signMessageRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(signMessageRequest: v) } +} +static func asSignMessageResponse(signMessageResponse: [String: Any?]) throws -> SignMessageResponse { + guard let signature = signMessageResponse["signature"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "SignMessageResponse")) } + + return SignMessageResponse(signature: signature) +} - static func dictionaryOf(signMessageResponse: SignMessageResponse) -> [String: Any?] { - return [ - "signature": signMessageResponse.signature, - ] - } +static func dictionaryOf(signMessageResponse: SignMessageResponse) -> [String: Any?] { + return [ + "signature": signMessageResponse.signature, + ] +} - static func asSignMessageResponseList(arr: [Any]) throws -> [SignMessageResponse] { - var list = [SignMessageResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var signMessageResponse = try asSignMessageResponse(signMessageResponse: val) - list.append(signMessageResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageResponse")) - } +static func asSignMessageResponseList(arr: [Any]) throws -> [SignMessageResponse] { + var list = [SignMessageResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var signMessageResponse = try asSignMessageResponse(signMessageResponse: val) + list.append(signMessageResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageResponse")) } - return list - } - - static func arrayOf(signMessageResponseList: [SignMessageResponse]) -> [Any] { - return signMessageResponseList.map { v -> [String: Any?] in return dictionaryOf(signMessageResponse: v) } } + return list +} - static func asSymbol(symbol: [String: Any?]) throws -> Symbol { +static func arrayOf(`signMessageResponseList`: [SignMessageResponse]) -> [Any] { + return `signMessageResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(signMessageResponse: v) } +} +static func asSymbol(symbol: [String: Any?]) throws -> Symbol { var grapheme: String? if hasNonNilKey(data: symbol, key: "grapheme") { guard let graphemeTmp = symbol["grapheme"] as? String else { @@ -2604,1363 +2575,1392 @@ enum BreezSDKLiquidMapper { } position = positionTmp } + + return Symbol(grapheme: grapheme, template: template, rtl: rtl, position: position) +} - return Symbol(grapheme: grapheme, template: template, rtl: rtl, position: position) - } - - static func dictionaryOf(symbol: Symbol) -> [String: Any?] { - return [ +static func dictionaryOf(symbol: Symbol) -> [String: Any?] { + return [ "grapheme": symbol.grapheme == nil ? nil : symbol.grapheme, "template": symbol.template == nil ? nil : symbol.template, "rtl": symbol.rtl == nil ? nil : symbol.rtl, - "position": symbol.position == nil ? nil : symbol.position, - ] - } + "position": symbol.position == nil ? nil : symbol.position, + ] +} - static func asSymbolList(arr: [Any]) throws -> [Symbol] { - var list = [Symbol]() - for value in arr { - if let val = value as? [String: Any?] { - var symbol = try asSymbol(symbol: val) - list.append(symbol) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Symbol")) - } +static func asSymbolList(arr: [Any]) throws -> [Symbol] { + var list = [Symbol]() + for value in arr { + if let val = value as? [String: Any?] { + var symbol = try asSymbol(symbol: val) + list.append(symbol) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Symbol")) } - return list } + return list +} - static func arrayOf(symbolList: [Symbol]) -> [Any] { - return symbolList.map { v -> [String: Any?] in return dictionaryOf(symbol: v) } +static func arrayOf(`symbolList`: [Symbol]) -> [Any] { + return `symbolList`.map { (v) -> [String: Any?] in return dictionaryOf(symbol: v) } +} +static func asUrlSuccessActionData(urlSuccessActionData: [String: Any?]) throws -> UrlSuccessActionData { + guard let description = urlSuccessActionData["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "UrlSuccessActionData")) } - - static func asUrlSuccessActionData(urlSuccessActionData: [String: Any?]) throws -> UrlSuccessActionData { - guard let description = urlSuccessActionData["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "UrlSuccessActionData")) - } - guard let url = urlSuccessActionData["url"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "UrlSuccessActionData")) - } - guard let matchesCallbackDomain = urlSuccessActionData["matchesCallbackDomain"] as? Bool else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "matchesCallbackDomain", typeName: "UrlSuccessActionData")) - } - - return UrlSuccessActionData(description: description, url: url, matchesCallbackDomain: matchesCallbackDomain) + guard let url = urlSuccessActionData["url"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "UrlSuccessActionData")) + } + guard let matchesCallbackDomain = urlSuccessActionData["matchesCallbackDomain"] as? Bool else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "matchesCallbackDomain", typeName: "UrlSuccessActionData")) } + + return UrlSuccessActionData(description: description, url: url, matchesCallbackDomain: matchesCallbackDomain) +} - static func dictionaryOf(urlSuccessActionData: UrlSuccessActionData) -> [String: Any?] { - return [ +static func dictionaryOf(urlSuccessActionData: UrlSuccessActionData) -> [String: Any?] { + return [ "description": urlSuccessActionData.description, "url": urlSuccessActionData.url, - "matchesCallbackDomain": urlSuccessActionData.matchesCallbackDomain, - ] - } + "matchesCallbackDomain": urlSuccessActionData.matchesCallbackDomain, + ] +} - static func asUrlSuccessActionDataList(arr: [Any]) throws -> [UrlSuccessActionData] { - var list = [UrlSuccessActionData]() - for value in arr { - if let val = value as? [String: Any?] { - var urlSuccessActionData = try asUrlSuccessActionData(urlSuccessActionData: val) - list.append(urlSuccessActionData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "UrlSuccessActionData")) - } +static func asUrlSuccessActionDataList(arr: [Any]) throws -> [UrlSuccessActionData] { + var list = [UrlSuccessActionData]() + for value in arr { + if let val = value as? [String: Any?] { + var urlSuccessActionData = try asUrlSuccessActionData(urlSuccessActionData: val) + list.append(urlSuccessActionData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "UrlSuccessActionData")) } - return list } + return list +} - static func arrayOf(urlSuccessActionDataList: [UrlSuccessActionData]) -> [Any] { - return urlSuccessActionDataList.map { v -> [String: Any?] in return dictionaryOf(urlSuccessActionData: v) } - } +static func arrayOf(`urlSuccessActionDataList`: [UrlSuccessActionData]) -> [Any] { + return `urlSuccessActionDataList`.map { (v) -> [String: Any?] in return dictionaryOf(urlSuccessActionData: v) } +} - static func asAesSuccessActionDataResult(aesSuccessActionDataResult: [String: Any?]) throws -> AesSuccessActionDataResult { - let type = aesSuccessActionDataResult["type"] as! String - if type == "decrypted" { - guard let dataTmp = aesSuccessActionDataResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "AesSuccessActionDataResult")) - } +static func asAesSuccessActionDataResult(aesSuccessActionDataResult: [String: Any?]) throws -> AesSuccessActionDataResult { + let type = aesSuccessActionDataResult["type"] as! String + if (type == "decrypted") { + guard let dataTmp = aesSuccessActionDataResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "AesSuccessActionDataResult")) + } let _data = try asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: dataTmp) - - return AesSuccessActionDataResult.decrypted(data: _data) - } - if type == "errorStatus" { - guard let _reason = aesSuccessActionDataResult["reason"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "AesSuccessActionDataResult")) - } - return AesSuccessActionDataResult.errorStatus(reason: _reason) + + return AesSuccessActionDataResult.decrypted(data: _data) } + if (type == "errorStatus") { + guard let _reason = aesSuccessActionDataResult["reason"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "AesSuccessActionDataResult")) + } + return AesSuccessActionDataResult.errorStatus(reason: _reason) + } - throw SdkError.Generic(message: "Unexpected type \(type) for enum AesSuccessActionDataResult") - } - - static func dictionaryOf(aesSuccessActionDataResult: AesSuccessActionDataResult) -> [String: Any?] { - switch aesSuccessActionDataResult { - case let .decrypted( - data - ): - return [ - "type": "decrypted", - "data": dictionaryOf(aesSuccessActionDataDecrypted: data), - ] + throw SdkError.Generic(message: "Unexpected type \(type) for enum AesSuccessActionDataResult") +} - case let .errorStatus( - reason - ): - return [ - "type": "errorStatus", - "reason": reason, - ] - } - } +static func dictionaryOf(aesSuccessActionDataResult: AesSuccessActionDataResult) -> [String: Any?] { + switch (aesSuccessActionDataResult) { + + case let .decrypted( + data + ): + return [ + "type": "decrypted", + "data": dictionaryOf(aesSuccessActionDataDecrypted: data), + ] + + case let .errorStatus( + reason + ): + return [ + "type": "errorStatus", + "reason": reason, + ] + } +} - static func arrayOf(aesSuccessActionDataResultList: [AesSuccessActionDataResult]) -> [Any] { - return aesSuccessActionDataResultList.map { v -> [String: Any?] in return dictionaryOf(aesSuccessActionDataResult: v) } - } +static func arrayOf(`aesSuccessActionDataResultList`: [AesSuccessActionDataResult]) -> [Any] { + return `aesSuccessActionDataResultList`.map { (v) -> [String: Any?] in return dictionaryOf(aesSuccessActionDataResult: v) } +} - static func asAesSuccessActionDataResultList(arr: [Any]) throws -> [AesSuccessActionDataResult] { - var list = [AesSuccessActionDataResult]() - for value in arr { - if let val = value as? [String: Any?] { - var aesSuccessActionDataResult = try asAesSuccessActionDataResult(aesSuccessActionDataResult: val) - list.append(aesSuccessActionDataResult) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataResult")) - } +static func asAesSuccessActionDataResultList(arr: [Any]) throws -> [AesSuccessActionDataResult] { + var list = [AesSuccessActionDataResult]() + for value in arr { + if let val = value as? [String: Any?] { + var aesSuccessActionDataResult = try asAesSuccessActionDataResult(aesSuccessActionDataResult: val) + list.append(aesSuccessActionDataResult) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataResult")) } - return list } + return list +} - static func asBuyBitcoinProvider(buyBitcoinProvider: String) throws -> BuyBitcoinProvider { - switch buyBitcoinProvider { - case "moonpay": - return BuyBitcoinProvider.moonpay +static func asBuyBitcoinProvider(buyBitcoinProvider: String) throws -> BuyBitcoinProvider { + switch(buyBitcoinProvider) { - default: throw SdkError.Generic(message: "Invalid variant \(buyBitcoinProvider) for enum BuyBitcoinProvider") - } + case "moonpay": + return BuyBitcoinProvider.moonpay + + default: throw SdkError.Generic(message: "Invalid variant \(buyBitcoinProvider) for enum BuyBitcoinProvider") } +} - static func valueOf(buyBitcoinProvider: BuyBitcoinProvider) -> String { - switch buyBitcoinProvider { - case .moonpay: - return "moonpay" - } - } +static func valueOf(buyBitcoinProvider: BuyBitcoinProvider) -> String { + switch(buyBitcoinProvider) { - static func arrayOf(buyBitcoinProviderList: [BuyBitcoinProvider]) -> [String] { - return buyBitcoinProviderList.map { v -> String in return valueOf(buyBitcoinProvider: v) } + case .moonpay: + return "moonpay" + } +} - static func asBuyBitcoinProviderList(arr: [Any]) throws -> [BuyBitcoinProvider] { - var list = [BuyBitcoinProvider]() - for value in arr { - if let val = value as? String { - var buyBitcoinProvider = try asBuyBitcoinProvider(buyBitcoinProvider: val) - list.append(buyBitcoinProvider) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinProvider")) - } +static func arrayOf(`buyBitcoinProviderList`: [BuyBitcoinProvider]) -> [String] { + return `buyBitcoinProviderList`.map { (v) -> String in return valueOf(buyBitcoinProvider: v) } +} + +static func asBuyBitcoinProviderList(arr: [Any]) throws -> [BuyBitcoinProvider] { + var list = [BuyBitcoinProvider]() + for value in arr { + if let val = value as? String { + var buyBitcoinProvider = try asBuyBitcoinProvider(buyBitcoinProvider: val) + list.append(buyBitcoinProvider) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinProvider")) } - return list } + return list +} - static func asGetPaymentRequest(getPaymentRequest: [String: Any?]) throws -> GetPaymentRequest { - let type = getPaymentRequest["type"] as! String - if type == "lightning" { - guard let _paymentHash = getPaymentRequest["paymentHash"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "GetPaymentRequest")) - } - return GetPaymentRequest.lightning(paymentHash: _paymentHash) - } +static func asGetPaymentRequest(getPaymentRequest: [String: Any?]) throws -> GetPaymentRequest { + let type = getPaymentRequest["type"] as! String + if (type == "lightning") { + guard let _paymentHash = getPaymentRequest["paymentHash"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "GetPaymentRequest")) + } + return GetPaymentRequest.lightning(paymentHash: _paymentHash) + } - throw SdkError.Generic(message: "Unexpected type \(type) for enum GetPaymentRequest") - } + throw SdkError.Generic(message: "Unexpected type \(type) for enum GetPaymentRequest") +} - static func dictionaryOf(getPaymentRequest: GetPaymentRequest) -> [String: Any?] { - switch getPaymentRequest { - case let .lightning( - paymentHash - ): - return [ - "type": "lightning", - "paymentHash": paymentHash, - ] - } - } +static func dictionaryOf(getPaymentRequest: GetPaymentRequest) -> [String: Any?] { + switch (getPaymentRequest) { + + case let .lightning( + paymentHash + ): + return [ + "type": "lightning", + "paymentHash": paymentHash, + ] + } +} - static func arrayOf(getPaymentRequestList: [GetPaymentRequest]) -> [Any] { - return getPaymentRequestList.map { v -> [String: Any?] in return dictionaryOf(getPaymentRequest: v) } - } +static func arrayOf(`getPaymentRequestList`: [GetPaymentRequest]) -> [Any] { + return `getPaymentRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(getPaymentRequest: v) } +} - static func asGetPaymentRequestList(arr: [Any]) throws -> [GetPaymentRequest] { - var list = [GetPaymentRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var getPaymentRequest = try asGetPaymentRequest(getPaymentRequest: val) - list.append(getPaymentRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "GetPaymentRequest")) - } +static func asGetPaymentRequestList(arr: [Any]) throws -> [GetPaymentRequest] { + var list = [GetPaymentRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var getPaymentRequest = try asGetPaymentRequest(getPaymentRequest: val) + list.append(getPaymentRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "GetPaymentRequest")) } - return list } + return list +} - static func asInputType(inputType: [String: Any?]) throws -> InputType { - let type = inputType["type"] as! String - if type == "bitcoinAddress" { - guard let addressTmp = inputType["address"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) - } +static func asInputType(inputType: [String: Any?]) throws -> InputType { + let type = inputType["type"] as! String + if (type == "bitcoinAddress") { + guard let addressTmp = inputType["address"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) + } let _address = try asBitcoinAddressData(bitcoinAddressData: addressTmp) - - return InputType.bitcoinAddress(address: _address) + + return InputType.bitcoinAddress(address: _address) } - if type == "liquidAddress" { - guard let addressTmp = inputType["address"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) - } + if (type == "liquidAddress") { + guard let addressTmp = inputType["address"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) + } let _address = try asLiquidAddressData(liquidAddressData: addressTmp) - - return InputType.liquidAddress(address: _address) + + return InputType.liquidAddress(address: _address) } - if type == "bolt11" { - guard let invoiceTmp = inputType["invoice"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "InputType")) - } + if (type == "bolt11") { + guard let invoiceTmp = inputType["invoice"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "InputType")) + } let _invoice = try asLnInvoice(lnInvoice: invoiceTmp) - - return InputType.bolt11(invoice: _invoice) - } - if type == "nodeId" { - guard let _nodeId = inputType["nodeId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "nodeId", typeName: "InputType")) - } - return InputType.nodeId(nodeId: _nodeId) - } - if type == "url" { - guard let _url = inputType["url"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "InputType")) - } - return InputType.url(url: _url) - } - if type == "lnUrlPay" { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + + return InputType.bolt11(invoice: _invoice) + } + if (type == "nodeId") { + guard let _nodeId = inputType["nodeId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "nodeId", typeName: "InputType")) + } + return InputType.nodeId(nodeId: _nodeId) + } + if (type == "url") { + guard let _url = inputType["url"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "InputType")) + } + return InputType.url(url: _url) + } + if (type == "lnUrlPay") { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlPayRequestData(lnUrlPayRequestData: dataTmp) - - return InputType.lnUrlPay(data: _data) + + return InputType.lnUrlPay(data: _data) } - if type == "lnUrlWithdraw" { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + if (type == "lnUrlWithdraw") { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: dataTmp) - - return InputType.lnUrlWithdraw(data: _data) + + return InputType.lnUrlWithdraw(data: _data) } - if type == "lnUrlAuth" { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + if (type == "lnUrlAuth") { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlAuthRequestData(lnUrlAuthRequestData: dataTmp) - - return InputType.lnUrlAuth(data: _data) + + return InputType.lnUrlAuth(data: _data) } - if type == "lnUrlError" { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + if (type == "lnUrlError") { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) + + return InputType.lnUrlError(data: _data) + } - return InputType.lnUrlError(data: _data) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum InputType") - } - - static func dictionaryOf(inputType: InputType) -> [String: Any?] { - switch inputType { - case let .bitcoinAddress( - address - ): - return [ - "type": "bitcoinAddress", - "address": dictionaryOf(bitcoinAddressData: address), - ] - - case let .liquidAddress( - address - ): - return [ - "type": "liquidAddress", - "address": dictionaryOf(liquidAddressData: address), - ] - - case let .bolt11( - invoice - ): - return [ - "type": "bolt11", - "invoice": dictionaryOf(lnInvoice: invoice), - ] - - case let .nodeId( - nodeId - ): - return [ - "type": "nodeId", - "nodeId": nodeId, - ] - - case let .url( - url - ): - return [ - "type": "url", - "url": url, - ] - - case let .lnUrlPay( - data - ): - return [ - "type": "lnUrlPay", - "data": dictionaryOf(lnUrlPayRequestData: data), - ] - - case let .lnUrlWithdraw( - data - ): - return [ - "type": "lnUrlWithdraw", - "data": dictionaryOf(lnUrlWithdrawRequestData: data), - ] - - case let .lnUrlAuth( - data - ): - return [ - "type": "lnUrlAuth", - "data": dictionaryOf(lnUrlAuthRequestData: data), - ] - - case let .lnUrlError( - data - ): - return [ - "type": "lnUrlError", - "data": dictionaryOf(lnUrlErrorData: data), - ] - } - } - - static func arrayOf(inputTypeList: [InputType]) -> [Any] { - return inputTypeList.map { v -> [String: Any?] in return dictionaryOf(inputType: v) } - } - - static func asInputTypeList(arr: [Any]) throws -> [InputType] { - var list = [InputType]() - for value in arr { - if let val = value as? [String: Any?] { - var inputType = try asInputType(inputType: val) - list.append(inputType) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "InputType")) - } - } - return list - } + throw SdkError.Generic(message: "Unexpected type \(type) for enum InputType") +} - static func asLiquidNetwork(liquidNetwork: String) throws -> LiquidNetwork { - switch liquidNetwork { - case "mainnet": - return LiquidNetwork.mainnet +static func dictionaryOf(inputType: InputType) -> [String: Any?] { + switch (inputType) { + + case let .bitcoinAddress( + address + ): + return [ + "type": "bitcoinAddress", + "address": dictionaryOf(bitcoinAddressData: address), + ] + + case let .liquidAddress( + address + ): + return [ + "type": "liquidAddress", + "address": dictionaryOf(liquidAddressData: address), + ] + + case let .bolt11( + invoice + ): + return [ + "type": "bolt11", + "invoice": dictionaryOf(lnInvoice: invoice), + ] + + case let .nodeId( + nodeId + ): + return [ + "type": "nodeId", + "nodeId": nodeId, + ] + + case let .url( + url + ): + return [ + "type": "url", + "url": url, + ] + + case let .lnUrlPay( + data + ): + return [ + "type": "lnUrlPay", + "data": dictionaryOf(lnUrlPayRequestData: data), + ] + + case let .lnUrlWithdraw( + data + ): + return [ + "type": "lnUrlWithdraw", + "data": dictionaryOf(lnUrlWithdrawRequestData: data), + ] + + case let .lnUrlAuth( + data + ): + return [ + "type": "lnUrlAuth", + "data": dictionaryOf(lnUrlAuthRequestData: data), + ] + + case let .lnUrlError( + data + ): + return [ + "type": "lnUrlError", + "data": dictionaryOf(lnUrlErrorData: data), + ] + } +} - case "testnet": - return LiquidNetwork.testnet +static func arrayOf(`inputTypeList`: [InputType]) -> [Any] { + return `inputTypeList`.map { (v) -> [String: Any?] in return dictionaryOf(inputType: v) } +} - default: throw SdkError.Generic(message: "Invalid variant \(liquidNetwork) for enum LiquidNetwork") +static func asInputTypeList(arr: [Any]) throws -> [InputType] { + var list = [InputType]() + for value in arr { + if let val = value as? [String: Any?] { + var inputType = try asInputType(inputType: val) + list.append(inputType) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "InputType")) } } + return list +} - static func valueOf(liquidNetwork: LiquidNetwork) -> String { - switch liquidNetwork { - case .mainnet: - return "mainnet" +static func asLiquidNetwork(liquidNetwork: String) throws -> LiquidNetwork { + switch(liquidNetwork) { - case .testnet: - return "testnet" - } - } + case "mainnet": + return LiquidNetwork.mainnet - static func arrayOf(liquidNetworkList: [LiquidNetwork]) -> [String] { - return liquidNetworkList.map { v -> String in return valueOf(liquidNetwork: v) } + case "testnet": + return LiquidNetwork.testnet + + default: throw SdkError.Generic(message: "Invalid variant \(liquidNetwork) for enum LiquidNetwork") } +} - static func asLiquidNetworkList(arr: [Any]) throws -> [LiquidNetwork] { - var list = [LiquidNetwork]() - for value in arr { - if let val = value as? String { - var liquidNetwork = try asLiquidNetwork(liquidNetwork: val) - list.append(liquidNetwork) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidNetwork")) - } - } - return list - } +static func valueOf(liquidNetwork: LiquidNetwork) -> String { + switch(liquidNetwork) { - static func asListPaymentDetails(listPaymentDetails: [String: Any?]) throws -> ListPaymentDetails { - let type = listPaymentDetails["type"] as! String - if type == "liquid" { - guard let _destination = listPaymentDetails["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ListPaymentDetails")) - } - return ListPaymentDetails.liquid(destination: _destination) - } - if type == "bitcoin" { - guard let _address = listPaymentDetails["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "ListPaymentDetails")) - } - return ListPaymentDetails.bitcoin(address: _address) - } + case .mainnet: + return "mainnet" - throw SdkError.Generic(message: "Unexpected type \(type) for enum ListPaymentDetails") + case .testnet: + return "testnet" + } +} - static func dictionaryOf(listPaymentDetails: ListPaymentDetails) -> [String: Any?] { - switch listPaymentDetails { - case let .liquid( - destination - ): - return [ - "type": "liquid", - "destination": destination, - ] +static func arrayOf(`liquidNetworkList`: [LiquidNetwork]) -> [String] { + return `liquidNetworkList`.map { (v) -> String in return valueOf(liquidNetwork: v) } +} - case let .bitcoin( - address - ): - return [ - "type": "bitcoin", - "address": address, - ] +static func asLiquidNetworkList(arr: [Any]) throws -> [LiquidNetwork] { + var list = [LiquidNetwork]() + for value in arr { + if let val = value as? String { + var liquidNetwork = try asLiquidNetwork(liquidNetwork: val) + list.append(liquidNetwork) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidNetwork")) } } + return list +} - static func arrayOf(listPaymentDetailsList: [ListPaymentDetails]) -> [Any] { - return listPaymentDetailsList.map { v -> [String: Any?] in return dictionaryOf(listPaymentDetails: v) } - } +static func asListPaymentDetails(listPaymentDetails: [String: Any?]) throws -> ListPaymentDetails { + let type = listPaymentDetails["type"] as! String + if (type == "liquid") { + guard let _destination = listPaymentDetails["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ListPaymentDetails")) + } + return ListPaymentDetails.liquid(destination: _destination) + } + if (type == "bitcoin") { + guard let _address = listPaymentDetails["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "ListPaymentDetails")) + } + return ListPaymentDetails.bitcoin(address: _address) + } + + throw SdkError.Generic(message: "Unexpected type \(type) for enum ListPaymentDetails") +} - static func asListPaymentDetailsList(arr: [Any]) throws -> [ListPaymentDetails] { - var list = [ListPaymentDetails]() - for value in arr { - if let val = value as? [String: Any?] { - var listPaymentDetails = try asListPaymentDetails(listPaymentDetails: val) - list.append(listPaymentDetails) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentDetails")) - } +static func dictionaryOf(listPaymentDetails: ListPaymentDetails) -> [String: Any?] { + switch (listPaymentDetails) { + + case let .liquid( + destination + ): + return [ + "type": "liquid", + "destination": destination, + ] + + case let .bitcoin( + address + ): + return [ + "type": "bitcoin", + "address": address, + ] + } +} + +static func arrayOf(`listPaymentDetailsList`: [ListPaymentDetails]) -> [Any] { + return `listPaymentDetailsList`.map { (v) -> [String: Any?] in return dictionaryOf(listPaymentDetails: v) } +} + +static func asListPaymentDetailsList(arr: [Any]) throws -> [ListPaymentDetails] { + var list = [ListPaymentDetails]() + for value in arr { + if let val = value as? [String: Any?] { + var listPaymentDetails = try asListPaymentDetails(listPaymentDetails: val) + list.append(listPaymentDetails) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentDetails")) } - return list } + return list +} - static func asLnUrlCallbackStatus(lnUrlCallbackStatus: [String: Any?]) throws -> LnUrlCallbackStatus { - let type = lnUrlCallbackStatus["type"] as! String - if type == "ok" { - return LnUrlCallbackStatus.ok +static func asLnUrlCallbackStatus(lnUrlCallbackStatus: [String: Any?]) throws -> LnUrlCallbackStatus { + let type = lnUrlCallbackStatus["type"] as! String + if (type == "ok") { + return LnUrlCallbackStatus.ok } - if type == "errorStatus" { - guard let dataTmp = lnUrlCallbackStatus["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlCallbackStatus")) - } + if (type == "errorStatus") { + guard let dataTmp = lnUrlCallbackStatus["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlCallbackStatus")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) + + return LnUrlCallbackStatus.errorStatus(data: _data) + } - return LnUrlCallbackStatus.errorStatus(data: _data) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlCallbackStatus") - } - - static func dictionaryOf(lnUrlCallbackStatus: LnUrlCallbackStatus) -> [String: Any?] { - switch lnUrlCallbackStatus { - case .ok: - return [ - "type": "ok", - ] + throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlCallbackStatus") +} - case let .errorStatus( - data - ): - return [ - "type": "errorStatus", - "data": dictionaryOf(lnUrlErrorData: data), - ] - } - } +static func dictionaryOf(lnUrlCallbackStatus: LnUrlCallbackStatus) -> [String: Any?] { + switch (lnUrlCallbackStatus) { + + case .ok: + return [ + "type": "ok", + ] + + case let .errorStatus( + data + ): + return [ + "type": "errorStatus", + "data": dictionaryOf(lnUrlErrorData: data), + ] + } +} - static func arrayOf(lnUrlCallbackStatusList: [LnUrlCallbackStatus]) -> [Any] { - return lnUrlCallbackStatusList.map { v -> [String: Any?] in return dictionaryOf(lnUrlCallbackStatus: v) } - } +static func arrayOf(`lnUrlCallbackStatusList`: [LnUrlCallbackStatus]) -> [Any] { + return `lnUrlCallbackStatusList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlCallbackStatus: v) } +} - static func asLnUrlCallbackStatusList(arr: [Any]) throws -> [LnUrlCallbackStatus] { - var list = [LnUrlCallbackStatus]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlCallbackStatus = try asLnUrlCallbackStatus(lnUrlCallbackStatus: val) - list.append(lnUrlCallbackStatus) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlCallbackStatus")) - } +static func asLnUrlCallbackStatusList(arr: [Any]) throws -> [LnUrlCallbackStatus] { + var list = [LnUrlCallbackStatus]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlCallbackStatus = try asLnUrlCallbackStatus(lnUrlCallbackStatus: val) + list.append(lnUrlCallbackStatus) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlCallbackStatus")) } - return list } + return list +} - static func asLnUrlPayResult(lnUrlPayResult: [String: Any?]) throws -> LnUrlPayResult { - let type = lnUrlPayResult["type"] as! String - if type == "endpointSuccess" { - guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) - } +static func asLnUrlPayResult(lnUrlPayResult: [String: Any?]) throws -> LnUrlPayResult { + let type = lnUrlPayResult["type"] as! String + if (type == "endpointSuccess") { + guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) + } let _data = try asLnUrlPaySuccessData(lnUrlPaySuccessData: dataTmp) - - return LnUrlPayResult.endpointSuccess(data: _data) + + return LnUrlPayResult.endpointSuccess(data: _data) } - if type == "endpointError" { - guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) - } + if (type == "endpointError") { + guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) - - return LnUrlPayResult.endpointError(data: _data) + + return LnUrlPayResult.endpointError(data: _data) } - if type == "payError" { - guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) - } + if (type == "payError") { + guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) + } let _data = try asLnUrlPayErrorData(lnUrlPayErrorData: dataTmp) + + return LnUrlPayResult.payError(data: _data) + } - return LnUrlPayResult.payError(data: _data) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlPayResult") - } - - static func dictionaryOf(lnUrlPayResult: LnUrlPayResult) -> [String: Any?] { - switch lnUrlPayResult { - case let .endpointSuccess( - data - ): - return [ - "type": "endpointSuccess", - "data": dictionaryOf(lnUrlPaySuccessData: data), - ] - - case let .endpointError( - data - ): - return [ - "type": "endpointError", - "data": dictionaryOf(lnUrlErrorData: data), - ] + throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlPayResult") +} - case let .payError( - data - ): - return [ - "type": "payError", - "data": dictionaryOf(lnUrlPayErrorData: data), - ] - } - } +static func dictionaryOf(lnUrlPayResult: LnUrlPayResult) -> [String: Any?] { + switch (lnUrlPayResult) { + + case let .endpointSuccess( + data + ): + return [ + "type": "endpointSuccess", + "data": dictionaryOf(lnUrlPaySuccessData: data), + ] + + case let .endpointError( + data + ): + return [ + "type": "endpointError", + "data": dictionaryOf(lnUrlErrorData: data), + ] + + case let .payError( + data + ): + return [ + "type": "payError", + "data": dictionaryOf(lnUrlPayErrorData: data), + ] + } +} - static func arrayOf(lnUrlPayResultList: [LnUrlPayResult]) -> [Any] { - return lnUrlPayResultList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayResult: v) } - } +static func arrayOf(`lnUrlPayResultList`: [LnUrlPayResult]) -> [Any] { + return `lnUrlPayResultList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayResult: v) } +} - static func asLnUrlPayResultList(arr: [Any]) throws -> [LnUrlPayResult] { - var list = [LnUrlPayResult]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayResult = try asLnUrlPayResult(lnUrlPayResult: val) - list.append(lnUrlPayResult) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayResult")) - } +static func asLnUrlPayResultList(arr: [Any]) throws -> [LnUrlPayResult] { + var list = [LnUrlPayResult]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayResult = try asLnUrlPayResult(lnUrlPayResult: val) + list.append(lnUrlPayResult) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayResult")) } - return list } + return list +} - static func asLnUrlWithdrawResult(lnUrlWithdrawResult: [String: Any?]) throws -> LnUrlWithdrawResult { - let type = lnUrlWithdrawResult["type"] as! String - if type == "ok" { - guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) - } +static func asLnUrlWithdrawResult(lnUrlWithdrawResult: [String: Any?]) throws -> LnUrlWithdrawResult { + let type = lnUrlWithdrawResult["type"] as! String + if (type == "ok") { + guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) + } let _data = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: dataTmp) - - return LnUrlWithdrawResult.ok(data: _data) + + return LnUrlWithdrawResult.ok(data: _data) } - if type == "timeout" { - guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) - } + if (type == "timeout") { + guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) + } let _data = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: dataTmp) - - return LnUrlWithdrawResult.timeout(data: _data) + + return LnUrlWithdrawResult.timeout(data: _data) } - if type == "errorStatus" { - guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) - } + if (type == "errorStatus") { + guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) + + return LnUrlWithdrawResult.errorStatus(data: _data) + } - return LnUrlWithdrawResult.errorStatus(data: _data) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlWithdrawResult") - } - - static func dictionaryOf(lnUrlWithdrawResult: LnUrlWithdrawResult) -> [String: Any?] { - switch lnUrlWithdrawResult { - case let .ok( - data - ): - return [ - "type": "ok", - "data": dictionaryOf(lnUrlWithdrawSuccessData: data), - ] - - case let .timeout( - data - ): - return [ - "type": "timeout", - "data": dictionaryOf(lnUrlWithdrawSuccessData: data), - ] + throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlWithdrawResult") +} - case let .errorStatus( - data - ): - return [ - "type": "errorStatus", - "data": dictionaryOf(lnUrlErrorData: data), - ] - } - } +static func dictionaryOf(lnUrlWithdrawResult: LnUrlWithdrawResult) -> [String: Any?] { + switch (lnUrlWithdrawResult) { + + case let .ok( + data + ): + return [ + "type": "ok", + "data": dictionaryOf(lnUrlWithdrawSuccessData: data), + ] + + case let .timeout( + data + ): + return [ + "type": "timeout", + "data": dictionaryOf(lnUrlWithdrawSuccessData: data), + ] + + case let .errorStatus( + data + ): + return [ + "type": "errorStatus", + "data": dictionaryOf(lnUrlErrorData: data), + ] + } +} - static func arrayOf(lnUrlWithdrawResultList: [LnUrlWithdrawResult]) -> [Any] { - return lnUrlWithdrawResultList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawResult: v) } - } +static func arrayOf(`lnUrlWithdrawResultList`: [LnUrlWithdrawResult]) -> [Any] { + return `lnUrlWithdrawResultList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawResult: v) } +} - static func asLnUrlWithdrawResultList(arr: [Any]) throws -> [LnUrlWithdrawResult] { - var list = [LnUrlWithdrawResult]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawResult = try asLnUrlWithdrawResult(lnUrlWithdrawResult: val) - list.append(lnUrlWithdrawResult) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawResult")) - } +static func asLnUrlWithdrawResultList(arr: [Any]) throws -> [LnUrlWithdrawResult] { + var list = [LnUrlWithdrawResult]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawResult = try asLnUrlWithdrawResult(lnUrlWithdrawResult: val) + list.append(lnUrlWithdrawResult) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawResult")) } - return list } + return list +} - static func asNetwork(network: String) throws -> Network { - switch network { - case "bitcoin": - return Network.bitcoin +static func asNetwork(network: String) throws -> Network { + switch(network) { - case "testnet": - return Network.testnet + case "bitcoin": + return Network.bitcoin - case "signet": - return Network.signet + case "testnet": + return Network.testnet - case "regtest": - return Network.regtest + case "signet": + return Network.signet - default: throw SdkError.Generic(message: "Invalid variant \(network) for enum Network") - } + case "regtest": + return Network.regtest + + default: throw SdkError.Generic(message: "Invalid variant \(network) for enum Network") } +} - static func valueOf(network: Network) -> String { - switch network { - case .bitcoin: - return "bitcoin" +static func valueOf(network: Network) -> String { + switch(network) { - case .testnet: - return "testnet" + case .bitcoin: + return "bitcoin" - case .signet: - return "signet" + case .testnet: + return "testnet" - case .regtest: - return "regtest" - } - } + case .signet: + return "signet" - static func arrayOf(networkList: [Network]) -> [String] { - return networkList.map { v -> String in return valueOf(network: v) } + case .regtest: + return "regtest" + } +} - static func asNetworkList(arr: [Any]) throws -> [Network] { - var list = [Network]() - for value in arr { - if let val = value as? String { - var network = try asNetwork(network: val) - list.append(network) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Network")) - } +static func arrayOf(`networkList`: [Network]) -> [String] { + return `networkList`.map { (v) -> String in return valueOf(network: v) } +} + +static func asNetworkList(arr: [Any]) throws -> [Network] { + var list = [Network]() + for value in arr { + if let val = value as? String { + var network = try asNetwork(network: val) + list.append(network) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Network")) } - return list } + return list +} - static func asPayOnchainAmount(payOnchainAmount: [String: Any?]) throws -> PayOnchainAmount { - let type = payOnchainAmount["type"] as! String - if type == "receiver" { - guard let _amountSat = payOnchainAmount["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PayOnchainAmount")) - } - return PayOnchainAmount.receiver(amountSat: _amountSat) - } - if type == "drain" { - return PayOnchainAmount.drain +static func asPayOnchainAmount(payOnchainAmount: [String: Any?]) throws -> PayOnchainAmount { + let type = payOnchainAmount["type"] as! String + if (type == "receiver") { + guard let _amountSat = payOnchainAmount["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PayOnchainAmount")) + } + return PayOnchainAmount.receiver(amountSat: _amountSat) } + if (type == "drain") { + return PayOnchainAmount.drain + } - throw SdkError.Generic(message: "Unexpected type \(type) for enum PayOnchainAmount") - } - - static func dictionaryOf(payOnchainAmount: PayOnchainAmount) -> [String: Any?] { - switch payOnchainAmount { - case let .receiver( - amountSat - ): - return [ - "type": "receiver", - "amountSat": amountSat, - ] + throw SdkError.Generic(message: "Unexpected type \(type) for enum PayOnchainAmount") +} - case .drain: - return [ - "type": "drain", - ] - } - } +static func dictionaryOf(payOnchainAmount: PayOnchainAmount) -> [String: Any?] { + switch (payOnchainAmount) { + + case let .receiver( + amountSat + ): + return [ + "type": "receiver", + "amountSat": amountSat, + ] + + case .drain: + return [ + "type": "drain", + ] + } +} - static func arrayOf(payOnchainAmountList: [PayOnchainAmount]) -> [Any] { - return payOnchainAmountList.map { v -> [String: Any?] in return dictionaryOf(payOnchainAmount: v) } - } +static func arrayOf(`payOnchainAmountList`: [PayOnchainAmount]) -> [Any] { + return `payOnchainAmountList`.map { (v) -> [String: Any?] in return dictionaryOf(payOnchainAmount: v) } +} - static func asPayOnchainAmountList(arr: [Any]) throws -> [PayOnchainAmount] { - var list = [PayOnchainAmount]() - for value in arr { - if let val = value as? [String: Any?] { - var payOnchainAmount = try asPayOnchainAmount(payOnchainAmount: val) - list.append(payOnchainAmount) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainAmount")) - } +static func asPayOnchainAmountList(arr: [Any]) throws -> [PayOnchainAmount] { + var list = [PayOnchainAmount]() + for value in arr { + if let val = value as? [String: Any?] { + var payOnchainAmount = try asPayOnchainAmount(payOnchainAmount: val) + list.append(payOnchainAmount) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainAmount")) } - return list } + return list +} - static func asPaymentDetails(paymentDetails: [String: Any?]) throws -> PaymentDetails { - let type = paymentDetails["type"] as! String - if type == "lightning" { - guard let _swapId = paymentDetails["swapId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) - } - guard let _description = paymentDetails["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) - } - let _preimage = paymentDetails["preimage"] as? String - - let _bolt11 = paymentDetails["bolt11"] as? String - - let _paymentHash = paymentDetails["paymentHash"] as? String +static func asPaymentDetails(paymentDetails: [String: Any?]) throws -> PaymentDetails { + let type = paymentDetails["type"] as! String + if (type == "lightning") { + guard let _swapId = paymentDetails["swapId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) + } + guard let _description = paymentDetails["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) + } + let _preimage = paymentDetails["preimage"] as? String + + let _bolt11 = paymentDetails["bolt11"] as? String + + let _paymentHash = paymentDetails["paymentHash"] as? String + + let _refundTxId = paymentDetails["refundTxId"] as? String + + let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 + + return PaymentDetails.lightning(swapId: _swapId, description: _description, preimage: _preimage, bolt11: _bolt11, paymentHash: _paymentHash, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) + } + if (type == "liquid") { + guard let _destination = paymentDetails["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PaymentDetails")) + } + guard let _description = paymentDetails["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) + } + return PaymentDetails.liquid(destination: _destination, description: _description) + } + if (type == "bitcoin") { + guard let _swapId = paymentDetails["swapId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) + } + guard let _description = paymentDetails["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) + } + let _refundTxId = paymentDetails["refundTxId"] as? String + + let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 + + return PaymentDetails.bitcoin(swapId: _swapId, description: _description, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) + } + + throw SdkError.Generic(message: "Unexpected type \(type) for enum PaymentDetails") +} - let _refundTxId = paymentDetails["refundTxId"] as? String +static func dictionaryOf(paymentDetails: PaymentDetails) -> [String: Any?] { + switch (paymentDetails) { + + case let .lightning( + swapId, description, preimage, bolt11, paymentHash, refundTxId, refundTxAmountSat + ): + return [ + "type": "lightning", + "swapId": swapId, + "description": description, + "preimage": preimage == nil ? nil : preimage, + "bolt11": bolt11 == nil ? nil : bolt11, + "paymentHash": paymentHash == nil ? nil : paymentHash, + "refundTxId": refundTxId == nil ? nil : refundTxId, + "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, + ] + + case let .liquid( + destination, description + ): + return [ + "type": "liquid", + "destination": destination, + "description": description, + ] + + case let .bitcoin( + swapId, description, refundTxId, refundTxAmountSat + ): + return [ + "type": "bitcoin", + "swapId": swapId, + "description": description, + "refundTxId": refundTxId == nil ? nil : refundTxId, + "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, + ] + } +} - let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 +static func arrayOf(`paymentDetailsList`: [PaymentDetails]) -> [Any] { + return `paymentDetailsList`.map { (v) -> [String: Any?] in return dictionaryOf(paymentDetails: v) } +} - return PaymentDetails.lightning(swapId: _swapId, description: _description, preimage: _preimage, bolt11: _bolt11, paymentHash: _paymentHash, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) - } - if type == "liquid" { - guard let _destination = paymentDetails["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PaymentDetails")) - } - guard let _description = paymentDetails["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) - } - return PaymentDetails.liquid(destination: _destination, description: _description) +static func asPaymentDetailsList(arr: [Any]) throws -> [PaymentDetails] { + var list = [PaymentDetails]() + for value in arr { + if let val = value as? [String: Any?] { + var paymentDetails = try asPaymentDetails(paymentDetails: val) + list.append(paymentDetails) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentDetails")) } - if type == "bitcoin" { - guard let _swapId = paymentDetails["swapId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) - } - guard let _description = paymentDetails["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) - } - let _refundTxId = paymentDetails["refundTxId"] as? String - - let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 - - return PaymentDetails.bitcoin(swapId: _swapId, description: _description, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum PaymentDetails") - } - - static func dictionaryOf(paymentDetails: PaymentDetails) -> [String: Any?] { - switch paymentDetails { - case let .lightning( - swapId, description, preimage, bolt11, paymentHash, refundTxId, refundTxAmountSat - ): - return [ - "type": "lightning", - "swapId": swapId, - "description": description, - "preimage": preimage == nil ? nil : preimage, - "bolt11": bolt11 == nil ? nil : bolt11, - "paymentHash": paymentHash == nil ? nil : paymentHash, - "refundTxId": refundTxId == nil ? nil : refundTxId, - "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, - ] - - case let .liquid( - destination, description - ): - return [ - "type": "liquid", - "destination": destination, - "description": description, - ] - - case let .bitcoin( - swapId, description, refundTxId, refundTxAmountSat - ): - return [ - "type": "bitcoin", - "swapId": swapId, - "description": description, - "refundTxId": refundTxId == nil ? nil : refundTxId, - "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, - ] - } - } - - static func arrayOf(paymentDetailsList: [PaymentDetails]) -> [Any] { - return paymentDetailsList.map { v -> [String: Any?] in return dictionaryOf(paymentDetails: v) } - } - - static func asPaymentDetailsList(arr: [Any]) throws -> [PaymentDetails] { - var list = [PaymentDetails]() - for value in arr { - if let val = value as? [String: Any?] { - var paymentDetails = try asPaymentDetails(paymentDetails: val) - list.append(paymentDetails) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentDetails")) - } - } - return list } + return list +} - static func asPaymentMethod(paymentMethod: String) throws -> PaymentMethod { - switch paymentMethod { - case "lightning": - return PaymentMethod.lightning +static func asPaymentMethod(paymentMethod: String) throws -> PaymentMethod { + switch(paymentMethod) { - case "bitcoinAddress": - return PaymentMethod.bitcoinAddress + case "lightning": + return PaymentMethod.lightning - case "liquidAddress": - return PaymentMethod.liquidAddress + case "bitcoinAddress": + return PaymentMethod.bitcoinAddress - default: throw SdkError.Generic(message: "Invalid variant \(paymentMethod) for enum PaymentMethod") - } + case "liquidAddress": + return PaymentMethod.liquidAddress + + default: throw SdkError.Generic(message: "Invalid variant \(paymentMethod) for enum PaymentMethod") } +} - static func valueOf(paymentMethod: PaymentMethod) -> String { - switch paymentMethod { - case .lightning: - return "lightning" +static func valueOf(paymentMethod: PaymentMethod) -> String { + switch(paymentMethod) { - case .bitcoinAddress: - return "bitcoinAddress" + case .lightning: + return "lightning" - case .liquidAddress: - return "liquidAddress" - } - } + case .bitcoinAddress: + return "bitcoinAddress" - static func arrayOf(paymentMethodList: [PaymentMethod]) -> [String] { - return paymentMethodList.map { v -> String in return valueOf(paymentMethod: v) } + case .liquidAddress: + return "liquidAddress" + } +} - static func asPaymentMethodList(arr: [Any]) throws -> [PaymentMethod] { - var list = [PaymentMethod]() - for value in arr { - if let val = value as? String { - var paymentMethod = try asPaymentMethod(paymentMethod: val) - list.append(paymentMethod) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentMethod")) - } +static func arrayOf(`paymentMethodList`: [PaymentMethod]) -> [String] { + return `paymentMethodList`.map { (v) -> String in return valueOf(paymentMethod: v) } +} + +static func asPaymentMethodList(arr: [Any]) throws -> [PaymentMethod] { + var list = [PaymentMethod]() + for value in arr { + if let val = value as? String { + var paymentMethod = try asPaymentMethod(paymentMethod: val) + list.append(paymentMethod) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentMethod")) } - return list } + return list +} - static func asPaymentState(paymentState: String) throws -> PaymentState { - switch paymentState { - case "created": - return PaymentState.created +static func asPaymentState(paymentState: String) throws -> PaymentState { + switch(paymentState) { - case "pending": - return PaymentState.pending + case "created": + return PaymentState.created - case "complete": - return PaymentState.complete + case "pending": + return PaymentState.pending - case "failed": - return PaymentState.failed + case "complete": + return PaymentState.complete - case "timedOut": - return PaymentState.timedOut + case "failed": + return PaymentState.failed - case "refundable": - return PaymentState.refundable + case "timedOut": + return PaymentState.timedOut - case "refundPending": - return PaymentState.refundPending + case "refundable": + return PaymentState.refundable - default: throw SdkError.Generic(message: "Invalid variant \(paymentState) for enum PaymentState") - } + case "refundPending": + return PaymentState.refundPending + + default: throw SdkError.Generic(message: "Invalid variant \(paymentState) for enum PaymentState") } +} - static func valueOf(paymentState: PaymentState) -> String { - switch paymentState { - case .created: - return "created" +static func valueOf(paymentState: PaymentState) -> String { + switch(paymentState) { - case .pending: - return "pending" + case .created: + return "created" - case .complete: - return "complete" + case .pending: + return "pending" - case .failed: - return "failed" + case .complete: + return "complete" - case .timedOut: - return "timedOut" + case .failed: + return "failed" - case .refundable: - return "refundable" + case .timedOut: + return "timedOut" - case .refundPending: - return "refundPending" - } - } + case .refundable: + return "refundable" - static func arrayOf(paymentStateList: [PaymentState]) -> [String] { - return paymentStateList.map { v -> String in return valueOf(paymentState: v) } + case .refundPending: + return "refundPending" + } +} - static func asPaymentStateList(arr: [Any]) throws -> [PaymentState] { - var list = [PaymentState]() - for value in arr { - if let val = value as? String { - var paymentState = try asPaymentState(paymentState: val) - list.append(paymentState) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentState")) - } +static func arrayOf(`paymentStateList`: [PaymentState]) -> [String] { + return `paymentStateList`.map { (v) -> String in return valueOf(paymentState: v) } +} + +static func asPaymentStateList(arr: [Any]) throws -> [PaymentState] { + var list = [PaymentState]() + for value in arr { + if let val = value as? String { + var paymentState = try asPaymentState(paymentState: val) + list.append(paymentState) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentState")) } - return list } + return list +} - static func asPaymentType(paymentType: String) throws -> PaymentType { - switch paymentType { - case "receive": - return PaymentType.receive +static func asPaymentType(paymentType: String) throws -> PaymentType { + switch(paymentType) { - case "send": - return PaymentType.send + case "receive": + return PaymentType.receive - default: throw SdkError.Generic(message: "Invalid variant \(paymentType) for enum PaymentType") - } + case "send": + return PaymentType.send + + default: throw SdkError.Generic(message: "Invalid variant \(paymentType) for enum PaymentType") } +} - static func valueOf(paymentType: PaymentType) -> String { - switch paymentType { - case .receive: - return "receive" +static func valueOf(paymentType: PaymentType) -> String { + switch(paymentType) { - case .send: - return "send" - } - } + case .receive: + return "receive" - static func arrayOf(paymentTypeList: [PaymentType]) -> [String] { - return paymentTypeList.map { v -> String in return valueOf(paymentType: v) } + case .send: + return "send" + } +} - static func asPaymentTypeList(arr: [Any]) throws -> [PaymentType] { - var list = [PaymentType]() - for value in arr { - if let val = value as? String { - var paymentType = try asPaymentType(paymentType: val) - list.append(paymentType) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentType")) - } +static func arrayOf(`paymentTypeList`: [PaymentType]) -> [String] { + return `paymentTypeList`.map { (v) -> String in return valueOf(paymentType: v) } +} + +static func asPaymentTypeList(arr: [Any]) throws -> [PaymentType] { + var list = [PaymentType]() + for value in arr { + if let val = value as? String { + var paymentType = try asPaymentType(paymentType: val) + list.append(paymentType) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentType")) } - return list } + return list +} - static func asSdkEvent(sdkEvent: [String: Any?]) throws -> SdkEvent { - let type = sdkEvent["type"] as! String - if type == "paymentFailed" { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } +static func asSdkEvent(sdkEvent: [String: Any?]) throws -> SdkEvent { + let type = sdkEvent["type"] as! String + if (type == "paymentFailed") { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentFailed(details: _details) + + return SdkEvent.paymentFailed(details: _details) } - if type == "paymentPending" { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if (type == "paymentPending") { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentPending(details: _details) + + return SdkEvent.paymentPending(details: _details) } - if type == "paymentRefunded" { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if (type == "paymentRefunded") { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentRefunded(details: _details) + + return SdkEvent.paymentRefunded(details: _details) } - if type == "paymentRefundPending" { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if (type == "paymentRefundPending") { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentRefundPending(details: _details) + + return SdkEvent.paymentRefundPending(details: _details) } - if type == "paymentSucceeded" { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if (type == "paymentSucceeded") { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentSucceeded(details: _details) + + return SdkEvent.paymentSucceeded(details: _details) } - if type == "paymentWaitingConfirmation" { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if (type == "paymentWaitingConfirmation") { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) + + return SdkEvent.paymentWaitingConfirmation(details: _details) + } + if (type == "synced") { + return SdkEvent.synced + } - return SdkEvent.paymentWaitingConfirmation(details: _details) - } - if type == "synced" { - return SdkEvent.synced - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum SdkEvent") - } - - static func dictionaryOf(sdkEvent: SdkEvent) -> [String: Any?] { - switch sdkEvent { - case let .paymentFailed( - details - ): - return [ - "type": "paymentFailed", - "details": dictionaryOf(payment: details), - ] - - case let .paymentPending( - details - ): - return [ - "type": "paymentPending", - "details": dictionaryOf(payment: details), - ] - - case let .paymentRefunded( - details - ): - return [ - "type": "paymentRefunded", - "details": dictionaryOf(payment: details), - ] - - case let .paymentRefundPending( - details - ): - return [ - "type": "paymentRefundPending", - "details": dictionaryOf(payment: details), - ] - - case let .paymentSucceeded( - details - ): - return [ - "type": "paymentSucceeded", - "details": dictionaryOf(payment: details), - ] - - case let .paymentWaitingConfirmation( - details - ): - return [ - "type": "paymentWaitingConfirmation", - "details": dictionaryOf(payment: details), - ] - - case .synced: - return [ - "type": "synced", - ] - } - } - - static func arrayOf(sdkEventList: [SdkEvent]) -> [Any] { - return sdkEventList.map { v -> [String: Any?] in return dictionaryOf(sdkEvent: v) } - } - - static func asSdkEventList(arr: [Any]) throws -> [SdkEvent] { - var list = [SdkEvent]() - for value in arr { - if let val = value as? [String: Any?] { - var sdkEvent = try asSdkEvent(sdkEvent: val) - list.append(sdkEvent) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SdkEvent")) - } + throw SdkError.Generic(message: "Unexpected type \(type) for enum SdkEvent") +} + +static func dictionaryOf(sdkEvent: SdkEvent) -> [String: Any?] { + switch (sdkEvent) { + + case let .paymentFailed( + details + ): + return [ + "type": "paymentFailed", + "details": dictionaryOf(payment: details), + ] + + case let .paymentPending( + details + ): + return [ + "type": "paymentPending", + "details": dictionaryOf(payment: details), + ] + + case let .paymentRefunded( + details + ): + return [ + "type": "paymentRefunded", + "details": dictionaryOf(payment: details), + ] + + case let .paymentRefundPending( + details + ): + return [ + "type": "paymentRefundPending", + "details": dictionaryOf(payment: details), + ] + + case let .paymentSucceeded( + details + ): + return [ + "type": "paymentSucceeded", + "details": dictionaryOf(payment: details), + ] + + case let .paymentWaitingConfirmation( + details + ): + return [ + "type": "paymentWaitingConfirmation", + "details": dictionaryOf(payment: details), + ] + + case .synced: + return [ + "type": "synced", + ] + } +} + +static func arrayOf(`sdkEventList`: [SdkEvent]) -> [Any] { + return `sdkEventList`.map { (v) -> [String: Any?] in return dictionaryOf(sdkEvent: v) } +} + +static func asSdkEventList(arr: [Any]) throws -> [SdkEvent] { + var list = [SdkEvent]() + for value in arr { + if let val = value as? [String: Any?] { + var sdkEvent = try asSdkEvent(sdkEvent: val) + list.append(sdkEvent) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SdkEvent")) } - return list } + return list +} - static func asSendDestination(sendDestination: [String: Any?]) throws -> SendDestination { - let type = sendDestination["type"] as! String - if type == "liquidAddress" { - guard let addressDataTmp = sendDestination["addressData"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "addressData", typeName: "SendDestination")) - } +static func asSendDestination(sendDestination: [String: Any?]) throws -> SendDestination { + let type = sendDestination["type"] as! String + if (type == "liquidAddress") { + guard let addressDataTmp = sendDestination["addressData"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "addressData", typeName: "SendDestination")) + } let _addressData = try asLiquidAddressData(liquidAddressData: addressDataTmp) - - return SendDestination.liquidAddress(addressData: _addressData) + + return SendDestination.liquidAddress(addressData: _addressData) } - if type == "bolt11" { - guard let invoiceTmp = sendDestination["invoice"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "SendDestination")) - } + if (type == "bolt11") { + guard let invoiceTmp = sendDestination["invoice"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "SendDestination")) + } let _invoice = try asLnInvoice(lnInvoice: invoiceTmp) + + return SendDestination.bolt11(invoice: _invoice) + } - return SendDestination.bolt11(invoice: _invoice) - } + throw SdkError.Generic(message: "Unexpected type \(type) for enum SendDestination") +} - throw SdkError.Generic(message: "Unexpected type \(type) for enum SendDestination") - } +static func dictionaryOf(sendDestination: SendDestination) -> [String: Any?] { + switch (sendDestination) { + + case let .liquidAddress( + addressData + ): + return [ + "type": "liquidAddress", + "addressData": dictionaryOf(liquidAddressData: addressData), + ] + + case let .bolt11( + invoice + ): + return [ + "type": "bolt11", + "invoice": dictionaryOf(lnInvoice: invoice), + ] + } +} - static func dictionaryOf(sendDestination: SendDestination) -> [String: Any?] { - switch sendDestination { - case let .liquidAddress( - addressData - ): - return [ - "type": "liquidAddress", - "addressData": dictionaryOf(liquidAddressData: addressData), - ] +static func arrayOf(`sendDestinationList`: [SendDestination]) -> [Any] { + return `sendDestinationList`.map { (v) -> [String: Any?] in return dictionaryOf(sendDestination: v) } +} - case let .bolt11( - invoice - ): - return [ - "type": "bolt11", - "invoice": dictionaryOf(lnInvoice: invoice), - ] +static func asSendDestinationList(arr: [Any]) throws -> [SendDestination] { + var list = [SendDestination]() + for value in arr { + if let val = value as? [String: Any?] { + var sendDestination = try asSendDestination(sendDestination: val) + list.append(sendDestination) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SendDestination")) } } + return list +} - static func arrayOf(sendDestinationList: [SendDestination]) -> [Any] { - return sendDestinationList.map { v -> [String: Any?] in return dictionaryOf(sendDestination: v) } - } - - static func asSendDestinationList(arr: [Any]) throws -> [SendDestination] { - var list = [SendDestination]() - for value in arr { - if let val = value as? [String: Any?] { - var sendDestination = try asSendDestination(sendDestination: val) - list.append(sendDestination) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SendDestination")) - } - } - return list - } - - static func asSuccessAction(successAction: [String: Any?]) throws -> SuccessAction { - let type = successAction["type"] as! String - if type == "aes" { - guard let dataTmp = successAction["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) - } +static func asSuccessAction(successAction: [String: Any?]) throws -> SuccessAction { + let type = successAction["type"] as! String + if (type == "aes") { + guard let dataTmp = successAction["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) + } let _data = try asAesSuccessActionData(aesSuccessActionData: dataTmp) - - return SuccessAction.aes(data: _data) + + return SuccessAction.aes(data: _data) } - if type == "message" { - guard let dataTmp = successAction["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) - } + if (type == "message") { + guard let dataTmp = successAction["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) + } let _data = try asMessageSuccessActionData(messageSuccessActionData: dataTmp) - - return SuccessAction.message(data: _data) + + return SuccessAction.message(data: _data) } - if type == "url" { - guard let dataTmp = successAction["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) - } + if (type == "url") { + guard let dataTmp = successAction["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) + } let _data = try asUrlSuccessActionData(urlSuccessActionData: dataTmp) + + return SuccessAction.url(data: _data) + } - return SuccessAction.url(data: _data) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessAction") - } - - static func dictionaryOf(successAction: SuccessAction) -> [String: Any?] { - switch successAction { - case let .aes( - data - ): - return [ - "type": "aes", - "data": dictionaryOf(aesSuccessActionData: data), - ] - - case let .message( - data - ): - return [ - "type": "message", - "data": dictionaryOf(messageSuccessActionData: data), - ] + throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessAction") +} - case let .url( - data - ): - return [ - "type": "url", - "data": dictionaryOf(urlSuccessActionData: data), - ] - } - } +static func dictionaryOf(successAction: SuccessAction) -> [String: Any?] { + switch (successAction) { + + case let .aes( + data + ): + return [ + "type": "aes", + "data": dictionaryOf(aesSuccessActionData: data), + ] + + case let .message( + data + ): + return [ + "type": "message", + "data": dictionaryOf(messageSuccessActionData: data), + ] + + case let .url( + data + ): + return [ + "type": "url", + "data": dictionaryOf(urlSuccessActionData: data), + ] + } +} - static func arrayOf(successActionList: [SuccessAction]) -> [Any] { - return successActionList.map { v -> [String: Any?] in return dictionaryOf(successAction: v) } - } +static func arrayOf(`successActionList`: [SuccessAction]) -> [Any] { + return `successActionList`.map { (v) -> [String: Any?] in return dictionaryOf(successAction: v) } +} - static func asSuccessActionList(arr: [Any]) throws -> [SuccessAction] { - var list = [SuccessAction]() - for value in arr { - if let val = value as? [String: Any?] { - var successAction = try asSuccessAction(successAction: val) - list.append(successAction) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessAction")) - } +static func asSuccessActionList(arr: [Any]) throws -> [SuccessAction] { + var list = [SuccessAction]() + for value in arr { + if let val = value as? [String: Any?] { + var successAction = try asSuccessAction(successAction: val) + list.append(successAction) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessAction")) } - return list } + return list +} - static func asSuccessActionProcessed(successActionProcessed: [String: Any?]) throws -> SuccessActionProcessed { - let type = successActionProcessed["type"] as! String - if type == "aes" { - guard let resultTmp = successActionProcessed["result"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "result", typeName: "SuccessActionProcessed")) - } +static func asSuccessActionProcessed(successActionProcessed: [String: Any?]) throws -> SuccessActionProcessed { + let type = successActionProcessed["type"] as! String + if (type == "aes") { + guard let resultTmp = successActionProcessed["result"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "result", typeName: "SuccessActionProcessed")) + } let _result = try asAesSuccessActionDataResult(aesSuccessActionDataResult: resultTmp) - - return SuccessActionProcessed.aes(result: _result) + + return SuccessActionProcessed.aes(result: _result) } - if type == "message" { - guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) - } + if (type == "message") { + guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) + } let _data = try asMessageSuccessActionData(messageSuccessActionData: dataTmp) - - return SuccessActionProcessed.message(data: _data) + + return SuccessActionProcessed.message(data: _data) } - if type == "url" { - guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) - } + if (type == "url") { + guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) + } let _data = try asUrlSuccessActionData(urlSuccessActionData: dataTmp) + + return SuccessActionProcessed.url(data: _data) + } - return SuccessActionProcessed.url(data: _data) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessActionProcessed") - } - - static func dictionaryOf(successActionProcessed: SuccessActionProcessed) -> [String: Any?] { - switch successActionProcessed { - case let .aes( - result - ): - return [ - "type": "aes", - "result": dictionaryOf(aesSuccessActionDataResult: result), - ] - - case let .message( - data - ): - return [ - "type": "message", - "data": dictionaryOf(messageSuccessActionData: data), - ] + throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessActionProcessed") +} - case let .url( - data - ): - return [ - "type": "url", - "data": dictionaryOf(urlSuccessActionData: data), - ] - } - } +static func dictionaryOf(successActionProcessed: SuccessActionProcessed) -> [String: Any?] { + switch (successActionProcessed) { + + case let .aes( + result + ): + return [ + "type": "aes", + "result": dictionaryOf(aesSuccessActionDataResult: result), + ] + + case let .message( + data + ): + return [ + "type": "message", + "data": dictionaryOf(messageSuccessActionData: data), + ] + + case let .url( + data + ): + return [ + "type": "url", + "data": dictionaryOf(urlSuccessActionData: data), + ] + } +} - static func arrayOf(successActionProcessedList: [SuccessActionProcessed]) -> [Any] { - return successActionProcessedList.map { v -> [String: Any?] in return dictionaryOf(successActionProcessed: v) } - } +static func arrayOf(`successActionProcessedList`: [SuccessActionProcessed]) -> [Any] { + return `successActionProcessedList`.map { (v) -> [String: Any?] in return dictionaryOf(successActionProcessed: v) } +} - static func asSuccessActionProcessedList(arr: [Any]) throws -> [SuccessActionProcessed] { - var list = [SuccessActionProcessed]() - for value in arr { - if let val = value as? [String: Any?] { - var successActionProcessed = try asSuccessActionProcessed(successActionProcessed: val) - list.append(successActionProcessed) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessActionProcessed")) - } +static func asSuccessActionProcessedList(arr: [Any]) throws -> [SuccessActionProcessed] { + var list = [SuccessActionProcessed]() + for value in arr { + if let val = value as? [String: Any?] { + var successActionProcessed = try asSuccessActionProcessed(successActionProcessed: val) + list.append(successActionProcessed) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessActionProcessed")) } - return list } - + return list +} static func hasNonNilKey(data: [String: Any?], key: String) -> Bool { if let val = data[key] { return !(val == nil || val is NSNull) @@ -3980,4 +3980,5 @@ enum BreezSDKLiquidMapper { static func errUnexpectedValue(fieldName: String) -> String { return "Unexpected value for optional field \(fieldName)" } -} + +} \ No newline at end of file diff --git a/packages/react-native/ios/RNBreezSDKLiquid.swift b/packages/react-native/ios/RNBreezSDKLiquid.swift index 11b484f87..2422b614f 100644 --- a/packages/react-native/ios/RNBreezSDKLiquid.swift +++ b/packages/react-native/ios/RNBreezSDKLiquid.swift @@ -1,27 +1,28 @@ -import BreezSDKLiquid import Foundation +import BreezSDKLiquid @objc(RNBreezSDKLiquid) class RNBreezSDKLiquid: RCTEventEmitter { static let TAG: String = "BreezSDKLiquid" - + public static var emitter: RCTEventEmitter! public static var hasListeners: Bool = false public static var supportedEvents: [String] = ["breezSdkLiquidLog"] private var bindingLiquidSdk: BindingLiquidSdk! + static var breezSdkLiquidDirectory: URL { let applicationDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first! let breezSdkLiquidDirectory = applicationDirectory.appendingPathComponent("breezSdkLiquid", isDirectory: true) - + if !FileManager.default.fileExists(atPath: breezSdkLiquidDirectory.path) { try! FileManager.default.createDirectory(atPath: breezSdkLiquidDirectory.path, withIntermediateDirectories: true) } - + return breezSdkLiquidDirectory } - + override init() { super.init() RNBreezSDKLiquid.emitter = self @@ -35,32 +36,32 @@ class RNBreezSDKLiquid: RCTEventEmitter { static func addSupportedEvent(name: String) { RNBreezSDKLiquid.supportedEvents.append(name) } - + override func supportedEvents() -> [String]! { return RNBreezSDKLiquid.supportedEvents } - + override func startObserving() { RNBreezSDKLiquid.hasListeners = true } - + override func stopObserving() { RNBreezSDKLiquid.hasListeners = false } - + @objc override static func requiresMainQueueSetup() -> Bool { return false } - + func getBindingLiquidSdk() throws -> BindingLiquidSdk { if bindingLiquidSdk != nil { return bindingLiquidSdk } - + throw SdkError.Generic(message: "Not initialized") } - + private func ensureWorkingDir(workingDir: String) throws { do { if !FileManager.default.fileExists(atPath: workingDir) { @@ -71,41 +72,42 @@ class RNBreezSDKLiquid: RCTEventEmitter { } } + @objc(defaultConfig:breezApiKey:resolve:reject:) - func defaultConfig(_ network: String, breezApiKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func defaultConfig(_ network: String, breezApiKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let networkTmp = try BreezSDKLiquidMapper.asLiquidNetwork(liquidNetwork: network) let breezApiKeyTmp = breezApiKey.isEmpty ? nil : breezApiKey - var res = try BreezSDKLiquid.defaultConfig(network: networkTmp, breezApiKey: breezApiKeyTmp) + var res =try BreezSDKLiquid.defaultConfig(network: networkTmp, breezApiKey: breezApiKeyTmp) res.workingDir = RNBreezSDKLiquid.breezSdkLiquidDirectory.path resolve(BreezSDKLiquidMapper.dictionaryOf(config: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(parse:resolve:reject:) - func parse(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func parse(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try BreezSDKLiquid.parse(input: input) + var res =try BreezSDKLiquid.parse(input: input) resolve(BreezSDKLiquidMapper.dictionaryOf(inputType: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(parseInvoice:resolve:reject:) - func parseInvoice(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func parseInvoice(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try BreezSDKLiquid.parseInvoice(input: input) + var res =try BreezSDKLiquid.parseInvoice(input: input) resolve(BreezSDKLiquidMapper.dictionaryOf(lnInvoice: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(setLogger:reject:) - func setLogger(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func setLogger(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { try BreezSDKLiquid.setLogger(logger: BreezSDKLiquidLogger()) resolve(["status": "ok"]) @@ -115,7 +117,7 @@ class RNBreezSDKLiquid: RCTEventEmitter { } @objc(connect:resolve:reject:) - func connect(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func connect(_ req:[String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { if bindingLiquidSdk != nil { reject("Generic", "Already initialized", nil) return @@ -131,7 +133,7 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(addEventListener:reject:) func addEventListener(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { @@ -145,8 +147,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { } } + @objc(removeEventListener:resolve:reject:) - func removeEventListener(_ id: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func removeEventListener(_ id: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { try getBindingLiquidSdk().removeEventListener(id: id) resolve(["status": "ok"]) @@ -154,163 +157,163 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(getInfo:reject:) - func getInfo(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func getInfo(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try getBindingLiquidSdk().getInfo() + var res =try getBindingLiquidSdk().getInfo() resolve(BreezSDKLiquidMapper.dictionaryOf(getInfoResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(signMessage:resolve:reject:) - func signMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func signMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let signMessageRequest = try BreezSDKLiquidMapper.asSignMessageRequest(signMessageRequest: req) - var res = try getBindingLiquidSdk().signMessage(req: signMessageRequest) + var res =try getBindingLiquidSdk().signMessage(req: signMessageRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(signMessageResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(checkMessage:resolve:reject:) - func checkMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func checkMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let checkMessageRequest = try BreezSDKLiquidMapper.asCheckMessageRequest(checkMessageRequest: req) - var res = try getBindingLiquidSdk().checkMessage(req: checkMessageRequest) + var res =try getBindingLiquidSdk().checkMessage(req: checkMessageRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(checkMessageResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareSendPayment:resolve:reject:) - func prepareSendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func prepareSendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let prepareSendRequest = try BreezSDKLiquidMapper.asPrepareSendRequest(prepareSendRequest: req) - var res = try getBindingLiquidSdk().prepareSendPayment(req: prepareSendRequest) + var res =try getBindingLiquidSdk().prepareSendPayment(req: prepareSendRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareSendResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(sendPayment:resolve:reject:) - func sendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func sendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let sendPaymentRequest = try BreezSDKLiquidMapper.asSendPaymentRequest(sendPaymentRequest: req) - var res = try getBindingLiquidSdk().sendPayment(req: sendPaymentRequest) + var res =try getBindingLiquidSdk().sendPayment(req: sendPaymentRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(sendPaymentResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareReceivePayment:resolve:reject:) - func prepareReceivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func prepareReceivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let prepareReceiveRequest = try BreezSDKLiquidMapper.asPrepareReceiveRequest(prepareReceiveRequest: req) - var res = try getBindingLiquidSdk().prepareReceivePayment(req: prepareReceiveRequest) + var res =try getBindingLiquidSdk().prepareReceivePayment(req: prepareReceiveRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareReceiveResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(receivePayment:resolve:reject:) - func receivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func receivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let receivePaymentRequest = try BreezSDKLiquidMapper.asReceivePaymentRequest(receivePaymentRequest: req) - var res = try getBindingLiquidSdk().receivePayment(req: receivePaymentRequest) + var res =try getBindingLiquidSdk().receivePayment(req: receivePaymentRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(receivePaymentResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(fetchLightningLimits:reject:) - func fetchLightningLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func fetchLightningLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try getBindingLiquidSdk().fetchLightningLimits() + var res =try getBindingLiquidSdk().fetchLightningLimits() resolve(BreezSDKLiquidMapper.dictionaryOf(lightningPaymentLimitsResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(fetchOnchainLimits:reject:) - func fetchOnchainLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func fetchOnchainLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try getBindingLiquidSdk().fetchOnchainLimits() + var res =try getBindingLiquidSdk().fetchOnchainLimits() resolve(BreezSDKLiquidMapper.dictionaryOf(onchainPaymentLimitsResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(preparePayOnchain:resolve:reject:) - func preparePayOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func preparePayOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let preparePayOnchainRequest = try BreezSDKLiquidMapper.asPreparePayOnchainRequest(preparePayOnchainRequest: req) - var res = try getBindingLiquidSdk().preparePayOnchain(req: preparePayOnchainRequest) + var res =try getBindingLiquidSdk().preparePayOnchain(req: preparePayOnchainRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(preparePayOnchainResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(payOnchain:resolve:reject:) - func payOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func payOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let payOnchainRequest = try BreezSDKLiquidMapper.asPayOnchainRequest(payOnchainRequest: req) - var res = try getBindingLiquidSdk().payOnchain(req: payOnchainRequest) + var res =try getBindingLiquidSdk().payOnchain(req: payOnchainRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(sendPaymentResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareBuyBitcoin:resolve:reject:) - func prepareBuyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func prepareBuyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let prepareBuyBitcoinRequest = try BreezSDKLiquidMapper.asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: req) - var res = try getBindingLiquidSdk().prepareBuyBitcoin(req: prepareBuyBitcoinRequest) + var res =try getBindingLiquidSdk().prepareBuyBitcoin(req: prepareBuyBitcoinRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareBuyBitcoinResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(buyBitcoin:resolve:reject:) - func buyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func buyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let buyBitcoinRequest = try BreezSDKLiquidMapper.asBuyBitcoinRequest(buyBitcoinRequest: req) - var res = try getBindingLiquidSdk().buyBitcoin(req: buyBitcoinRequest) + var res =try getBindingLiquidSdk().buyBitcoin(req: buyBitcoinRequest) resolve(res) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(listPayments:resolve:reject:) - func listPayments(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func listPayments(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let listPaymentsRequest = try BreezSDKLiquidMapper.asListPaymentsRequest(listPaymentsRequest: req) - var res = try getBindingLiquidSdk().listPayments(req: listPaymentsRequest) + var res =try getBindingLiquidSdk().listPayments(req: listPaymentsRequest) resolve(BreezSDKLiquidMapper.arrayOf(paymentList: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(getPayment:resolve:reject:) - func getPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func getPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let reqTmp = try BreezSDKLiquidMapper.asGetPaymentRequest(getPaymentRequest: req) - var res = try getBindingLiquidSdk().getPayment(req: reqTmp) + var res =try getBindingLiquidSdk().getPayment(req: reqTmp) if res != nil { resolve(BreezSDKLiquidMapper.dictionaryOf(payment: res!)) } else { @@ -320,41 +323,41 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(listRefundables:reject:) - func listRefundables(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func listRefundables(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try getBindingLiquidSdk().listRefundables() + var res =try getBindingLiquidSdk().listRefundables() resolve(BreezSDKLiquidMapper.arrayOf(refundableSwapList: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareRefund:resolve:reject:) - func prepareRefund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func prepareRefund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let prepareRefundRequest = try BreezSDKLiquidMapper.asPrepareRefundRequest(prepareRefundRequest: req) - var res = try getBindingLiquidSdk().prepareRefund(req: prepareRefundRequest) + var res =try getBindingLiquidSdk().prepareRefund(req: prepareRefundRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareRefundResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(refund:resolve:reject:) - func refund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func refund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let refundRequest = try BreezSDKLiquidMapper.asRefundRequest(refundRequest: req) - var res = try getBindingLiquidSdk().refund(req: refundRequest) + var res =try getBindingLiquidSdk().refund(req: refundRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(refundResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(rescanOnchainSwaps:reject:) - func rescanOnchainSwaps(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func rescanOnchainSwaps(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { try getBindingLiquidSdk().rescanOnchainSwaps() resolve(["status": "ok"]) @@ -362,9 +365,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(sync:reject:) - func sync(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func sync(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { try getBindingLiquidSdk().sync() resolve(["status": "ok"]) @@ -372,19 +375,19 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(recommendedFees:reject:) - func recommendedFees(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func recommendedFees(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try getBindingLiquidSdk().recommendedFees() + var res =try getBindingLiquidSdk().recommendedFees() resolve(BreezSDKLiquidMapper.dictionaryOf(recommendedFees: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(backup:resolve:reject:) - func backup(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func backup(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let backupRequest = try BreezSDKLiquidMapper.asBackupRequest(backupRequest: req) try getBindingLiquidSdk().backup(req: backupRequest) @@ -393,9 +396,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(restore:resolve:reject:) - func restore(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func restore(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let restoreRequest = try BreezSDKLiquidMapper.asRestoreRequest(restoreRequest: req) try getBindingLiquidSdk().restore(req: restoreRequest) @@ -404,9 +407,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(disconnect:reject:) - func disconnect(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func disconnect(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { try getBindingLiquidSdk().disconnect() bindingLiquidSdk = nil @@ -415,53 +418,53 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(prepareLnurlPay:resolve:reject:) - func prepareLnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func prepareLnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let prepareLnUrlPayRequest = try BreezSDKLiquidMapper.asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: req) - var res = try getBindingLiquidSdk().prepareLnurlPay(req: prepareLnUrlPayRequest) + var res =try getBindingLiquidSdk().prepareLnurlPay(req: prepareLnUrlPayRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareLnUrlPayResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(lnurlPay:resolve:reject:) - func lnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func lnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let lnUrlPayRequest = try BreezSDKLiquidMapper.asLnUrlPayRequest(lnUrlPayRequest: req) - var res = try getBindingLiquidSdk().lnurlPay(req: lnUrlPayRequest) + var res =try getBindingLiquidSdk().lnurlPay(req: lnUrlPayRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(lnUrlPayResult: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(lnurlWithdraw:resolve:reject:) - func lnurlWithdraw(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func lnurlWithdraw(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let lnUrlWithdrawRequest = try BreezSDKLiquidMapper.asLnUrlWithdrawRequest(lnUrlWithdrawRequest: req) - var res = try getBindingLiquidSdk().lnurlWithdraw(req: lnUrlWithdrawRequest) + var res =try getBindingLiquidSdk().lnurlWithdraw(req: lnUrlWithdrawRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(lnUrlWithdrawResult: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(lnurlAuth:resolve:reject:) - func lnurlAuth(_ reqData: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func lnurlAuth(_ reqData: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { let lnUrlAuthRequestData = try BreezSDKLiquidMapper.asLnUrlAuthRequestData(lnUrlAuthRequestData: reqData) - var res = try getBindingLiquidSdk().lnurlAuth(reqData: lnUrlAuthRequestData) + var res =try getBindingLiquidSdk().lnurlAuth(reqData: lnUrlAuthRequestData) resolve(BreezSDKLiquidMapper.dictionaryOf(lnUrlCallbackStatus: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(registerWebhook:resolve:reject:) - func registerWebhook(_ webhookUrl: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func registerWebhook(_ webhookUrl: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { try getBindingLiquidSdk().registerWebhook(webhookUrl: webhookUrl) resolve(["status": "ok"]) @@ -469,9 +472,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(unregisterWebhook:reject:) - func unregisterWebhook(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func unregisterWebhook(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { try getBindingLiquidSdk().unregisterWebhook() resolve(["status": "ok"]) @@ -479,27 +482,28 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(fetchFiatRates:reject:) - func fetchFiatRates(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func fetchFiatRates(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try getBindingLiquidSdk().fetchFiatRates() + var res =try getBindingLiquidSdk().fetchFiatRates() resolve(BreezSDKLiquidMapper.arrayOf(rateList: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(listFiatCurrencies:reject:) - func listFiatCurrencies(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { + func listFiatCurrencies(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { do { - var res = try getBindingLiquidSdk().listFiatCurrencies() + var res =try getBindingLiquidSdk().listFiatCurrencies() resolve(BreezSDKLiquidMapper.arrayOf(fiatCurrencyList: res)) } catch let err { rejectErr(err: err, reject: reject) } } + func rejectErr(err: Error, reject: @escaping RCTPromiseRejectBlock) { var errorName = "Generic" var message = "\(err)" @@ -512,3 +516,4 @@ class RNBreezSDKLiquid: RCTEventEmitter { reject(errorName, message, err) } } + diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index dac70d1d1..387da05d0 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -19,22 +19,22 @@ const BreezSDKLiquid = NativeModules.RNBreezSDKLiquid const BreezSDKLiquidEmitter = new NativeEventEmitter(BreezSDKLiquid) -export interface AesSuccessActionData { +export type AesSuccessActionData = { description: string ciphertext: string iv: string } -export interface AesSuccessActionDataDecrypted { +export type AesSuccessActionDataDecrypted = { description: string plaintext: string } -export interface BackupRequest { +export type BackupRequest = { backupPath?: string } -export interface BitcoinAddressData { +export type BitcoinAddressData = { address: string network: Network amountSat?: number @@ -42,22 +42,22 @@ export interface BitcoinAddressData { message?: string } -export interface BuyBitcoinRequest { +export type BuyBitcoinRequest = { prepareResponse: PrepareBuyBitcoinResponse redirectUrl?: string } -export interface CheckMessageRequest { +export type CheckMessageRequest = { message: string pubkey: string signature: string } -export interface CheckMessageResponse { +export type CheckMessageResponse = { isValid: boolean } -export interface Config { +export type Config = { liquidElectrumUrl: string bitcoinElectrumUrl: string mempoolspaceUrl: string @@ -69,16 +69,16 @@ export interface Config { zeroConfMaxAmountSat?: number } -export interface ConnectRequest { +export type ConnectRequest = { config: Config mnemonic: string } -export interface ConnectWithSignerRequest { +export type ConnectWithSignerRequest = { config: Config } -export interface CurrencyInfo { +export type CurrencyInfo = { name: string fractionSize: number spacing?: number @@ -88,12 +88,12 @@ export interface CurrencyInfo { localeOverrides: LocaleOverrides[] } -export interface FiatCurrency { +export type FiatCurrency = { id: string info: CurrencyInfo } -export interface GetInfoResponse { +export type GetInfoResponse = { balanceSat: number pendingSendSat: number pendingReceiveSat: number @@ -101,7 +101,7 @@ export interface GetInfoResponse { pubkey: string } -export interface LnInvoice { +export type LnInvoice = { bolt11: string network: Network payeePubkey: string @@ -116,18 +116,18 @@ export interface LnInvoice { minFinalCltvExpiryDelta: number } -export interface LightningPaymentLimitsResponse { +export type LightningPaymentLimitsResponse = { send: Limits receive: Limits } -export interface Limits { +export type Limits = { minSat: number maxSat: number maxZeroConfSat: number } -export interface LiquidAddressData { +export type LiquidAddressData = { address: string network: Network assetId?: string @@ -136,7 +136,7 @@ export interface LiquidAddressData { message?: string } -export interface ListPaymentsRequest { +export type ListPaymentsRequest = { filters?: PaymentType[] fromTimestamp?: number toTimestamp?: number @@ -145,27 +145,27 @@ export interface ListPaymentsRequest { details?: ListPaymentDetails } -export interface LnUrlAuthRequestData { +export type LnUrlAuthRequestData = { k1: string domain: string url: string action?: string } -export interface LnUrlErrorData { +export type LnUrlErrorData = { reason: string } -export interface LnUrlPayErrorData { +export type LnUrlPayErrorData = { paymentHash: string reason: string } -export interface LnUrlPayRequest { +export type LnUrlPayRequest = { prepareResponse: PrepareLnUrlPayResponse } -export interface LnUrlPayRequestData { +export type LnUrlPayRequestData = { callback: string minSendable: number maxSendable: number @@ -177,18 +177,18 @@ export interface LnUrlPayRequestData { lnAddress?: string } -export interface LnUrlPaySuccessData { +export type LnUrlPaySuccessData = { successAction?: SuccessActionProcessed payment: Payment } -export interface LnUrlWithdrawRequest { +export type LnUrlWithdrawRequest = { data: LnUrlWithdrawRequestData amountMsat: number description?: string } -export interface LnUrlWithdrawRequestData { +export type LnUrlWithdrawRequestData = { callback: string k1: string defaultDescription: string @@ -196,41 +196,41 @@ export interface LnUrlWithdrawRequestData { maxWithdrawable: number } -export interface LnUrlWithdrawSuccessData { +export type LnUrlWithdrawSuccessData = { invoice: LnInvoice } -export interface LocaleOverrides { +export type LocaleOverrides = { locale: string spacing?: number symbol: SymbolType } -export interface LocalizedName { +export type LocalizedName = { locale: string name: string } -export interface LogEntry { +export type LogEntry = { line: string level: string } -export interface MessageSuccessActionData { +export type MessageSuccessActionData = { message: string } -export interface OnchainPaymentLimitsResponse { +export type OnchainPaymentLimitsResponse = { send: Limits receive: Limits } -export interface PayOnchainRequest { +export type PayOnchainRequest = { address: string prepareResponse: PreparePayOnchainResponse } -export interface Payment { +export type Payment = { timestamp: number amountSat: number feesSat: number @@ -241,90 +241,92 @@ export interface Payment { txId?: string } -export interface PrepareBuyBitcoinRequest { +export type PrepareBuyBitcoinRequest = { provider: BuyBitcoinProvider amountSat: number } -export interface PrepareBuyBitcoinResponse { +export type PrepareBuyBitcoinResponse = { provider: BuyBitcoinProvider amountSat: number feesSat: number } -export interface PrepareLnUrlPayRequest { +export type PrepareLnUrlPayRequest = { data: LnUrlPayRequestData amountMsat: number comment?: string validateSuccessActionUrl?: boolean } -export interface PrepareLnUrlPayResponse { +export type PrepareLnUrlPayResponse = { destination: SendDestination feesSat: number successAction?: SuccessAction } -export interface PreparePayOnchainRequest { +export type PreparePayOnchainRequest = { amount: PayOnchainAmount feeRateSatPerVbyte?: number } -export interface PreparePayOnchainResponse { +export type PreparePayOnchainResponse = { receiverAmountSat: number claimFeesSat: number totalFeesSat: number } -export interface PrepareReceiveRequest { +export type PrepareReceiveRequest = { paymentMethod: PaymentMethod payerAmountSat?: number } -export interface PrepareReceiveResponse { - payerAmountSat?: number +export type PrepareReceiveResponse = { paymentMethod: PaymentMethod feesSat: number + payerAmountSat?: number + minPayerAmountSat?: number + maxPayerAmountSat?: number } -export interface PrepareRefundRequest { +export type PrepareRefundRequest = { swapAddress: string refundAddress: string feeRateSatPerVbyte: number } -export interface PrepareRefundResponse { +export type PrepareRefundResponse = { txVsize: number txFeeSat: number refundTxId?: string } -export interface PrepareSendRequest { +export type PrepareSendRequest = { destination: string amountSat?: number } -export interface PrepareSendResponse { +export type PrepareSendResponse = { destination: SendDestination feesSat: number } -export interface Rate { +export type Rate = { coin: string value: number } -export interface ReceivePaymentRequest { +export type ReceivePaymentRequest = { prepareResponse: PrepareReceiveResponse description?: string useDescriptionHash?: boolean } -export interface ReceivePaymentResponse { +export type ReceivePaymentResponse = { destination: string } -export interface RecommendedFees { +export type RecommendedFees = { fastestFee: number halfHourFee: number hourFee: number @@ -332,31 +334,31 @@ export interface RecommendedFees { minimumFee: number } -export interface RefundRequest { +export type RefundRequest = { swapAddress: string refundAddress: string feeRateSatPerVbyte: number } -export interface RefundResponse { +export type RefundResponse = { refundTxId: string } -export interface RefundableSwap { +export type RefundableSwap = { swapAddress: string timestamp: number amountSat: number } -export interface RestoreRequest { +export type RestoreRequest = { backupPath?: string } -export interface RouteHint { +export type RouteHint = { hops: RouteHintHop[] } -export interface RouteHintHop { +export type RouteHintHop = { srcNodeId: string shortChannelId: string feesBaseMsat: number @@ -366,30 +368,30 @@ export interface RouteHintHop { htlcMaximumMsat?: number } -export interface SendPaymentRequest { +export type SendPaymentRequest = { prepareResponse: PrepareSendResponse } -export interface SendPaymentResponse { +export type SendPaymentResponse = { payment: Payment } -export interface SignMessageRequest { +export type SignMessageRequest = { message: string } -export interface SignMessageResponse { +export type SignMessageResponse = { signature: string } -export interface SymbolType { +export type SymbolType = { grapheme?: string template?: string rtl?: boolean position?: number } -export interface UrlSuccessActionData { +export type UrlSuccessActionData = { description: string url: string matchesCallbackDomain: boolean @@ -416,7 +418,7 @@ export enum GetPaymentRequestVariant { LIGHTNING = "lightning" } -export interface GetPaymentRequest { +export type GetPaymentRequest = { type: GetPaymentRequestVariant.LIGHTNING, paymentHash: string } @@ -684,7 +686,7 @@ export const connect = async (req: ConnectRequest): Promise => { export const addEventListener = async (listener: EventListener): Promise => { const response = await BreezSDKLiquid.addEventListener() BreezSDKLiquidEmitter.addListener(`event-${response}`, listener) - + return response } From 92c403b592df0945c0bc15cc1f1153bff02f7bf1 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:33:10 +0100 Subject: [PATCH 03/22] prep-receive-payment: Add service feerate for zero-amount swaps --- cli/src/commands.rs | 11 ++- .../include/breez_sdk_liquid.h | 8 +- lib/bindings/src/breez_sdk_liquid.udl | 5 +- lib/core/src/frb_generated.rs | 77 +++++++++++++++---- lib/core/src/model.rs | 11 ++- lib/core/src/sdk.rs | 15 ++-- packages/dart/lib/src/frb_generated.dart | 67 +++++++++++++--- packages/dart/lib/src/frb_generated.io.dart | 57 +++++++++++++- packages/dart/lib/src/model.dart | 24 ++++-- .../breezsdkliquid/BreezSDKLiquidMapper.kt | 36 ++++++--- .../ios/BreezSDKLiquidMapper.swift | 34 ++++---- packages/react-native/src/index.ts | 5 +- 12 files changed, 276 insertions(+), 74 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 2d3422d84..c655df215 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -267,9 +267,14 @@ pub(crate) async fn handle_command( let confirmation_msg = match payer_amount_sat { Some(_) => format!("Fees: {fees} sat. Are the fees acceptable? (y/N)"), None => { - let min = prepare_response.min_payer_amount_sat.unwrap(); - let max = prepare_response.max_payer_amount_sat.unwrap(); - format!("Fees: {fees} sat. Sender should send between {min} sat - {max} sat. Are the fees acceptable? (y/N)") + let min = prepare_response.zero_amount_min_payer_amount_sat.unwrap(); + let max = prepare_response.zero_amount_max_payer_amount_sat.unwrap(); + let service_feerate = prepare_response.zero_amount_service_feerate.unwrap(); + format!( + "Fees: {fees} sat + {service_feerate}% of the sent amount. \ + Sender should send between {min} sat and {max} sat. \ + Are the fees acceptable? (y/N)" + ) } }; wait_confirmation!(confirmation_msg, "Payment receive halted"); diff --git a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h index a62868a61..9d846aa73 100644 --- a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h +++ b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h @@ -317,8 +317,9 @@ typedef struct wire_cst_prepare_receive_response { int32_t payment_method; uint64_t *payer_amount_sat; uint64_t fees_sat; - uint64_t *min_payer_amount_sat; - uint64_t *max_payer_amount_sat; + uint64_t *zero_amount_min_payer_amount_sat; + uint64_t *zero_amount_max_payer_amount_sat; + double *zero_amount_service_feerate; } wire_cst_prepare_receive_response; typedef struct wire_cst_receive_payment_request { @@ -1136,6 +1137,8 @@ struct wire_cst_check_message_request *frbgen_breez_liquid_cst_new_box_autoadd_c struct wire_cst_connect_request *frbgen_breez_liquid_cst_new_box_autoadd_connect_request(void); +double *frbgen_breez_liquid_cst_new_box_autoadd_f_64(double value); + struct wire_cst_get_payment_request *frbgen_breez_liquid_cst_new_box_autoadd_get_payment_request(void); int64_t *frbgen_breez_liquid_cst_new_box_autoadd_i_64(int64_t value); @@ -1239,6 +1242,7 @@ static int64_t dummy_method_to_enforce_bundling(void) { dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_buy_bitcoin_request); dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_check_message_request); dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_connect_request); + dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_f_64); dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_get_payment_request); dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_i_64); dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_liquid_address_data); diff --git a/lib/bindings/src/breez_sdk_liquid.udl b/lib/bindings/src/breez_sdk_liquid.udl index 227dfe4ee..bfa24cf70 100644 --- a/lib/bindings/src/breez_sdk_liquid.udl +++ b/lib/bindings/src/breez_sdk_liquid.udl @@ -410,8 +410,9 @@ dictionary PrepareReceiveResponse { PaymentMethod payment_method; u64 fees_sat; u64? payer_amount_sat; - u64? min_payer_amount_sat; - u64? max_payer_amount_sat; + u64? zero_amount_min_payer_amount_sat; + u64? zero_amount_max_payer_amount_sat; + f64? zero_amount_service_feerate; }; dictionary ReceivePaymentRequest { diff --git a/lib/core/src/frb_generated.rs b/lib/core/src/frb_generated.rs index f22d2275e..743d820bb 100644 --- a/lib/core/src/frb_generated.rs +++ b/lib/core/src/frb_generated.rs @@ -3158,6 +3158,17 @@ impl SseDecode for Option { } } +impl SseDecode for Option { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + if (::sse_decode(deserializer)) { + return Some(::sse_decode(deserializer)); + } else { + return None; + } + } +} + impl SseDecode for Option { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -3599,14 +3610,16 @@ impl SseDecode for crate::model::PrepareReceiveResponse { let mut var_paymentMethod = ::sse_decode(deserializer); let mut var_payerAmountSat = >::sse_decode(deserializer); let mut var_feesSat = ::sse_decode(deserializer); - let mut var_minPayerAmountSat = >::sse_decode(deserializer); - let mut var_maxPayerAmountSat = >::sse_decode(deserializer); + let mut var_zeroAmountMinPayerAmountSat = >::sse_decode(deserializer); + let mut var_zeroAmountMaxPayerAmountSat = >::sse_decode(deserializer); + let mut var_zeroAmountServiceFeerate = >::sse_decode(deserializer); return crate::model::PrepareReceiveResponse { payment_method: var_paymentMethod, payer_amount_sat: var_payerAmountSat, fees_sat: var_feesSat, - min_payer_amount_sat: var_minPayerAmountSat, - max_payer_amount_sat: var_maxPayerAmountSat, + zero_amount_min_payer_amount_sat: var_zeroAmountMinPayerAmountSat, + zero_amount_max_payer_amount_sat: var_zeroAmountMaxPayerAmountSat, + zero_amount_service_feerate: var_zeroAmountServiceFeerate, }; } } @@ -5576,8 +5589,15 @@ impl flutter_rust_bridge::IntoDart for crate::model::PrepareReceiveResponse { self.payment_method.into_into_dart().into_dart(), self.payer_amount_sat.into_into_dart().into_dart(), self.fees_sat.into_into_dart().into_dart(), - self.min_payer_amount_sat.into_into_dart().into_dart(), - self.max_payer_amount_sat.into_into_dart().into_dart(), + self.zero_amount_min_payer_amount_sat + .into_into_dart() + .into_dart(), + self.zero_amount_max_payer_amount_sat + .into_into_dart() + .into_dart(), + self.zero_amount_service_feerate + .into_into_dart() + .into_dart(), ] .into_dart() } @@ -6965,6 +6985,16 @@ impl SseEncode for Option { } } +impl SseEncode for Option { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.is_some(), serializer); + if let Some(value) = self { + ::sse_encode(value, serializer); + } + } +} + impl SseEncode for Option { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -7350,8 +7380,9 @@ impl SseEncode for crate::model::PrepareReceiveResponse { ::sse_encode(self.payment_method, serializer); >::sse_encode(self.payer_amount_sat, serializer); ::sse_encode(self.fees_sat, serializer); - >::sse_encode(self.min_payer_amount_sat, serializer); - >::sse_encode(self.max_payer_amount_sat, serializer); + >::sse_encode(self.zero_amount_min_payer_amount_sat, serializer); + >::sse_encode(self.zero_amount_max_payer_amount_sat, serializer); + >::sse_encode(self.zero_amount_service_feerate, serializer); } } @@ -7926,6 +7957,12 @@ mod io { CstDecode::::cst_decode(*wrap).into() } } + impl CstDecode for *mut f64 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> f64 { + unsafe { *flutter_rust_bridge::for_generated::box_from_leak_ptr(self) } + } + } impl CstDecode for *mut wire_cst_get_payment_request { // Codec=Cst (C-struct based), see doc to use other codecs fn cst_decode(self) -> crate::model::GetPaymentRequest { @@ -9122,8 +9159,13 @@ mod io { payment_method: self.payment_method.cst_decode(), payer_amount_sat: self.payer_amount_sat.cst_decode(), fees_sat: self.fees_sat.cst_decode(), - min_payer_amount_sat: self.min_payer_amount_sat.cst_decode(), - max_payer_amount_sat: self.max_payer_amount_sat.cst_decode(), + zero_amount_min_payer_amount_sat: self + .zero_amount_min_payer_amount_sat + .cst_decode(), + zero_amount_max_payer_amount_sat: self + .zero_amount_max_payer_amount_sat + .cst_decode(), + zero_amount_service_feerate: self.zero_amount_service_feerate.cst_decode(), } } } @@ -10219,8 +10261,9 @@ mod io { payment_method: Default::default(), payer_amount_sat: core::ptr::null_mut(), fees_sat: Default::default(), - min_payer_amount_sat: core::ptr::null_mut(), - max_payer_amount_sat: core::ptr::null_mut(), + zero_amount_min_payer_amount_sat: core::ptr::null_mut(), + zero_amount_max_payer_amount_sat: core::ptr::null_mut(), + zero_amount_service_feerate: core::ptr::null_mut(), } } } @@ -10995,6 +11038,11 @@ mod io { ) } + #[no_mangle] + pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_f_64(value: f64) -> *mut f64 { + flutter_rust_bridge::for_generated::new_leak_box_ptr(value) + } + #[no_mangle] pub extern "C" fn frbgen_breez_liquid_cst_new_box_autoadd_get_payment_request( ) -> *mut wire_cst_get_payment_request { @@ -12251,8 +12299,9 @@ mod io { payment_method: i32, payer_amount_sat: *mut u64, fees_sat: u64, - min_payer_amount_sat: *mut u64, - max_payer_amount_sat: *mut u64, + zero_amount_min_payer_amount_sat: *mut u64, + zero_amount_max_payer_amount_sat: *mut u64, + zero_amount_service_feerate: *mut f64, } #[repr(C)] #[derive(Clone, Copy)] diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index b69512ee4..53a0c1061 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -284,14 +284,21 @@ pub struct PrepareReceiveResponse { pub payment_method: PaymentMethod, pub payer_amount_sat: Option, pub fees_sat: u64, + /// The minimum amount the payer can send for this swap to succeed. /// /// Only applicable to Zero-Amount Receive Chain Swaps. - pub min_payer_amount_sat: Option, + pub zero_amount_min_payer_amount_sat: Option, + /// The maximum amount the payer can send for this swap to succeed. /// /// Only applicable to Zero-Amount Receive Chain Swaps. - pub max_payer_amount_sat: Option, + pub zero_amount_max_payer_amount_sat: Option, + + /// The percentage of the sent amount that will count towards the service fee. + /// + /// Only applicable to Zero-Amount Receive Chain Swaps. + pub zero_amount_service_feerate: Option, } /// An argument when calling [crate::sdk::LiquidSdk::receive_payment]. diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index db38df10d..7e203fcb7 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -1419,8 +1419,9 @@ impl LiquidSdk { ) -> Result { self.ensure_is_started().await?; - let mut min_payer_amount_sat = None; - let mut max_payer_amount_sat = None; + let mut zero_amount_min_payer_amount_sat = None; + let mut zero_amount_max_payer_amount_sat = None; + let mut zero_amount_service_feerate = None; let fees_sat; match req.payment_method { PaymentMethod::Lightning => { @@ -1456,8 +1457,9 @@ impl LiquidSdk { .unwrap_or_default(); if payer_amount_sat.is_none() { - min_payer_amount_sat = Some(pair.limits.minimal); - max_payer_amount_sat = Some(pair.limits.maximal); + zero_amount_min_payer_amount_sat = Some(pair.limits.minimal); + zero_amount_max_payer_amount_sat = Some(pair.limits.maximal); + zero_amount_service_feerate = Some(pair.fees.percentage); } fees_sat = service_fees_sat + claim_fees_sat + server_fees_sat; @@ -1474,8 +1476,9 @@ impl LiquidSdk { payer_amount_sat: req.payer_amount_sat, fees_sat, payment_method: req.payment_method.clone(), - min_payer_amount_sat, - max_payer_amount_sat, + zero_amount_min_payer_amount_sat, + zero_amount_max_payer_amount_sat, + zero_amount_service_feerate, }) } diff --git a/packages/dart/lib/src/frb_generated.dart b/packages/dart/lib/src/frb_generated.dart index 6848f40ba..1c7fa7b19 100644 --- a/packages/dart/lib/src/frb_generated.dart +++ b/packages/dart/lib/src/frb_generated.dart @@ -1387,6 +1387,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return dco_decode_connect_request(raw); } + @protected + double dco_decode_box_autoadd_f_64(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as double; + } + @protected GetPaymentRequest dco_decode_box_autoadd_get_payment_request(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -2293,6 +2299,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return raw == null ? null : dco_decode_box_autoadd_bool(raw); } + @protected + double? dco_decode_opt_box_autoadd_f_64(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw == null ? null : dco_decode_box_autoadd_f_64(raw); + } + @protected PlatformInt64? dco_decode_opt_box_autoadd_i_64(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -2597,13 +2609,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { PrepareReceiveResponse dco_decode_prepare_receive_response(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 5) throw Exception('unexpected arr length: expect 5 but see ${arr.length}'); + if (arr.length != 6) throw Exception('unexpected arr length: expect 6 but see ${arr.length}'); return PrepareReceiveResponse( paymentMethod: dco_decode_payment_method(arr[0]), payerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[1]), feesSat: dco_decode_u_64(arr[2]), - minPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[3]), - maxPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[4]), + zeroAmountMinPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[3]), + zeroAmountMaxPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[4]), + zeroAmountServiceFeerate: dco_decode_opt_box_autoadd_f_64(arr[5]), ); } @@ -3170,6 +3183,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return (sse_decode_connect_request(deserializer)); } + @protected + double sse_decode_box_autoadd_f_64(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return (sse_decode_f_64(deserializer)); + } + @protected GetPaymentRequest sse_decode_box_autoadd_get_payment_request(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -4101,6 +4120,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + double? sse_decode_opt_box_autoadd_f_64(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + if (sse_decode_bool(deserializer)) { + return (sse_decode_box_autoadd_f_64(deserializer)); + } else { + return null; + } + } + @protected PlatformInt64? sse_decode_opt_box_autoadd_i_64(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -4447,14 +4477,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_paymentMethod = sse_decode_payment_method(deserializer); var var_payerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); var var_feesSat = sse_decode_u_64(deserializer); - var var_minPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); - var var_maxPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); + var var_zeroAmountMinPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); + var var_zeroAmountMaxPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); + var var_zeroAmountServiceFeerate = sse_decode_opt_box_autoadd_f_64(deserializer); return PrepareReceiveResponse( paymentMethod: var_paymentMethod, payerAmountSat: var_payerAmountSat, feesSat: var_feesSat, - minPayerAmountSat: var_minPayerAmountSat, - maxPayerAmountSat: var_maxPayerAmountSat); + zeroAmountMinPayerAmountSat: var_zeroAmountMinPayerAmountSat, + zeroAmountMaxPayerAmountSat: var_zeroAmountMaxPayerAmountSat, + zeroAmountServiceFeerate: var_zeroAmountServiceFeerate); } @protected @@ -5071,6 +5103,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_connect_request(self, serializer); } + @protected + void sse_encode_box_autoadd_f_64(double self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_f_64(self, serializer); + } + @protected void sse_encode_box_autoadd_get_payment_request(GetPaymentRequest self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -5875,6 +5913,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } } + @protected + void sse_encode_opt_box_autoadd_f_64(double? self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + sse_encode_bool(self != null, serializer); + if (self != null) { + sse_encode_box_autoadd_f_64(self, serializer); + } + } + @protected void sse_encode_opt_box_autoadd_i_64(PlatformInt64? self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -6181,8 +6229,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_payment_method(self.paymentMethod, serializer); sse_encode_opt_box_autoadd_u_64(self.payerAmountSat, serializer); sse_encode_u_64(self.feesSat, serializer); - sse_encode_opt_box_autoadd_u_64(self.minPayerAmountSat, serializer); - sse_encode_opt_box_autoadd_u_64(self.maxPayerAmountSat, serializer); + sse_encode_opt_box_autoadd_u_64(self.zeroAmountMinPayerAmountSat, serializer); + sse_encode_opt_box_autoadd_u_64(self.zeroAmountMaxPayerAmountSat, serializer); + sse_encode_opt_box_autoadd_f_64(self.zeroAmountServiceFeerate, serializer); } @protected diff --git a/packages/dart/lib/src/frb_generated.io.dart b/packages/dart/lib/src/frb_generated.io.dart index b9ae06b6d..00d02a9fc 100644 --- a/packages/dart/lib/src/frb_generated.io.dart +++ b/packages/dart/lib/src/frb_generated.io.dart @@ -101,6 +101,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected ConnectRequest dco_decode_box_autoadd_connect_request(dynamic raw); + @protected + double dco_decode_box_autoadd_f_64(dynamic raw); + @protected GetPaymentRequest dco_decode_box_autoadd_get_payment_request(dynamic raw); @@ -371,6 +374,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected bool? dco_decode_opt_box_autoadd_bool(dynamic raw); + @protected + double? dco_decode_opt_box_autoadd_f_64(dynamic raw); + @protected PlatformInt64? dco_decode_opt_box_autoadd_i_64(dynamic raw); @@ -618,6 +624,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected ConnectRequest sse_decode_box_autoadd_connect_request(SseDeserializer deserializer); + @protected + double sse_decode_box_autoadd_f_64(SseDeserializer deserializer); + @protected GetPaymentRequest sse_decode_box_autoadd_get_payment_request(SseDeserializer deserializer); @@ -888,6 +897,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected bool? sse_decode_opt_box_autoadd_bool(SseDeserializer deserializer); + @protected + double? sse_decode_opt_box_autoadd_f_64(SseDeserializer deserializer); + @protected PlatformInt64? sse_decode_opt_box_autoadd_i_64(SseDeserializer deserializer); @@ -1175,6 +1187,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { return ptr; } + @protected + ffi.Pointer cst_encode_box_autoadd_f_64(double raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return wire.cst_new_box_autoadd_f_64(cst_encode_f_64(raw)); + } + @protected ffi.Pointer cst_encode_box_autoadd_get_payment_request( GetPaymentRequest raw) { @@ -1597,6 +1615,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { return raw == null ? ffi.nullptr : cst_encode_box_autoadd_bool(raw); } + @protected + ffi.Pointer cst_encode_opt_box_autoadd_f_64(double? raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw == null ? ffi.nullptr : cst_encode_box_autoadd_f_64(raw); + } + @protected ffi.Pointer cst_encode_opt_box_autoadd_i_64(PlatformInt64? raw) { // Codec=Cst (C-struct based), see doc to use other codecs @@ -2716,8 +2740,11 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { wireObj.payment_method = cst_encode_payment_method(apiObj.paymentMethod); wireObj.payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.payerAmountSat); wireObj.fees_sat = cst_encode_u_64(apiObj.feesSat); - wireObj.min_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.minPayerAmountSat); - wireObj.max_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.maxPayerAmountSat); + wireObj.zero_amount_min_payer_amount_sat = + cst_encode_opt_box_autoadd_u_64(apiObj.zeroAmountMinPayerAmountSat); + wireObj.zero_amount_max_payer_amount_sat = + cst_encode_opt_box_autoadd_u_64(apiObj.zeroAmountMaxPayerAmountSat); + wireObj.zero_amount_service_feerate = cst_encode_opt_box_autoadd_f_64(apiObj.zeroAmountServiceFeerate); } @protected @@ -3117,6 +3144,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_box_autoadd_connect_request(ConnectRequest self, SseSerializer serializer); + @protected + void sse_encode_box_autoadd_f_64(double self, SseSerializer serializer); + @protected void sse_encode_box_autoadd_get_payment_request(GetPaymentRequest self, SseSerializer serializer); @@ -3395,6 +3425,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected void sse_encode_opt_box_autoadd_bool(bool? self, SseSerializer serializer); + @protected + void sse_encode_opt_box_autoadd_f_64(double? self, SseSerializer serializer); + @protected void sse_encode_opt_box_autoadd_i_64(PlatformInt64? self, SseSerializer serializer); @@ -4464,6 +4497,20 @@ class RustLibWire implements BaseWire { late final _cst_new_box_autoadd_connect_request = _cst_new_box_autoadd_connect_requestPtr.asFunction Function()>(); + ffi.Pointer cst_new_box_autoadd_f_64( + double value, + ) { + return _cst_new_box_autoadd_f_64( + value, + ); + } + + late final _cst_new_box_autoadd_f_64Ptr = + _lookup Function(ffi.Double)>>( + 'frbgen_breez_liquid_cst_new_box_autoadd_f_64'); + late final _cst_new_box_autoadd_f_64 = + _cst_new_box_autoadd_f_64Ptr.asFunction Function(double)>(); + ffi.Pointer cst_new_box_autoadd_get_payment_request() { return _cst_new_box_autoadd_get_payment_request(); } @@ -5402,9 +5449,11 @@ final class wire_cst_prepare_receive_response extends ffi.Struct { @ffi.Uint64() external int fees_sat; - external ffi.Pointer min_payer_amount_sat; + external ffi.Pointer zero_amount_min_payer_amount_sat; + + external ffi.Pointer zero_amount_max_payer_amount_sat; - external ffi.Pointer max_payer_amount_sat; + external ffi.Pointer zero_amount_service_feerate; } final class wire_cst_receive_payment_request extends ffi.Struct { diff --git a/packages/dart/lib/src/model.dart b/packages/dart/lib/src/model.dart index 9c6b6cd87..4c6d4229b 100644 --- a/packages/dart/lib/src/model.dart +++ b/packages/dart/lib/src/model.dart @@ -927,19 +927,25 @@ class PrepareReceiveResponse { /// The minimum amount the payer can send for this swap to succeed. /// /// Only applicable to Zero-Amount Receive Chain Swaps. - final BigInt? minPayerAmountSat; + final BigInt? zeroAmountMinPayerAmountSat; /// The maximum amount the payer can send for this swap to succeed. /// /// Only applicable to Zero-Amount Receive Chain Swaps. - final BigInt? maxPayerAmountSat; + final BigInt? zeroAmountMaxPayerAmountSat; + + /// The percentage of the sent amount that will count towards the service fee. + /// + /// Only applicable to Zero-Amount Receive Chain Swaps. + final double? zeroAmountServiceFeerate; const PrepareReceiveResponse({ required this.paymentMethod, this.payerAmountSat, required this.feesSat, - this.minPayerAmountSat, - this.maxPayerAmountSat, + this.zeroAmountMinPayerAmountSat, + this.zeroAmountMaxPayerAmountSat, + this.zeroAmountServiceFeerate, }); @override @@ -947,8 +953,9 @@ class PrepareReceiveResponse { paymentMethod.hashCode ^ payerAmountSat.hashCode ^ feesSat.hashCode ^ - minPayerAmountSat.hashCode ^ - maxPayerAmountSat.hashCode; + zeroAmountMinPayerAmountSat.hashCode ^ + zeroAmountMaxPayerAmountSat.hashCode ^ + zeroAmountServiceFeerate.hashCode; @override bool operator ==(Object other) => @@ -958,8 +965,9 @@ class PrepareReceiveResponse { paymentMethod == other.paymentMethod && payerAmountSat == other.payerAmountSat && feesSat == other.feesSat && - minPayerAmountSat == other.minPayerAmountSat && - maxPayerAmountSat == other.maxPayerAmountSat; + zeroAmountMinPayerAmountSat == other.zeroAmountMinPayerAmountSat && + zeroAmountMaxPayerAmountSat == other.zeroAmountMaxPayerAmountSat && + zeroAmountServiceFeerate == other.zeroAmountServiceFeerate; } /// An argument when calling [crate::sdk::LiquidSdk::prepare_refund]. diff --git a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt index 27bb19d83..b3ab01e80 100644 --- a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt +++ b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt @@ -1618,27 +1618,44 @@ fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiv } else { null } - val minPayerAmountSat = + val zeroAmountMinPayerAmountSat = if (hasNonNullKey( prepareReceiveResponse, - "minPayerAmountSat", + "zeroAmountMinPayerAmountSat", ) ) { - prepareReceiveResponse.getDouble("minPayerAmountSat").toULong() + prepareReceiveResponse.getDouble("zeroAmountMinPayerAmountSat").toULong() } else { null } - val maxPayerAmountSat = + val zeroAmountMaxPayerAmountSat = if (hasNonNullKey( prepareReceiveResponse, - "maxPayerAmountSat", + "zeroAmountMaxPayerAmountSat", ) ) { - prepareReceiveResponse.getDouble("maxPayerAmountSat").toULong() + prepareReceiveResponse.getDouble("zeroAmountMaxPayerAmountSat").toULong() } else { null } - return PrepareReceiveResponse(paymentMethod, feesSat, payerAmountSat, minPayerAmountSat, maxPayerAmountSat) + val zeroAmountServiceFeerate = + if (hasNonNullKey( + prepareReceiveResponse, + "zeroAmountServiceFeerate", + ) + ) { + prepareReceiveResponse.getDouble("zeroAmountServiceFeerate") + } else { + null + } + return PrepareReceiveResponse( + paymentMethod, + feesSat, + payerAmountSat, + zeroAmountMinPayerAmountSat, + zeroAmountMaxPayerAmountSat, + zeroAmountServiceFeerate, + ) } fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap = @@ -1646,8 +1663,9 @@ fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap = "paymentMethod" to prepareReceiveResponse.paymentMethod.name.lowercase(), "feesSat" to prepareReceiveResponse.feesSat, "payerAmountSat" to prepareReceiveResponse.payerAmountSat, - "minPayerAmountSat" to prepareReceiveResponse.minPayerAmountSat, - "maxPayerAmountSat" to prepareReceiveResponse.maxPayerAmountSat, + "zeroAmountMinPayerAmountSat" to prepareReceiveResponse.zeroAmountMinPayerAmountSat, + "zeroAmountMaxPayerAmountSat" to prepareReceiveResponse.zeroAmountMaxPayerAmountSat, + "zeroAmountServiceFeerate" to prepareReceiveResponse.zeroAmountServiceFeerate, ) fun asPrepareReceiveResponseList(arr: ReadableArray): List { diff --git a/packages/react-native/ios/BreezSDKLiquidMapper.swift b/packages/react-native/ios/BreezSDKLiquidMapper.swift index c01edec79..3c31c50f6 100644 --- a/packages/react-native/ios/BreezSDKLiquidMapper.swift +++ b/packages/react-native/ios/BreezSDKLiquidMapper.swift @@ -1832,22 +1832,29 @@ static func asPrepareReceiveResponse(prepareReceiveResponse: [String: Any?]) thr } payerAmountSat = payerAmountSatTmp } - var minPayerAmountSat: UInt64? - if hasNonNilKey(data: prepareReceiveResponse, key: "minPayerAmountSat") { - guard let minPayerAmountSatTmp = prepareReceiveResponse["minPayerAmountSat"] as? UInt64 else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "minPayerAmountSat")) + var zeroAmountMinPayerAmountSat: UInt64? + if hasNonNilKey(data: prepareReceiveResponse, key: "zeroAmountMinPayerAmountSat") { + guard let zeroAmountMinPayerAmountSatTmp = prepareReceiveResponse["zeroAmountMinPayerAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "zeroAmountMinPayerAmountSat")) } - minPayerAmountSat = minPayerAmountSatTmp + zeroAmountMinPayerAmountSat = zeroAmountMinPayerAmountSatTmp } - var maxPayerAmountSat: UInt64? - if hasNonNilKey(data: prepareReceiveResponse, key: "maxPayerAmountSat") { - guard let maxPayerAmountSatTmp = prepareReceiveResponse["maxPayerAmountSat"] as? UInt64 else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "maxPayerAmountSat")) + var zeroAmountMaxPayerAmountSat: UInt64? + if hasNonNilKey(data: prepareReceiveResponse, key: "zeroAmountMaxPayerAmountSat") { + guard let zeroAmountMaxPayerAmountSatTmp = prepareReceiveResponse["zeroAmountMaxPayerAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "zeroAmountMaxPayerAmountSat")) } - maxPayerAmountSat = maxPayerAmountSatTmp + zeroAmountMaxPayerAmountSat = zeroAmountMaxPayerAmountSatTmp + } + var zeroAmountServiceFeerate: Double? + if hasNonNilKey(data: prepareReceiveResponse, key: "zeroAmountServiceFeerate") { + guard let zeroAmountServiceFeerateTmp = prepareReceiveResponse["zeroAmountServiceFeerate"] as? Double else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "zeroAmountServiceFeerate")) + } + zeroAmountServiceFeerate = zeroAmountServiceFeerateTmp } - return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, minPayerAmountSat: minPayerAmountSat, maxPayerAmountSat: maxPayerAmountSat) + return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, zeroAmountMinPayerAmountSat: zeroAmountMinPayerAmountSat, zeroAmountMaxPayerAmountSat: zeroAmountMaxPayerAmountSat, zeroAmountServiceFeerate: zeroAmountServiceFeerate) } static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [String: Any?] { @@ -1855,8 +1862,9 @@ static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [St "paymentMethod": valueOf( paymentMethod: prepareReceiveResponse.paymentMethod), "feesSat": prepareReceiveResponse.feesSat, "payerAmountSat": prepareReceiveResponse.payerAmountSat == nil ? nil : prepareReceiveResponse.payerAmountSat, - "minPayerAmountSat": prepareReceiveResponse.minPayerAmountSat == nil ? nil : prepareReceiveResponse.minPayerAmountSat, - "maxPayerAmountSat": prepareReceiveResponse.maxPayerAmountSat == nil ? nil : prepareReceiveResponse.maxPayerAmountSat, + "zeroAmountMinPayerAmountSat": prepareReceiveResponse.zeroAmountMinPayerAmountSat == nil ? nil : prepareReceiveResponse.zeroAmountMinPayerAmountSat, + "zeroAmountMaxPayerAmountSat": prepareReceiveResponse.zeroAmountMaxPayerAmountSat == nil ? nil : prepareReceiveResponse.zeroAmountMaxPayerAmountSat, + "zeroAmountServiceFeerate": prepareReceiveResponse.zeroAmountServiceFeerate == nil ? nil : prepareReceiveResponse.zeroAmountServiceFeerate, ] } diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 387da05d0..6157c8407 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -285,8 +285,9 @@ export type PrepareReceiveResponse = { paymentMethod: PaymentMethod feesSat: number payerAmountSat?: number - minPayerAmountSat?: number - maxPayerAmountSat?: number + zeroAmountMinPayerAmountSat?: number + zeroAmountMaxPayerAmountSat?: number + zeroAmountServiceFeerate?: number } export type PrepareRefundRequest = { From c1a556b89f5fb28af43c04a1337940839219ab58 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:48:49 +0100 Subject: [PATCH 04/22] Get and accept quote to advance Zero-Amount Chain Swaps --- cli/Cargo.lock | 2 +- lib/Cargo.lock | 2 +- lib/core/Cargo.toml | 3 ++- lib/core/src/chain_swap.rs | 24 +++++++++++++++++++++++- lib/core/src/swapper/boltz/mod.rs | 18 ++++++++++++++++++ lib/core/src/swapper/mod.rs | 14 ++++++++++++++ 6 files changed, 59 insertions(+), 4 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 4d0b8f500..ec0d8e649 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -539,7 +539,7 @@ dependencies = [ [[package]] name = "boltz-client" version = "0.1.3" -source = "git+https://github.com/SatoshiPortal/boltz-rust?branch=trunk#8b8bddeb362b6d62ae92ed9a6cb759e1d0506a12" +source = "git+https://github.com/ok300/boltz-rust?branch=ok300-support-quote#8c832aa44a752bb752cfcb2bda6b70adfd744b1a" dependencies = [ "bip39", "bitcoin 0.31.2", diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 28dfd6c8a..da6f029aa 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -653,7 +653,7 @@ dependencies = [ [[package]] name = "boltz-client" version = "0.1.3" -source = "git+https://github.com/SatoshiPortal/boltz-rust?branch=trunk#8b8bddeb362b6d62ae92ed9a6cb759e1d0506a12" +source = "git+https://github.com/ok300/boltz-rust?branch=ok300-support-quote#8c832aa44a752bb752cfcb2bda6b70adfd744b1a" dependencies = [ "bip39", "bitcoin 0.31.2", diff --git a/lib/core/Cargo.toml b/lib/core/Cargo.toml index 9a9fb5add..24cf66391 100644 --- a/lib/core/Cargo.toml +++ b/lib/core/Cargo.toml @@ -14,7 +14,8 @@ frb = ["dep:flutter_rust_bridge"] [dependencies] anyhow = { workspace = true } bip39 = "2.0.0" -boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust", branch = "trunk" } +#boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust", branch = "trunk" } +boltz-client = { git = "https://github.com/ok300/boltz-rust", branch = "ok300-support-quote" } chrono = "0.4" env_logger = "0.11" flutter_rust_bridge = { version = "=2.4.0", features = [ diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index 9b4f87852..c8baf2917 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -367,6 +367,28 @@ impl ChainSwapHandler { | ChainSwapStates::TransactionLockupFailed | ChainSwapStates::TransactionRefunded | ChainSwapStates::SwapExpired => { + // Zero-amount Receive Chain Swaps also get to TransactionLockupFailed when user locks up funds + let is_zero_amount = swap.payer_amount_sat == 0; + if matches!(swap_state, ChainSwapStates::TransactionLockupFailed) && is_zero_amount + { + if let Err(e) = self + .swapper + .get_zero_amount_chain_swap_quote(&swap.id) + .map(|quote| quote.to_sat()) + .and_then(|quote| { + info!("Got quote of {quote} sat for swap {}", &swap.id); + + self.swapper + .accept_zero_amount_chain_swap_quote(&swap.id, quote) + }) + { + warn!("Failed to accept the quote for swap {}: {e:?}", &swap.id); + } + + // We successfully accepted the quote, the swap should continue as normal + return Ok(()); // Break from TxLockupFailed branch + } + match swap.refund_tx_id.clone() { None => { warn!("Chain Swap {id} is in an unrecoverable state: {swap_state:?}"); @@ -384,7 +406,7 @@ impl ChainSwapHandler { } } Some(refund_tx_id) => warn!( - "Refund tx for Chain Swap {id} was already broadcast: txid {refund_tx_id}" + "Refund for Chain Swap {id} was already broadcast: txid {refund_tx_id}" ), }; Ok(()) diff --git a/lib/core/src/swapper/boltz/mod.rs b/lib/core/src/swapper/boltz/mod.rs index 6ee15ac92..c9d69824c 100644 --- a/lib/core/src/swapper/boltz/mod.rs +++ b/lib/core/src/swapper/boltz/mod.rs @@ -8,6 +8,7 @@ use boltz_client::{ elements::secp256k1_zkp::{MusigPartialSignature, MusigPubNonce}, network::{electrum::ElectrumConfig, Chain}, util::secrets::Preimage, + Amount, }; use log::info; use url::Url; @@ -179,6 +180,23 @@ impl Swapper for BoltzSwapper { Ok((pair_outgoing, pair_incoming)) } + fn get_zero_amount_chain_swap_quote(&self, swap_id: &str) -> Result { + self.client + .get_quote(swap_id) + .map(|r| Amount::from_sat(r.amount)) + .map_err(Into::into) + } + + fn accept_zero_amount_chain_swap_quote( + &self, + swap_id: &str, + server_lockup_sat: u64, + ) -> Result<(), PaymentError> { + self.client + .accept_quote(swap_id, server_lockup_sat) + .map_err(Into::into) + } + /// Get a submarine pair information fn get_submarine_pairs(&self) -> Result, PaymentError> { Ok(self.client.get_submarine_pairs()?.get_lbtc_to_btc_pair()) diff --git a/lib/core/src/swapper/mod.rs b/lib/core/src/swapper/mod.rs index 499069410..4d8475856 100644 --- a/lib/core/src/swapper/mod.rs +++ b/lib/core/src/swapper/mod.rs @@ -8,6 +8,7 @@ use boltz_client::{ SubmarineClaimTxResponse, SubmarinePair, }, network::Chain, + Amount, }; use tokio::sync::{broadcast, watch}; @@ -40,6 +41,19 @@ pub trait Swapper: Send + Sync { /// Get the current rate, limits and fees for both swap directions fn get_chain_pairs(&self) -> Result<(Option, Option), PaymentError>; + /// Get the quote for a Zero-Amount Receive Chain Swap. + /// + /// If the user locked-up funds in the valid range this will return that amount. In all other + /// cases, this will return an error. + fn get_zero_amount_chain_swap_quote(&self, swap_id: &str) -> Result; + + /// Accept a specific quote for a Zero-Amount Receive Chain Swap + fn accept_zero_amount_chain_swap_quote( + &self, + swap_id: &str, + server_lockup_sat: u64, + ) -> Result<(), PaymentError>; + /// Get a submarine pair information fn get_submarine_pairs(&self) -> Result, PaymentError>; From 333c5c556f0b89a891b94b83bdbfff6eea6a0bb4 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:58:19 +0100 Subject: [PATCH 05/22] Fix tests --- lib/core/src/test_utils/swapper.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/core/src/test_utils/swapper.rs b/lib/core/src/test_utils/swapper.rs index 599039bed..515e6b7df 100644 --- a/lib/core/src/test_utils/swapper.rs +++ b/lib/core/src/test_utils/swapper.rs @@ -8,7 +8,7 @@ use boltz_client::{ SubmarinePair, SwapTree, }, util::secrets::Preimage, - PublicKey, + Amount, PublicKey, }; use sdk_common::invoice::parse_invoice; @@ -309,4 +309,16 @@ impl Swapper for MockSwapper { // Ok(Some(("".to_string(), 0.0))) unimplemented!() } + + fn get_zero_amount_chain_swap_quote(&self, swap_id: &str) -> Result { + unimplemented!() + } + + fn accept_zero_amount_chain_swap_quote( + &self, + _swap_id: &str, + _server_lockup_sat: u64, + ) -> Result<(), PaymentError> { + unimplemented!() + } } From 05483a5158c6f048c229a3609fc1bcfea9a9ba01 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:23:29 +0100 Subject: [PATCH 06/22] Re-generate flutter bindings --- ...utter_breez_liquid_bindings_generated.dart | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart index 46b986ea1..c6e3b1e83 100644 --- a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart +++ b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart @@ -928,6 +928,20 @@ class FlutterBreezLiquidBindings { _frbgen_breez_liquid_cst_new_box_autoadd_connect_requestPtr .asFunction Function()>(); + ffi.Pointer frbgen_breez_liquid_cst_new_box_autoadd_f_64( + double value, + ) { + return _frbgen_breez_liquid_cst_new_box_autoadd_f_64( + value, + ); + } + + late final _frbgen_breez_liquid_cst_new_box_autoadd_f_64Ptr = + _lookup Function(ffi.Double)>>( + 'frbgen_breez_liquid_cst_new_box_autoadd_f_64'); + late final _frbgen_breez_liquid_cst_new_box_autoadd_f_64 = + _frbgen_breez_liquid_cst_new_box_autoadd_f_64Ptr.asFunction Function(double)>(); + ffi.Pointer frbgen_breez_liquid_cst_new_box_autoadd_get_payment_request() { return _frbgen_breez_liquid_cst_new_box_autoadd_get_payment_request(); } @@ -4195,6 +4209,12 @@ final class wire_cst_prepare_receive_response extends ffi.Struct { @ffi.Uint64() external int fees_sat; + + external ffi.Pointer zero_amount_min_payer_amount_sat; + + external ffi.Pointer zero_amount_max_payer_amount_sat; + + external ffi.Pointer zero_amount_service_feerate; } final class wire_cst_receive_payment_request extends ffi.Struct { From 322972f2ea2429db1cfa160eb63c5d5a71bd92af Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:25:00 +0100 Subject: [PATCH 07/22] Re-generate RN bindings --- .../ios/BreezSDKLiquidMapper.swift | 5829 +++++++++-------- .../react-native/ios/RNBreezSDKLiquid.swift | 233 +- packages/react-native/src/index.ts | 128 +- 3 files changed, 3100 insertions(+), 3090 deletions(-) diff --git a/packages/react-native/ios/BreezSDKLiquidMapper.swift b/packages/react-native/ios/BreezSDKLiquidMapper.swift index 3c31c50f6..d2af4f19d 100644 --- a/packages/react-native/ios/BreezSDKLiquidMapper.swift +++ b/packages/react-native/ios/BreezSDKLiquidMapper.swift @@ -1,80 +1,82 @@ -import Foundation import BreezSDKLiquid +import Foundation enum BreezSDKLiquidMapper { -static func asAesSuccessActionData(aesSuccessActionData: [String: Any?]) throws -> AesSuccessActionData { - guard let description = aesSuccessActionData["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionData")) - } - guard let ciphertext = aesSuccessActionData["ciphertext"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "ciphertext", typeName: "AesSuccessActionData")) - } - guard let iv = aesSuccessActionData["iv"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "iv", typeName: "AesSuccessActionData")) + static func asAesSuccessActionData(aesSuccessActionData: [String: Any?]) throws -> AesSuccessActionData { + guard let description = aesSuccessActionData["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionData")) + } + guard let ciphertext = aesSuccessActionData["ciphertext"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "ciphertext", typeName: "AesSuccessActionData")) + } + guard let iv = aesSuccessActionData["iv"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "iv", typeName: "AesSuccessActionData")) + } + + return AesSuccessActionData(description: description, ciphertext: ciphertext, iv: iv) } - - return AesSuccessActionData(description: description, ciphertext: ciphertext, iv: iv) -} -static func dictionaryOf(aesSuccessActionData: AesSuccessActionData) -> [String: Any?] { - return [ + static func dictionaryOf(aesSuccessActionData: AesSuccessActionData) -> [String: Any?] { + return [ "description": aesSuccessActionData.description, "ciphertext": aesSuccessActionData.ciphertext, - "iv": aesSuccessActionData.iv, - ] -} + "iv": aesSuccessActionData.iv, + ] + } -static func asAesSuccessActionDataList(arr: [Any]) throws -> [AesSuccessActionData] { - var list = [AesSuccessActionData]() - for value in arr { - if let val = value as? [String: Any?] { - var aesSuccessActionData = try asAesSuccessActionData(aesSuccessActionData: val) - list.append(aesSuccessActionData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionData")) + static func asAesSuccessActionDataList(arr: [Any]) throws -> [AesSuccessActionData] { + var list = [AesSuccessActionData]() + for value in arr { + if let val = value as? [String: Any?] { + var aesSuccessActionData = try asAesSuccessActionData(aesSuccessActionData: val) + list.append(aesSuccessActionData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionData")) + } } + return list } - return list -} -static func arrayOf(`aesSuccessActionDataList`: [AesSuccessActionData]) -> [Any] { - return `aesSuccessActionDataList`.map { (v) -> [String: Any?] in return dictionaryOf(aesSuccessActionData: v) } -} -static func asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: [String: Any?]) throws -> AesSuccessActionDataDecrypted { - guard let description = aesSuccessActionDataDecrypted["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionDataDecrypted")) + static func arrayOf(aesSuccessActionDataList: [AesSuccessActionData]) -> [Any] { + return aesSuccessActionDataList.map { v -> [String: Any?] in return dictionaryOf(aesSuccessActionData: v) } } - guard let plaintext = aesSuccessActionDataDecrypted["plaintext"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "plaintext", typeName: "AesSuccessActionDataDecrypted")) + + static func asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: [String: Any?]) throws -> AesSuccessActionDataDecrypted { + guard let description = aesSuccessActionDataDecrypted["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "AesSuccessActionDataDecrypted")) + } + guard let plaintext = aesSuccessActionDataDecrypted["plaintext"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "plaintext", typeName: "AesSuccessActionDataDecrypted")) + } + + return AesSuccessActionDataDecrypted(description: description, plaintext: plaintext) } - - return AesSuccessActionDataDecrypted(description: description, plaintext: plaintext) -} -static func dictionaryOf(aesSuccessActionDataDecrypted: AesSuccessActionDataDecrypted) -> [String: Any?] { - return [ + static func dictionaryOf(aesSuccessActionDataDecrypted: AesSuccessActionDataDecrypted) -> [String: Any?] { + return [ "description": aesSuccessActionDataDecrypted.description, - "plaintext": aesSuccessActionDataDecrypted.plaintext, - ] -} + "plaintext": aesSuccessActionDataDecrypted.plaintext, + ] + } -static func asAesSuccessActionDataDecryptedList(arr: [Any]) throws -> [AesSuccessActionDataDecrypted] { - var list = [AesSuccessActionDataDecrypted]() - for value in arr { - if let val = value as? [String: Any?] { - var aesSuccessActionDataDecrypted = try asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: val) - list.append(aesSuccessActionDataDecrypted) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataDecrypted")) + static func asAesSuccessActionDataDecryptedList(arr: [Any]) throws -> [AesSuccessActionDataDecrypted] { + var list = [AesSuccessActionDataDecrypted]() + for value in arr { + if let val = value as? [String: Any?] { + var aesSuccessActionDataDecrypted = try asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: val) + list.append(aesSuccessActionDataDecrypted) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataDecrypted")) + } } + return list } - return list -} -static func arrayOf(`aesSuccessActionDataDecryptedList`: [AesSuccessActionDataDecrypted]) -> [Any] { - return `aesSuccessActionDataDecryptedList`.map { (v) -> [String: Any?] in return dictionaryOf(aesSuccessActionDataDecrypted: v) } -} -static func asBackupRequest(backupRequest: [String: Any?]) throws -> BackupRequest { + static func arrayOf(aesSuccessActionDataDecryptedList: [AesSuccessActionDataDecrypted]) -> [Any] { + return aesSuccessActionDataDecryptedList.map { v -> [String: Any?] in return dictionaryOf(aesSuccessActionDataDecrypted: v) } + } + + static func asBackupRequest(backupRequest: [String: Any?]) throws -> BackupRequest { var backupPath: String? if hasNonNilKey(data: backupRequest, key: "backupPath") { guard let backupPathTmp = backupRequest["backupPath"] as? String else { @@ -82,41 +84,42 @@ static func asBackupRequest(backupRequest: [String: Any?]) throws -> BackupReque } backupPath = backupPathTmp } - - return BackupRequest(backupPath: backupPath) -} -static func dictionaryOf(backupRequest: BackupRequest) -> [String: Any?] { - return [ - "backupPath": backupRequest.backupPath == nil ? nil : backupRequest.backupPath, - ] -} + return BackupRequest(backupPath: backupPath) + } -static func asBackupRequestList(arr: [Any]) throws -> [BackupRequest] { - var list = [BackupRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var backupRequest = try asBackupRequest(backupRequest: val) - list.append(backupRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BackupRequest")) - } + static func dictionaryOf(backupRequest: BackupRequest) -> [String: Any?] { + return [ + "backupPath": backupRequest.backupPath == nil ? nil : backupRequest.backupPath, + ] } - return list -} -static func arrayOf(`backupRequestList`: [BackupRequest]) -> [Any] { - return `backupRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(backupRequest: v) } -} -static func asBitcoinAddressData(bitcoinAddressData: [String: Any?]) throws -> BitcoinAddressData { - guard let address = bitcoinAddressData["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "BitcoinAddressData")) + static func asBackupRequestList(arr: [Any]) throws -> [BackupRequest] { + var list = [BackupRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var backupRequest = try asBackupRequest(backupRequest: val) + list.append(backupRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BackupRequest")) + } + } + return list } - guard let networkTmp = bitcoinAddressData["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "BitcoinAddressData")) + + static func arrayOf(backupRequestList: [BackupRequest]) -> [Any] { + return backupRequestList.map { v -> [String: Any?] in return dictionaryOf(backupRequest: v) } } - let network = try asNetwork(network: networkTmp) - + + static func asBitcoinAddressData(bitcoinAddressData: [String: Any?]) throws -> BitcoinAddressData { + guard let address = bitcoinAddressData["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "BitcoinAddressData")) + } + guard let networkTmp = bitcoinAddressData["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "BitcoinAddressData")) + } + let network = try asNetwork(network: networkTmp) + var amountSat: UInt64? if hasNonNilKey(data: bitcoinAddressData, key: "amountSat") { guard let amountSatTmp = bitcoinAddressData["amountSat"] as? UInt64 else { @@ -138,42 +141,43 @@ static func asBitcoinAddressData(bitcoinAddressData: [String: Any?]) throws -> B } message = messageTmp } - - return BitcoinAddressData(address: address, network: network, amountSat: amountSat, label: label, message: message) -} -static func dictionaryOf(bitcoinAddressData: BitcoinAddressData) -> [String: Any?] { - return [ + return BitcoinAddressData(address: address, network: network, amountSat: amountSat, label: label, message: message) + } + + static func dictionaryOf(bitcoinAddressData: BitcoinAddressData) -> [String: Any?] { + return [ "address": bitcoinAddressData.address, - "network": valueOf( network: bitcoinAddressData.network), + "network": valueOf(network: bitcoinAddressData.network), "amountSat": bitcoinAddressData.amountSat == nil ? nil : bitcoinAddressData.amountSat, "label": bitcoinAddressData.label == nil ? nil : bitcoinAddressData.label, - "message": bitcoinAddressData.message == nil ? nil : bitcoinAddressData.message, - ] -} + "message": bitcoinAddressData.message == nil ? nil : bitcoinAddressData.message, + ] + } -static func asBitcoinAddressDataList(arr: [Any]) throws -> [BitcoinAddressData] { - var list = [BitcoinAddressData]() - for value in arr { - if let val = value as? [String: Any?] { - var bitcoinAddressData = try asBitcoinAddressData(bitcoinAddressData: val) - list.append(bitcoinAddressData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BitcoinAddressData")) + static func asBitcoinAddressDataList(arr: [Any]) throws -> [BitcoinAddressData] { + var list = [BitcoinAddressData]() + for value in arr { + if let val = value as? [String: Any?] { + var bitcoinAddressData = try asBitcoinAddressData(bitcoinAddressData: val) + list.append(bitcoinAddressData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BitcoinAddressData")) + } } + return list } - return list -} -static func arrayOf(`bitcoinAddressDataList`: [BitcoinAddressData]) -> [Any] { - return `bitcoinAddressDataList`.map { (v) -> [String: Any?] in return dictionaryOf(bitcoinAddressData: v) } -} -static func asBuyBitcoinRequest(buyBitcoinRequest: [String: Any?]) throws -> BuyBitcoinRequest { - guard let prepareResponseTmp = buyBitcoinRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "BuyBitcoinRequest")) + static func arrayOf(bitcoinAddressDataList: [BitcoinAddressData]) -> [Any] { + return bitcoinAddressDataList.map { v -> [String: Any?] in return dictionaryOf(bitcoinAddressData: v) } } - let prepareResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: prepareResponseTmp) - + + static func asBuyBitcoinRequest(buyBitcoinRequest: [String: Any?]) throws -> BuyBitcoinRequest { + guard let prepareResponseTmp = buyBitcoinRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "BuyBitcoinRequest")) + } + let prepareResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: prepareResponseTmp) + var redirectUrl: String? if hasNonNilKey(data: buyBitcoinRequest, key: "redirectUrl") { guard let redirectUrlTmp = buyBitcoinRequest["redirectUrl"] as? String else { @@ -181,125 +185,128 @@ static func asBuyBitcoinRequest(buyBitcoinRequest: [String: Any?]) throws -> Buy } redirectUrl = redirectUrlTmp } - - return BuyBitcoinRequest(prepareResponse: prepareResponse, redirectUrl: redirectUrl) -} -static func dictionaryOf(buyBitcoinRequest: BuyBitcoinRequest) -> [String: Any?] { - return [ + return BuyBitcoinRequest(prepareResponse: prepareResponse, redirectUrl: redirectUrl) + } + + static func dictionaryOf(buyBitcoinRequest: BuyBitcoinRequest) -> [String: Any?] { + return [ "prepareResponse": dictionaryOf(prepareBuyBitcoinResponse: buyBitcoinRequest.prepareResponse), - "redirectUrl": buyBitcoinRequest.redirectUrl == nil ? nil : buyBitcoinRequest.redirectUrl, - ] -} + "redirectUrl": buyBitcoinRequest.redirectUrl == nil ? nil : buyBitcoinRequest.redirectUrl, + ] + } -static func asBuyBitcoinRequestList(arr: [Any]) throws -> [BuyBitcoinRequest] { - var list = [BuyBitcoinRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var buyBitcoinRequest = try asBuyBitcoinRequest(buyBitcoinRequest: val) - list.append(buyBitcoinRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinRequest")) + static func asBuyBitcoinRequestList(arr: [Any]) throws -> [BuyBitcoinRequest] { + var list = [BuyBitcoinRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var buyBitcoinRequest = try asBuyBitcoinRequest(buyBitcoinRequest: val) + list.append(buyBitcoinRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinRequest")) + } } + return list } - return list -} -static func arrayOf(`buyBitcoinRequestList`: [BuyBitcoinRequest]) -> [Any] { - return `buyBitcoinRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(buyBitcoinRequest: v) } -} -static func asCheckMessageRequest(checkMessageRequest: [String: Any?]) throws -> CheckMessageRequest { - guard let message = checkMessageRequest["message"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "CheckMessageRequest")) - } - guard let pubkey = checkMessageRequest["pubkey"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "CheckMessageRequest")) + static func arrayOf(buyBitcoinRequestList: [BuyBitcoinRequest]) -> [Any] { + return buyBitcoinRequestList.map { v -> [String: Any?] in return dictionaryOf(buyBitcoinRequest: v) } } - guard let signature = checkMessageRequest["signature"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "CheckMessageRequest")) + + static func asCheckMessageRequest(checkMessageRequest: [String: Any?]) throws -> CheckMessageRequest { + guard let message = checkMessageRequest["message"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "CheckMessageRequest")) + } + guard let pubkey = checkMessageRequest["pubkey"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "CheckMessageRequest")) + } + guard let signature = checkMessageRequest["signature"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "CheckMessageRequest")) + } + + return CheckMessageRequest(message: message, pubkey: pubkey, signature: signature) } - - return CheckMessageRequest(message: message, pubkey: pubkey, signature: signature) -} -static func dictionaryOf(checkMessageRequest: CheckMessageRequest) -> [String: Any?] { - return [ + static func dictionaryOf(checkMessageRequest: CheckMessageRequest) -> [String: Any?] { + return [ "message": checkMessageRequest.message, "pubkey": checkMessageRequest.pubkey, - "signature": checkMessageRequest.signature, - ] -} + "signature": checkMessageRequest.signature, + ] + } -static func asCheckMessageRequestList(arr: [Any]) throws -> [CheckMessageRequest] { - var list = [CheckMessageRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var checkMessageRequest = try asCheckMessageRequest(checkMessageRequest: val) - list.append(checkMessageRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageRequest")) + static func asCheckMessageRequestList(arr: [Any]) throws -> [CheckMessageRequest] { + var list = [CheckMessageRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var checkMessageRequest = try asCheckMessageRequest(checkMessageRequest: val) + list.append(checkMessageRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageRequest")) + } } + return list } - return list -} -static func arrayOf(`checkMessageRequestList`: [CheckMessageRequest]) -> [Any] { - return `checkMessageRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(checkMessageRequest: v) } -} -static func asCheckMessageResponse(checkMessageResponse: [String: Any?]) throws -> CheckMessageResponse { - guard let isValid = checkMessageResponse["isValid"] as? Bool else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "isValid", typeName: "CheckMessageResponse")) + static func arrayOf(checkMessageRequestList: [CheckMessageRequest]) -> [Any] { + return checkMessageRequestList.map { v -> [String: Any?] in return dictionaryOf(checkMessageRequest: v) } } - - return CheckMessageResponse(isValid: isValid) -} - -static func dictionaryOf(checkMessageResponse: CheckMessageResponse) -> [String: Any?] { - return [ - "isValid": checkMessageResponse.isValid, - ] -} -static func asCheckMessageResponseList(arr: [Any]) throws -> [CheckMessageResponse] { - var list = [CheckMessageResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var checkMessageResponse = try asCheckMessageResponse(checkMessageResponse: val) - list.append(checkMessageResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageResponse")) + static func asCheckMessageResponse(checkMessageResponse: [String: Any?]) throws -> CheckMessageResponse { + guard let isValid = checkMessageResponse["isValid"] as? Bool else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "isValid", typeName: "CheckMessageResponse")) } - } - return list -} -static func arrayOf(`checkMessageResponseList`: [CheckMessageResponse]) -> [Any] { - return `checkMessageResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(checkMessageResponse: v) } -} -static func asConfig(config: [String: Any?]) throws -> Config { - guard let liquidElectrumUrl = config["liquidElectrumUrl"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "liquidElectrumUrl", typeName: "Config")) - } - guard let bitcoinElectrumUrl = config["bitcoinElectrumUrl"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bitcoinElectrumUrl", typeName: "Config")) - } - guard let mempoolspaceUrl = config["mempoolspaceUrl"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mempoolspaceUrl", typeName: "Config")) + return CheckMessageResponse(isValid: isValid) } - guard let workingDir = config["workingDir"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "workingDir", typeName: "Config")) - } - guard let networkTmp = config["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "Config")) + + static func dictionaryOf(checkMessageResponse: CheckMessageResponse) -> [String: Any?] { + return [ + "isValid": checkMessageResponse.isValid, + ] } - let network = try asLiquidNetwork(liquidNetwork: networkTmp) - - guard let paymentTimeoutSec = config["paymentTimeoutSec"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentTimeoutSec", typeName: "Config")) + + static func asCheckMessageResponseList(arr: [Any]) throws -> [CheckMessageResponse] { + var list = [CheckMessageResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var checkMessageResponse = try asCheckMessageResponse(checkMessageResponse: val) + list.append(checkMessageResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "CheckMessageResponse")) + } + } + return list } - guard let zeroConfMinFeeRateMsat = config["zeroConfMinFeeRateMsat"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "zeroConfMinFeeRateMsat", typeName: "Config")) + + static func arrayOf(checkMessageResponseList: [CheckMessageResponse]) -> [Any] { + return checkMessageResponseList.map { v -> [String: Any?] in return dictionaryOf(checkMessageResponse: v) } } + + static func asConfig(config: [String: Any?]) throws -> Config { + guard let liquidElectrumUrl = config["liquidElectrumUrl"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "liquidElectrumUrl", typeName: "Config")) + } + guard let bitcoinElectrumUrl = config["bitcoinElectrumUrl"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bitcoinElectrumUrl", typeName: "Config")) + } + guard let mempoolspaceUrl = config["mempoolspaceUrl"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mempoolspaceUrl", typeName: "Config")) + } + guard let workingDir = config["workingDir"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "workingDir", typeName: "Config")) + } + guard let networkTmp = config["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "Config")) + } + let network = try asLiquidNetwork(liquidNetwork: networkTmp) + + guard let paymentTimeoutSec = config["paymentTimeoutSec"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentTimeoutSec", typeName: "Config")) + } + guard let zeroConfMinFeeRateMsat = config["zeroConfMinFeeRateMsat"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "zeroConfMinFeeRateMsat", typeName: "Config")) + } var breezApiKey: String? if hasNonNilKey(data: config, key: "breezApiKey") { guard let breezApiKeyTmp = config["breezApiKey"] as? String else { @@ -314,115 +321,117 @@ static func asConfig(config: [String: Any?]) throws -> Config { } zeroConfMaxAmountSat = zeroConfMaxAmountSatTmp } - - return Config(liquidElectrumUrl: liquidElectrumUrl, bitcoinElectrumUrl: bitcoinElectrumUrl, mempoolspaceUrl: mempoolspaceUrl, workingDir: workingDir, network: network, paymentTimeoutSec: paymentTimeoutSec, zeroConfMinFeeRateMsat: zeroConfMinFeeRateMsat, breezApiKey: breezApiKey, zeroConfMaxAmountSat: zeroConfMaxAmountSat) -} -static func dictionaryOf(config: Config) -> [String: Any?] { - return [ + return Config(liquidElectrumUrl: liquidElectrumUrl, bitcoinElectrumUrl: bitcoinElectrumUrl, mempoolspaceUrl: mempoolspaceUrl, workingDir: workingDir, network: network, paymentTimeoutSec: paymentTimeoutSec, zeroConfMinFeeRateMsat: zeroConfMinFeeRateMsat, breezApiKey: breezApiKey, zeroConfMaxAmountSat: zeroConfMaxAmountSat) + } + + static func dictionaryOf(config: Config) -> [String: Any?] { + return [ "liquidElectrumUrl": config.liquidElectrumUrl, "bitcoinElectrumUrl": config.bitcoinElectrumUrl, "mempoolspaceUrl": config.mempoolspaceUrl, "workingDir": config.workingDir, - "network": valueOf( liquidNetwork: config.network), + "network": valueOf(liquidNetwork: config.network), "paymentTimeoutSec": config.paymentTimeoutSec, "zeroConfMinFeeRateMsat": config.zeroConfMinFeeRateMsat, "breezApiKey": config.breezApiKey == nil ? nil : config.breezApiKey, - "zeroConfMaxAmountSat": config.zeroConfMaxAmountSat == nil ? nil : config.zeroConfMaxAmountSat, - ] -} + "zeroConfMaxAmountSat": config.zeroConfMaxAmountSat == nil ? nil : config.zeroConfMaxAmountSat, + ] + } -static func asConfigList(arr: [Any]) throws -> [Config] { - var list = [Config]() - for value in arr { - if let val = value as? [String: Any?] { - var config = try asConfig(config: val) - list.append(config) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Config")) + static func asConfigList(arr: [Any]) throws -> [Config] { + var list = [Config]() + for value in arr { + if let val = value as? [String: Any?] { + var config = try asConfig(config: val) + list.append(config) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Config")) + } } + return list } - return list -} -static func arrayOf(`configList`: [Config]) -> [Any] { - return `configList`.map { (v) -> [String: Any?] in return dictionaryOf(config: v) } -} -static func asConnectRequest(connectRequest: [String: Any?]) throws -> ConnectRequest { - guard let configTmp = connectRequest["config"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectRequest")) + static func arrayOf(configList: [Config]) -> [Any] { + return configList.map { v -> [String: Any?] in return dictionaryOf(config: v) } } - let config = try asConfig(config: configTmp) - - guard let mnemonic = connectRequest["mnemonic"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mnemonic", typeName: "ConnectRequest")) + + static func asConnectRequest(connectRequest: [String: Any?]) throws -> ConnectRequest { + guard let configTmp = connectRequest["config"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectRequest")) + } + let config = try asConfig(config: configTmp) + + guard let mnemonic = connectRequest["mnemonic"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "mnemonic", typeName: "ConnectRequest")) + } + + return ConnectRequest(config: config, mnemonic: mnemonic) } - - return ConnectRequest(config: config, mnemonic: mnemonic) -} -static func dictionaryOf(connectRequest: ConnectRequest) -> [String: Any?] { - return [ + static func dictionaryOf(connectRequest: ConnectRequest) -> [String: Any?] { + return [ "config": dictionaryOf(config: connectRequest.config), - "mnemonic": connectRequest.mnemonic, - ] -} + "mnemonic": connectRequest.mnemonic, + ] + } -static func asConnectRequestList(arr: [Any]) throws -> [ConnectRequest] { - var list = [ConnectRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var connectRequest = try asConnectRequest(connectRequest: val) - list.append(connectRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectRequest")) + static func asConnectRequestList(arr: [Any]) throws -> [ConnectRequest] { + var list = [ConnectRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var connectRequest = try asConnectRequest(connectRequest: val) + list.append(connectRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectRequest")) + } } + return list } - return list -} -static func arrayOf(`connectRequestList`: [ConnectRequest]) -> [Any] { - return `connectRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(connectRequest: v) } -} -static func asConnectWithSignerRequest(connectWithSignerRequest: [String: Any?]) throws -> ConnectWithSignerRequest { - guard let configTmp = connectWithSignerRequest["config"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectWithSignerRequest")) - } - let config = try asConfig(config: configTmp) - - - return ConnectWithSignerRequest(config: config) -} - -static func dictionaryOf(connectWithSignerRequest: ConnectWithSignerRequest) -> [String: Any?] { - return [ - "config": dictionaryOf(config: connectWithSignerRequest.config), - ] -} + static func arrayOf(connectRequestList: [ConnectRequest]) -> [Any] { + return connectRequestList.map { v -> [String: Any?] in return dictionaryOf(connectRequest: v) } + } -static func asConnectWithSignerRequestList(arr: [Any]) throws -> [ConnectWithSignerRequest] { - var list = [ConnectWithSignerRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var connectWithSignerRequest = try asConnectWithSignerRequest(connectWithSignerRequest: val) - list.append(connectWithSignerRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectWithSignerRequest")) + static func asConnectWithSignerRequest(connectWithSignerRequest: [String: Any?]) throws -> ConnectWithSignerRequest { + guard let configTmp = connectWithSignerRequest["config"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "config", typeName: "ConnectWithSignerRequest")) } + let config = try asConfig(config: configTmp) + + return ConnectWithSignerRequest(config: config) } - return list -} -static func arrayOf(`connectWithSignerRequestList`: [ConnectWithSignerRequest]) -> [Any] { - return `connectWithSignerRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(connectWithSignerRequest: v) } -} -static func asCurrencyInfo(currencyInfo: [String: Any?]) throws -> CurrencyInfo { - guard let name = currencyInfo["name"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "CurrencyInfo")) + static func dictionaryOf(connectWithSignerRequest: ConnectWithSignerRequest) -> [String: Any?] { + return [ + "config": dictionaryOf(config: connectWithSignerRequest.config), + ] + } + + static func asConnectWithSignerRequestList(arr: [Any]) throws -> [ConnectWithSignerRequest] { + var list = [ConnectWithSignerRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var connectWithSignerRequest = try asConnectWithSignerRequest(connectWithSignerRequest: val) + list.append(connectWithSignerRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ConnectWithSignerRequest")) + } + } + return list } - guard let fractionSize = currencyInfo["fractionSize"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fractionSize", typeName: "CurrencyInfo")) + + static func arrayOf(connectWithSignerRequestList: [ConnectWithSignerRequest]) -> [Any] { + return connectWithSignerRequestList.map { v -> [String: Any?] in return dictionaryOf(connectWithSignerRequest: v) } } + + static func asCurrencyInfo(currencyInfo: [String: Any?]) throws -> CurrencyInfo { + guard let name = currencyInfo["name"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "CurrencyInfo")) + } + guard let fractionSize = currencyInfo["fractionSize"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fractionSize", typeName: "CurrencyInfo")) + } var spacing: UInt32? if hasNonNilKey(data: currencyInfo, key: "spacing") { guard let spacingTmp = currencyInfo["spacing"] as? UInt32 else { @@ -434,151 +443,152 @@ static func asCurrencyInfo(currencyInfo: [String: Any?]) throws -> CurrencyInfo if let symbolTmp = currencyInfo["symbol"] as? [String: Any?] { symbol = try asSymbol(symbol: symbolTmp) } - + var uniqSymbol: Symbol? if let uniqSymbolTmp = currencyInfo["uniqSymbol"] as? [String: Any?] { uniqSymbol = try asSymbol(symbol: uniqSymbolTmp) } - - guard let localizedNameTmp = currencyInfo["localizedName"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localizedName", typeName: "CurrencyInfo")) - } - let localizedName = try asLocalizedNameList(arr: localizedNameTmp) - - guard let localeOverridesTmp = currencyInfo["localeOverrides"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localeOverrides", typeName: "CurrencyInfo")) + + guard let localizedNameTmp = currencyInfo["localizedName"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localizedName", typeName: "CurrencyInfo")) + } + let localizedName = try asLocalizedNameList(arr: localizedNameTmp) + + guard let localeOverridesTmp = currencyInfo["localeOverrides"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "localeOverrides", typeName: "CurrencyInfo")) + } + let localeOverrides = try asLocaleOverridesList(arr: localeOverridesTmp) + + return CurrencyInfo(name: name, fractionSize: fractionSize, spacing: spacing, symbol: symbol, uniqSymbol: uniqSymbol, localizedName: localizedName, localeOverrides: localeOverrides) } - let localeOverrides = try asLocaleOverridesList(arr: localeOverridesTmp) - - - return CurrencyInfo(name: name, fractionSize: fractionSize, spacing: spacing, symbol: symbol, uniqSymbol: uniqSymbol, localizedName: localizedName, localeOverrides: localeOverrides) -} -static func dictionaryOf(currencyInfo: CurrencyInfo) -> [String: Any?] { - return [ + static func dictionaryOf(currencyInfo: CurrencyInfo) -> [String: Any?] { + return [ "name": currencyInfo.name, "fractionSize": currencyInfo.fractionSize, "spacing": currencyInfo.spacing == nil ? nil : currencyInfo.spacing, "symbol": currencyInfo.symbol == nil ? nil : dictionaryOf(symbol: currencyInfo.symbol!), "uniqSymbol": currencyInfo.uniqSymbol == nil ? nil : dictionaryOf(symbol: currencyInfo.uniqSymbol!), "localizedName": arrayOf(localizedNameList: currencyInfo.localizedName), - "localeOverrides": arrayOf(localeOverridesList: currencyInfo.localeOverrides), - ] -} + "localeOverrides": arrayOf(localeOverridesList: currencyInfo.localeOverrides), + ] + } -static func asCurrencyInfoList(arr: [Any]) throws -> [CurrencyInfo] { - var list = [CurrencyInfo]() - for value in arr { - if let val = value as? [String: Any?] { - var currencyInfo = try asCurrencyInfo(currencyInfo: val) - list.append(currencyInfo) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "CurrencyInfo")) + static func asCurrencyInfoList(arr: [Any]) throws -> [CurrencyInfo] { + var list = [CurrencyInfo]() + for value in arr { + if let val = value as? [String: Any?] { + var currencyInfo = try asCurrencyInfo(currencyInfo: val) + list.append(currencyInfo) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "CurrencyInfo")) + } } + return list } - return list -} -static func arrayOf(`currencyInfoList`: [CurrencyInfo]) -> [Any] { - return `currencyInfoList`.map { (v) -> [String: Any?] in return dictionaryOf(currencyInfo: v) } -} -static func asFiatCurrency(fiatCurrency: [String: Any?]) throws -> FiatCurrency { - guard let id = fiatCurrency["id"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "id", typeName: "FiatCurrency")) + static func arrayOf(currencyInfoList: [CurrencyInfo]) -> [Any] { + return currencyInfoList.map { v -> [String: Any?] in return dictionaryOf(currencyInfo: v) } } - guard let infoTmp = fiatCurrency["info"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "info", typeName: "FiatCurrency")) + + static func asFiatCurrency(fiatCurrency: [String: Any?]) throws -> FiatCurrency { + guard let id = fiatCurrency["id"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "id", typeName: "FiatCurrency")) + } + guard let infoTmp = fiatCurrency["info"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "info", typeName: "FiatCurrency")) + } + let info = try asCurrencyInfo(currencyInfo: infoTmp) + + return FiatCurrency(id: id, info: info) } - let info = try asCurrencyInfo(currencyInfo: infoTmp) - - - return FiatCurrency(id: id, info: info) -} -static func dictionaryOf(fiatCurrency: FiatCurrency) -> [String: Any?] { - return [ + static func dictionaryOf(fiatCurrency: FiatCurrency) -> [String: Any?] { + return [ "id": fiatCurrency.id, - "info": dictionaryOf(currencyInfo: fiatCurrency.info), - ] -} + "info": dictionaryOf(currencyInfo: fiatCurrency.info), + ] + } -static func asFiatCurrencyList(arr: [Any]) throws -> [FiatCurrency] { - var list = [FiatCurrency]() - for value in arr { - if let val = value as? [String: Any?] { - var fiatCurrency = try asFiatCurrency(fiatCurrency: val) - list.append(fiatCurrency) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "FiatCurrency")) + static func asFiatCurrencyList(arr: [Any]) throws -> [FiatCurrency] { + var list = [FiatCurrency]() + for value in arr { + if let val = value as? [String: Any?] { + var fiatCurrency = try asFiatCurrency(fiatCurrency: val) + list.append(fiatCurrency) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "FiatCurrency")) + } } + return list } - return list -} -static func arrayOf(`fiatCurrencyList`: [FiatCurrency]) -> [Any] { - return `fiatCurrencyList`.map { (v) -> [String: Any?] in return dictionaryOf(fiatCurrency: v) } -} -static func asGetInfoResponse(getInfoResponse: [String: Any?]) throws -> GetInfoResponse { - guard let balanceSat = getInfoResponse["balanceSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "balanceSat", typeName: "GetInfoResponse")) - } - guard let pendingSendSat = getInfoResponse["pendingSendSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingSendSat", typeName: "GetInfoResponse")) - } - guard let pendingReceiveSat = getInfoResponse["pendingReceiveSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingReceiveSat", typeName: "GetInfoResponse")) + static func arrayOf(fiatCurrencyList: [FiatCurrency]) -> [Any] { + return fiatCurrencyList.map { v -> [String: Any?] in return dictionaryOf(fiatCurrency: v) } } - guard let fingerprint = getInfoResponse["fingerprint"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fingerprint", typeName: "GetInfoResponse")) - } - guard let pubkey = getInfoResponse["pubkey"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "GetInfoResponse")) + + static func asGetInfoResponse(getInfoResponse: [String: Any?]) throws -> GetInfoResponse { + guard let balanceSat = getInfoResponse["balanceSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "balanceSat", typeName: "GetInfoResponse")) + } + guard let pendingSendSat = getInfoResponse["pendingSendSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingSendSat", typeName: "GetInfoResponse")) + } + guard let pendingReceiveSat = getInfoResponse["pendingReceiveSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pendingReceiveSat", typeName: "GetInfoResponse")) + } + guard let fingerprint = getInfoResponse["fingerprint"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fingerprint", typeName: "GetInfoResponse")) + } + guard let pubkey = getInfoResponse["pubkey"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "pubkey", typeName: "GetInfoResponse")) + } + + return GetInfoResponse(balanceSat: balanceSat, pendingSendSat: pendingSendSat, pendingReceiveSat: pendingReceiveSat, fingerprint: fingerprint, pubkey: pubkey) } - - return GetInfoResponse(balanceSat: balanceSat, pendingSendSat: pendingSendSat, pendingReceiveSat: pendingReceiveSat, fingerprint: fingerprint, pubkey: pubkey) -} -static func dictionaryOf(getInfoResponse: GetInfoResponse) -> [String: Any?] { - return [ + static func dictionaryOf(getInfoResponse: GetInfoResponse) -> [String: Any?] { + return [ "balanceSat": getInfoResponse.balanceSat, "pendingSendSat": getInfoResponse.pendingSendSat, "pendingReceiveSat": getInfoResponse.pendingReceiveSat, "fingerprint": getInfoResponse.fingerprint, - "pubkey": getInfoResponse.pubkey, - ] -} + "pubkey": getInfoResponse.pubkey, + ] + } -static func asGetInfoResponseList(arr: [Any]) throws -> [GetInfoResponse] { - var list = [GetInfoResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var getInfoResponse = try asGetInfoResponse(getInfoResponse: val) - list.append(getInfoResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "GetInfoResponse")) + static func asGetInfoResponseList(arr: [Any]) throws -> [GetInfoResponse] { + var list = [GetInfoResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var getInfoResponse = try asGetInfoResponse(getInfoResponse: val) + list.append(getInfoResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "GetInfoResponse")) + } } + return list } - return list -} -static func arrayOf(`getInfoResponseList`: [GetInfoResponse]) -> [Any] { - return `getInfoResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(getInfoResponse: v) } -} -static func asLnInvoice(lnInvoice: [String: Any?]) throws -> LnInvoice { - guard let bolt11 = lnInvoice["bolt11"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bolt11", typeName: "LnInvoice")) - } - guard let networkTmp = lnInvoice["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LnInvoice")) - } - let network = try asNetwork(network: networkTmp) - - guard let payeePubkey = lnInvoice["payeePubkey"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payeePubkey", typeName: "LnInvoice")) - } - guard let paymentHash = lnInvoice["paymentHash"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnInvoice")) + static func arrayOf(getInfoResponseList: [GetInfoResponse]) -> [Any] { + return getInfoResponseList.map { v -> [String: Any?] in return dictionaryOf(getInfoResponse: v) } } + + static func asLnInvoice(lnInvoice: [String: Any?]) throws -> LnInvoice { + guard let bolt11 = lnInvoice["bolt11"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "bolt11", typeName: "LnInvoice")) + } + guard let networkTmp = lnInvoice["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LnInvoice")) + } + let network = try asNetwork(network: networkTmp) + + guard let payeePubkey = lnInvoice["payeePubkey"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payeePubkey", typeName: "LnInvoice")) + } + guard let paymentHash = lnInvoice["paymentHash"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnInvoice")) + } var description: String? if hasNonNilKey(data: lnInvoice, key: "description") { guard let descriptionTmp = lnInvoice["description"] as? String else { @@ -600,31 +610,31 @@ static func asLnInvoice(lnInvoice: [String: Any?]) throws -> LnInvoice { } amountMsat = amountMsatTmp } - guard let timestamp = lnInvoice["timestamp"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "LnInvoice")) - } - guard let expiry = lnInvoice["expiry"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "expiry", typeName: "LnInvoice")) - } - guard let routingHintsTmp = lnInvoice["routingHints"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "routingHints", typeName: "LnInvoice")) - } - let routingHints = try asRouteHintList(arr: routingHintsTmp) - - guard let paymentSecret = lnInvoice["paymentSecret"] as? [UInt8] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentSecret", typeName: "LnInvoice")) - } - guard let minFinalCltvExpiryDelta = lnInvoice["minFinalCltvExpiryDelta"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minFinalCltvExpiryDelta", typeName: "LnInvoice")) + guard let timestamp = lnInvoice["timestamp"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "LnInvoice")) + } + guard let expiry = lnInvoice["expiry"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "expiry", typeName: "LnInvoice")) + } + guard let routingHintsTmp = lnInvoice["routingHints"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "routingHints", typeName: "LnInvoice")) + } + let routingHints = try asRouteHintList(arr: routingHintsTmp) + + guard let paymentSecret = lnInvoice["paymentSecret"] as? [UInt8] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentSecret", typeName: "LnInvoice")) + } + guard let minFinalCltvExpiryDelta = lnInvoice["minFinalCltvExpiryDelta"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minFinalCltvExpiryDelta", typeName: "LnInvoice")) + } + + return LnInvoice(bolt11: bolt11, network: network, payeePubkey: payeePubkey, paymentHash: paymentHash, description: description, descriptionHash: descriptionHash, amountMsat: amountMsat, timestamp: timestamp, expiry: expiry, routingHints: routingHints, paymentSecret: paymentSecret, minFinalCltvExpiryDelta: minFinalCltvExpiryDelta) } - - return LnInvoice(bolt11: bolt11, network: network, payeePubkey: payeePubkey, paymentHash: paymentHash, description: description, descriptionHash: descriptionHash, amountMsat: amountMsat, timestamp: timestamp, expiry: expiry, routingHints: routingHints, paymentSecret: paymentSecret, minFinalCltvExpiryDelta: minFinalCltvExpiryDelta) -} -static func dictionaryOf(lnInvoice: LnInvoice) -> [String: Any?] { - return [ + static func dictionaryOf(lnInvoice: LnInvoice) -> [String: Any?] { + return [ "bolt11": lnInvoice.bolt11, - "network": valueOf( network: lnInvoice.network), + "network": valueOf(network: lnInvoice.network), "payeePubkey": lnInvoice.payeePubkey, "paymentHash": lnInvoice.paymentHash, "description": lnInvoice.description == nil ? nil : lnInvoice.description, @@ -634,111 +644,113 @@ static func dictionaryOf(lnInvoice: LnInvoice) -> [String: Any?] { "expiry": lnInvoice.expiry, "routingHints": arrayOf(routeHintList: lnInvoice.routingHints), "paymentSecret": lnInvoice.paymentSecret, - "minFinalCltvExpiryDelta": lnInvoice.minFinalCltvExpiryDelta, - ] -} + "minFinalCltvExpiryDelta": lnInvoice.minFinalCltvExpiryDelta, + ] + } -static func asLnInvoiceList(arr: [Any]) throws -> [LnInvoice] { - var list = [LnInvoice]() - for value in arr { - if let val = value as? [String: Any?] { - var lnInvoice = try asLnInvoice(lnInvoice: val) - list.append(lnInvoice) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnInvoice")) + static func asLnInvoiceList(arr: [Any]) throws -> [LnInvoice] { + var list = [LnInvoice]() + for value in arr { + if let val = value as? [String: Any?] { + var lnInvoice = try asLnInvoice(lnInvoice: val) + list.append(lnInvoice) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnInvoice")) + } } + return list } - return list -} -static func arrayOf(`lnInvoiceList`: [LnInvoice]) -> [Any] { - return `lnInvoiceList`.map { (v) -> [String: Any?] in return dictionaryOf(lnInvoice: v) } -} -static func asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: [String: Any?]) throws -> LightningPaymentLimitsResponse { - guard let sendTmp = lightningPaymentLimitsResponse["send"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "LightningPaymentLimitsResponse")) - } - let send = try asLimits(limits: sendTmp) - - guard let receiveTmp = lightningPaymentLimitsResponse["receive"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "LightningPaymentLimitsResponse")) - } - let receive = try asLimits(limits: receiveTmp) - - - return LightningPaymentLimitsResponse(send: send, receive: receive) -} + static func arrayOf(lnInvoiceList: [LnInvoice]) -> [Any] { + return lnInvoiceList.map { v -> [String: Any?] in return dictionaryOf(lnInvoice: v) } + } -static func dictionaryOf(lightningPaymentLimitsResponse: LightningPaymentLimitsResponse) -> [String: Any?] { - return [ - "send": dictionaryOf(limits: lightningPaymentLimitsResponse.send), - "receive": dictionaryOf(limits: lightningPaymentLimitsResponse.receive), - ] -} + static func asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: [String: Any?]) throws -> LightningPaymentLimitsResponse { + guard let sendTmp = lightningPaymentLimitsResponse["send"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "LightningPaymentLimitsResponse")) + } + let send = try asLimits(limits: sendTmp) -static func asLightningPaymentLimitsResponseList(arr: [Any]) throws -> [LightningPaymentLimitsResponse] { - var list = [LightningPaymentLimitsResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var lightningPaymentLimitsResponse = try asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: val) - list.append(lightningPaymentLimitsResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LightningPaymentLimitsResponse")) + guard let receiveTmp = lightningPaymentLimitsResponse["receive"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "LightningPaymentLimitsResponse")) } + let receive = try asLimits(limits: receiveTmp) + + return LightningPaymentLimitsResponse(send: send, receive: receive) } - return list -} -static func arrayOf(`lightningPaymentLimitsResponseList`: [LightningPaymentLimitsResponse]) -> [Any] { - return `lightningPaymentLimitsResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(lightningPaymentLimitsResponse: v) } -} -static func asLimits(limits: [String: Any?]) throws -> Limits { - guard let minSat = limits["minSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSat", typeName: "Limits")) + static func dictionaryOf(lightningPaymentLimitsResponse: LightningPaymentLimitsResponse) -> [String: Any?] { + return [ + "send": dictionaryOf(limits: lightningPaymentLimitsResponse.send), + "receive": dictionaryOf(limits: lightningPaymentLimitsResponse.receive), + ] } - guard let maxSat = limits["maxSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSat", typeName: "Limits")) + + static func asLightningPaymentLimitsResponseList(arr: [Any]) throws -> [LightningPaymentLimitsResponse] { + var list = [LightningPaymentLimitsResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var lightningPaymentLimitsResponse = try asLightningPaymentLimitsResponse(lightningPaymentLimitsResponse: val) + list.append(lightningPaymentLimitsResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LightningPaymentLimitsResponse")) + } + } + return list } - guard let maxZeroConfSat = limits["maxZeroConfSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxZeroConfSat", typeName: "Limits")) + + static func arrayOf(lightningPaymentLimitsResponseList: [LightningPaymentLimitsResponse]) -> [Any] { + return lightningPaymentLimitsResponseList.map { v -> [String: Any?] in return dictionaryOf(lightningPaymentLimitsResponse: v) } + } + + static func asLimits(limits: [String: Any?]) throws -> Limits { + guard let minSat = limits["minSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSat", typeName: "Limits")) + } + guard let maxSat = limits["maxSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSat", typeName: "Limits")) + } + guard let maxZeroConfSat = limits["maxZeroConfSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxZeroConfSat", typeName: "Limits")) + } + + return Limits(minSat: minSat, maxSat: maxSat, maxZeroConfSat: maxZeroConfSat) } - - return Limits(minSat: minSat, maxSat: maxSat, maxZeroConfSat: maxZeroConfSat) -} -static func dictionaryOf(limits: Limits) -> [String: Any?] { - return [ + static func dictionaryOf(limits: Limits) -> [String: Any?] { + return [ "minSat": limits.minSat, "maxSat": limits.maxSat, - "maxZeroConfSat": limits.maxZeroConfSat, - ] -} + "maxZeroConfSat": limits.maxZeroConfSat, + ] + } -static func asLimitsList(arr: [Any]) throws -> [Limits] { - var list = [Limits]() - for value in arr { - if let val = value as? [String: Any?] { - var limits = try asLimits(limits: val) - list.append(limits) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Limits")) + static func asLimitsList(arr: [Any]) throws -> [Limits] { + var list = [Limits]() + for value in arr { + if let val = value as? [String: Any?] { + var limits = try asLimits(limits: val) + list.append(limits) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Limits")) + } } + return list } - return list -} -static func arrayOf(`limitsList`: [Limits]) -> [Any] { - return `limitsList`.map { (v) -> [String: Any?] in return dictionaryOf(limits: v) } -} -static func asLiquidAddressData(liquidAddressData: [String: Any?]) throws -> LiquidAddressData { - guard let address = liquidAddressData["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "LiquidAddressData")) - } - guard let networkTmp = liquidAddressData["network"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LiquidAddressData")) + static func arrayOf(limitsList: [Limits]) -> [Any] { + return limitsList.map { v -> [String: Any?] in return dictionaryOf(limits: v) } } - let network = try asNetwork(network: networkTmp) - + + static func asLiquidAddressData(liquidAddressData: [String: Any?]) throws -> LiquidAddressData { + guard let address = liquidAddressData["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "LiquidAddressData")) + } + guard let networkTmp = liquidAddressData["network"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "network", typeName: "LiquidAddressData")) + } + let network = try asNetwork(network: networkTmp) + var assetId: String? if hasNonNilKey(data: liquidAddressData, key: "assetId") { guard let assetIdTmp = liquidAddressData["assetId"] as? String else { @@ -767,43 +779,44 @@ static func asLiquidAddressData(liquidAddressData: [String: Any?]) throws -> Liq } message = messageTmp } - - return LiquidAddressData(address: address, network: network, assetId: assetId, amountSat: amountSat, label: label, message: message) -} -static func dictionaryOf(liquidAddressData: LiquidAddressData) -> [String: Any?] { - return [ + return LiquidAddressData(address: address, network: network, assetId: assetId, amountSat: amountSat, label: label, message: message) + } + + static func dictionaryOf(liquidAddressData: LiquidAddressData) -> [String: Any?] { + return [ "address": liquidAddressData.address, - "network": valueOf( network: liquidAddressData.network), + "network": valueOf(network: liquidAddressData.network), "assetId": liquidAddressData.assetId == nil ? nil : liquidAddressData.assetId, "amountSat": liquidAddressData.amountSat == nil ? nil : liquidAddressData.amountSat, "label": liquidAddressData.label == nil ? nil : liquidAddressData.label, - "message": liquidAddressData.message == nil ? nil : liquidAddressData.message, - ] -} + "message": liquidAddressData.message == nil ? nil : liquidAddressData.message, + ] + } -static func asLiquidAddressDataList(arr: [Any]) throws -> [LiquidAddressData] { - var list = [LiquidAddressData]() - for value in arr { - if let val = value as? [String: Any?] { - var liquidAddressData = try asLiquidAddressData(liquidAddressData: val) - list.append(liquidAddressData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidAddressData")) + static func asLiquidAddressDataList(arr: [Any]) throws -> [LiquidAddressData] { + var list = [LiquidAddressData]() + for value in arr { + if let val = value as? [String: Any?] { + var liquidAddressData = try asLiquidAddressData(liquidAddressData: val) + list.append(liquidAddressData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidAddressData")) + } } + return list } - return list -} -static func arrayOf(`liquidAddressDataList`: [LiquidAddressData]) -> [Any] { - return `liquidAddressDataList`.map { (v) -> [String: Any?] in return dictionaryOf(liquidAddressData: v) } -} -static func asListPaymentsRequest(listPaymentsRequest: [String: Any?]) throws -> ListPaymentsRequest { + static func arrayOf(liquidAddressDataList: [LiquidAddressData]) -> [Any] { + return liquidAddressDataList.map { v -> [String: Any?] in return dictionaryOf(liquidAddressData: v) } + } + + static func asListPaymentsRequest(listPaymentsRequest: [String: Any?]) throws -> ListPaymentsRequest { var filters: [PaymentType]? if let filtersTmp = listPaymentsRequest["filters"] as? [String] { filters = try asPaymentTypeList(arr: filtersTmp) } - + var fromTimestamp: Int64? if hasNonNilKey(data: listPaymentsRequest, key: "fromTimestamp") { guard let fromTimestampTmp = listPaymentsRequest["fromTimestamp"] as? Int64 else { @@ -836,48 +849,48 @@ static func asListPaymentsRequest(listPaymentsRequest: [String: Any?]) throws -> if let detailsTmp = listPaymentsRequest["details"] as? [String: Any?] { details = try asListPaymentDetails(listPaymentDetails: detailsTmp) } - - - return ListPaymentsRequest(filters: filters, fromTimestamp: fromTimestamp, toTimestamp: toTimestamp, offset: offset, limit: limit, details: details) -} -static func dictionaryOf(listPaymentsRequest: ListPaymentsRequest) -> [String: Any?] { - return [ + return ListPaymentsRequest(filters: filters, fromTimestamp: fromTimestamp, toTimestamp: toTimestamp, offset: offset, limit: limit, details: details) + } + + static func dictionaryOf(listPaymentsRequest: ListPaymentsRequest) -> [String: Any?] { + return [ "filters": listPaymentsRequest.filters == nil ? nil : arrayOf(paymentTypeList: listPaymentsRequest.filters!), "fromTimestamp": listPaymentsRequest.fromTimestamp == nil ? nil : listPaymentsRequest.fromTimestamp, "toTimestamp": listPaymentsRequest.toTimestamp == nil ? nil : listPaymentsRequest.toTimestamp, "offset": listPaymentsRequest.offset == nil ? nil : listPaymentsRequest.offset, "limit": listPaymentsRequest.limit == nil ? nil : listPaymentsRequest.limit, - "details": listPaymentsRequest.details == nil ? nil : dictionaryOf(listPaymentDetails: listPaymentsRequest.details!), - ] -} + "details": listPaymentsRequest.details == nil ? nil : dictionaryOf(listPaymentDetails: listPaymentsRequest.details!), + ] + } -static func asListPaymentsRequestList(arr: [Any]) throws -> [ListPaymentsRequest] { - var list = [ListPaymentsRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var listPaymentsRequest = try asListPaymentsRequest(listPaymentsRequest: val) - list.append(listPaymentsRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentsRequest")) + static func asListPaymentsRequestList(arr: [Any]) throws -> [ListPaymentsRequest] { + var list = [ListPaymentsRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var listPaymentsRequest = try asListPaymentsRequest(listPaymentsRequest: val) + list.append(listPaymentsRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentsRequest")) + } } + return list } - return list -} -static func arrayOf(`listPaymentsRequestList`: [ListPaymentsRequest]) -> [Any] { - return `listPaymentsRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(listPaymentsRequest: v) } -} -static func asLnUrlAuthRequestData(lnUrlAuthRequestData: [String: Any?]) throws -> LnUrlAuthRequestData { - guard let k1 = lnUrlAuthRequestData["k1"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlAuthRequestData")) - } - guard let domain = lnUrlAuthRequestData["domain"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlAuthRequestData")) - } - guard let url = lnUrlAuthRequestData["url"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "LnUrlAuthRequestData")) + static func arrayOf(listPaymentsRequestList: [ListPaymentsRequest]) -> [Any] { + return listPaymentsRequestList.map { v -> [String: Any?] in return dictionaryOf(listPaymentsRequest: v) } } + + static func asLnUrlAuthRequestData(lnUrlAuthRequestData: [String: Any?]) throws -> LnUrlAuthRequestData { + guard let k1 = lnUrlAuthRequestData["k1"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlAuthRequestData")) + } + guard let domain = lnUrlAuthRequestData["domain"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlAuthRequestData")) + } + guard let url = lnUrlAuthRequestData["url"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "LnUrlAuthRequestData")) + } var action: String? if hasNonNilKey(data: lnUrlAuthRequestData, key: "action") { guard let actionTmp = lnUrlAuthRequestData["action"] as? String else { @@ -885,153 +898,156 @@ static func asLnUrlAuthRequestData(lnUrlAuthRequestData: [String: Any?]) throws } action = actionTmp } - - return LnUrlAuthRequestData(k1: k1, domain: domain, url: url, action: action) -} -static func dictionaryOf(lnUrlAuthRequestData: LnUrlAuthRequestData) -> [String: Any?] { - return [ + return LnUrlAuthRequestData(k1: k1, domain: domain, url: url, action: action) + } + + static func dictionaryOf(lnUrlAuthRequestData: LnUrlAuthRequestData) -> [String: Any?] { + return [ "k1": lnUrlAuthRequestData.k1, "domain": lnUrlAuthRequestData.domain, "url": lnUrlAuthRequestData.url, - "action": lnUrlAuthRequestData.action == nil ? nil : lnUrlAuthRequestData.action, - ] -} + "action": lnUrlAuthRequestData.action == nil ? nil : lnUrlAuthRequestData.action, + ] + } -static func asLnUrlAuthRequestDataList(arr: [Any]) throws -> [LnUrlAuthRequestData] { - var list = [LnUrlAuthRequestData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlAuthRequestData = try asLnUrlAuthRequestData(lnUrlAuthRequestData: val) - list.append(lnUrlAuthRequestData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlAuthRequestData")) + static func asLnUrlAuthRequestDataList(arr: [Any]) throws -> [LnUrlAuthRequestData] { + var list = [LnUrlAuthRequestData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlAuthRequestData = try asLnUrlAuthRequestData(lnUrlAuthRequestData: val) + list.append(lnUrlAuthRequestData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlAuthRequestData")) + } } + return list } - return list -} -static func arrayOf(`lnUrlAuthRequestDataList`: [LnUrlAuthRequestData]) -> [Any] { - return `lnUrlAuthRequestDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlAuthRequestData: v) } -} -static func asLnUrlErrorData(lnUrlErrorData: [String: Any?]) throws -> LnUrlErrorData { - guard let reason = lnUrlErrorData["reason"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlErrorData")) + static func arrayOf(lnUrlAuthRequestDataList: [LnUrlAuthRequestData]) -> [Any] { + return lnUrlAuthRequestDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlAuthRequestData: v) } } - - return LnUrlErrorData(reason: reason) -} - -static func dictionaryOf(lnUrlErrorData: LnUrlErrorData) -> [String: Any?] { - return [ - "reason": lnUrlErrorData.reason, - ] -} -static func asLnUrlErrorDataList(arr: [Any]) throws -> [LnUrlErrorData] { - var list = [LnUrlErrorData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlErrorData = try asLnUrlErrorData(lnUrlErrorData: val) - list.append(lnUrlErrorData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlErrorData")) + static func asLnUrlErrorData(lnUrlErrorData: [String: Any?]) throws -> LnUrlErrorData { + guard let reason = lnUrlErrorData["reason"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlErrorData")) } - } - return list -} -static func arrayOf(`lnUrlErrorDataList`: [LnUrlErrorData]) -> [Any] { - return `lnUrlErrorDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlErrorData: v) } -} -static func asLnUrlPayErrorData(lnUrlPayErrorData: [String: Any?]) throws -> LnUrlPayErrorData { - guard let paymentHash = lnUrlPayErrorData["paymentHash"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnUrlPayErrorData")) + return LnUrlErrorData(reason: reason) } - guard let reason = lnUrlPayErrorData["reason"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlPayErrorData")) - } - - return LnUrlPayErrorData(paymentHash: paymentHash, reason: reason) -} -static func dictionaryOf(lnUrlPayErrorData: LnUrlPayErrorData) -> [String: Any?] { - return [ - "paymentHash": lnUrlPayErrorData.paymentHash, - "reason": lnUrlPayErrorData.reason, - ] -} + static func dictionaryOf(lnUrlErrorData: LnUrlErrorData) -> [String: Any?] { + return [ + "reason": lnUrlErrorData.reason, + ] + } -static func asLnUrlPayErrorDataList(arr: [Any]) throws -> [LnUrlPayErrorData] { - var list = [LnUrlPayErrorData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayErrorData = try asLnUrlPayErrorData(lnUrlPayErrorData: val) - list.append(lnUrlPayErrorData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayErrorData")) + static func asLnUrlErrorDataList(arr: [Any]) throws -> [LnUrlErrorData] { + var list = [LnUrlErrorData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlErrorData = try asLnUrlErrorData(lnUrlErrorData: val) + list.append(lnUrlErrorData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlErrorData")) + } } + return list } - return list -} -static func arrayOf(`lnUrlPayErrorDataList`: [LnUrlPayErrorData]) -> [Any] { - return `lnUrlPayErrorDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayErrorData: v) } -} -static func asLnUrlPayRequest(lnUrlPayRequest: [String: Any?]) throws -> LnUrlPayRequest { - guard let prepareResponseTmp = lnUrlPayRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "LnUrlPayRequest")) - } - let prepareResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: prepareResponseTmp) - - - return LnUrlPayRequest(prepareResponse: prepareResponse) -} - -static func dictionaryOf(lnUrlPayRequest: LnUrlPayRequest) -> [String: Any?] { - return [ - "prepareResponse": dictionaryOf(prepareLnUrlPayResponse: lnUrlPayRequest.prepareResponse), - ] -} + static func arrayOf(lnUrlErrorDataList: [LnUrlErrorData]) -> [Any] { + return lnUrlErrorDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlErrorData: v) } + } -static func asLnUrlPayRequestList(arr: [Any]) throws -> [LnUrlPayRequest] { - var list = [LnUrlPayRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayRequest = try asLnUrlPayRequest(lnUrlPayRequest: val) - list.append(lnUrlPayRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequest")) + static func asLnUrlPayErrorData(lnUrlPayErrorData: [String: Any?]) throws -> LnUrlPayErrorData { + guard let paymentHash = lnUrlPayErrorData["paymentHash"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "LnUrlPayErrorData")) + } + guard let reason = lnUrlPayErrorData["reason"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "LnUrlPayErrorData")) } + + return LnUrlPayErrorData(paymentHash: paymentHash, reason: reason) } - return list -} -static func arrayOf(`lnUrlPayRequestList`: [LnUrlPayRequest]) -> [Any] { - return `lnUrlPayRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayRequest: v) } -} -static func asLnUrlPayRequestData(lnUrlPayRequestData: [String: Any?]) throws -> LnUrlPayRequestData { - guard let callback = lnUrlPayRequestData["callback"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlPayRequestData")) + static func dictionaryOf(lnUrlPayErrorData: LnUrlPayErrorData) -> [String: Any?] { + return [ + "paymentHash": lnUrlPayErrorData.paymentHash, + "reason": lnUrlPayErrorData.reason, + ] } - guard let minSendable = lnUrlPayRequestData["minSendable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSendable", typeName: "LnUrlPayRequestData")) + + static func asLnUrlPayErrorDataList(arr: [Any]) throws -> [LnUrlPayErrorData] { + var list = [LnUrlPayErrorData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayErrorData = try asLnUrlPayErrorData(lnUrlPayErrorData: val) + list.append(lnUrlPayErrorData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayErrorData")) + } + } + return list } - guard let maxSendable = lnUrlPayRequestData["maxSendable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSendable", typeName: "LnUrlPayRequestData")) + + static func arrayOf(lnUrlPayErrorDataList: [LnUrlPayErrorData]) -> [Any] { + return lnUrlPayErrorDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayErrorData: v) } } - guard let metadataStr = lnUrlPayRequestData["metadataStr"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "metadataStr", typeName: "LnUrlPayRequestData")) + + static func asLnUrlPayRequest(lnUrlPayRequest: [String: Any?]) throws -> LnUrlPayRequest { + guard let prepareResponseTmp = lnUrlPayRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "LnUrlPayRequest")) + } + let prepareResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: prepareResponseTmp) + + return LnUrlPayRequest(prepareResponse: prepareResponse) } - guard let commentAllowed = lnUrlPayRequestData["commentAllowed"] as? UInt16 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "commentAllowed", typeName: "LnUrlPayRequestData")) + + static func dictionaryOf(lnUrlPayRequest: LnUrlPayRequest) -> [String: Any?] { + return [ + "prepareResponse": dictionaryOf(prepareLnUrlPayResponse: lnUrlPayRequest.prepareResponse), + ] } - guard let domain = lnUrlPayRequestData["domain"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlPayRequestData")) + + static func asLnUrlPayRequestList(arr: [Any]) throws -> [LnUrlPayRequest] { + var list = [LnUrlPayRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayRequest = try asLnUrlPayRequest(lnUrlPayRequest: val) + list.append(lnUrlPayRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequest")) + } + } + return list } - guard let allowsNostr = lnUrlPayRequestData["allowsNostr"] as? Bool else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "allowsNostr", typeName: "LnUrlPayRequestData")) + + static func arrayOf(lnUrlPayRequestList: [LnUrlPayRequest]) -> [Any] { + return lnUrlPayRequestList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayRequest: v) } } + + static func asLnUrlPayRequestData(lnUrlPayRequestData: [String: Any?]) throws -> LnUrlPayRequestData { + guard let callback = lnUrlPayRequestData["callback"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlPayRequestData")) + } + guard let minSendable = lnUrlPayRequestData["minSendable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minSendable", typeName: "LnUrlPayRequestData")) + } + guard let maxSendable = lnUrlPayRequestData["maxSendable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxSendable", typeName: "LnUrlPayRequestData")) + } + guard let metadataStr = lnUrlPayRequestData["metadataStr"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "metadataStr", typeName: "LnUrlPayRequestData")) + } + guard let commentAllowed = lnUrlPayRequestData["commentAllowed"] as? UInt16 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "commentAllowed", typeName: "LnUrlPayRequestData")) + } + guard let domain = lnUrlPayRequestData["domain"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "domain", typeName: "LnUrlPayRequestData")) + } + guard let allowsNostr = lnUrlPayRequestData["allowsNostr"] as? Bool else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "allowsNostr", typeName: "LnUrlPayRequestData")) + } var nostrPubkey: String? if hasNonNilKey(data: lnUrlPayRequestData, key: "nostrPubkey") { guard let nostrPubkeyTmp = lnUrlPayRequestData["nostrPubkey"] as? String else { @@ -1046,12 +1062,12 @@ static func asLnUrlPayRequestData(lnUrlPayRequestData: [String: Any?]) throws -> } lnAddress = lnAddressTmp } - - return LnUrlPayRequestData(callback: callback, minSendable: minSendable, maxSendable: maxSendable, metadataStr: metadataStr, commentAllowed: commentAllowed, domain: domain, allowsNostr: allowsNostr, nostrPubkey: nostrPubkey, lnAddress: lnAddress) -} -static func dictionaryOf(lnUrlPayRequestData: LnUrlPayRequestData) -> [String: Any?] { - return [ + return LnUrlPayRequestData(callback: callback, minSendable: minSendable, maxSendable: maxSendable, metadataStr: metadataStr, commentAllowed: commentAllowed, domain: domain, allowsNostr: allowsNostr, nostrPubkey: nostrPubkey, lnAddress: lnAddress) + } + + static func dictionaryOf(lnUrlPayRequestData: LnUrlPayRequestData) -> [String: Any?] { + return [ "callback": lnUrlPayRequestData.callback, "minSendable": lnUrlPayRequestData.minSendable, "maxSendable": lnUrlPayRequestData.maxSendable, @@ -1060,73 +1076,74 @@ static func dictionaryOf(lnUrlPayRequestData: LnUrlPayRequestData) -> [String: "domain": lnUrlPayRequestData.domain, "allowsNostr": lnUrlPayRequestData.allowsNostr, "nostrPubkey": lnUrlPayRequestData.nostrPubkey == nil ? nil : lnUrlPayRequestData.nostrPubkey, - "lnAddress": lnUrlPayRequestData.lnAddress == nil ? nil : lnUrlPayRequestData.lnAddress, - ] -} + "lnAddress": lnUrlPayRequestData.lnAddress == nil ? nil : lnUrlPayRequestData.lnAddress, + ] + } -static func asLnUrlPayRequestDataList(arr: [Any]) throws -> [LnUrlPayRequestData] { - var list = [LnUrlPayRequestData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayRequestData = try asLnUrlPayRequestData(lnUrlPayRequestData: val) - list.append(lnUrlPayRequestData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequestData")) + static func asLnUrlPayRequestDataList(arr: [Any]) throws -> [LnUrlPayRequestData] { + var list = [LnUrlPayRequestData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayRequestData = try asLnUrlPayRequestData(lnUrlPayRequestData: val) + list.append(lnUrlPayRequestData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayRequestData")) + } } + return list } - return list -} -static func arrayOf(`lnUrlPayRequestDataList`: [LnUrlPayRequestData]) -> [Any] { - return `lnUrlPayRequestDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayRequestData: v) } -} -static func asLnUrlPaySuccessData(lnUrlPaySuccessData: [String: Any?]) throws -> LnUrlPaySuccessData { + static func arrayOf(lnUrlPayRequestDataList: [LnUrlPayRequestData]) -> [Any] { + return lnUrlPayRequestDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayRequestData: v) } + } + + static func asLnUrlPaySuccessData(lnUrlPaySuccessData: [String: Any?]) throws -> LnUrlPaySuccessData { var successAction: SuccessActionProcessed? if let successActionTmp = lnUrlPaySuccessData["successAction"] as? [String: Any?] { successAction = try asSuccessActionProcessed(successActionProcessed: successActionTmp) } - - guard let paymentTmp = lnUrlPaySuccessData["payment"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "LnUrlPaySuccessData")) + + guard let paymentTmp = lnUrlPaySuccessData["payment"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "LnUrlPaySuccessData")) + } + let payment = try asPayment(payment: paymentTmp) + + return LnUrlPaySuccessData(successAction: successAction, payment: payment) } - let payment = try asPayment(payment: paymentTmp) - - - return LnUrlPaySuccessData(successAction: successAction, payment: payment) -} -static func dictionaryOf(lnUrlPaySuccessData: LnUrlPaySuccessData) -> [String: Any?] { - return [ + static func dictionaryOf(lnUrlPaySuccessData: LnUrlPaySuccessData) -> [String: Any?] { + return [ "successAction": lnUrlPaySuccessData.successAction == nil ? nil : dictionaryOf(successActionProcessed: lnUrlPaySuccessData.successAction!), - "payment": dictionaryOf(payment: lnUrlPaySuccessData.payment), - ] -} + "payment": dictionaryOf(payment: lnUrlPaySuccessData.payment), + ] + } -static func asLnUrlPaySuccessDataList(arr: [Any]) throws -> [LnUrlPaySuccessData] { - var list = [LnUrlPaySuccessData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPaySuccessData = try asLnUrlPaySuccessData(lnUrlPaySuccessData: val) - list.append(lnUrlPaySuccessData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPaySuccessData")) + static func asLnUrlPaySuccessDataList(arr: [Any]) throws -> [LnUrlPaySuccessData] { + var list = [LnUrlPaySuccessData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPaySuccessData = try asLnUrlPaySuccessData(lnUrlPaySuccessData: val) + list.append(lnUrlPaySuccessData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPaySuccessData")) + } } + return list } - return list -} -static func arrayOf(`lnUrlPaySuccessDataList`: [LnUrlPaySuccessData]) -> [Any] { - return `lnUrlPaySuccessDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPaySuccessData: v) } -} -static func asLnUrlWithdrawRequest(lnUrlWithdrawRequest: [String: Any?]) throws -> LnUrlWithdrawRequest { - guard let dataTmp = lnUrlWithdrawRequest["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawRequest")) - } - let data = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: dataTmp) - - guard let amountMsat = lnUrlWithdrawRequest["amountMsat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "LnUrlWithdrawRequest")) + static func arrayOf(lnUrlPaySuccessDataList: [LnUrlPaySuccessData]) -> [Any] { + return lnUrlPaySuccessDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPaySuccessData: v) } } + + static func asLnUrlWithdrawRequest(lnUrlWithdrawRequest: [String: Any?]) throws -> LnUrlWithdrawRequest { + guard let dataTmp = lnUrlWithdrawRequest["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawRequest")) + } + let data = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: dataTmp) + + guard let amountMsat = lnUrlWithdrawRequest["amountMsat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "LnUrlWithdrawRequest")) + } var description: String? if hasNonNilKey(data: lnUrlWithdrawRequest, key: "description") { guard let descriptionTmp = lnUrlWithdrawRequest["description"] as? String else { @@ -1134,116 +1151,118 @@ static func asLnUrlWithdrawRequest(lnUrlWithdrawRequest: [String: Any?]) throws } description = descriptionTmp } - - return LnUrlWithdrawRequest(data: data, amountMsat: amountMsat, description: description) -} -static func dictionaryOf(lnUrlWithdrawRequest: LnUrlWithdrawRequest) -> [String: Any?] { - return [ + return LnUrlWithdrawRequest(data: data, amountMsat: amountMsat, description: description) + } + + static func dictionaryOf(lnUrlWithdrawRequest: LnUrlWithdrawRequest) -> [String: Any?] { + return [ "data": dictionaryOf(lnUrlWithdrawRequestData: lnUrlWithdrawRequest.data), "amountMsat": lnUrlWithdrawRequest.amountMsat, - "description": lnUrlWithdrawRequest.description == nil ? nil : lnUrlWithdrawRequest.description, - ] -} + "description": lnUrlWithdrawRequest.description == nil ? nil : lnUrlWithdrawRequest.description, + ] + } -static func asLnUrlWithdrawRequestList(arr: [Any]) throws -> [LnUrlWithdrawRequest] { - var list = [LnUrlWithdrawRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawRequest = try asLnUrlWithdrawRequest(lnUrlWithdrawRequest: val) - list.append(lnUrlWithdrawRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequest")) + static func asLnUrlWithdrawRequestList(arr: [Any]) throws -> [LnUrlWithdrawRequest] { + var list = [LnUrlWithdrawRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawRequest = try asLnUrlWithdrawRequest(lnUrlWithdrawRequest: val) + list.append(lnUrlWithdrawRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequest")) + } } + return list } - return list -} -static func arrayOf(`lnUrlWithdrawRequestList`: [LnUrlWithdrawRequest]) -> [Any] { - return `lnUrlWithdrawRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequest: v) } -} -static func asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: [String: Any?]) throws -> LnUrlWithdrawRequestData { - guard let callback = lnUrlWithdrawRequestData["callback"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlWithdrawRequestData")) - } - guard let k1 = lnUrlWithdrawRequestData["k1"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlWithdrawRequestData")) + static func arrayOf(lnUrlWithdrawRequestList: [LnUrlWithdrawRequest]) -> [Any] { + return lnUrlWithdrawRequestList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequest: v) } } - guard let defaultDescription = lnUrlWithdrawRequestData["defaultDescription"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "defaultDescription", typeName: "LnUrlWithdrawRequestData")) - } - guard let minWithdrawable = lnUrlWithdrawRequestData["minWithdrawable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minWithdrawable", typeName: "LnUrlWithdrawRequestData")) - } - guard let maxWithdrawable = lnUrlWithdrawRequestData["maxWithdrawable"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxWithdrawable", typeName: "LnUrlWithdrawRequestData")) + + static func asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: [String: Any?]) throws -> LnUrlWithdrawRequestData { + guard let callback = lnUrlWithdrawRequestData["callback"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "callback", typeName: "LnUrlWithdrawRequestData")) + } + guard let k1 = lnUrlWithdrawRequestData["k1"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "k1", typeName: "LnUrlWithdrawRequestData")) + } + guard let defaultDescription = lnUrlWithdrawRequestData["defaultDescription"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "defaultDescription", typeName: "LnUrlWithdrawRequestData")) + } + guard let minWithdrawable = lnUrlWithdrawRequestData["minWithdrawable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minWithdrawable", typeName: "LnUrlWithdrawRequestData")) + } + guard let maxWithdrawable = lnUrlWithdrawRequestData["maxWithdrawable"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "maxWithdrawable", typeName: "LnUrlWithdrawRequestData")) + } + + return LnUrlWithdrawRequestData(callback: callback, k1: k1, defaultDescription: defaultDescription, minWithdrawable: minWithdrawable, maxWithdrawable: maxWithdrawable) } - - return LnUrlWithdrawRequestData(callback: callback, k1: k1, defaultDescription: defaultDescription, minWithdrawable: minWithdrawable, maxWithdrawable: maxWithdrawable) -} -static func dictionaryOf(lnUrlWithdrawRequestData: LnUrlWithdrawRequestData) -> [String: Any?] { - return [ + static func dictionaryOf(lnUrlWithdrawRequestData: LnUrlWithdrawRequestData) -> [String: Any?] { + return [ "callback": lnUrlWithdrawRequestData.callback, "k1": lnUrlWithdrawRequestData.k1, "defaultDescription": lnUrlWithdrawRequestData.defaultDescription, "minWithdrawable": lnUrlWithdrawRequestData.minWithdrawable, - "maxWithdrawable": lnUrlWithdrawRequestData.maxWithdrawable, - ] -} + "maxWithdrawable": lnUrlWithdrawRequestData.maxWithdrawable, + ] + } -static func asLnUrlWithdrawRequestDataList(arr: [Any]) throws -> [LnUrlWithdrawRequestData] { - var list = [LnUrlWithdrawRequestData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawRequestData = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: val) - list.append(lnUrlWithdrawRequestData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequestData")) + static func asLnUrlWithdrawRequestDataList(arr: [Any]) throws -> [LnUrlWithdrawRequestData] { + var list = [LnUrlWithdrawRequestData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawRequestData = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: val) + list.append(lnUrlWithdrawRequestData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawRequestData")) + } } + return list } - return list -} -static func arrayOf(`lnUrlWithdrawRequestDataList`: [LnUrlWithdrawRequestData]) -> [Any] { - return `lnUrlWithdrawRequestDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequestData: v) } -} -static func asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: [String: Any?]) throws -> LnUrlWithdrawSuccessData { - guard let invoiceTmp = lnUrlWithdrawSuccessData["invoice"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "LnUrlWithdrawSuccessData")) - } - let invoice = try asLnInvoice(lnInvoice: invoiceTmp) - - - return LnUrlWithdrawSuccessData(invoice: invoice) -} + static func arrayOf(lnUrlWithdrawRequestDataList: [LnUrlWithdrawRequestData]) -> [Any] { + return lnUrlWithdrawRequestDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawRequestData: v) } + } -static func dictionaryOf(lnUrlWithdrawSuccessData: LnUrlWithdrawSuccessData) -> [String: Any?] { - return [ - "invoice": dictionaryOf(lnInvoice: lnUrlWithdrawSuccessData.invoice), - ] -} + static func asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: [String: Any?]) throws -> LnUrlWithdrawSuccessData { + guard let invoiceTmp = lnUrlWithdrawSuccessData["invoice"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "LnUrlWithdrawSuccessData")) + } + let invoice = try asLnInvoice(lnInvoice: invoiceTmp) -static func asLnUrlWithdrawSuccessDataList(arr: [Any]) throws -> [LnUrlWithdrawSuccessData] { - var list = [LnUrlWithdrawSuccessData]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawSuccessData = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: val) - list.append(lnUrlWithdrawSuccessData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawSuccessData")) + return LnUrlWithdrawSuccessData(invoice: invoice) + } + + static func dictionaryOf(lnUrlWithdrawSuccessData: LnUrlWithdrawSuccessData) -> [String: Any?] { + return [ + "invoice": dictionaryOf(lnInvoice: lnUrlWithdrawSuccessData.invoice), + ] + } + + static func asLnUrlWithdrawSuccessDataList(arr: [Any]) throws -> [LnUrlWithdrawSuccessData] { + var list = [LnUrlWithdrawSuccessData]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawSuccessData = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: val) + list.append(lnUrlWithdrawSuccessData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawSuccessData")) + } } + return list } - return list -} -static func arrayOf(`lnUrlWithdrawSuccessDataList`: [LnUrlWithdrawSuccessData]) -> [Any] { - return `lnUrlWithdrawSuccessDataList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawSuccessData: v) } -} -static func asLocaleOverrides(localeOverrides: [String: Any?]) throws -> LocaleOverrides { - guard let locale = localeOverrides["locale"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocaleOverrides")) + static func arrayOf(lnUrlWithdrawSuccessDataList: [LnUrlWithdrawSuccessData]) -> [Any] { + return lnUrlWithdrawSuccessDataList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawSuccessData: v) } } + + static func asLocaleOverrides(localeOverrides: [String: Any?]) throws -> LocaleOverrides { + guard let locale = localeOverrides["locale"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocaleOverrides")) + } var spacing: UInt32? if hasNonNilKey(data: localeOverrides, key: "spacing") { guard let spacingTmp = localeOverrides["spacing"] as? UInt32 else { @@ -1251,236 +1270,239 @@ static func asLocaleOverrides(localeOverrides: [String: Any?]) throws -> LocaleO } spacing = spacingTmp } - guard let symbolTmp = localeOverrides["symbol"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "symbol", typeName: "LocaleOverrides")) + guard let symbolTmp = localeOverrides["symbol"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "symbol", typeName: "LocaleOverrides")) + } + let symbol = try asSymbol(symbol: symbolTmp) + + return LocaleOverrides(locale: locale, spacing: spacing, symbol: symbol) } - let symbol = try asSymbol(symbol: symbolTmp) - - - return LocaleOverrides(locale: locale, spacing: spacing, symbol: symbol) -} -static func dictionaryOf(localeOverrides: LocaleOverrides) -> [String: Any?] { - return [ + static func dictionaryOf(localeOverrides: LocaleOverrides) -> [String: Any?] { + return [ "locale": localeOverrides.locale, "spacing": localeOverrides.spacing == nil ? nil : localeOverrides.spacing, - "symbol": dictionaryOf(symbol: localeOverrides.symbol), - ] -} + "symbol": dictionaryOf(symbol: localeOverrides.symbol), + ] + } -static func asLocaleOverridesList(arr: [Any]) throws -> [LocaleOverrides] { - var list = [LocaleOverrides]() - for value in arr { - if let val = value as? [String: Any?] { - var localeOverrides = try asLocaleOverrides(localeOverrides: val) - list.append(localeOverrides) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LocaleOverrides")) + static func asLocaleOverridesList(arr: [Any]) throws -> [LocaleOverrides] { + var list = [LocaleOverrides]() + for value in arr { + if let val = value as? [String: Any?] { + var localeOverrides = try asLocaleOverrides(localeOverrides: val) + list.append(localeOverrides) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LocaleOverrides")) + } } + return list } - return list -} -static func arrayOf(`localeOverridesList`: [LocaleOverrides]) -> [Any] { - return `localeOverridesList`.map { (v) -> [String: Any?] in return dictionaryOf(localeOverrides: v) } -} -static func asLocalizedName(localizedName: [String: Any?]) throws -> LocalizedName { - guard let locale = localizedName["locale"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocalizedName")) + static func arrayOf(localeOverridesList: [LocaleOverrides]) -> [Any] { + return localeOverridesList.map { v -> [String: Any?] in return dictionaryOf(localeOverrides: v) } } - guard let name = localizedName["name"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "LocalizedName")) + + static func asLocalizedName(localizedName: [String: Any?]) throws -> LocalizedName { + guard let locale = localizedName["locale"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "locale", typeName: "LocalizedName")) + } + guard let name = localizedName["name"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "name", typeName: "LocalizedName")) + } + + return LocalizedName(locale: locale, name: name) } - - return LocalizedName(locale: locale, name: name) -} -static func dictionaryOf(localizedName: LocalizedName) -> [String: Any?] { - return [ + static func dictionaryOf(localizedName: LocalizedName) -> [String: Any?] { + return [ "locale": localizedName.locale, - "name": localizedName.name, - ] -} + "name": localizedName.name, + ] + } -static func asLocalizedNameList(arr: [Any]) throws -> [LocalizedName] { - var list = [LocalizedName]() - for value in arr { - if let val = value as? [String: Any?] { - var localizedName = try asLocalizedName(localizedName: val) - list.append(localizedName) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LocalizedName")) + static func asLocalizedNameList(arr: [Any]) throws -> [LocalizedName] { + var list = [LocalizedName]() + for value in arr { + if let val = value as? [String: Any?] { + var localizedName = try asLocalizedName(localizedName: val) + list.append(localizedName) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LocalizedName")) + } } + return list } - return list -} -static func arrayOf(`localizedNameList`: [LocalizedName]) -> [Any] { - return `localizedNameList`.map { (v) -> [String: Any?] in return dictionaryOf(localizedName: v) } -} -static func asLogEntry(logEntry: [String: Any?]) throws -> LogEntry { - guard let line = logEntry["line"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "line", typeName: "LogEntry")) + static func arrayOf(localizedNameList: [LocalizedName]) -> [Any] { + return localizedNameList.map { v -> [String: Any?] in return dictionaryOf(localizedName: v) } } - guard let level = logEntry["level"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "level", typeName: "LogEntry")) + + static func asLogEntry(logEntry: [String: Any?]) throws -> LogEntry { + guard let line = logEntry["line"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "line", typeName: "LogEntry")) + } + guard let level = logEntry["level"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "level", typeName: "LogEntry")) + } + + return LogEntry(line: line, level: level) } - - return LogEntry(line: line, level: level) -} -static func dictionaryOf(logEntry: LogEntry) -> [String: Any?] { - return [ + static func dictionaryOf(logEntry: LogEntry) -> [String: Any?] { + return [ "line": logEntry.line, - "level": logEntry.level, - ] -} + "level": logEntry.level, + ] + } -static func asLogEntryList(arr: [Any]) throws -> [LogEntry] { - var list = [LogEntry]() - for value in arr { - if let val = value as? [String: Any?] { - var logEntry = try asLogEntry(logEntry: val) - list.append(logEntry) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LogEntry")) + static func asLogEntryList(arr: [Any]) throws -> [LogEntry] { + var list = [LogEntry]() + for value in arr { + if let val = value as? [String: Any?] { + var logEntry = try asLogEntry(logEntry: val) + list.append(logEntry) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LogEntry")) + } } + return list } - return list -} -static func arrayOf(`logEntryList`: [LogEntry]) -> [Any] { - return `logEntryList`.map { (v) -> [String: Any?] in return dictionaryOf(logEntry: v) } -} -static func asMessageSuccessActionData(messageSuccessActionData: [String: Any?]) throws -> MessageSuccessActionData { - guard let message = messageSuccessActionData["message"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "MessageSuccessActionData")) + static func arrayOf(logEntryList: [LogEntry]) -> [Any] { + return logEntryList.map { v -> [String: Any?] in return dictionaryOf(logEntry: v) } } - - return MessageSuccessActionData(message: message) -} - -static func dictionaryOf(messageSuccessActionData: MessageSuccessActionData) -> [String: Any?] { - return [ - "message": messageSuccessActionData.message, - ] -} -static func asMessageSuccessActionDataList(arr: [Any]) throws -> [MessageSuccessActionData] { - var list = [MessageSuccessActionData]() - for value in arr { - if let val = value as? [String: Any?] { - var messageSuccessActionData = try asMessageSuccessActionData(messageSuccessActionData: val) - list.append(messageSuccessActionData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "MessageSuccessActionData")) + static func asMessageSuccessActionData(messageSuccessActionData: [String: Any?]) throws -> MessageSuccessActionData { + guard let message = messageSuccessActionData["message"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "MessageSuccessActionData")) } - } - return list -} -static func arrayOf(`messageSuccessActionDataList`: [MessageSuccessActionData]) -> [Any] { - return `messageSuccessActionDataList`.map { (v) -> [String: Any?] in return dictionaryOf(messageSuccessActionData: v) } -} -static func asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: [String: Any?]) throws -> OnchainPaymentLimitsResponse { - guard let sendTmp = onchainPaymentLimitsResponse["send"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "OnchainPaymentLimitsResponse")) - } - let send = try asLimits(limits: sendTmp) - - guard let receiveTmp = onchainPaymentLimitsResponse["receive"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "OnchainPaymentLimitsResponse")) - } - let receive = try asLimits(limits: receiveTmp) - - - return OnchainPaymentLimitsResponse(send: send, receive: receive) -} + return MessageSuccessActionData(message: message) + } -static func dictionaryOf(onchainPaymentLimitsResponse: OnchainPaymentLimitsResponse) -> [String: Any?] { - return [ - "send": dictionaryOf(limits: onchainPaymentLimitsResponse.send), - "receive": dictionaryOf(limits: onchainPaymentLimitsResponse.receive), - ] -} + static func dictionaryOf(messageSuccessActionData: MessageSuccessActionData) -> [String: Any?] { + return [ + "message": messageSuccessActionData.message, + ] + } -static func asOnchainPaymentLimitsResponseList(arr: [Any]) throws -> [OnchainPaymentLimitsResponse] { - var list = [OnchainPaymentLimitsResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var onchainPaymentLimitsResponse = try asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: val) - list.append(onchainPaymentLimitsResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "OnchainPaymentLimitsResponse")) + static func asMessageSuccessActionDataList(arr: [Any]) throws -> [MessageSuccessActionData] { + var list = [MessageSuccessActionData]() + for value in arr { + if let val = value as? [String: Any?] { + var messageSuccessActionData = try asMessageSuccessActionData(messageSuccessActionData: val) + list.append(messageSuccessActionData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "MessageSuccessActionData")) + } } + return list } - return list -} -static func arrayOf(`onchainPaymentLimitsResponseList`: [OnchainPaymentLimitsResponse]) -> [Any] { - return `onchainPaymentLimitsResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(onchainPaymentLimitsResponse: v) } -} -static func asPayOnchainRequest(payOnchainRequest: [String: Any?]) throws -> PayOnchainRequest { - guard let address = payOnchainRequest["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "PayOnchainRequest")) + static func arrayOf(messageSuccessActionDataList: [MessageSuccessActionData]) -> [Any] { + return messageSuccessActionDataList.map { v -> [String: Any?] in return dictionaryOf(messageSuccessActionData: v) } } - guard let prepareResponseTmp = payOnchainRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "PayOnchainRequest")) - } - let prepareResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: prepareResponseTmp) - - - return PayOnchainRequest(address: address, prepareResponse: prepareResponse) -} -static func dictionaryOf(payOnchainRequest: PayOnchainRequest) -> [String: Any?] { - return [ - "address": payOnchainRequest.address, - "prepareResponse": dictionaryOf(preparePayOnchainResponse: payOnchainRequest.prepareResponse), - ] -} + static func asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: [String: Any?]) throws -> OnchainPaymentLimitsResponse { + guard let sendTmp = onchainPaymentLimitsResponse["send"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "send", typeName: "OnchainPaymentLimitsResponse")) + } + let send = try asLimits(limits: sendTmp) -static func asPayOnchainRequestList(arr: [Any]) throws -> [PayOnchainRequest] { - var list = [PayOnchainRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var payOnchainRequest = try asPayOnchainRequest(payOnchainRequest: val) - list.append(payOnchainRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainRequest")) + guard let receiveTmp = onchainPaymentLimitsResponse["receive"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receive", typeName: "OnchainPaymentLimitsResponse")) } + let receive = try asLimits(limits: receiveTmp) + + return OnchainPaymentLimitsResponse(send: send, receive: receive) } - return list -} -static func arrayOf(`payOnchainRequestList`: [PayOnchainRequest]) -> [Any] { - return `payOnchainRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(payOnchainRequest: v) } -} -static func asPayment(payment: [String: Any?]) throws -> Payment { - guard let timestamp = payment["timestamp"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "Payment")) + static func dictionaryOf(onchainPaymentLimitsResponse: OnchainPaymentLimitsResponse) -> [String: Any?] { + return [ + "send": dictionaryOf(limits: onchainPaymentLimitsResponse.send), + "receive": dictionaryOf(limits: onchainPaymentLimitsResponse.receive), + ] + } + + static func asOnchainPaymentLimitsResponseList(arr: [Any]) throws -> [OnchainPaymentLimitsResponse] { + var list = [OnchainPaymentLimitsResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var onchainPaymentLimitsResponse = try asOnchainPaymentLimitsResponse(onchainPaymentLimitsResponse: val) + list.append(onchainPaymentLimitsResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "OnchainPaymentLimitsResponse")) + } + } + return list } - guard let amountSat = payment["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "Payment")) + + static func arrayOf(onchainPaymentLimitsResponseList: [OnchainPaymentLimitsResponse]) -> [Any] { + return onchainPaymentLimitsResponseList.map { v -> [String: Any?] in return dictionaryOf(onchainPaymentLimitsResponse: v) } } - guard let feesSat = payment["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "Payment")) + + static func asPayOnchainRequest(payOnchainRequest: [String: Any?]) throws -> PayOnchainRequest { + guard let address = payOnchainRequest["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "PayOnchainRequest")) + } + guard let prepareResponseTmp = payOnchainRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "PayOnchainRequest")) + } + let prepareResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: prepareResponseTmp) + + return PayOnchainRequest(address: address, prepareResponse: prepareResponse) } - guard let paymentTypeTmp = payment["paymentType"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentType", typeName: "Payment")) + + static func dictionaryOf(payOnchainRequest: PayOnchainRequest) -> [String: Any?] { + return [ + "address": payOnchainRequest.address, + "prepareResponse": dictionaryOf(preparePayOnchainResponse: payOnchainRequest.prepareResponse), + ] } - let paymentType = try asPaymentType(paymentType: paymentTypeTmp) - - guard let statusTmp = payment["status"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "status", typeName: "Payment")) + + static func asPayOnchainRequestList(arr: [Any]) throws -> [PayOnchainRequest] { + var list = [PayOnchainRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var payOnchainRequest = try asPayOnchainRequest(payOnchainRequest: val) + list.append(payOnchainRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainRequest")) + } + } + return list } - let status = try asPaymentState(paymentState: statusTmp) - - guard let detailsTmp = payment["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "Payment")) + + static func arrayOf(payOnchainRequestList: [PayOnchainRequest]) -> [Any] { + return payOnchainRequestList.map { v -> [String: Any?] in return dictionaryOf(payOnchainRequest: v) } } - let details = try asPaymentDetails(paymentDetails: detailsTmp) - + + static func asPayment(payment: [String: Any?]) throws -> Payment { + guard let timestamp = payment["timestamp"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "Payment")) + } + guard let amountSat = payment["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "Payment")) + } + guard let feesSat = payment["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "Payment")) + } + guard let paymentTypeTmp = payment["paymentType"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentType", typeName: "Payment")) + } + let paymentType = try asPaymentType(paymentType: paymentTypeTmp) + + guard let statusTmp = payment["status"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "status", typeName: "Payment")) + } + let status = try asPaymentState(paymentState: statusTmp) + + guard let detailsTmp = payment["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "Payment")) + } + let details = try asPaymentDetails(paymentDetails: detailsTmp) + var destination: String? if hasNonNilKey(data: payment, key: "destination") { guard let destinationTmp = payment["destination"] as? String else { @@ -1495,124 +1517,127 @@ static func asPayment(payment: [String: Any?]) throws -> Payment { } txId = txIdTmp } - - return Payment(timestamp: timestamp, amountSat: amountSat, feesSat: feesSat, paymentType: paymentType, status: status, details: details, destination: destination, txId: txId) -} -static func dictionaryOf(payment: Payment) -> [String: Any?] { - return [ + return Payment(timestamp: timestamp, amountSat: amountSat, feesSat: feesSat, paymentType: paymentType, status: status, details: details, destination: destination, txId: txId) + } + + static func dictionaryOf(payment: Payment) -> [String: Any?] { + return [ "timestamp": payment.timestamp, "amountSat": payment.amountSat, "feesSat": payment.feesSat, - "paymentType": valueOf( paymentType: payment.paymentType), - "status": valueOf( paymentState: payment.status), + "paymentType": valueOf(paymentType: payment.paymentType), + "status": valueOf(paymentState: payment.status), "details": dictionaryOf(paymentDetails: payment.details), "destination": payment.destination == nil ? nil : payment.destination, - "txId": payment.txId == nil ? nil : payment.txId, - ] -} + "txId": payment.txId == nil ? nil : payment.txId, + ] + } -static func asPaymentList(arr: [Any]) throws -> [Payment] { - var list = [Payment]() - for value in arr { - if let val = value as? [String: Any?] { - var payment = try asPayment(payment: val) - list.append(payment) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Payment")) + static func asPaymentList(arr: [Any]) throws -> [Payment] { + var list = [Payment]() + for value in arr { + if let val = value as? [String: Any?] { + var payment = try asPayment(payment: val) + list.append(payment) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Payment")) + } } + return list } - return list -} -static func arrayOf(`paymentList`: [Payment]) -> [Any] { - return `paymentList`.map { (v) -> [String: Any?] in return dictionaryOf(payment: v) } -} -static func asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: [String: Any?]) throws -> PrepareBuyBitcoinRequest { - guard let providerTmp = prepareBuyBitcoinRequest["provider"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinRequest")) - } - let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) - - guard let amountSat = prepareBuyBitcoinRequest["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinRequest")) + static func arrayOf(paymentList: [Payment]) -> [Any] { + return paymentList.map { v -> [String: Any?] in return dictionaryOf(payment: v) } } - - return PrepareBuyBitcoinRequest(provider: provider, amountSat: amountSat) -} -static func dictionaryOf(prepareBuyBitcoinRequest: PrepareBuyBitcoinRequest) -> [String: Any?] { - return [ - "provider": valueOf( buyBitcoinProvider: prepareBuyBitcoinRequest.provider), - "amountSat": prepareBuyBitcoinRequest.amountSat, - ] -} + static func asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: [String: Any?]) throws -> PrepareBuyBitcoinRequest { + guard let providerTmp = prepareBuyBitcoinRequest["provider"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinRequest")) + } + let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) -static func asPrepareBuyBitcoinRequestList(arr: [Any]) throws -> [PrepareBuyBitcoinRequest] { - var list = [PrepareBuyBitcoinRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareBuyBitcoinRequest = try asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: val) - list.append(prepareBuyBitcoinRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinRequest")) + guard let amountSat = prepareBuyBitcoinRequest["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinRequest")) } + + return PrepareBuyBitcoinRequest(provider: provider, amountSat: amountSat) } - return list -} -static func arrayOf(`prepareBuyBitcoinRequestList`: [PrepareBuyBitcoinRequest]) -> [Any] { - return `prepareBuyBitcoinRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinRequest: v) } -} -static func asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: [String: Any?]) throws -> PrepareBuyBitcoinResponse { - guard let providerTmp = prepareBuyBitcoinResponse["provider"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinResponse")) + static func dictionaryOf(prepareBuyBitcoinRequest: PrepareBuyBitcoinRequest) -> [String: Any?] { + return [ + "provider": valueOf(buyBitcoinProvider: prepareBuyBitcoinRequest.provider), + "amountSat": prepareBuyBitcoinRequest.amountSat, + ] } - let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) - - guard let amountSat = prepareBuyBitcoinResponse["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinResponse")) + + static func asPrepareBuyBitcoinRequestList(arr: [Any]) throws -> [PrepareBuyBitcoinRequest] { + var list = [PrepareBuyBitcoinRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareBuyBitcoinRequest = try asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: val) + list.append(prepareBuyBitcoinRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinRequest")) + } + } + return list } - guard let feesSat = prepareBuyBitcoinResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareBuyBitcoinResponse")) + + static func arrayOf(prepareBuyBitcoinRequestList: [PrepareBuyBitcoinRequest]) -> [Any] { + return prepareBuyBitcoinRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinRequest: v) } } - - return PrepareBuyBitcoinResponse(provider: provider, amountSat: amountSat, feesSat: feesSat) -} -static func dictionaryOf(prepareBuyBitcoinResponse: PrepareBuyBitcoinResponse) -> [String: Any?] { - return [ - "provider": valueOf( buyBitcoinProvider: prepareBuyBitcoinResponse.provider), - "amountSat": prepareBuyBitcoinResponse.amountSat, - "feesSat": prepareBuyBitcoinResponse.feesSat, - ] -} + static func asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: [String: Any?]) throws -> PrepareBuyBitcoinResponse { + guard let providerTmp = prepareBuyBitcoinResponse["provider"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "provider", typeName: "PrepareBuyBitcoinResponse")) + } + let provider = try asBuyBitcoinProvider(buyBitcoinProvider: providerTmp) -static func asPrepareBuyBitcoinResponseList(arr: [Any]) throws -> [PrepareBuyBitcoinResponse] { - var list = [PrepareBuyBitcoinResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareBuyBitcoinResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: val) - list.append(prepareBuyBitcoinResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinResponse")) + guard let amountSat = prepareBuyBitcoinResponse["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PrepareBuyBitcoinResponse")) + } + guard let feesSat = prepareBuyBitcoinResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareBuyBitcoinResponse")) } + + return PrepareBuyBitcoinResponse(provider: provider, amountSat: amountSat, feesSat: feesSat) } - return list -} -static func arrayOf(`prepareBuyBitcoinResponseList`: [PrepareBuyBitcoinResponse]) -> [Any] { - return `prepareBuyBitcoinResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinResponse: v) } -} -static func asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: [String: Any?]) throws -> PrepareLnUrlPayRequest { - guard let dataTmp = prepareLnUrlPayRequest["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "PrepareLnUrlPayRequest")) + static func dictionaryOf(prepareBuyBitcoinResponse: PrepareBuyBitcoinResponse) -> [String: Any?] { + return [ + "provider": valueOf(buyBitcoinProvider: prepareBuyBitcoinResponse.provider), + "amountSat": prepareBuyBitcoinResponse.amountSat, + "feesSat": prepareBuyBitcoinResponse.feesSat, + ] + } + + static func asPrepareBuyBitcoinResponseList(arr: [Any]) throws -> [PrepareBuyBitcoinResponse] { + var list = [PrepareBuyBitcoinResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareBuyBitcoinResponse = try asPrepareBuyBitcoinResponse(prepareBuyBitcoinResponse: val) + list.append(prepareBuyBitcoinResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareBuyBitcoinResponse")) + } + } + return list } - let data = try asLnUrlPayRequestData(lnUrlPayRequestData: dataTmp) - - guard let amountMsat = prepareLnUrlPayRequest["amountMsat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "PrepareLnUrlPayRequest")) + + static func arrayOf(prepareBuyBitcoinResponseList: [PrepareBuyBitcoinResponse]) -> [Any] { + return prepareBuyBitcoinResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareBuyBitcoinResponse: v) } } + + static func asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: [String: Any?]) throws -> PrepareLnUrlPayRequest { + guard let dataTmp = prepareLnUrlPayRequest["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "PrepareLnUrlPayRequest")) + } + let data = try asLnUrlPayRequestData(lnUrlPayRequestData: dataTmp) + + guard let amountMsat = prepareLnUrlPayRequest["amountMsat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountMsat", typeName: "PrepareLnUrlPayRequest")) + } var comment: String? if hasNonNilKey(data: prepareLnUrlPayRequest, key: "comment") { guard let commentTmp = prepareLnUrlPayRequest["comment"] as? String else { @@ -1627,83 +1652,84 @@ static func asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: [String: Any?]) thr } validateSuccessActionUrl = validateSuccessActionUrlTmp } - - return PrepareLnUrlPayRequest(data: data, amountMsat: amountMsat, comment: comment, validateSuccessActionUrl: validateSuccessActionUrl) -} -static func dictionaryOf(prepareLnUrlPayRequest: PrepareLnUrlPayRequest) -> [String: Any?] { - return [ + return PrepareLnUrlPayRequest(data: data, amountMsat: amountMsat, comment: comment, validateSuccessActionUrl: validateSuccessActionUrl) + } + + static func dictionaryOf(prepareLnUrlPayRequest: PrepareLnUrlPayRequest) -> [String: Any?] { + return [ "data": dictionaryOf(lnUrlPayRequestData: prepareLnUrlPayRequest.data), "amountMsat": prepareLnUrlPayRequest.amountMsat, "comment": prepareLnUrlPayRequest.comment == nil ? nil : prepareLnUrlPayRequest.comment, - "validateSuccessActionUrl": prepareLnUrlPayRequest.validateSuccessActionUrl == nil ? nil : prepareLnUrlPayRequest.validateSuccessActionUrl, - ] -} + "validateSuccessActionUrl": prepareLnUrlPayRequest.validateSuccessActionUrl == nil ? nil : prepareLnUrlPayRequest.validateSuccessActionUrl, + ] + } -static func asPrepareLnUrlPayRequestList(arr: [Any]) throws -> [PrepareLnUrlPayRequest] { - var list = [PrepareLnUrlPayRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareLnUrlPayRequest = try asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: val) - list.append(prepareLnUrlPayRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayRequest")) + static func asPrepareLnUrlPayRequestList(arr: [Any]) throws -> [PrepareLnUrlPayRequest] { + var list = [PrepareLnUrlPayRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareLnUrlPayRequest = try asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: val) + list.append(prepareLnUrlPayRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayRequest")) + } } + return list } - return list -} -static func arrayOf(`prepareLnUrlPayRequestList`: [PrepareLnUrlPayRequest]) -> [Any] { - return `prepareLnUrlPayRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareLnUrlPayRequest: v) } -} -static func asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: [String: Any?]) throws -> PrepareLnUrlPayResponse { - guard let destinationTmp = prepareLnUrlPayResponse["destination"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareLnUrlPayResponse")) - } - let destination = try asSendDestination(sendDestination: destinationTmp) - - guard let feesSat = prepareLnUrlPayResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareLnUrlPayResponse")) + static func arrayOf(prepareLnUrlPayRequestList: [PrepareLnUrlPayRequest]) -> [Any] { + return prepareLnUrlPayRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareLnUrlPayRequest: v) } } + + static func asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: [String: Any?]) throws -> PrepareLnUrlPayResponse { + guard let destinationTmp = prepareLnUrlPayResponse["destination"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareLnUrlPayResponse")) + } + let destination = try asSendDestination(sendDestination: destinationTmp) + + guard let feesSat = prepareLnUrlPayResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareLnUrlPayResponse")) + } var successAction: SuccessAction? if let successActionTmp = prepareLnUrlPayResponse["successAction"] as? [String: Any?] { successAction = try asSuccessAction(successAction: successActionTmp) } - - - return PrepareLnUrlPayResponse(destination: destination, feesSat: feesSat, successAction: successAction) -} -static func dictionaryOf(prepareLnUrlPayResponse: PrepareLnUrlPayResponse) -> [String: Any?] { - return [ + return PrepareLnUrlPayResponse(destination: destination, feesSat: feesSat, successAction: successAction) + } + + static func dictionaryOf(prepareLnUrlPayResponse: PrepareLnUrlPayResponse) -> [String: Any?] { + return [ "destination": dictionaryOf(sendDestination: prepareLnUrlPayResponse.destination), "feesSat": prepareLnUrlPayResponse.feesSat, - "successAction": prepareLnUrlPayResponse.successAction == nil ? nil : dictionaryOf(successAction: prepareLnUrlPayResponse.successAction!), - ] -} + "successAction": prepareLnUrlPayResponse.successAction == nil ? nil : dictionaryOf(successAction: prepareLnUrlPayResponse.successAction!), + ] + } -static func asPrepareLnUrlPayResponseList(arr: [Any]) throws -> [PrepareLnUrlPayResponse] { - var list = [PrepareLnUrlPayResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareLnUrlPayResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: val) - list.append(prepareLnUrlPayResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayResponse")) + static func asPrepareLnUrlPayResponseList(arr: [Any]) throws -> [PrepareLnUrlPayResponse] { + var list = [PrepareLnUrlPayResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareLnUrlPayResponse = try asPrepareLnUrlPayResponse(prepareLnUrlPayResponse: val) + list.append(prepareLnUrlPayResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareLnUrlPayResponse")) + } } + return list } - return list -} -static func arrayOf(`prepareLnUrlPayResponseList`: [PrepareLnUrlPayResponse]) -> [Any] { - return `prepareLnUrlPayResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareLnUrlPayResponse: v) } -} -static func asPreparePayOnchainRequest(preparePayOnchainRequest: [String: Any?]) throws -> PreparePayOnchainRequest { - guard let amountTmp = preparePayOnchainRequest["amount"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amount", typeName: "PreparePayOnchainRequest")) + static func arrayOf(prepareLnUrlPayResponseList: [PrepareLnUrlPayResponse]) -> [Any] { + return prepareLnUrlPayResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareLnUrlPayResponse: v) } } - let amount = try asPayOnchainAmount(payOnchainAmount: amountTmp) - + + static func asPreparePayOnchainRequest(preparePayOnchainRequest: [String: Any?]) throws -> PreparePayOnchainRequest { + guard let amountTmp = preparePayOnchainRequest["amount"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amount", typeName: "PreparePayOnchainRequest")) + } + let amount = try asPayOnchainAmount(payOnchainAmount: amountTmp) + var feeRateSatPerVbyte: UInt32? if hasNonNilKey(data: preparePayOnchainRequest, key: "feeRateSatPerVbyte") { guard let feeRateSatPerVbyteTmp = preparePayOnchainRequest["feeRateSatPerVbyte"] as? UInt32 else { @@ -1711,77 +1737,79 @@ static func asPreparePayOnchainRequest(preparePayOnchainRequest: [String: Any?]) } feeRateSatPerVbyte = feeRateSatPerVbyteTmp } - - return PreparePayOnchainRequest(amount: amount, feeRateSatPerVbyte: feeRateSatPerVbyte) -} -static func dictionaryOf(preparePayOnchainRequest: PreparePayOnchainRequest) -> [String: Any?] { - return [ + return PreparePayOnchainRequest(amount: amount, feeRateSatPerVbyte: feeRateSatPerVbyte) + } + + static func dictionaryOf(preparePayOnchainRequest: PreparePayOnchainRequest) -> [String: Any?] { + return [ "amount": dictionaryOf(payOnchainAmount: preparePayOnchainRequest.amount), - "feeRateSatPerVbyte": preparePayOnchainRequest.feeRateSatPerVbyte == nil ? nil : preparePayOnchainRequest.feeRateSatPerVbyte, - ] -} + "feeRateSatPerVbyte": preparePayOnchainRequest.feeRateSatPerVbyte == nil ? nil : preparePayOnchainRequest.feeRateSatPerVbyte, + ] + } -static func asPreparePayOnchainRequestList(arr: [Any]) throws -> [PreparePayOnchainRequest] { - var list = [PreparePayOnchainRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var preparePayOnchainRequest = try asPreparePayOnchainRequest(preparePayOnchainRequest: val) - list.append(preparePayOnchainRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainRequest")) + static func asPreparePayOnchainRequestList(arr: [Any]) throws -> [PreparePayOnchainRequest] { + var list = [PreparePayOnchainRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var preparePayOnchainRequest = try asPreparePayOnchainRequest(preparePayOnchainRequest: val) + list.append(preparePayOnchainRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainRequest")) + } } + return list } - return list -} -static func arrayOf(`preparePayOnchainRequestList`: [PreparePayOnchainRequest]) -> [Any] { - return `preparePayOnchainRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(preparePayOnchainRequest: v) } -} -static func asPreparePayOnchainResponse(preparePayOnchainResponse: [String: Any?]) throws -> PreparePayOnchainResponse { - guard let receiverAmountSat = preparePayOnchainResponse["receiverAmountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receiverAmountSat", typeName: "PreparePayOnchainResponse")) - } - guard let claimFeesSat = preparePayOnchainResponse["claimFeesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "claimFeesSat", typeName: "PreparePayOnchainResponse")) + static func arrayOf(preparePayOnchainRequestList: [PreparePayOnchainRequest]) -> [Any] { + return preparePayOnchainRequestList.map { v -> [String: Any?] in return dictionaryOf(preparePayOnchainRequest: v) } } - guard let totalFeesSat = preparePayOnchainResponse["totalFeesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "totalFeesSat", typeName: "PreparePayOnchainResponse")) + + static func asPreparePayOnchainResponse(preparePayOnchainResponse: [String: Any?]) throws -> PreparePayOnchainResponse { + guard let receiverAmountSat = preparePayOnchainResponse["receiverAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receiverAmountSat", typeName: "PreparePayOnchainResponse")) + } + guard let claimFeesSat = preparePayOnchainResponse["claimFeesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "claimFeesSat", typeName: "PreparePayOnchainResponse")) + } + guard let totalFeesSat = preparePayOnchainResponse["totalFeesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "totalFeesSat", typeName: "PreparePayOnchainResponse")) + } + + return PreparePayOnchainResponse(receiverAmountSat: receiverAmountSat, claimFeesSat: claimFeesSat, totalFeesSat: totalFeesSat) } - - return PreparePayOnchainResponse(receiverAmountSat: receiverAmountSat, claimFeesSat: claimFeesSat, totalFeesSat: totalFeesSat) -} -static func dictionaryOf(preparePayOnchainResponse: PreparePayOnchainResponse) -> [String: Any?] { - return [ + static func dictionaryOf(preparePayOnchainResponse: PreparePayOnchainResponse) -> [String: Any?] { + return [ "receiverAmountSat": preparePayOnchainResponse.receiverAmountSat, "claimFeesSat": preparePayOnchainResponse.claimFeesSat, - "totalFeesSat": preparePayOnchainResponse.totalFeesSat, - ] -} + "totalFeesSat": preparePayOnchainResponse.totalFeesSat, + ] + } -static func asPreparePayOnchainResponseList(arr: [Any]) throws -> [PreparePayOnchainResponse] { - var list = [PreparePayOnchainResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var preparePayOnchainResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: val) - list.append(preparePayOnchainResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainResponse")) + static func asPreparePayOnchainResponseList(arr: [Any]) throws -> [PreparePayOnchainResponse] { + var list = [PreparePayOnchainResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var preparePayOnchainResponse = try asPreparePayOnchainResponse(preparePayOnchainResponse: val) + list.append(preparePayOnchainResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PreparePayOnchainResponse")) + } } + return list } - return list -} -static func arrayOf(`preparePayOnchainResponseList`: [PreparePayOnchainResponse]) -> [Any] { - return `preparePayOnchainResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(preparePayOnchainResponse: v) } -} -static func asPrepareReceiveRequest(prepareReceiveRequest: [String: Any?]) throws -> PrepareReceiveRequest { - guard let paymentMethodTmp = prepareReceiveRequest["paymentMethod"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveRequest")) + static func arrayOf(preparePayOnchainResponseList: [PreparePayOnchainResponse]) -> [Any] { + return preparePayOnchainResponseList.map { v -> [String: Any?] in return dictionaryOf(preparePayOnchainResponse: v) } } - let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) - + + static func asPrepareReceiveRequest(prepareReceiveRequest: [String: Any?]) throws -> PrepareReceiveRequest { + guard let paymentMethodTmp = prepareReceiveRequest["paymentMethod"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveRequest")) + } + let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) + var payerAmountSat: UInt64? if hasNonNilKey(data: prepareReceiveRequest, key: "payerAmountSat") { guard let payerAmountSatTmp = prepareReceiveRequest["payerAmountSat"] as? UInt64 else { @@ -1789,42 +1817,43 @@ static func asPrepareReceiveRequest(prepareReceiveRequest: [String: Any?]) throw } payerAmountSat = payerAmountSatTmp } - - return PrepareReceiveRequest(paymentMethod: paymentMethod, payerAmountSat: payerAmountSat) -} -static func dictionaryOf(prepareReceiveRequest: PrepareReceiveRequest) -> [String: Any?] { - return [ - "paymentMethod": valueOf( paymentMethod: prepareReceiveRequest.paymentMethod), - "payerAmountSat": prepareReceiveRequest.payerAmountSat == nil ? nil : prepareReceiveRequest.payerAmountSat, - ] -} + return PrepareReceiveRequest(paymentMethod: paymentMethod, payerAmountSat: payerAmountSat) + } -static func asPrepareReceiveRequestList(arr: [Any]) throws -> [PrepareReceiveRequest] { - var list = [PrepareReceiveRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareReceiveRequest = try asPrepareReceiveRequest(prepareReceiveRequest: val) - list.append(prepareReceiveRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveRequest")) - } + static func dictionaryOf(prepareReceiveRequest: PrepareReceiveRequest) -> [String: Any?] { + return [ + "paymentMethod": valueOf(paymentMethod: prepareReceiveRequest.paymentMethod), + "payerAmountSat": prepareReceiveRequest.payerAmountSat == nil ? nil : prepareReceiveRequest.payerAmountSat, + ] } - return list -} -static func arrayOf(`prepareReceiveRequestList`: [PrepareReceiveRequest]) -> [Any] { - return `prepareReceiveRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareReceiveRequest: v) } -} -static func asPrepareReceiveResponse(prepareReceiveResponse: [String: Any?]) throws -> PrepareReceiveResponse { - guard let paymentMethodTmp = prepareReceiveResponse["paymentMethod"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveResponse")) + static func asPrepareReceiveRequestList(arr: [Any]) throws -> [PrepareReceiveRequest] { + var list = [PrepareReceiveRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareReceiveRequest = try asPrepareReceiveRequest(prepareReceiveRequest: val) + list.append(prepareReceiveRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveRequest")) + } + } + return list } - let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) - - guard let feesSat = prepareReceiveResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareReceiveResponse")) + + static func arrayOf(prepareReceiveRequestList: [PrepareReceiveRequest]) -> [Any] { + return prepareReceiveRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareReceiveRequest: v) } } + + static func asPrepareReceiveResponse(prepareReceiveResponse: [String: Any?]) throws -> PrepareReceiveResponse { + guard let paymentMethodTmp = prepareReceiveResponse["paymentMethod"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentMethod", typeName: "PrepareReceiveResponse")) + } + let paymentMethod = try asPaymentMethod(paymentMethod: paymentMethodTmp) + + guard let feesSat = prepareReceiveResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareReceiveResponse")) + } var payerAmountSat: UInt64? if hasNonNilKey(data: prepareReceiveResponse, key: "payerAmountSat") { guard let payerAmountSatTmp = prepareReceiveResponse["payerAmountSat"] as? UInt64 else { @@ -1853,82 +1882,84 @@ static func asPrepareReceiveResponse(prepareReceiveResponse: [String: Any?]) thr } zeroAmountServiceFeerate = zeroAmountServiceFeerateTmp } - - return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, zeroAmountMinPayerAmountSat: zeroAmountMinPayerAmountSat, zeroAmountMaxPayerAmountSat: zeroAmountMaxPayerAmountSat, zeroAmountServiceFeerate: zeroAmountServiceFeerate) -} -static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [String: Any?] { - return [ - "paymentMethod": valueOf( paymentMethod: prepareReceiveResponse.paymentMethod), + return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, zeroAmountMinPayerAmountSat: zeroAmountMinPayerAmountSat, zeroAmountMaxPayerAmountSat: zeroAmountMaxPayerAmountSat, zeroAmountServiceFeerate: zeroAmountServiceFeerate) + } + + static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [String: Any?] { + return [ + "paymentMethod": valueOf(paymentMethod: prepareReceiveResponse.paymentMethod), "feesSat": prepareReceiveResponse.feesSat, "payerAmountSat": prepareReceiveResponse.payerAmountSat == nil ? nil : prepareReceiveResponse.payerAmountSat, "zeroAmountMinPayerAmountSat": prepareReceiveResponse.zeroAmountMinPayerAmountSat == nil ? nil : prepareReceiveResponse.zeroAmountMinPayerAmountSat, "zeroAmountMaxPayerAmountSat": prepareReceiveResponse.zeroAmountMaxPayerAmountSat == nil ? nil : prepareReceiveResponse.zeroAmountMaxPayerAmountSat, - "zeroAmountServiceFeerate": prepareReceiveResponse.zeroAmountServiceFeerate == nil ? nil : prepareReceiveResponse.zeroAmountServiceFeerate, - ] -} + "zeroAmountServiceFeerate": prepareReceiveResponse.zeroAmountServiceFeerate == nil ? nil : prepareReceiveResponse.zeroAmountServiceFeerate, + ] + } -static func asPrepareReceiveResponseList(arr: [Any]) throws -> [PrepareReceiveResponse] { - var list = [PrepareReceiveResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareReceiveResponse = try asPrepareReceiveResponse(prepareReceiveResponse: val) - list.append(prepareReceiveResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveResponse")) + static func asPrepareReceiveResponseList(arr: [Any]) throws -> [PrepareReceiveResponse] { + var list = [PrepareReceiveResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareReceiveResponse = try asPrepareReceiveResponse(prepareReceiveResponse: val) + list.append(prepareReceiveResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareReceiveResponse")) + } } + return list } - return list -} -static func arrayOf(`prepareReceiveResponseList`: [PrepareReceiveResponse]) -> [Any] { - return `prepareReceiveResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareReceiveResponse: v) } -} -static func asPrepareRefundRequest(prepareRefundRequest: [String: Any?]) throws -> PrepareRefundRequest { - guard let swapAddress = prepareRefundRequest["swapAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "PrepareRefundRequest")) + static func arrayOf(prepareReceiveResponseList: [PrepareReceiveResponse]) -> [Any] { + return prepareReceiveResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareReceiveResponse: v) } } - guard let refundAddress = prepareRefundRequest["refundAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "PrepareRefundRequest")) - } - guard let feeRateSatPerVbyte = prepareRefundRequest["feeRateSatPerVbyte"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "PrepareRefundRequest")) + + static func asPrepareRefundRequest(prepareRefundRequest: [String: Any?]) throws -> PrepareRefundRequest { + guard let swapAddress = prepareRefundRequest["swapAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "PrepareRefundRequest")) + } + guard let refundAddress = prepareRefundRequest["refundAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "PrepareRefundRequest")) + } + guard let feeRateSatPerVbyte = prepareRefundRequest["feeRateSatPerVbyte"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "PrepareRefundRequest")) + } + + return PrepareRefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) } - - return PrepareRefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) -} -static func dictionaryOf(prepareRefundRequest: PrepareRefundRequest) -> [String: Any?] { - return [ + static func dictionaryOf(prepareRefundRequest: PrepareRefundRequest) -> [String: Any?] { + return [ "swapAddress": prepareRefundRequest.swapAddress, "refundAddress": prepareRefundRequest.refundAddress, - "feeRateSatPerVbyte": prepareRefundRequest.feeRateSatPerVbyte, - ] -} + "feeRateSatPerVbyte": prepareRefundRequest.feeRateSatPerVbyte, + ] + } -static func asPrepareRefundRequestList(arr: [Any]) throws -> [PrepareRefundRequest] { - var list = [PrepareRefundRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareRefundRequest = try asPrepareRefundRequest(prepareRefundRequest: val) - list.append(prepareRefundRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundRequest")) + static func asPrepareRefundRequestList(arr: [Any]) throws -> [PrepareRefundRequest] { + var list = [PrepareRefundRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareRefundRequest = try asPrepareRefundRequest(prepareRefundRequest: val) + list.append(prepareRefundRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundRequest")) + } } + return list } - return list -} -static func arrayOf(`prepareRefundRequestList`: [PrepareRefundRequest]) -> [Any] { - return `prepareRefundRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareRefundRequest: v) } -} -static func asPrepareRefundResponse(prepareRefundResponse: [String: Any?]) throws -> PrepareRefundResponse { - guard let txVsize = prepareRefundResponse["txVsize"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txVsize", typeName: "PrepareRefundResponse")) - } - guard let txFeeSat = prepareRefundResponse["txFeeSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txFeeSat", typeName: "PrepareRefundResponse")) + static func arrayOf(prepareRefundRequestList: [PrepareRefundRequest]) -> [Any] { + return prepareRefundRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareRefundRequest: v) } } + + static func asPrepareRefundResponse(prepareRefundResponse: [String: Any?]) throws -> PrepareRefundResponse { + guard let txVsize = prepareRefundResponse["txVsize"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txVsize", typeName: "PrepareRefundResponse")) + } + guard let txFeeSat = prepareRefundResponse["txFeeSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "txFeeSat", typeName: "PrepareRefundResponse")) + } var refundTxId: String? if hasNonNilKey(data: prepareRefundResponse, key: "refundTxId") { guard let refundTxIdTmp = prepareRefundResponse["refundTxId"] as? String else { @@ -1936,38 +1967,39 @@ static func asPrepareRefundResponse(prepareRefundResponse: [String: Any?]) throw } refundTxId = refundTxIdTmp } - - return PrepareRefundResponse(txVsize: txVsize, txFeeSat: txFeeSat, refundTxId: refundTxId) -} -static func dictionaryOf(prepareRefundResponse: PrepareRefundResponse) -> [String: Any?] { - return [ + return PrepareRefundResponse(txVsize: txVsize, txFeeSat: txFeeSat, refundTxId: refundTxId) + } + + static func dictionaryOf(prepareRefundResponse: PrepareRefundResponse) -> [String: Any?] { + return [ "txVsize": prepareRefundResponse.txVsize, "txFeeSat": prepareRefundResponse.txFeeSat, - "refundTxId": prepareRefundResponse.refundTxId == nil ? nil : prepareRefundResponse.refundTxId, - ] -} + "refundTxId": prepareRefundResponse.refundTxId == nil ? nil : prepareRefundResponse.refundTxId, + ] + } -static func asPrepareRefundResponseList(arr: [Any]) throws -> [PrepareRefundResponse] { - var list = [PrepareRefundResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareRefundResponse = try asPrepareRefundResponse(prepareRefundResponse: val) - list.append(prepareRefundResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundResponse")) + static func asPrepareRefundResponseList(arr: [Any]) throws -> [PrepareRefundResponse] { + var list = [PrepareRefundResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareRefundResponse = try asPrepareRefundResponse(prepareRefundResponse: val) + list.append(prepareRefundResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareRefundResponse")) + } } + return list } - return list -} -static func arrayOf(`prepareRefundResponseList`: [PrepareRefundResponse]) -> [Any] { - return `prepareRefundResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareRefundResponse: v) } -} -static func asPrepareSendRequest(prepareSendRequest: [String: Any?]) throws -> PrepareSendRequest { - guard let destination = prepareSendRequest["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendRequest")) + static func arrayOf(prepareRefundResponseList: [PrepareRefundResponse]) -> [Any] { + return prepareRefundResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareRefundResponse: v) } } + + static func asPrepareSendRequest(prepareSendRequest: [String: Any?]) throws -> PrepareSendRequest { + guard let destination = prepareSendRequest["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendRequest")) + } var amountSat: UInt64? if hasNonNilKey(data: prepareSendRequest, key: "amountSat") { guard let amountSatTmp = prepareSendRequest["amountSat"] as? UInt64 else { @@ -1975,109 +2007,112 @@ static func asPrepareSendRequest(prepareSendRequest: [String: Any?]) throws -> P } amountSat = amountSatTmp } - - return PrepareSendRequest(destination: destination, amountSat: amountSat) -} -static func dictionaryOf(prepareSendRequest: PrepareSendRequest) -> [String: Any?] { - return [ + return PrepareSendRequest(destination: destination, amountSat: amountSat) + } + + static func dictionaryOf(prepareSendRequest: PrepareSendRequest) -> [String: Any?] { + return [ "destination": prepareSendRequest.destination, - "amountSat": prepareSendRequest.amountSat == nil ? nil : prepareSendRequest.amountSat, - ] -} + "amountSat": prepareSendRequest.amountSat == nil ? nil : prepareSendRequest.amountSat, + ] + } -static func asPrepareSendRequestList(arr: [Any]) throws -> [PrepareSendRequest] { - var list = [PrepareSendRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareSendRequest = try asPrepareSendRequest(prepareSendRequest: val) - list.append(prepareSendRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendRequest")) + static func asPrepareSendRequestList(arr: [Any]) throws -> [PrepareSendRequest] { + var list = [PrepareSendRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareSendRequest = try asPrepareSendRequest(prepareSendRequest: val) + list.append(prepareSendRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendRequest")) + } } + return list } - return list -} -static func arrayOf(`prepareSendRequestList`: [PrepareSendRequest]) -> [Any] { - return `prepareSendRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareSendRequest: v) } -} -static func asPrepareSendResponse(prepareSendResponse: [String: Any?]) throws -> PrepareSendResponse { - guard let destinationTmp = prepareSendResponse["destination"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendResponse")) + static func arrayOf(prepareSendRequestList: [PrepareSendRequest]) -> [Any] { + return prepareSendRequestList.map { v -> [String: Any?] in return dictionaryOf(prepareSendRequest: v) } } - let destination = try asSendDestination(sendDestination: destinationTmp) - - guard let feesSat = prepareSendResponse["feesSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareSendResponse")) + + static func asPrepareSendResponse(prepareSendResponse: [String: Any?]) throws -> PrepareSendResponse { + guard let destinationTmp = prepareSendResponse["destination"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PrepareSendResponse")) + } + let destination = try asSendDestination(sendDestination: destinationTmp) + + guard let feesSat = prepareSendResponse["feesSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesSat", typeName: "PrepareSendResponse")) + } + + return PrepareSendResponse(destination: destination, feesSat: feesSat) } - - return PrepareSendResponse(destination: destination, feesSat: feesSat) -} -static func dictionaryOf(prepareSendResponse: PrepareSendResponse) -> [String: Any?] { - return [ + static func dictionaryOf(prepareSendResponse: PrepareSendResponse) -> [String: Any?] { + return [ "destination": dictionaryOf(sendDestination: prepareSendResponse.destination), - "feesSat": prepareSendResponse.feesSat, - ] -} + "feesSat": prepareSendResponse.feesSat, + ] + } -static func asPrepareSendResponseList(arr: [Any]) throws -> [PrepareSendResponse] { - var list = [PrepareSendResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var prepareSendResponse = try asPrepareSendResponse(prepareSendResponse: val) - list.append(prepareSendResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendResponse")) + static func asPrepareSendResponseList(arr: [Any]) throws -> [PrepareSendResponse] { + var list = [PrepareSendResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var prepareSendResponse = try asPrepareSendResponse(prepareSendResponse: val) + list.append(prepareSendResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PrepareSendResponse")) + } } + return list } - return list -} -static func arrayOf(`prepareSendResponseList`: [PrepareSendResponse]) -> [Any] { - return `prepareSendResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(prepareSendResponse: v) } -} -static func asRate(rate: [String: Any?]) throws -> Rate { - guard let coin = rate["coin"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "coin", typeName: "Rate")) + static func arrayOf(prepareSendResponseList: [PrepareSendResponse]) -> [Any] { + return prepareSendResponseList.map { v -> [String: Any?] in return dictionaryOf(prepareSendResponse: v) } } - guard let value = rate["value"] as? Double else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "value", typeName: "Rate")) + + static func asRate(rate: [String: Any?]) throws -> Rate { + guard let coin = rate["coin"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "coin", typeName: "Rate")) + } + guard let value = rate["value"] as? Double else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "value", typeName: "Rate")) + } + + return Rate(coin: coin, value: value) } - - return Rate(coin: coin, value: value) -} -static func dictionaryOf(rate: Rate) -> [String: Any?] { - return [ + static func dictionaryOf(rate: Rate) -> [String: Any?] { + return [ "coin": rate.coin, - "value": rate.value, - ] -} + "value": rate.value, + ] + } -static func asRateList(arr: [Any]) throws -> [Rate] { - var list = [Rate]() - for value in arr { - if let val = value as? [String: Any?] { - var rate = try asRate(rate: val) - list.append(rate) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Rate")) + static func asRateList(arr: [Any]) throws -> [Rate] { + var list = [Rate]() + for value in arr { + if let val = value as? [String: Any?] { + var rate = try asRate(rate: val) + list.append(rate) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Rate")) + } } + return list } - return list -} -static func arrayOf(`rateList`: [Rate]) -> [Any] { - return `rateList`.map { (v) -> [String: Any?] in return dictionaryOf(rate: v) } -} -static func asReceivePaymentRequest(receivePaymentRequest: [String: Any?]) throws -> ReceivePaymentRequest { - guard let prepareResponseTmp = receivePaymentRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "ReceivePaymentRequest")) + static func arrayOf(rateList: [Rate]) -> [Any] { + return rateList.map { v -> [String: Any?] in return dictionaryOf(rate: v) } } - let prepareResponse = try asPrepareReceiveResponse(prepareReceiveResponse: prepareResponseTmp) - + + static func asReceivePaymentRequest(receivePaymentRequest: [String: Any?]) throws -> ReceivePaymentRequest { + guard let prepareResponseTmp = receivePaymentRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "ReceivePaymentRequest")) + } + let prepareResponse = try asPrepareReceiveResponse(prepareReceiveResponse: prepareResponseTmp) + var description: String? if hasNonNilKey(data: receivePaymentRequest, key: "description") { guard let descriptionTmp = receivePaymentRequest["description"] as? String else { @@ -2092,217 +2127,223 @@ static func asReceivePaymentRequest(receivePaymentRequest: [String: Any?]) throw } useDescriptionHash = useDescriptionHashTmp } - - return ReceivePaymentRequest(prepareResponse: prepareResponse, description: description, useDescriptionHash: useDescriptionHash) -} -static func dictionaryOf(receivePaymentRequest: ReceivePaymentRequest) -> [String: Any?] { - return [ + return ReceivePaymentRequest(prepareResponse: prepareResponse, description: description, useDescriptionHash: useDescriptionHash) + } + + static func dictionaryOf(receivePaymentRequest: ReceivePaymentRequest) -> [String: Any?] { + return [ "prepareResponse": dictionaryOf(prepareReceiveResponse: receivePaymentRequest.prepareResponse), "description": receivePaymentRequest.description == nil ? nil : receivePaymentRequest.description, - "useDescriptionHash": receivePaymentRequest.useDescriptionHash == nil ? nil : receivePaymentRequest.useDescriptionHash, - ] -} + "useDescriptionHash": receivePaymentRequest.useDescriptionHash == nil ? nil : receivePaymentRequest.useDescriptionHash, + ] + } -static func asReceivePaymentRequestList(arr: [Any]) throws -> [ReceivePaymentRequest] { - var list = [ReceivePaymentRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var receivePaymentRequest = try asReceivePaymentRequest(receivePaymentRequest: val) - list.append(receivePaymentRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentRequest")) + static func asReceivePaymentRequestList(arr: [Any]) throws -> [ReceivePaymentRequest] { + var list = [ReceivePaymentRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var receivePaymentRequest = try asReceivePaymentRequest(receivePaymentRequest: val) + list.append(receivePaymentRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentRequest")) + } } + return list } - return list -} -static func arrayOf(`receivePaymentRequestList`: [ReceivePaymentRequest]) -> [Any] { - return `receivePaymentRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(receivePaymentRequest: v) } -} -static func asReceivePaymentResponse(receivePaymentResponse: [String: Any?]) throws -> ReceivePaymentResponse { - guard let destination = receivePaymentResponse["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ReceivePaymentResponse")) + static func arrayOf(receivePaymentRequestList: [ReceivePaymentRequest]) -> [Any] { + return receivePaymentRequestList.map { v -> [String: Any?] in return dictionaryOf(receivePaymentRequest: v) } } - - return ReceivePaymentResponse(destination: destination) -} - -static func dictionaryOf(receivePaymentResponse: ReceivePaymentResponse) -> [String: Any?] { - return [ - "destination": receivePaymentResponse.destination, - ] -} -static func asReceivePaymentResponseList(arr: [Any]) throws -> [ReceivePaymentResponse] { - var list = [ReceivePaymentResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var receivePaymentResponse = try asReceivePaymentResponse(receivePaymentResponse: val) - list.append(receivePaymentResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentResponse")) + static func asReceivePaymentResponse(receivePaymentResponse: [String: Any?]) throws -> ReceivePaymentResponse { + guard let destination = receivePaymentResponse["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ReceivePaymentResponse")) } - } - return list -} -static func arrayOf(`receivePaymentResponseList`: [ReceivePaymentResponse]) -> [Any] { - return `receivePaymentResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(receivePaymentResponse: v) } -} -static func asRecommendedFees(recommendedFees: [String: Any?]) throws -> RecommendedFees { - guard let fastestFee = recommendedFees["fastestFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fastestFee", typeName: "RecommendedFees")) + return ReceivePaymentResponse(destination: destination) } - guard let halfHourFee = recommendedFees["halfHourFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "halfHourFee", typeName: "RecommendedFees")) + + static func dictionaryOf(receivePaymentResponse: ReceivePaymentResponse) -> [String: Any?] { + return [ + "destination": receivePaymentResponse.destination, + ] } - guard let hourFee = recommendedFees["hourFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hourFee", typeName: "RecommendedFees")) + + static func asReceivePaymentResponseList(arr: [Any]) throws -> [ReceivePaymentResponse] { + var list = [ReceivePaymentResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var receivePaymentResponse = try asReceivePaymentResponse(receivePaymentResponse: val) + list.append(receivePaymentResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ReceivePaymentResponse")) + } + } + return list } - guard let economyFee = recommendedFees["economyFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "economyFee", typeName: "RecommendedFees")) + + static func arrayOf(receivePaymentResponseList: [ReceivePaymentResponse]) -> [Any] { + return receivePaymentResponseList.map { v -> [String: Any?] in return dictionaryOf(receivePaymentResponse: v) } } - guard let minimumFee = recommendedFees["minimumFee"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minimumFee", typeName: "RecommendedFees")) + + static func asRecommendedFees(recommendedFees: [String: Any?]) throws -> RecommendedFees { + guard let fastestFee = recommendedFees["fastestFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "fastestFee", typeName: "RecommendedFees")) + } + guard let halfHourFee = recommendedFees["halfHourFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "halfHourFee", typeName: "RecommendedFees")) + } + guard let hourFee = recommendedFees["hourFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hourFee", typeName: "RecommendedFees")) + } + guard let economyFee = recommendedFees["economyFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "economyFee", typeName: "RecommendedFees")) + } + guard let minimumFee = recommendedFees["minimumFee"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "minimumFee", typeName: "RecommendedFees")) + } + + return RecommendedFees(fastestFee: fastestFee, halfHourFee: halfHourFee, hourFee: hourFee, economyFee: economyFee, minimumFee: minimumFee) } - - return RecommendedFees(fastestFee: fastestFee, halfHourFee: halfHourFee, hourFee: hourFee, economyFee: economyFee, minimumFee: minimumFee) -} -static func dictionaryOf(recommendedFees: RecommendedFees) -> [String: Any?] { - return [ + static func dictionaryOf(recommendedFees: RecommendedFees) -> [String: Any?] { + return [ "fastestFee": recommendedFees.fastestFee, "halfHourFee": recommendedFees.halfHourFee, "hourFee": recommendedFees.hourFee, "economyFee": recommendedFees.economyFee, - "minimumFee": recommendedFees.minimumFee, - ] -} + "minimumFee": recommendedFees.minimumFee, + ] + } -static func asRecommendedFeesList(arr: [Any]) throws -> [RecommendedFees] { - var list = [RecommendedFees]() - for value in arr { - if let val = value as? [String: Any?] { - var recommendedFees = try asRecommendedFees(recommendedFees: val) - list.append(recommendedFees) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RecommendedFees")) + static func asRecommendedFeesList(arr: [Any]) throws -> [RecommendedFees] { + var list = [RecommendedFees]() + for value in arr { + if let val = value as? [String: Any?] { + var recommendedFees = try asRecommendedFees(recommendedFees: val) + list.append(recommendedFees) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RecommendedFees")) + } } + return list } - return list -} -static func arrayOf(`recommendedFeesList`: [RecommendedFees]) -> [Any] { - return `recommendedFeesList`.map { (v) -> [String: Any?] in return dictionaryOf(recommendedFees: v) } -} -static func asRefundRequest(refundRequest: [String: Any?]) throws -> RefundRequest { - guard let swapAddress = refundRequest["swapAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundRequest")) + static func arrayOf(recommendedFeesList: [RecommendedFees]) -> [Any] { + return recommendedFeesList.map { v -> [String: Any?] in return dictionaryOf(recommendedFees: v) } } - guard let refundAddress = refundRequest["refundAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "RefundRequest")) - } - guard let feeRateSatPerVbyte = refundRequest["feeRateSatPerVbyte"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "RefundRequest")) + + static func asRefundRequest(refundRequest: [String: Any?]) throws -> RefundRequest { + guard let swapAddress = refundRequest["swapAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundRequest")) + } + guard let refundAddress = refundRequest["refundAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundAddress", typeName: "RefundRequest")) + } + guard let feeRateSatPerVbyte = refundRequest["feeRateSatPerVbyte"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feeRateSatPerVbyte", typeName: "RefundRequest")) + } + + return RefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) } - - return RefundRequest(swapAddress: swapAddress, refundAddress: refundAddress, feeRateSatPerVbyte: feeRateSatPerVbyte) -} -static func dictionaryOf(refundRequest: RefundRequest) -> [String: Any?] { - return [ + static func dictionaryOf(refundRequest: RefundRequest) -> [String: Any?] { + return [ "swapAddress": refundRequest.swapAddress, "refundAddress": refundRequest.refundAddress, - "feeRateSatPerVbyte": refundRequest.feeRateSatPerVbyte, - ] -} + "feeRateSatPerVbyte": refundRequest.feeRateSatPerVbyte, + ] + } -static func asRefundRequestList(arr: [Any]) throws -> [RefundRequest] { - var list = [RefundRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var refundRequest = try asRefundRequest(refundRequest: val) - list.append(refundRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundRequest")) + static func asRefundRequestList(arr: [Any]) throws -> [RefundRequest] { + var list = [RefundRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var refundRequest = try asRefundRequest(refundRequest: val) + list.append(refundRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundRequest")) + } } + return list } - return list -} -static func arrayOf(`refundRequestList`: [RefundRequest]) -> [Any] { - return `refundRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(refundRequest: v) } -} -static func asRefundResponse(refundResponse: [String: Any?]) throws -> RefundResponse { - guard let refundTxId = refundResponse["refundTxId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundTxId", typeName: "RefundResponse")) + static func arrayOf(refundRequestList: [RefundRequest]) -> [Any] { + return refundRequestList.map { v -> [String: Any?] in return dictionaryOf(refundRequest: v) } } - - return RefundResponse(refundTxId: refundTxId) -} - -static func dictionaryOf(refundResponse: RefundResponse) -> [String: Any?] { - return [ - "refundTxId": refundResponse.refundTxId, - ] -} -static func asRefundResponseList(arr: [Any]) throws -> [RefundResponse] { - var list = [RefundResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var refundResponse = try asRefundResponse(refundResponse: val) - list.append(refundResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundResponse")) + static func asRefundResponse(refundResponse: [String: Any?]) throws -> RefundResponse { + guard let refundTxId = refundResponse["refundTxId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "refundTxId", typeName: "RefundResponse")) } + + return RefundResponse(refundTxId: refundTxId) } - return list -} -static func arrayOf(`refundResponseList`: [RefundResponse]) -> [Any] { - return `refundResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(refundResponse: v) } -} -static func asRefundableSwap(refundableSwap: [String: Any?]) throws -> RefundableSwap { - guard let swapAddress = refundableSwap["swapAddress"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundableSwap")) + static func dictionaryOf(refundResponse: RefundResponse) -> [String: Any?] { + return [ + "refundTxId": refundResponse.refundTxId, + ] + } + + static func asRefundResponseList(arr: [Any]) throws -> [RefundResponse] { + var list = [RefundResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var refundResponse = try asRefundResponse(refundResponse: val) + list.append(refundResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundResponse")) + } + } + return list } - guard let timestamp = refundableSwap["timestamp"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "RefundableSwap")) + + static func arrayOf(refundResponseList: [RefundResponse]) -> [Any] { + return refundResponseList.map { v -> [String: Any?] in return dictionaryOf(refundResponse: v) } } - guard let amountSat = refundableSwap["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "RefundableSwap")) + + static func asRefundableSwap(refundableSwap: [String: Any?]) throws -> RefundableSwap { + guard let swapAddress = refundableSwap["swapAddress"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapAddress", typeName: "RefundableSwap")) + } + guard let timestamp = refundableSwap["timestamp"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "RefundableSwap")) + } + guard let amountSat = refundableSwap["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "RefundableSwap")) + } + + return RefundableSwap(swapAddress: swapAddress, timestamp: timestamp, amountSat: amountSat) } - - return RefundableSwap(swapAddress: swapAddress, timestamp: timestamp, amountSat: amountSat) -} -static func dictionaryOf(refundableSwap: RefundableSwap) -> [String: Any?] { - return [ + static func dictionaryOf(refundableSwap: RefundableSwap) -> [String: Any?] { + return [ "swapAddress": refundableSwap.swapAddress, "timestamp": refundableSwap.timestamp, - "amountSat": refundableSwap.amountSat, - ] -} + "amountSat": refundableSwap.amountSat, + ] + } -static func asRefundableSwapList(arr: [Any]) throws -> [RefundableSwap] { - var list = [RefundableSwap]() - for value in arr { - if let val = value as? [String: Any?] { - var refundableSwap = try asRefundableSwap(refundableSwap: val) - list.append(refundableSwap) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundableSwap")) + static func asRefundableSwapList(arr: [Any]) throws -> [RefundableSwap] { + var list = [RefundableSwap]() + for value in arr { + if let val = value as? [String: Any?] { + var refundableSwap = try asRefundableSwap(refundableSwap: val) + list.append(refundableSwap) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RefundableSwap")) + } } + return list } - return list -} -static func arrayOf(`refundableSwapList`: [RefundableSwap]) -> [Any] { - return `refundableSwapList`.map { (v) -> [String: Any?] in return dictionaryOf(refundableSwap: v) } -} -static func asRestoreRequest(restoreRequest: [String: Any?]) throws -> RestoreRequest { + static func arrayOf(refundableSwapList: [RefundableSwap]) -> [Any] { + return refundableSwapList.map { v -> [String: Any?] in return dictionaryOf(refundableSwap: v) } + } + + static func asRestoreRequest(restoreRequest: [String: Any?]) throws -> RestoreRequest { var backupPath: String? if hasNonNilKey(data: restoreRequest, key: "backupPath") { guard let backupPathTmp = restoreRequest["backupPath"] as? String else { @@ -2310,80 +2351,81 @@ static func asRestoreRequest(restoreRequest: [String: Any?]) throws -> RestoreRe } backupPath = backupPathTmp } - - return RestoreRequest(backupPath: backupPath) -} -static func dictionaryOf(restoreRequest: RestoreRequest) -> [String: Any?] { - return [ - "backupPath": restoreRequest.backupPath == nil ? nil : restoreRequest.backupPath, - ] -} - -static func asRestoreRequestList(arr: [Any]) throws -> [RestoreRequest] { - var list = [RestoreRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var restoreRequest = try asRestoreRequest(restoreRequest: val) - list.append(restoreRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RestoreRequest")) - } + return RestoreRequest(backupPath: backupPath) } - return list -} -static func arrayOf(`restoreRequestList`: [RestoreRequest]) -> [Any] { - return `restoreRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(restoreRequest: v) } -} -static func asRouteHint(routeHint: [String: Any?]) throws -> RouteHint { - guard let hopsTmp = routeHint["hops"] as? [[String: Any?]] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hops", typeName: "RouteHint")) - } - let hops = try asRouteHintHopList(arr: hopsTmp) - - - return RouteHint(hops: hops) -} - -static func dictionaryOf(routeHint: RouteHint) -> [String: Any?] { - return [ - "hops": arrayOf(routeHintHopList: routeHint.hops), - ] -} + static func dictionaryOf(restoreRequest: RestoreRequest) -> [String: Any?] { + return [ + "backupPath": restoreRequest.backupPath == nil ? nil : restoreRequest.backupPath, + ] + } -static func asRouteHintList(arr: [Any]) throws -> [RouteHint] { - var list = [RouteHint]() - for value in arr { - if let val = value as? [String: Any?] { - var routeHint = try asRouteHint(routeHint: val) - list.append(routeHint) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHint")) + static func asRestoreRequestList(arr: [Any]) throws -> [RestoreRequest] { + var list = [RestoreRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var restoreRequest = try asRestoreRequest(restoreRequest: val) + list.append(restoreRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RestoreRequest")) + } } + return list } - return list -} -static func arrayOf(`routeHintList`: [RouteHint]) -> [Any] { - return `routeHintList`.map { (v) -> [String: Any?] in return dictionaryOf(routeHint: v) } -} -static func asRouteHintHop(routeHintHop: [String: Any?]) throws -> RouteHintHop { - guard let srcNodeId = routeHintHop["srcNodeId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "srcNodeId", typeName: "RouteHintHop")) + static func arrayOf(restoreRequestList: [RestoreRequest]) -> [Any] { + return restoreRequestList.map { v -> [String: Any?] in return dictionaryOf(restoreRequest: v) } } - guard let shortChannelId = routeHintHop["shortChannelId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "shortChannelId", typeName: "RouteHintHop")) + + static func asRouteHint(routeHint: [String: Any?]) throws -> RouteHint { + guard let hopsTmp = routeHint["hops"] as? [[String: Any?]] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "hops", typeName: "RouteHint")) + } + let hops = try asRouteHintHopList(arr: hopsTmp) + + return RouteHint(hops: hops) } - guard let feesBaseMsat = routeHintHop["feesBaseMsat"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesBaseMsat", typeName: "RouteHintHop")) + + static func dictionaryOf(routeHint: RouteHint) -> [String: Any?] { + return [ + "hops": arrayOf(routeHintHopList: routeHint.hops), + ] } - guard let feesProportionalMillionths = routeHintHop["feesProportionalMillionths"] as? UInt32 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesProportionalMillionths", typeName: "RouteHintHop")) + + static func asRouteHintList(arr: [Any]) throws -> [RouteHint] { + var list = [RouteHint]() + for value in arr { + if let val = value as? [String: Any?] { + var routeHint = try asRouteHint(routeHint: val) + list.append(routeHint) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHint")) + } + } + return list } - guard let cltvExpiryDelta = routeHintHop["cltvExpiryDelta"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "cltvExpiryDelta", typeName: "RouteHintHop")) + + static func arrayOf(routeHintList: [RouteHint]) -> [Any] { + return routeHintList.map { v -> [String: Any?] in return dictionaryOf(routeHint: v) } } + + static func asRouteHintHop(routeHintHop: [String: Any?]) throws -> RouteHintHop { + guard let srcNodeId = routeHintHop["srcNodeId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "srcNodeId", typeName: "RouteHintHop")) + } + guard let shortChannelId = routeHintHop["shortChannelId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "shortChannelId", typeName: "RouteHintHop")) + } + guard let feesBaseMsat = routeHintHop["feesBaseMsat"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesBaseMsat", typeName: "RouteHintHop")) + } + guard let feesProportionalMillionths = routeHintHop["feesProportionalMillionths"] as? UInt32 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "feesProportionalMillionths", typeName: "RouteHintHop")) + } + guard let cltvExpiryDelta = routeHintHop["cltvExpiryDelta"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "cltvExpiryDelta", typeName: "RouteHintHop")) + } var htlcMinimumMsat: UInt64? if hasNonNilKey(data: routeHintHop, key: "htlcMinimumMsat") { guard let htlcMinimumMsatTmp = routeHintHop["htlcMinimumMsat"] as? UInt64 else { @@ -2398,163 +2440,166 @@ static func asRouteHintHop(routeHintHop: [String: Any?]) throws -> RouteHintHop } htlcMaximumMsat = htlcMaximumMsatTmp } - - return RouteHintHop(srcNodeId: srcNodeId, shortChannelId: shortChannelId, feesBaseMsat: feesBaseMsat, feesProportionalMillionths: feesProportionalMillionths, cltvExpiryDelta: cltvExpiryDelta, htlcMinimumMsat: htlcMinimumMsat, htlcMaximumMsat: htlcMaximumMsat) -} -static func dictionaryOf(routeHintHop: RouteHintHop) -> [String: Any?] { - return [ + return RouteHintHop(srcNodeId: srcNodeId, shortChannelId: shortChannelId, feesBaseMsat: feesBaseMsat, feesProportionalMillionths: feesProportionalMillionths, cltvExpiryDelta: cltvExpiryDelta, htlcMinimumMsat: htlcMinimumMsat, htlcMaximumMsat: htlcMaximumMsat) + } + + static func dictionaryOf(routeHintHop: RouteHintHop) -> [String: Any?] { + return [ "srcNodeId": routeHintHop.srcNodeId, "shortChannelId": routeHintHop.shortChannelId, "feesBaseMsat": routeHintHop.feesBaseMsat, "feesProportionalMillionths": routeHintHop.feesProportionalMillionths, "cltvExpiryDelta": routeHintHop.cltvExpiryDelta, "htlcMinimumMsat": routeHintHop.htlcMinimumMsat == nil ? nil : routeHintHop.htlcMinimumMsat, - "htlcMaximumMsat": routeHintHop.htlcMaximumMsat == nil ? nil : routeHintHop.htlcMaximumMsat, - ] -} + "htlcMaximumMsat": routeHintHop.htlcMaximumMsat == nil ? nil : routeHintHop.htlcMaximumMsat, + ] + } -static func asRouteHintHopList(arr: [Any]) throws -> [RouteHintHop] { - var list = [RouteHintHop]() - for value in arr { - if let val = value as? [String: Any?] { - var routeHintHop = try asRouteHintHop(routeHintHop: val) - list.append(routeHintHop) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHintHop")) + static func asRouteHintHopList(arr: [Any]) throws -> [RouteHintHop] { + var list = [RouteHintHop]() + for value in arr { + if let val = value as? [String: Any?] { + var routeHintHop = try asRouteHintHop(routeHintHop: val) + list.append(routeHintHop) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "RouteHintHop")) + } } + return list } - return list -} -static func arrayOf(`routeHintHopList`: [RouteHintHop]) -> [Any] { - return `routeHintHopList`.map { (v) -> [String: Any?] in return dictionaryOf(routeHintHop: v) } -} -static func asSendPaymentRequest(sendPaymentRequest: [String: Any?]) throws -> SendPaymentRequest { - guard let prepareResponseTmp = sendPaymentRequest["prepareResponse"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "SendPaymentRequest")) - } - let prepareResponse = try asPrepareSendResponse(prepareSendResponse: prepareResponseTmp) - - - return SendPaymentRequest(prepareResponse: prepareResponse) -} - -static func dictionaryOf(sendPaymentRequest: SendPaymentRequest) -> [String: Any?] { - return [ - "prepareResponse": dictionaryOf(prepareSendResponse: sendPaymentRequest.prepareResponse), - ] -} + static func arrayOf(routeHintHopList: [RouteHintHop]) -> [Any] { + return routeHintHopList.map { v -> [String: Any?] in return dictionaryOf(routeHintHop: v) } + } -static func asSendPaymentRequestList(arr: [Any]) throws -> [SendPaymentRequest] { - var list = [SendPaymentRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var sendPaymentRequest = try asSendPaymentRequest(sendPaymentRequest: val) - list.append(sendPaymentRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentRequest")) + static func asSendPaymentRequest(sendPaymentRequest: [String: Any?]) throws -> SendPaymentRequest { + guard let prepareResponseTmp = sendPaymentRequest["prepareResponse"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "prepareResponse", typeName: "SendPaymentRequest")) } + let prepareResponse = try asPrepareSendResponse(prepareSendResponse: prepareResponseTmp) + + return SendPaymentRequest(prepareResponse: prepareResponse) } - return list -} -static func arrayOf(`sendPaymentRequestList`: [SendPaymentRequest]) -> [Any] { - return `sendPaymentRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(sendPaymentRequest: v) } -} -static func asSendPaymentResponse(sendPaymentResponse: [String: Any?]) throws -> SendPaymentResponse { - guard let paymentTmp = sendPaymentResponse["payment"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "SendPaymentResponse")) - } - let payment = try asPayment(payment: paymentTmp) - - - return SendPaymentResponse(payment: payment) -} + static func dictionaryOf(sendPaymentRequest: SendPaymentRequest) -> [String: Any?] { + return [ + "prepareResponse": dictionaryOf(prepareSendResponse: sendPaymentRequest.prepareResponse), + ] + } -static func dictionaryOf(sendPaymentResponse: SendPaymentResponse) -> [String: Any?] { - return [ - "payment": dictionaryOf(payment: sendPaymentResponse.payment), - ] -} + static func asSendPaymentRequestList(arr: [Any]) throws -> [SendPaymentRequest] { + var list = [SendPaymentRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var sendPaymentRequest = try asSendPaymentRequest(sendPaymentRequest: val) + list.append(sendPaymentRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentRequest")) + } + } + return list + } -static func asSendPaymentResponseList(arr: [Any]) throws -> [SendPaymentResponse] { - var list = [SendPaymentResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var sendPaymentResponse = try asSendPaymentResponse(sendPaymentResponse: val) - list.append(sendPaymentResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentResponse")) + static func arrayOf(sendPaymentRequestList: [SendPaymentRequest]) -> [Any] { + return sendPaymentRequestList.map { v -> [String: Any?] in return dictionaryOf(sendPaymentRequest: v) } + } + + static func asSendPaymentResponse(sendPaymentResponse: [String: Any?]) throws -> SendPaymentResponse { + guard let paymentTmp = sendPaymentResponse["payment"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payment", typeName: "SendPaymentResponse")) } + let payment = try asPayment(payment: paymentTmp) + + return SendPaymentResponse(payment: payment) } - return list -} -static func arrayOf(`sendPaymentResponseList`: [SendPaymentResponse]) -> [Any] { - return `sendPaymentResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(sendPaymentResponse: v) } -} -static func asSignMessageRequest(signMessageRequest: [String: Any?]) throws -> SignMessageRequest { - guard let message = signMessageRequest["message"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "SignMessageRequest")) + static func dictionaryOf(sendPaymentResponse: SendPaymentResponse) -> [String: Any?] { + return [ + "payment": dictionaryOf(payment: sendPaymentResponse.payment), + ] } - - return SignMessageRequest(message: message) -} -static func dictionaryOf(signMessageRequest: SignMessageRequest) -> [String: Any?] { - return [ - "message": signMessageRequest.message, - ] -} + static func asSendPaymentResponseList(arr: [Any]) throws -> [SendPaymentResponse] { + var list = [SendPaymentResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var sendPaymentResponse = try asSendPaymentResponse(sendPaymentResponse: val) + list.append(sendPaymentResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SendPaymentResponse")) + } + } + return list + } + + static func arrayOf(sendPaymentResponseList: [SendPaymentResponse]) -> [Any] { + return sendPaymentResponseList.map { v -> [String: Any?] in return dictionaryOf(sendPaymentResponse: v) } + } -static func asSignMessageRequestList(arr: [Any]) throws -> [SignMessageRequest] { - var list = [SignMessageRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var signMessageRequest = try asSignMessageRequest(signMessageRequest: val) - list.append(signMessageRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageRequest")) + static func asSignMessageRequest(signMessageRequest: [String: Any?]) throws -> SignMessageRequest { + guard let message = signMessageRequest["message"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "message", typeName: "SignMessageRequest")) } + + return SignMessageRequest(message: message) } - return list -} -static func arrayOf(`signMessageRequestList`: [SignMessageRequest]) -> [Any] { - return `signMessageRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(signMessageRequest: v) } -} -static func asSignMessageResponse(signMessageResponse: [String: Any?]) throws -> SignMessageResponse { - guard let signature = signMessageResponse["signature"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "SignMessageResponse")) + static func dictionaryOf(signMessageRequest: SignMessageRequest) -> [String: Any?] { + return [ + "message": signMessageRequest.message, + ] } - - return SignMessageResponse(signature: signature) -} -static func dictionaryOf(signMessageResponse: SignMessageResponse) -> [String: Any?] { - return [ - "signature": signMessageResponse.signature, - ] -} + static func asSignMessageRequestList(arr: [Any]) throws -> [SignMessageRequest] { + var list = [SignMessageRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var signMessageRequest = try asSignMessageRequest(signMessageRequest: val) + list.append(signMessageRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageRequest")) + } + } + return list + } + + static func arrayOf(signMessageRequestList: [SignMessageRequest]) -> [Any] { + return signMessageRequestList.map { v -> [String: Any?] in return dictionaryOf(signMessageRequest: v) } + } -static func asSignMessageResponseList(arr: [Any]) throws -> [SignMessageResponse] { - var list = [SignMessageResponse]() - for value in arr { - if let val = value as? [String: Any?] { - var signMessageResponse = try asSignMessageResponse(signMessageResponse: val) - list.append(signMessageResponse) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageResponse")) + static func asSignMessageResponse(signMessageResponse: [String: Any?]) throws -> SignMessageResponse { + guard let signature = signMessageResponse["signature"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "signature", typeName: "SignMessageResponse")) } + + return SignMessageResponse(signature: signature) } - return list -} -static func arrayOf(`signMessageResponseList`: [SignMessageResponse]) -> [Any] { - return `signMessageResponseList`.map { (v) -> [String: Any?] in return dictionaryOf(signMessageResponse: v) } -} -static func asSymbol(symbol: [String: Any?]) throws -> Symbol { + static func dictionaryOf(signMessageResponse: SignMessageResponse) -> [String: Any?] { + return [ + "signature": signMessageResponse.signature, + ] + } + + static func asSignMessageResponseList(arr: [Any]) throws -> [SignMessageResponse] { + var list = [SignMessageResponse]() + for value in arr { + if let val = value as? [String: Any?] { + var signMessageResponse = try asSignMessageResponse(signMessageResponse: val) + list.append(signMessageResponse) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SignMessageResponse")) + } + } + return list + } + + static func arrayOf(signMessageResponseList: [SignMessageResponse]) -> [Any] { + return signMessageResponseList.map { v -> [String: Any?] in return dictionaryOf(signMessageResponse: v) } + } + + static func asSymbol(symbol: [String: Any?]) throws -> Symbol { var grapheme: String? if hasNonNilKey(data: symbol, key: "grapheme") { guard let graphemeTmp = symbol["grapheme"] as? String else { @@ -2583,1392 +2628,1363 @@ static func asSymbol(symbol: [String: Any?]) throws -> Symbol { } position = positionTmp } - - return Symbol(grapheme: grapheme, template: template, rtl: rtl, position: position) -} -static func dictionaryOf(symbol: Symbol) -> [String: Any?] { - return [ + return Symbol(grapheme: grapheme, template: template, rtl: rtl, position: position) + } + + static func dictionaryOf(symbol: Symbol) -> [String: Any?] { + return [ "grapheme": symbol.grapheme == nil ? nil : symbol.grapheme, "template": symbol.template == nil ? nil : symbol.template, "rtl": symbol.rtl == nil ? nil : symbol.rtl, - "position": symbol.position == nil ? nil : symbol.position, - ] -} + "position": symbol.position == nil ? nil : symbol.position, + ] + } -static func asSymbolList(arr: [Any]) throws -> [Symbol] { - var list = [Symbol]() - for value in arr { - if let val = value as? [String: Any?] { - var symbol = try asSymbol(symbol: val) - list.append(symbol) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Symbol")) + static func asSymbolList(arr: [Any]) throws -> [Symbol] { + var list = [Symbol]() + for value in arr { + if let val = value as? [String: Any?] { + var symbol = try asSymbol(symbol: val) + list.append(symbol) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Symbol")) + } } + return list } - return list -} -static func arrayOf(`symbolList`: [Symbol]) -> [Any] { - return `symbolList`.map { (v) -> [String: Any?] in return dictionaryOf(symbol: v) } -} -static func asUrlSuccessActionData(urlSuccessActionData: [String: Any?]) throws -> UrlSuccessActionData { - guard let description = urlSuccessActionData["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "UrlSuccessActionData")) + static func arrayOf(symbolList: [Symbol]) -> [Any] { + return symbolList.map { v -> [String: Any?] in return dictionaryOf(symbol: v) } } - guard let url = urlSuccessActionData["url"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "UrlSuccessActionData")) - } - guard let matchesCallbackDomain = urlSuccessActionData["matchesCallbackDomain"] as? Bool else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "matchesCallbackDomain", typeName: "UrlSuccessActionData")) + + static func asUrlSuccessActionData(urlSuccessActionData: [String: Any?]) throws -> UrlSuccessActionData { + guard let description = urlSuccessActionData["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "UrlSuccessActionData")) + } + guard let url = urlSuccessActionData["url"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "UrlSuccessActionData")) + } + guard let matchesCallbackDomain = urlSuccessActionData["matchesCallbackDomain"] as? Bool else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "matchesCallbackDomain", typeName: "UrlSuccessActionData")) + } + + return UrlSuccessActionData(description: description, url: url, matchesCallbackDomain: matchesCallbackDomain) } - - return UrlSuccessActionData(description: description, url: url, matchesCallbackDomain: matchesCallbackDomain) -} -static func dictionaryOf(urlSuccessActionData: UrlSuccessActionData) -> [String: Any?] { - return [ + static func dictionaryOf(urlSuccessActionData: UrlSuccessActionData) -> [String: Any?] { + return [ "description": urlSuccessActionData.description, "url": urlSuccessActionData.url, - "matchesCallbackDomain": urlSuccessActionData.matchesCallbackDomain, - ] -} + "matchesCallbackDomain": urlSuccessActionData.matchesCallbackDomain, + ] + } -static func asUrlSuccessActionDataList(arr: [Any]) throws -> [UrlSuccessActionData] { - var list = [UrlSuccessActionData]() - for value in arr { - if let val = value as? [String: Any?] { - var urlSuccessActionData = try asUrlSuccessActionData(urlSuccessActionData: val) - list.append(urlSuccessActionData) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "UrlSuccessActionData")) + static func asUrlSuccessActionDataList(arr: [Any]) throws -> [UrlSuccessActionData] { + var list = [UrlSuccessActionData]() + for value in arr { + if let val = value as? [String: Any?] { + var urlSuccessActionData = try asUrlSuccessActionData(urlSuccessActionData: val) + list.append(urlSuccessActionData) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "UrlSuccessActionData")) + } } + return list } - return list -} -static func arrayOf(`urlSuccessActionDataList`: [UrlSuccessActionData]) -> [Any] { - return `urlSuccessActionDataList`.map { (v) -> [String: Any?] in return dictionaryOf(urlSuccessActionData: v) } -} + static func arrayOf(urlSuccessActionDataList: [UrlSuccessActionData]) -> [Any] { + return urlSuccessActionDataList.map { v -> [String: Any?] in return dictionaryOf(urlSuccessActionData: v) } + } -static func asAesSuccessActionDataResult(aesSuccessActionDataResult: [String: Any?]) throws -> AesSuccessActionDataResult { - let type = aesSuccessActionDataResult["type"] as! String - if (type == "decrypted") { - guard let dataTmp = aesSuccessActionDataResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "AesSuccessActionDataResult")) - } + static func asAesSuccessActionDataResult(aesSuccessActionDataResult: [String: Any?]) throws -> AesSuccessActionDataResult { + let type = aesSuccessActionDataResult["type"] as! String + if type == "decrypted" { + guard let dataTmp = aesSuccessActionDataResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "AesSuccessActionDataResult")) + } let _data = try asAesSuccessActionDataDecrypted(aesSuccessActionDataDecrypted: dataTmp) - - return AesSuccessActionDataResult.decrypted(data: _data) - } - if (type == "errorStatus") { - guard let _reason = aesSuccessActionDataResult["reason"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "AesSuccessActionDataResult")) - } - return AesSuccessActionDataResult.errorStatus(reason: _reason) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum AesSuccessActionDataResult") -} + return AesSuccessActionDataResult.decrypted(data: _data) + } + if type == "errorStatus" { + guard let _reason = aesSuccessActionDataResult["reason"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "reason", typeName: "AesSuccessActionDataResult")) + } + return AesSuccessActionDataResult.errorStatus(reason: _reason) + } -static func dictionaryOf(aesSuccessActionDataResult: AesSuccessActionDataResult) -> [String: Any?] { - switch (aesSuccessActionDataResult) { - - case let .decrypted( - data - ): - return [ - "type": "decrypted", - "data": dictionaryOf(aesSuccessActionDataDecrypted: data), - ] - - case let .errorStatus( - reason - ): - return [ - "type": "errorStatus", - "reason": reason, - ] - } -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum AesSuccessActionDataResult") + } -static func arrayOf(`aesSuccessActionDataResultList`: [AesSuccessActionDataResult]) -> [Any] { - return `aesSuccessActionDataResultList`.map { (v) -> [String: Any?] in return dictionaryOf(aesSuccessActionDataResult: v) } -} + static func dictionaryOf(aesSuccessActionDataResult: AesSuccessActionDataResult) -> [String: Any?] { + switch aesSuccessActionDataResult { + case let .decrypted( + data + ): + return [ + "type": "decrypted", + "data": dictionaryOf(aesSuccessActionDataDecrypted: data), + ] -static func asAesSuccessActionDataResultList(arr: [Any]) throws -> [AesSuccessActionDataResult] { - var list = [AesSuccessActionDataResult]() - for value in arr { - if let val = value as? [String: Any?] { - var aesSuccessActionDataResult = try asAesSuccessActionDataResult(aesSuccessActionDataResult: val) - list.append(aesSuccessActionDataResult) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataResult")) + case let .errorStatus( + reason + ): + return [ + "type": "errorStatus", + "reason": reason, + ] } } - return list -} -static func asBuyBitcoinProvider(buyBitcoinProvider: String) throws -> BuyBitcoinProvider { - switch(buyBitcoinProvider) { + static func arrayOf(aesSuccessActionDataResultList: [AesSuccessActionDataResult]) -> [Any] { + return aesSuccessActionDataResultList.map { v -> [String: Any?] in return dictionaryOf(aesSuccessActionDataResult: v) } + } - case "moonpay": - return BuyBitcoinProvider.moonpay - - default: throw SdkError.Generic(message: "Invalid variant \(buyBitcoinProvider) for enum BuyBitcoinProvider") + static func asAesSuccessActionDataResultList(arr: [Any]) throws -> [AesSuccessActionDataResult] { + var list = [AesSuccessActionDataResult]() + for value in arr { + if let val = value as? [String: Any?] { + var aesSuccessActionDataResult = try asAesSuccessActionDataResult(aesSuccessActionDataResult: val) + list.append(aesSuccessActionDataResult) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "AesSuccessActionDataResult")) + } + } + return list } -} -static func valueOf(buyBitcoinProvider: BuyBitcoinProvider) -> String { - switch(buyBitcoinProvider) { + static func asBuyBitcoinProvider(buyBitcoinProvider: String) throws -> BuyBitcoinProvider { + switch buyBitcoinProvider { + case "moonpay": + return BuyBitcoinProvider.moonpay + + default: throw SdkError.Generic(message: "Invalid variant \(buyBitcoinProvider) for enum BuyBitcoinProvider") + } + } - case .moonpay: - return "moonpay" - + static func valueOf(buyBitcoinProvider: BuyBitcoinProvider) -> String { + switch buyBitcoinProvider { + case .moonpay: + return "moonpay" + } } -} -static func arrayOf(`buyBitcoinProviderList`: [BuyBitcoinProvider]) -> [String] { - return `buyBitcoinProviderList`.map { (v) -> String in return valueOf(buyBitcoinProvider: v) } -} + static func arrayOf(buyBitcoinProviderList: [BuyBitcoinProvider]) -> [String] { + return buyBitcoinProviderList.map { v -> String in return valueOf(buyBitcoinProvider: v) } + } -static func asBuyBitcoinProviderList(arr: [Any]) throws -> [BuyBitcoinProvider] { - var list = [BuyBitcoinProvider]() - for value in arr { - if let val = value as? String { - var buyBitcoinProvider = try asBuyBitcoinProvider(buyBitcoinProvider: val) - list.append(buyBitcoinProvider) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinProvider")) + static func asBuyBitcoinProviderList(arr: [Any]) throws -> [BuyBitcoinProvider] { + var list = [BuyBitcoinProvider]() + for value in arr { + if let val = value as? String { + var buyBitcoinProvider = try asBuyBitcoinProvider(buyBitcoinProvider: val) + list.append(buyBitcoinProvider) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "BuyBitcoinProvider")) + } } + return list } - return list -} -static func asGetPaymentRequest(getPaymentRequest: [String: Any?]) throws -> GetPaymentRequest { - let type = getPaymentRequest["type"] as! String - if (type == "lightning") { - guard let _paymentHash = getPaymentRequest["paymentHash"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "GetPaymentRequest")) - } - return GetPaymentRequest.lightning(paymentHash: _paymentHash) - } + static func asGetPaymentRequest(getPaymentRequest: [String: Any?]) throws -> GetPaymentRequest { + let type = getPaymentRequest["type"] as! String + if type == "lightning" { + guard let _paymentHash = getPaymentRequest["paymentHash"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "paymentHash", typeName: "GetPaymentRequest")) + } + return GetPaymentRequest.lightning(paymentHash: _paymentHash) + } - throw SdkError.Generic(message: "Unexpected type \(type) for enum GetPaymentRequest") -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum GetPaymentRequest") + } -static func dictionaryOf(getPaymentRequest: GetPaymentRequest) -> [String: Any?] { - switch (getPaymentRequest) { - - case let .lightning( - paymentHash - ): - return [ - "type": "lightning", - "paymentHash": paymentHash, - ] - } -} + static func dictionaryOf(getPaymentRequest: GetPaymentRequest) -> [String: Any?] { + switch getPaymentRequest { + case let .lightning( + paymentHash + ): + return [ + "type": "lightning", + "paymentHash": paymentHash, + ] + } + } -static func arrayOf(`getPaymentRequestList`: [GetPaymentRequest]) -> [Any] { - return `getPaymentRequestList`.map { (v) -> [String: Any?] in return dictionaryOf(getPaymentRequest: v) } -} + static func arrayOf(getPaymentRequestList: [GetPaymentRequest]) -> [Any] { + return getPaymentRequestList.map { v -> [String: Any?] in return dictionaryOf(getPaymentRequest: v) } + } -static func asGetPaymentRequestList(arr: [Any]) throws -> [GetPaymentRequest] { - var list = [GetPaymentRequest]() - for value in arr { - if let val = value as? [String: Any?] { - var getPaymentRequest = try asGetPaymentRequest(getPaymentRequest: val) - list.append(getPaymentRequest) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "GetPaymentRequest")) + static func asGetPaymentRequestList(arr: [Any]) throws -> [GetPaymentRequest] { + var list = [GetPaymentRequest]() + for value in arr { + if let val = value as? [String: Any?] { + var getPaymentRequest = try asGetPaymentRequest(getPaymentRequest: val) + list.append(getPaymentRequest) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "GetPaymentRequest")) + } } + return list } - return list -} -static func asInputType(inputType: [String: Any?]) throws -> InputType { - let type = inputType["type"] as! String - if (type == "bitcoinAddress") { - guard let addressTmp = inputType["address"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) - } + static func asInputType(inputType: [String: Any?]) throws -> InputType { + let type = inputType["type"] as! String + if type == "bitcoinAddress" { + guard let addressTmp = inputType["address"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) + } let _address = try asBitcoinAddressData(bitcoinAddressData: addressTmp) - - return InputType.bitcoinAddress(address: _address) + + return InputType.bitcoinAddress(address: _address) } - if (type == "liquidAddress") { - guard let addressTmp = inputType["address"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) - } + if type == "liquidAddress" { + guard let addressTmp = inputType["address"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "InputType")) + } let _address = try asLiquidAddressData(liquidAddressData: addressTmp) - - return InputType.liquidAddress(address: _address) + + return InputType.liquidAddress(address: _address) } - if (type == "bolt11") { - guard let invoiceTmp = inputType["invoice"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "InputType")) - } + if type == "bolt11" { + guard let invoiceTmp = inputType["invoice"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "InputType")) + } let _invoice = try asLnInvoice(lnInvoice: invoiceTmp) - - return InputType.bolt11(invoice: _invoice) - } - if (type == "nodeId") { - guard let _nodeId = inputType["nodeId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "nodeId", typeName: "InputType")) - } - return InputType.nodeId(nodeId: _nodeId) - } - if (type == "url") { - guard let _url = inputType["url"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "InputType")) - } - return InputType.url(url: _url) - } - if (type == "lnUrlPay") { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + + return InputType.bolt11(invoice: _invoice) + } + if type == "nodeId" { + guard let _nodeId = inputType["nodeId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "nodeId", typeName: "InputType")) + } + return InputType.nodeId(nodeId: _nodeId) + } + if type == "url" { + guard let _url = inputType["url"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "url", typeName: "InputType")) + } + return InputType.url(url: _url) + } + if type == "lnUrlPay" { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlPayRequestData(lnUrlPayRequestData: dataTmp) - - return InputType.lnUrlPay(data: _data) + + return InputType.lnUrlPay(data: _data) } - if (type == "lnUrlWithdraw") { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + if type == "lnUrlWithdraw" { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlWithdrawRequestData(lnUrlWithdrawRequestData: dataTmp) - - return InputType.lnUrlWithdraw(data: _data) + + return InputType.lnUrlWithdraw(data: _data) } - if (type == "lnUrlAuth") { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + if type == "lnUrlAuth" { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlAuthRequestData(lnUrlAuthRequestData: dataTmp) - - return InputType.lnUrlAuth(data: _data) + + return InputType.lnUrlAuth(data: _data) } - if (type == "lnUrlError") { - guard let dataTmp = inputType["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) - } + if type == "lnUrlError" { + guard let dataTmp = inputType["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "InputType")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) - - return InputType.lnUrlError(data: _data) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum InputType") -} + return InputType.lnUrlError(data: _data) + } + + throw SdkError.Generic(message: "Unexpected type \(type) for enum InputType") + } + + static func dictionaryOf(inputType: InputType) -> [String: Any?] { + switch inputType { + case let .bitcoinAddress( + address + ): + return [ + "type": "bitcoinAddress", + "address": dictionaryOf(bitcoinAddressData: address), + ] + + case let .liquidAddress( + address + ): + return [ + "type": "liquidAddress", + "address": dictionaryOf(liquidAddressData: address), + ] + + case let .bolt11( + invoice + ): + return [ + "type": "bolt11", + "invoice": dictionaryOf(lnInvoice: invoice), + ] + + case let .nodeId( + nodeId + ): + return [ + "type": "nodeId", + "nodeId": nodeId, + ] + + case let .url( + url + ): + return [ + "type": "url", + "url": url, + ] + + case let .lnUrlPay( + data + ): + return [ + "type": "lnUrlPay", + "data": dictionaryOf(lnUrlPayRequestData: data), + ] + + case let .lnUrlWithdraw( + data + ): + return [ + "type": "lnUrlWithdraw", + "data": dictionaryOf(lnUrlWithdrawRequestData: data), + ] + + case let .lnUrlAuth( + data + ): + return [ + "type": "lnUrlAuth", + "data": dictionaryOf(lnUrlAuthRequestData: data), + ] + + case let .lnUrlError( + data + ): + return [ + "type": "lnUrlError", + "data": dictionaryOf(lnUrlErrorData: data), + ] + } + } + + static func arrayOf(inputTypeList: [InputType]) -> [Any] { + return inputTypeList.map { v -> [String: Any?] in return dictionaryOf(inputType: v) } + } + + static func asInputTypeList(arr: [Any]) throws -> [InputType] { + var list = [InputType]() + for value in arr { + if let val = value as? [String: Any?] { + var inputType = try asInputType(inputType: val) + list.append(inputType) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "InputType")) + } + } + return list + } -static func dictionaryOf(inputType: InputType) -> [String: Any?] { - switch (inputType) { - - case let .bitcoinAddress( - address - ): - return [ - "type": "bitcoinAddress", - "address": dictionaryOf(bitcoinAddressData: address), - ] - - case let .liquidAddress( - address - ): - return [ - "type": "liquidAddress", - "address": dictionaryOf(liquidAddressData: address), - ] - - case let .bolt11( - invoice - ): - return [ - "type": "bolt11", - "invoice": dictionaryOf(lnInvoice: invoice), - ] - - case let .nodeId( - nodeId - ): - return [ - "type": "nodeId", - "nodeId": nodeId, - ] - - case let .url( - url - ): - return [ - "type": "url", - "url": url, - ] - - case let .lnUrlPay( - data - ): - return [ - "type": "lnUrlPay", - "data": dictionaryOf(lnUrlPayRequestData: data), - ] - - case let .lnUrlWithdraw( - data - ): - return [ - "type": "lnUrlWithdraw", - "data": dictionaryOf(lnUrlWithdrawRequestData: data), - ] - - case let .lnUrlAuth( - data - ): - return [ - "type": "lnUrlAuth", - "data": dictionaryOf(lnUrlAuthRequestData: data), - ] - - case let .lnUrlError( - data - ): - return [ - "type": "lnUrlError", - "data": dictionaryOf(lnUrlErrorData: data), - ] - } -} + static func asLiquidNetwork(liquidNetwork: String) throws -> LiquidNetwork { + switch liquidNetwork { + case "mainnet": + return LiquidNetwork.mainnet -static func arrayOf(`inputTypeList`: [InputType]) -> [Any] { - return `inputTypeList`.map { (v) -> [String: Any?] in return dictionaryOf(inputType: v) } -} + case "testnet": + return LiquidNetwork.testnet -static func asInputTypeList(arr: [Any]) throws -> [InputType] { - var list = [InputType]() - for value in arr { - if let val = value as? [String: Any?] { - var inputType = try asInputType(inputType: val) - list.append(inputType) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "InputType")) + default: throw SdkError.Generic(message: "Invalid variant \(liquidNetwork) for enum LiquidNetwork") } } - return list -} -static func asLiquidNetwork(liquidNetwork: String) throws -> LiquidNetwork { - switch(liquidNetwork) { + static func valueOf(liquidNetwork: LiquidNetwork) -> String { + switch liquidNetwork { + case .mainnet: + return "mainnet" - case "mainnet": - return LiquidNetwork.mainnet + case .testnet: + return "testnet" + } + } - case "testnet": - return LiquidNetwork.testnet - - default: throw SdkError.Generic(message: "Invalid variant \(liquidNetwork) for enum LiquidNetwork") + static func arrayOf(liquidNetworkList: [LiquidNetwork]) -> [String] { + return liquidNetworkList.map { v -> String in return valueOf(liquidNetwork: v) } } -} -static func valueOf(liquidNetwork: LiquidNetwork) -> String { - switch(liquidNetwork) { + static func asLiquidNetworkList(arr: [Any]) throws -> [LiquidNetwork] { + var list = [LiquidNetwork]() + for value in arr { + if let val = value as? String { + var liquidNetwork = try asLiquidNetwork(liquidNetwork: val) + list.append(liquidNetwork) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidNetwork")) + } + } + return list + } - case .mainnet: - return "mainnet" + static func asListPaymentDetails(listPaymentDetails: [String: Any?]) throws -> ListPaymentDetails { + let type = listPaymentDetails["type"] as! String + if type == "liquid" { + guard let _destination = listPaymentDetails["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ListPaymentDetails")) + } + return ListPaymentDetails.liquid(destination: _destination) + } + if type == "bitcoin" { + guard let _address = listPaymentDetails["address"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "ListPaymentDetails")) + } + return ListPaymentDetails.bitcoin(address: _address) + } - case .testnet: - return "testnet" - + throw SdkError.Generic(message: "Unexpected type \(type) for enum ListPaymentDetails") } -} -static func arrayOf(`liquidNetworkList`: [LiquidNetwork]) -> [String] { - return `liquidNetworkList`.map { (v) -> String in return valueOf(liquidNetwork: v) } -} + static func dictionaryOf(listPaymentDetails: ListPaymentDetails) -> [String: Any?] { + switch listPaymentDetails { + case let .liquid( + destination + ): + return [ + "type": "liquid", + "destination": destination, + ] -static func asLiquidNetworkList(arr: [Any]) throws -> [LiquidNetwork] { - var list = [LiquidNetwork]() - for value in arr { - if let val = value as? String { - var liquidNetwork = try asLiquidNetwork(liquidNetwork: val) - list.append(liquidNetwork) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LiquidNetwork")) + case let .bitcoin( + address + ): + return [ + "type": "bitcoin", + "address": address, + ] } } - return list -} - -static func asListPaymentDetails(listPaymentDetails: [String: Any?]) throws -> ListPaymentDetails { - let type = listPaymentDetails["type"] as! String - if (type == "liquid") { - guard let _destination = listPaymentDetails["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "ListPaymentDetails")) - } - return ListPaymentDetails.liquid(destination: _destination) - } - if (type == "bitcoin") { - guard let _address = listPaymentDetails["address"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "address", typeName: "ListPaymentDetails")) - } - return ListPaymentDetails.bitcoin(address: _address) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum ListPaymentDetails") -} -static func dictionaryOf(listPaymentDetails: ListPaymentDetails) -> [String: Any?] { - switch (listPaymentDetails) { - - case let .liquid( - destination - ): - return [ - "type": "liquid", - "destination": destination, - ] - - case let .bitcoin( - address - ): - return [ - "type": "bitcoin", - "address": address, - ] - } -} - -static func arrayOf(`listPaymentDetailsList`: [ListPaymentDetails]) -> [Any] { - return `listPaymentDetailsList`.map { (v) -> [String: Any?] in return dictionaryOf(listPaymentDetails: v) } -} + static func arrayOf(listPaymentDetailsList: [ListPaymentDetails]) -> [Any] { + return listPaymentDetailsList.map { v -> [String: Any?] in return dictionaryOf(listPaymentDetails: v) } + } -static func asListPaymentDetailsList(arr: [Any]) throws -> [ListPaymentDetails] { - var list = [ListPaymentDetails]() - for value in arr { - if let val = value as? [String: Any?] { - var listPaymentDetails = try asListPaymentDetails(listPaymentDetails: val) - list.append(listPaymentDetails) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentDetails")) + static func asListPaymentDetailsList(arr: [Any]) throws -> [ListPaymentDetails] { + var list = [ListPaymentDetails]() + for value in arr { + if let val = value as? [String: Any?] { + var listPaymentDetails = try asListPaymentDetails(listPaymentDetails: val) + list.append(listPaymentDetails) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "ListPaymentDetails")) + } } + return list } - return list -} -static func asLnUrlCallbackStatus(lnUrlCallbackStatus: [String: Any?]) throws -> LnUrlCallbackStatus { - let type = lnUrlCallbackStatus["type"] as! String - if (type == "ok") { - return LnUrlCallbackStatus.ok + static func asLnUrlCallbackStatus(lnUrlCallbackStatus: [String: Any?]) throws -> LnUrlCallbackStatus { + let type = lnUrlCallbackStatus["type"] as! String + if type == "ok" { + return LnUrlCallbackStatus.ok } - if (type == "errorStatus") { - guard let dataTmp = lnUrlCallbackStatus["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlCallbackStatus")) - } + if type == "errorStatus" { + guard let dataTmp = lnUrlCallbackStatus["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlCallbackStatus")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) - - return LnUrlCallbackStatus.errorStatus(data: _data) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlCallbackStatus") -} + return LnUrlCallbackStatus.errorStatus(data: _data) + } -static func dictionaryOf(lnUrlCallbackStatus: LnUrlCallbackStatus) -> [String: Any?] { - switch (lnUrlCallbackStatus) { - - case .ok: - return [ - "type": "ok", - ] - - case let .errorStatus( - data - ): - return [ - "type": "errorStatus", - "data": dictionaryOf(lnUrlErrorData: data), - ] - } -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlCallbackStatus") + } -static func arrayOf(`lnUrlCallbackStatusList`: [LnUrlCallbackStatus]) -> [Any] { - return `lnUrlCallbackStatusList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlCallbackStatus: v) } -} + static func dictionaryOf(lnUrlCallbackStatus: LnUrlCallbackStatus) -> [String: Any?] { + switch lnUrlCallbackStatus { + case .ok: + return [ + "type": "ok", + ] -static func asLnUrlCallbackStatusList(arr: [Any]) throws -> [LnUrlCallbackStatus] { - var list = [LnUrlCallbackStatus]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlCallbackStatus = try asLnUrlCallbackStatus(lnUrlCallbackStatus: val) - list.append(lnUrlCallbackStatus) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlCallbackStatus")) + case let .errorStatus( + data + ): + return [ + "type": "errorStatus", + "data": dictionaryOf(lnUrlErrorData: data), + ] } } - return list -} -static func asLnUrlPayResult(lnUrlPayResult: [String: Any?]) throws -> LnUrlPayResult { - let type = lnUrlPayResult["type"] as! String - if (type == "endpointSuccess") { - guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) - } + static func arrayOf(lnUrlCallbackStatusList: [LnUrlCallbackStatus]) -> [Any] { + return lnUrlCallbackStatusList.map { v -> [String: Any?] in return dictionaryOf(lnUrlCallbackStatus: v) } + } + + static func asLnUrlCallbackStatusList(arr: [Any]) throws -> [LnUrlCallbackStatus] { + var list = [LnUrlCallbackStatus]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlCallbackStatus = try asLnUrlCallbackStatus(lnUrlCallbackStatus: val) + list.append(lnUrlCallbackStatus) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlCallbackStatus")) + } + } + return list + } + + static func asLnUrlPayResult(lnUrlPayResult: [String: Any?]) throws -> LnUrlPayResult { + let type = lnUrlPayResult["type"] as! String + if type == "endpointSuccess" { + guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) + } let _data = try asLnUrlPaySuccessData(lnUrlPaySuccessData: dataTmp) - - return LnUrlPayResult.endpointSuccess(data: _data) + + return LnUrlPayResult.endpointSuccess(data: _data) } - if (type == "endpointError") { - guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) - } + if type == "endpointError" { + guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) - - return LnUrlPayResult.endpointError(data: _data) + + return LnUrlPayResult.endpointError(data: _data) } - if (type == "payError") { - guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) - } + if type == "payError" { + guard let dataTmp = lnUrlPayResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlPayResult")) + } let _data = try asLnUrlPayErrorData(lnUrlPayErrorData: dataTmp) - - return LnUrlPayResult.payError(data: _data) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlPayResult") -} + return LnUrlPayResult.payError(data: _data) + } -static func dictionaryOf(lnUrlPayResult: LnUrlPayResult) -> [String: Any?] { - switch (lnUrlPayResult) { - - case let .endpointSuccess( - data - ): - return [ - "type": "endpointSuccess", - "data": dictionaryOf(lnUrlPaySuccessData: data), - ] - - case let .endpointError( - data - ): - return [ - "type": "endpointError", - "data": dictionaryOf(lnUrlErrorData: data), - ] - - case let .payError( - data - ): - return [ - "type": "payError", - "data": dictionaryOf(lnUrlPayErrorData: data), - ] - } -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlPayResult") + } -static func arrayOf(`lnUrlPayResultList`: [LnUrlPayResult]) -> [Any] { - return `lnUrlPayResultList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlPayResult: v) } -} + static func dictionaryOf(lnUrlPayResult: LnUrlPayResult) -> [String: Any?] { + switch lnUrlPayResult { + case let .endpointSuccess( + data + ): + return [ + "type": "endpointSuccess", + "data": dictionaryOf(lnUrlPaySuccessData: data), + ] -static func asLnUrlPayResultList(arr: [Any]) throws -> [LnUrlPayResult] { - var list = [LnUrlPayResult]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlPayResult = try asLnUrlPayResult(lnUrlPayResult: val) - list.append(lnUrlPayResult) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayResult")) + case let .endpointError( + data + ): + return [ + "type": "endpointError", + "data": dictionaryOf(lnUrlErrorData: data), + ] + + case let .payError( + data + ): + return [ + "type": "payError", + "data": dictionaryOf(lnUrlPayErrorData: data), + ] } } - return list -} -static func asLnUrlWithdrawResult(lnUrlWithdrawResult: [String: Any?]) throws -> LnUrlWithdrawResult { - let type = lnUrlWithdrawResult["type"] as! String - if (type == "ok") { - guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) - } + static func arrayOf(lnUrlPayResultList: [LnUrlPayResult]) -> [Any] { + return lnUrlPayResultList.map { v -> [String: Any?] in return dictionaryOf(lnUrlPayResult: v) } + } + + static func asLnUrlPayResultList(arr: [Any]) throws -> [LnUrlPayResult] { + var list = [LnUrlPayResult]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlPayResult = try asLnUrlPayResult(lnUrlPayResult: val) + list.append(lnUrlPayResult) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlPayResult")) + } + } + return list + } + + static func asLnUrlWithdrawResult(lnUrlWithdrawResult: [String: Any?]) throws -> LnUrlWithdrawResult { + let type = lnUrlWithdrawResult["type"] as! String + if type == "ok" { + guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) + } let _data = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: dataTmp) - - return LnUrlWithdrawResult.ok(data: _data) + + return LnUrlWithdrawResult.ok(data: _data) } - if (type == "timeout") { - guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) - } + if type == "timeout" { + guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) + } let _data = try asLnUrlWithdrawSuccessData(lnUrlWithdrawSuccessData: dataTmp) - - return LnUrlWithdrawResult.timeout(data: _data) + + return LnUrlWithdrawResult.timeout(data: _data) } - if (type == "errorStatus") { - guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) - } + if type == "errorStatus" { + guard let dataTmp = lnUrlWithdrawResult["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "LnUrlWithdrawResult")) + } let _data = try asLnUrlErrorData(lnUrlErrorData: dataTmp) - - return LnUrlWithdrawResult.errorStatus(data: _data) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlWithdrawResult") -} + return LnUrlWithdrawResult.errorStatus(data: _data) + } -static func dictionaryOf(lnUrlWithdrawResult: LnUrlWithdrawResult) -> [String: Any?] { - switch (lnUrlWithdrawResult) { - - case let .ok( - data - ): - return [ - "type": "ok", - "data": dictionaryOf(lnUrlWithdrawSuccessData: data), - ] - - case let .timeout( - data - ): - return [ - "type": "timeout", - "data": dictionaryOf(lnUrlWithdrawSuccessData: data), - ] - - case let .errorStatus( - data - ): - return [ - "type": "errorStatus", - "data": dictionaryOf(lnUrlErrorData: data), - ] - } -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum LnUrlWithdrawResult") + } -static func arrayOf(`lnUrlWithdrawResultList`: [LnUrlWithdrawResult]) -> [Any] { - return `lnUrlWithdrawResultList`.map { (v) -> [String: Any?] in return dictionaryOf(lnUrlWithdrawResult: v) } -} + static func dictionaryOf(lnUrlWithdrawResult: LnUrlWithdrawResult) -> [String: Any?] { + switch lnUrlWithdrawResult { + case let .ok( + data + ): + return [ + "type": "ok", + "data": dictionaryOf(lnUrlWithdrawSuccessData: data), + ] + + case let .timeout( + data + ): + return [ + "type": "timeout", + "data": dictionaryOf(lnUrlWithdrawSuccessData: data), + ] -static func asLnUrlWithdrawResultList(arr: [Any]) throws -> [LnUrlWithdrawResult] { - var list = [LnUrlWithdrawResult]() - for value in arr { - if let val = value as? [String: Any?] { - var lnUrlWithdrawResult = try asLnUrlWithdrawResult(lnUrlWithdrawResult: val) - list.append(lnUrlWithdrawResult) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawResult")) + case let .errorStatus( + data + ): + return [ + "type": "errorStatus", + "data": dictionaryOf(lnUrlErrorData: data), + ] } } - return list -} -static func asNetwork(network: String) throws -> Network { - switch(network) { + static func arrayOf(lnUrlWithdrawResultList: [LnUrlWithdrawResult]) -> [Any] { + return lnUrlWithdrawResultList.map { v -> [String: Any?] in return dictionaryOf(lnUrlWithdrawResult: v) } + } - case "bitcoin": - return Network.bitcoin + static func asLnUrlWithdrawResultList(arr: [Any]) throws -> [LnUrlWithdrawResult] { + var list = [LnUrlWithdrawResult]() + for value in arr { + if let val = value as? [String: Any?] { + var lnUrlWithdrawResult = try asLnUrlWithdrawResult(lnUrlWithdrawResult: val) + list.append(lnUrlWithdrawResult) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "LnUrlWithdrawResult")) + } + } + return list + } - case "testnet": - return Network.testnet + static func asNetwork(network: String) throws -> Network { + switch network { + case "bitcoin": + return Network.bitcoin - case "signet": - return Network.signet + case "testnet": + return Network.testnet - case "regtest": - return Network.regtest - - default: throw SdkError.Generic(message: "Invalid variant \(network) for enum Network") - } -} + case "signet": + return Network.signet -static func valueOf(network: Network) -> String { - switch(network) { + case "regtest": + return Network.regtest - case .bitcoin: - return "bitcoin" + default: throw SdkError.Generic(message: "Invalid variant \(network) for enum Network") + } + } + + static func valueOf(network: Network) -> String { + switch network { + case .bitcoin: + return "bitcoin" - case .testnet: - return "testnet" + case .testnet: + return "testnet" - case .signet: - return "signet" + case .signet: + return "signet" - case .regtest: - return "regtest" - + case .regtest: + return "regtest" + } } -} -static func arrayOf(`networkList`: [Network]) -> [String] { - return `networkList`.map { (v) -> String in return valueOf(network: v) } -} + static func arrayOf(networkList: [Network]) -> [String] { + return networkList.map { v -> String in return valueOf(network: v) } + } -static func asNetworkList(arr: [Any]) throws -> [Network] { - var list = [Network]() - for value in arr { - if let val = value as? String { - var network = try asNetwork(network: val) - list.append(network) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "Network")) + static func asNetworkList(arr: [Any]) throws -> [Network] { + var list = [Network]() + for value in arr { + if let val = value as? String { + var network = try asNetwork(network: val) + list.append(network) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "Network")) + } } + return list } - return list -} -static func asPayOnchainAmount(payOnchainAmount: [String: Any?]) throws -> PayOnchainAmount { - let type = payOnchainAmount["type"] as! String - if (type == "receiver") { - guard let _amountSat = payOnchainAmount["amountSat"] as? UInt64 else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PayOnchainAmount")) - } - return PayOnchainAmount.receiver(amountSat: _amountSat) + static func asPayOnchainAmount(payOnchainAmount: [String: Any?]) throws -> PayOnchainAmount { + let type = payOnchainAmount["type"] as! String + if type == "receiver" { + guard let _amountSat = payOnchainAmount["amountSat"] as? UInt64 else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "amountSat", typeName: "PayOnchainAmount")) + } + return PayOnchainAmount.receiver(amountSat: _amountSat) + } + if type == "drain" { + return PayOnchainAmount.drain } - if (type == "drain") { - return PayOnchainAmount.drain - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum PayOnchainAmount") -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum PayOnchainAmount") + } -static func dictionaryOf(payOnchainAmount: PayOnchainAmount) -> [String: Any?] { - switch (payOnchainAmount) { - - case let .receiver( - amountSat - ): - return [ - "type": "receiver", - "amountSat": amountSat, - ] - - case .drain: - return [ - "type": "drain", - ] - } -} + static func dictionaryOf(payOnchainAmount: PayOnchainAmount) -> [String: Any?] { + switch payOnchainAmount { + case let .receiver( + amountSat + ): + return [ + "type": "receiver", + "amountSat": amountSat, + ] -static func arrayOf(`payOnchainAmountList`: [PayOnchainAmount]) -> [Any] { - return `payOnchainAmountList`.map { (v) -> [String: Any?] in return dictionaryOf(payOnchainAmount: v) } -} + case .drain: + return [ + "type": "drain", + ] + } + } + + static func arrayOf(payOnchainAmountList: [PayOnchainAmount]) -> [Any] { + return payOnchainAmountList.map { v -> [String: Any?] in return dictionaryOf(payOnchainAmount: v) } + } -static func asPayOnchainAmountList(arr: [Any]) throws -> [PayOnchainAmount] { - var list = [PayOnchainAmount]() - for value in arr { - if let val = value as? [String: Any?] { - var payOnchainAmount = try asPayOnchainAmount(payOnchainAmount: val) - list.append(payOnchainAmount) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainAmount")) + static func asPayOnchainAmountList(arr: [Any]) throws -> [PayOnchainAmount] { + var list = [PayOnchainAmount]() + for value in arr { + if let val = value as? [String: Any?] { + var payOnchainAmount = try asPayOnchainAmount(payOnchainAmount: val) + list.append(payOnchainAmount) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PayOnchainAmount")) + } } + return list } - return list -} -static func asPaymentDetails(paymentDetails: [String: Any?]) throws -> PaymentDetails { - let type = paymentDetails["type"] as! String - if (type == "lightning") { - guard let _swapId = paymentDetails["swapId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) - } - guard let _description = paymentDetails["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) - } - let _preimage = paymentDetails["preimage"] as? String - - let _bolt11 = paymentDetails["bolt11"] as? String - - let _paymentHash = paymentDetails["paymentHash"] as? String - - let _refundTxId = paymentDetails["refundTxId"] as? String - - let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 - - return PaymentDetails.lightning(swapId: _swapId, description: _description, preimage: _preimage, bolt11: _bolt11, paymentHash: _paymentHash, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) - } - if (type == "liquid") { - guard let _destination = paymentDetails["destination"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PaymentDetails")) - } - guard let _description = paymentDetails["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) - } - return PaymentDetails.liquid(destination: _destination, description: _description) - } - if (type == "bitcoin") { - guard let _swapId = paymentDetails["swapId"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) - } - guard let _description = paymentDetails["description"] as? String else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) - } - let _refundTxId = paymentDetails["refundTxId"] as? String - - let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 - - return PaymentDetails.bitcoin(swapId: _swapId, description: _description, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) - } - - throw SdkError.Generic(message: "Unexpected type \(type) for enum PaymentDetails") -} + static func asPaymentDetails(paymentDetails: [String: Any?]) throws -> PaymentDetails { + let type = paymentDetails["type"] as! String + if type == "lightning" { + guard let _swapId = paymentDetails["swapId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) + } + guard let _description = paymentDetails["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) + } + let _preimage = paymentDetails["preimage"] as? String -static func dictionaryOf(paymentDetails: PaymentDetails) -> [String: Any?] { - switch (paymentDetails) { - - case let .lightning( - swapId, description, preimage, bolt11, paymentHash, refundTxId, refundTxAmountSat - ): - return [ - "type": "lightning", - "swapId": swapId, - "description": description, - "preimage": preimage == nil ? nil : preimage, - "bolt11": bolt11 == nil ? nil : bolt11, - "paymentHash": paymentHash == nil ? nil : paymentHash, - "refundTxId": refundTxId == nil ? nil : refundTxId, - "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, - ] - - case let .liquid( - destination, description - ): - return [ - "type": "liquid", - "destination": destination, - "description": description, - ] - - case let .bitcoin( - swapId, description, refundTxId, refundTxAmountSat - ): - return [ - "type": "bitcoin", - "swapId": swapId, - "description": description, - "refundTxId": refundTxId == nil ? nil : refundTxId, - "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, - ] - } -} + let _bolt11 = paymentDetails["bolt11"] as? String -static func arrayOf(`paymentDetailsList`: [PaymentDetails]) -> [Any] { - return `paymentDetailsList`.map { (v) -> [String: Any?] in return dictionaryOf(paymentDetails: v) } -} + let _paymentHash = paymentDetails["paymentHash"] as? String + + let _refundTxId = paymentDetails["refundTxId"] as? String + + let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 -static func asPaymentDetailsList(arr: [Any]) throws -> [PaymentDetails] { - var list = [PaymentDetails]() - for value in arr { - if let val = value as? [String: Any?] { - var paymentDetails = try asPaymentDetails(paymentDetails: val) - list.append(paymentDetails) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentDetails")) + return PaymentDetails.lightning(swapId: _swapId, description: _description, preimage: _preimage, bolt11: _bolt11, paymentHash: _paymentHash, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) + } + if type == "liquid" { + guard let _destination = paymentDetails["destination"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "destination", typeName: "PaymentDetails")) + } + guard let _description = paymentDetails["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) + } + return PaymentDetails.liquid(destination: _destination, description: _description) } + if type == "bitcoin" { + guard let _swapId = paymentDetails["swapId"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "swapId", typeName: "PaymentDetails")) + } + guard let _description = paymentDetails["description"] as? String else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "description", typeName: "PaymentDetails")) + } + let _refundTxId = paymentDetails["refundTxId"] as? String + + let _refundTxAmountSat = paymentDetails["refundTxAmountSat"] as? UInt64 + + return PaymentDetails.bitcoin(swapId: _swapId, description: _description, refundTxId: _refundTxId, refundTxAmountSat: _refundTxAmountSat) + } + + throw SdkError.Generic(message: "Unexpected type \(type) for enum PaymentDetails") + } + + static func dictionaryOf(paymentDetails: PaymentDetails) -> [String: Any?] { + switch paymentDetails { + case let .lightning( + swapId, description, preimage, bolt11, paymentHash, refundTxId, refundTxAmountSat + ): + return [ + "type": "lightning", + "swapId": swapId, + "description": description, + "preimage": preimage == nil ? nil : preimage, + "bolt11": bolt11 == nil ? nil : bolt11, + "paymentHash": paymentHash == nil ? nil : paymentHash, + "refundTxId": refundTxId == nil ? nil : refundTxId, + "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, + ] + + case let .liquid( + destination, description + ): + return [ + "type": "liquid", + "destination": destination, + "description": description, + ] + + case let .bitcoin( + swapId, description, refundTxId, refundTxAmountSat + ): + return [ + "type": "bitcoin", + "swapId": swapId, + "description": description, + "refundTxId": refundTxId == nil ? nil : refundTxId, + "refundTxAmountSat": refundTxAmountSat == nil ? nil : refundTxAmountSat, + ] + } + } + + static func arrayOf(paymentDetailsList: [PaymentDetails]) -> [Any] { + return paymentDetailsList.map { v -> [String: Any?] in return dictionaryOf(paymentDetails: v) } + } + + static func asPaymentDetailsList(arr: [Any]) throws -> [PaymentDetails] { + var list = [PaymentDetails]() + for value in arr { + if let val = value as? [String: Any?] { + var paymentDetails = try asPaymentDetails(paymentDetails: val) + list.append(paymentDetails) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentDetails")) + } + } + return list } - return list -} -static func asPaymentMethod(paymentMethod: String) throws -> PaymentMethod { - switch(paymentMethod) { + static func asPaymentMethod(paymentMethod: String) throws -> PaymentMethod { + switch paymentMethod { + case "lightning": + return PaymentMethod.lightning - case "lightning": - return PaymentMethod.lightning + case "bitcoinAddress": + return PaymentMethod.bitcoinAddress - case "bitcoinAddress": - return PaymentMethod.bitcoinAddress + case "liquidAddress": + return PaymentMethod.liquidAddress - case "liquidAddress": - return PaymentMethod.liquidAddress - - default: throw SdkError.Generic(message: "Invalid variant \(paymentMethod) for enum PaymentMethod") + default: throw SdkError.Generic(message: "Invalid variant \(paymentMethod) for enum PaymentMethod") + } } -} - -static func valueOf(paymentMethod: PaymentMethod) -> String { - switch(paymentMethod) { - case .lightning: - return "lightning" + static func valueOf(paymentMethod: PaymentMethod) -> String { + switch paymentMethod { + case .lightning: + return "lightning" - case .bitcoinAddress: - return "bitcoinAddress" + case .bitcoinAddress: + return "bitcoinAddress" - case .liquidAddress: - return "liquidAddress" - + case .liquidAddress: + return "liquidAddress" + } } -} -static func arrayOf(`paymentMethodList`: [PaymentMethod]) -> [String] { - return `paymentMethodList`.map { (v) -> String in return valueOf(paymentMethod: v) } -} + static func arrayOf(paymentMethodList: [PaymentMethod]) -> [String] { + return paymentMethodList.map { v -> String in return valueOf(paymentMethod: v) } + } -static func asPaymentMethodList(arr: [Any]) throws -> [PaymentMethod] { - var list = [PaymentMethod]() - for value in arr { - if let val = value as? String { - var paymentMethod = try asPaymentMethod(paymentMethod: val) - list.append(paymentMethod) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentMethod")) + static func asPaymentMethodList(arr: [Any]) throws -> [PaymentMethod] { + var list = [PaymentMethod]() + for value in arr { + if let val = value as? String { + var paymentMethod = try asPaymentMethod(paymentMethod: val) + list.append(paymentMethod) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentMethod")) + } } + return list } - return list -} -static func asPaymentState(paymentState: String) throws -> PaymentState { - switch(paymentState) { + static func asPaymentState(paymentState: String) throws -> PaymentState { + switch paymentState { + case "created": + return PaymentState.created - case "created": - return PaymentState.created + case "pending": + return PaymentState.pending - case "pending": - return PaymentState.pending + case "complete": + return PaymentState.complete - case "complete": - return PaymentState.complete + case "failed": + return PaymentState.failed - case "failed": - return PaymentState.failed + case "timedOut": + return PaymentState.timedOut - case "timedOut": - return PaymentState.timedOut + case "refundable": + return PaymentState.refundable - case "refundable": - return PaymentState.refundable + case "refundPending": + return PaymentState.refundPending - case "refundPending": - return PaymentState.refundPending - - default: throw SdkError.Generic(message: "Invalid variant \(paymentState) for enum PaymentState") + default: throw SdkError.Generic(message: "Invalid variant \(paymentState) for enum PaymentState") + } } -} -static func valueOf(paymentState: PaymentState) -> String { - switch(paymentState) { + static func valueOf(paymentState: PaymentState) -> String { + switch paymentState { + case .created: + return "created" - case .created: - return "created" + case .pending: + return "pending" - case .pending: - return "pending" + case .complete: + return "complete" - case .complete: - return "complete" + case .failed: + return "failed" - case .failed: - return "failed" + case .timedOut: + return "timedOut" - case .timedOut: - return "timedOut" + case .refundable: + return "refundable" - case .refundable: - return "refundable" - - case .refundPending: - return "refundPending" - + case .refundPending: + return "refundPending" + } } -} -static func arrayOf(`paymentStateList`: [PaymentState]) -> [String] { - return `paymentStateList`.map { (v) -> String in return valueOf(paymentState: v) } -} + static func arrayOf(paymentStateList: [PaymentState]) -> [String] { + return paymentStateList.map { v -> String in return valueOf(paymentState: v) } + } -static func asPaymentStateList(arr: [Any]) throws -> [PaymentState] { - var list = [PaymentState]() - for value in arr { - if let val = value as? String { - var paymentState = try asPaymentState(paymentState: val) - list.append(paymentState) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentState")) + static func asPaymentStateList(arr: [Any]) throws -> [PaymentState] { + var list = [PaymentState]() + for value in arr { + if let val = value as? String { + var paymentState = try asPaymentState(paymentState: val) + list.append(paymentState) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentState")) + } } + return list } - return list -} -static func asPaymentType(paymentType: String) throws -> PaymentType { - switch(paymentType) { + static func asPaymentType(paymentType: String) throws -> PaymentType { + switch paymentType { + case "receive": + return PaymentType.receive - case "receive": - return PaymentType.receive + case "send": + return PaymentType.send - case "send": - return PaymentType.send - - default: throw SdkError.Generic(message: "Invalid variant \(paymentType) for enum PaymentType") + default: throw SdkError.Generic(message: "Invalid variant \(paymentType) for enum PaymentType") + } } -} -static func valueOf(paymentType: PaymentType) -> String { - switch(paymentType) { + static func valueOf(paymentType: PaymentType) -> String { + switch paymentType { + case .receive: + return "receive" - case .receive: - return "receive" - - case .send: - return "send" - + case .send: + return "send" + } } -} -static func arrayOf(`paymentTypeList`: [PaymentType]) -> [String] { - return `paymentTypeList`.map { (v) -> String in return valueOf(paymentType: v) } -} + static func arrayOf(paymentTypeList: [PaymentType]) -> [String] { + return paymentTypeList.map { v -> String in return valueOf(paymentType: v) } + } -static func asPaymentTypeList(arr: [Any]) throws -> [PaymentType] { - var list = [PaymentType]() - for value in arr { - if let val = value as? String { - var paymentType = try asPaymentType(paymentType: val) - list.append(paymentType) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentType")) + static func asPaymentTypeList(arr: [Any]) throws -> [PaymentType] { + var list = [PaymentType]() + for value in arr { + if let val = value as? String { + var paymentType = try asPaymentType(paymentType: val) + list.append(paymentType) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "PaymentType")) + } } + return list } - return list -} -static func asSdkEvent(sdkEvent: [String: Any?]) throws -> SdkEvent { - let type = sdkEvent["type"] as! String - if (type == "paymentFailed") { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + static func asSdkEvent(sdkEvent: [String: Any?]) throws -> SdkEvent { + let type = sdkEvent["type"] as! String + if type == "paymentFailed" { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentFailed(details: _details) + + return SdkEvent.paymentFailed(details: _details) } - if (type == "paymentPending") { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if type == "paymentPending" { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentPending(details: _details) + + return SdkEvent.paymentPending(details: _details) } - if (type == "paymentRefunded") { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if type == "paymentRefunded" { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentRefunded(details: _details) + + return SdkEvent.paymentRefunded(details: _details) } - if (type == "paymentRefundPending") { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if type == "paymentRefundPending" { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentRefundPending(details: _details) + + return SdkEvent.paymentRefundPending(details: _details) } - if (type == "paymentSucceeded") { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if type == "paymentSucceeded" { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentSucceeded(details: _details) + + return SdkEvent.paymentSucceeded(details: _details) } - if (type == "paymentWaitingConfirmation") { - guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) - } + if type == "paymentWaitingConfirmation" { + guard let detailsTmp = sdkEvent["details"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "details", typeName: "SdkEvent")) + } let _details = try asPayment(payment: detailsTmp) - - return SdkEvent.paymentWaitingConfirmation(details: _details) - } - if (type == "synced") { - return SdkEvent.synced - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum SdkEvent") -} - -static func dictionaryOf(sdkEvent: SdkEvent) -> [String: Any?] { - switch (sdkEvent) { - - case let .paymentFailed( - details - ): - return [ - "type": "paymentFailed", - "details": dictionaryOf(payment: details), - ] - - case let .paymentPending( - details - ): - return [ - "type": "paymentPending", - "details": dictionaryOf(payment: details), - ] - - case let .paymentRefunded( - details - ): - return [ - "type": "paymentRefunded", - "details": dictionaryOf(payment: details), - ] - - case let .paymentRefundPending( - details - ): - return [ - "type": "paymentRefundPending", - "details": dictionaryOf(payment: details), - ] - - case let .paymentSucceeded( - details - ): - return [ - "type": "paymentSucceeded", - "details": dictionaryOf(payment: details), - ] - - case let .paymentWaitingConfirmation( - details - ): - return [ - "type": "paymentWaitingConfirmation", - "details": dictionaryOf(payment: details), - ] - - case .synced: - return [ - "type": "synced", - ] - } -} - -static func arrayOf(`sdkEventList`: [SdkEvent]) -> [Any] { - return `sdkEventList`.map { (v) -> [String: Any?] in return dictionaryOf(sdkEvent: v) } -} - -static func asSdkEventList(arr: [Any]) throws -> [SdkEvent] { - var list = [SdkEvent]() - for value in arr { - if let val = value as? [String: Any?] { - var sdkEvent = try asSdkEvent(sdkEvent: val) - list.append(sdkEvent) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SdkEvent")) + return SdkEvent.paymentWaitingConfirmation(details: _details) + } + if type == "synced" { + return SdkEvent.synced + } + + throw SdkError.Generic(message: "Unexpected type \(type) for enum SdkEvent") + } + + static func dictionaryOf(sdkEvent: SdkEvent) -> [String: Any?] { + switch sdkEvent { + case let .paymentFailed( + details + ): + return [ + "type": "paymentFailed", + "details": dictionaryOf(payment: details), + ] + + case let .paymentPending( + details + ): + return [ + "type": "paymentPending", + "details": dictionaryOf(payment: details), + ] + + case let .paymentRefunded( + details + ): + return [ + "type": "paymentRefunded", + "details": dictionaryOf(payment: details), + ] + + case let .paymentRefundPending( + details + ): + return [ + "type": "paymentRefundPending", + "details": dictionaryOf(payment: details), + ] + + case let .paymentSucceeded( + details + ): + return [ + "type": "paymentSucceeded", + "details": dictionaryOf(payment: details), + ] + + case let .paymentWaitingConfirmation( + details + ): + return [ + "type": "paymentWaitingConfirmation", + "details": dictionaryOf(payment: details), + ] + + case .synced: + return [ + "type": "synced", + ] + } + } + + static func arrayOf(sdkEventList: [SdkEvent]) -> [Any] { + return sdkEventList.map { v -> [String: Any?] in return dictionaryOf(sdkEvent: v) } + } + + static func asSdkEventList(arr: [Any]) throws -> [SdkEvent] { + var list = [SdkEvent]() + for value in arr { + if let val = value as? [String: Any?] { + var sdkEvent = try asSdkEvent(sdkEvent: val) + list.append(sdkEvent) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SdkEvent")) + } } + return list } - return list -} -static func asSendDestination(sendDestination: [String: Any?]) throws -> SendDestination { - let type = sendDestination["type"] as! String - if (type == "liquidAddress") { - guard let addressDataTmp = sendDestination["addressData"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "addressData", typeName: "SendDestination")) - } + static func asSendDestination(sendDestination: [String: Any?]) throws -> SendDestination { + let type = sendDestination["type"] as! String + if type == "liquidAddress" { + guard let addressDataTmp = sendDestination["addressData"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "addressData", typeName: "SendDestination")) + } let _addressData = try asLiquidAddressData(liquidAddressData: addressDataTmp) - - return SendDestination.liquidAddress(addressData: _addressData) + + return SendDestination.liquidAddress(addressData: _addressData) } - if (type == "bolt11") { - guard let invoiceTmp = sendDestination["invoice"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "SendDestination")) - } + if type == "bolt11" { + guard let invoiceTmp = sendDestination["invoice"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "invoice", typeName: "SendDestination")) + } let _invoice = try asLnInvoice(lnInvoice: invoiceTmp) - - return SendDestination.bolt11(invoice: _invoice) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum SendDestination") -} + return SendDestination.bolt11(invoice: _invoice) + } -static func dictionaryOf(sendDestination: SendDestination) -> [String: Any?] { - switch (sendDestination) { - - case let .liquidAddress( - addressData - ): - return [ - "type": "liquidAddress", - "addressData": dictionaryOf(liquidAddressData: addressData), - ] - - case let .bolt11( - invoice - ): - return [ - "type": "bolt11", - "invoice": dictionaryOf(lnInvoice: invoice), - ] - } -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum SendDestination") + } -static func arrayOf(`sendDestinationList`: [SendDestination]) -> [Any] { - return `sendDestinationList`.map { (v) -> [String: Any?] in return dictionaryOf(sendDestination: v) } -} + static func dictionaryOf(sendDestination: SendDestination) -> [String: Any?] { + switch sendDestination { + case let .liquidAddress( + addressData + ): + return [ + "type": "liquidAddress", + "addressData": dictionaryOf(liquidAddressData: addressData), + ] -static func asSendDestinationList(arr: [Any]) throws -> [SendDestination] { - var list = [SendDestination]() - for value in arr { - if let val = value as? [String: Any?] { - var sendDestination = try asSendDestination(sendDestination: val) - list.append(sendDestination) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SendDestination")) + case let .bolt11( + invoice + ): + return [ + "type": "bolt11", + "invoice": dictionaryOf(lnInvoice: invoice), + ] } } - return list -} -static func asSuccessAction(successAction: [String: Any?]) throws -> SuccessAction { - let type = successAction["type"] as! String - if (type == "aes") { - guard let dataTmp = successAction["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) - } + static func arrayOf(sendDestinationList: [SendDestination]) -> [Any] { + return sendDestinationList.map { v -> [String: Any?] in return dictionaryOf(sendDestination: v) } + } + + static func asSendDestinationList(arr: [Any]) throws -> [SendDestination] { + var list = [SendDestination]() + for value in arr { + if let val = value as? [String: Any?] { + var sendDestination = try asSendDestination(sendDestination: val) + list.append(sendDestination) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SendDestination")) + } + } + return list + } + + static func asSuccessAction(successAction: [String: Any?]) throws -> SuccessAction { + let type = successAction["type"] as! String + if type == "aes" { + guard let dataTmp = successAction["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) + } let _data = try asAesSuccessActionData(aesSuccessActionData: dataTmp) - - return SuccessAction.aes(data: _data) + + return SuccessAction.aes(data: _data) } - if (type == "message") { - guard let dataTmp = successAction["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) - } + if type == "message" { + guard let dataTmp = successAction["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) + } let _data = try asMessageSuccessActionData(messageSuccessActionData: dataTmp) - - return SuccessAction.message(data: _data) + + return SuccessAction.message(data: _data) } - if (type == "url") { - guard let dataTmp = successAction["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) - } + if type == "url" { + guard let dataTmp = successAction["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessAction")) + } let _data = try asUrlSuccessActionData(urlSuccessActionData: dataTmp) - - return SuccessAction.url(data: _data) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessAction") -} + return SuccessAction.url(data: _data) + } -static func dictionaryOf(successAction: SuccessAction) -> [String: Any?] { - switch (successAction) { - - case let .aes( - data - ): - return [ - "type": "aes", - "data": dictionaryOf(aesSuccessActionData: data), - ] - - case let .message( - data - ): - return [ - "type": "message", - "data": dictionaryOf(messageSuccessActionData: data), - ] - - case let .url( - data - ): - return [ - "type": "url", - "data": dictionaryOf(urlSuccessActionData: data), - ] - } -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessAction") + } -static func arrayOf(`successActionList`: [SuccessAction]) -> [Any] { - return `successActionList`.map { (v) -> [String: Any?] in return dictionaryOf(successAction: v) } -} + static func dictionaryOf(successAction: SuccessAction) -> [String: Any?] { + switch successAction { + case let .aes( + data + ): + return [ + "type": "aes", + "data": dictionaryOf(aesSuccessActionData: data), + ] -static func asSuccessActionList(arr: [Any]) throws -> [SuccessAction] { - var list = [SuccessAction]() - for value in arr { - if let val = value as? [String: Any?] { - var successAction = try asSuccessAction(successAction: val) - list.append(successAction) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessAction")) + case let .message( + data + ): + return [ + "type": "message", + "data": dictionaryOf(messageSuccessActionData: data), + ] + + case let .url( + data + ): + return [ + "type": "url", + "data": dictionaryOf(urlSuccessActionData: data), + ] } } - return list -} -static func asSuccessActionProcessed(successActionProcessed: [String: Any?]) throws -> SuccessActionProcessed { - let type = successActionProcessed["type"] as! String - if (type == "aes") { - guard let resultTmp = successActionProcessed["result"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "result", typeName: "SuccessActionProcessed")) - } + static func arrayOf(successActionList: [SuccessAction]) -> [Any] { + return successActionList.map { v -> [String: Any?] in return dictionaryOf(successAction: v) } + } + + static func asSuccessActionList(arr: [Any]) throws -> [SuccessAction] { + var list = [SuccessAction]() + for value in arr { + if let val = value as? [String: Any?] { + var successAction = try asSuccessAction(successAction: val) + list.append(successAction) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessAction")) + } + } + return list + } + + static func asSuccessActionProcessed(successActionProcessed: [String: Any?]) throws -> SuccessActionProcessed { + let type = successActionProcessed["type"] as! String + if type == "aes" { + guard let resultTmp = successActionProcessed["result"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "result", typeName: "SuccessActionProcessed")) + } let _result = try asAesSuccessActionDataResult(aesSuccessActionDataResult: resultTmp) - - return SuccessActionProcessed.aes(result: _result) + + return SuccessActionProcessed.aes(result: _result) } - if (type == "message") { - guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) - } + if type == "message" { + guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) + } let _data = try asMessageSuccessActionData(messageSuccessActionData: dataTmp) - - return SuccessActionProcessed.message(data: _data) + + return SuccessActionProcessed.message(data: _data) } - if (type == "url") { - guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { - throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) - } + if type == "url" { + guard let dataTmp = successActionProcessed["data"] as? [String: Any?] else { + throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "data", typeName: "SuccessActionProcessed")) + } let _data = try asUrlSuccessActionData(urlSuccessActionData: dataTmp) - - return SuccessActionProcessed.url(data: _data) - } - throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessActionProcessed") -} + return SuccessActionProcessed.url(data: _data) + } -static func dictionaryOf(successActionProcessed: SuccessActionProcessed) -> [String: Any?] { - switch (successActionProcessed) { - - case let .aes( - result - ): - return [ - "type": "aes", - "result": dictionaryOf(aesSuccessActionDataResult: result), - ] - - case let .message( - data - ): - return [ - "type": "message", - "data": dictionaryOf(messageSuccessActionData: data), - ] - - case let .url( - data - ): - return [ - "type": "url", - "data": dictionaryOf(urlSuccessActionData: data), - ] - } -} + throw SdkError.Generic(message: "Unexpected type \(type) for enum SuccessActionProcessed") + } -static func arrayOf(`successActionProcessedList`: [SuccessActionProcessed]) -> [Any] { - return `successActionProcessedList`.map { (v) -> [String: Any?] in return dictionaryOf(successActionProcessed: v) } -} + static func dictionaryOf(successActionProcessed: SuccessActionProcessed) -> [String: Any?] { + switch successActionProcessed { + case let .aes( + result + ): + return [ + "type": "aes", + "result": dictionaryOf(aesSuccessActionDataResult: result), + ] + + case let .message( + data + ): + return [ + "type": "message", + "data": dictionaryOf(messageSuccessActionData: data), + ] -static func asSuccessActionProcessedList(arr: [Any]) throws -> [SuccessActionProcessed] { - var list = [SuccessActionProcessed]() - for value in arr { - if let val = value as? [String: Any?] { - var successActionProcessed = try asSuccessActionProcessed(successActionProcessed: val) - list.append(successActionProcessed) - } else { - throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessActionProcessed")) + case let .url( + data + ): + return [ + "type": "url", + "data": dictionaryOf(urlSuccessActionData: data), + ] } } - return list -} + + static func arrayOf(successActionProcessedList: [SuccessActionProcessed]) -> [Any] { + return successActionProcessedList.map { v -> [String: Any?] in return dictionaryOf(successActionProcessed: v) } + } + + static func asSuccessActionProcessedList(arr: [Any]) throws -> [SuccessActionProcessed] { + var list = [SuccessActionProcessed]() + for value in arr { + if let val = value as? [String: Any?] { + var successActionProcessed = try asSuccessActionProcessed(successActionProcessed: val) + list.append(successActionProcessed) + } else { + throw SdkError.Generic(message: errUnexpectedType(typeName: "SuccessActionProcessed")) + } + } + return list + } + static func hasNonNilKey(data: [String: Any?], key: String) -> Bool { if let val = data[key] { return !(val == nil || val is NSNull) @@ -3988,5 +4004,4 @@ static func asSuccessActionProcessedList(arr: [Any]) throws -> [SuccessActionPro static func errUnexpectedValue(fieldName: String) -> String { return "Unexpected value for optional field \(fieldName)" } - -} \ No newline at end of file +} diff --git a/packages/react-native/ios/RNBreezSDKLiquid.swift b/packages/react-native/ios/RNBreezSDKLiquid.swift index 2422b614f..11b484f87 100644 --- a/packages/react-native/ios/RNBreezSDKLiquid.swift +++ b/packages/react-native/ios/RNBreezSDKLiquid.swift @@ -1,28 +1,27 @@ -import Foundation import BreezSDKLiquid +import Foundation @objc(RNBreezSDKLiquid) class RNBreezSDKLiquid: RCTEventEmitter { static let TAG: String = "BreezSDKLiquid" - + public static var emitter: RCTEventEmitter! public static var hasListeners: Bool = false public static var supportedEvents: [String] = ["breezSdkLiquidLog"] private var bindingLiquidSdk: BindingLiquidSdk! - static var breezSdkLiquidDirectory: URL { let applicationDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first! let breezSdkLiquidDirectory = applicationDirectory.appendingPathComponent("breezSdkLiquid", isDirectory: true) - + if !FileManager.default.fileExists(atPath: breezSdkLiquidDirectory.path) { try! FileManager.default.createDirectory(atPath: breezSdkLiquidDirectory.path, withIntermediateDirectories: true) } - + return breezSdkLiquidDirectory } - + override init() { super.init() RNBreezSDKLiquid.emitter = self @@ -36,32 +35,32 @@ class RNBreezSDKLiquid: RCTEventEmitter { static func addSupportedEvent(name: String) { RNBreezSDKLiquid.supportedEvents.append(name) } - + override func supportedEvents() -> [String]! { return RNBreezSDKLiquid.supportedEvents } - + override func startObserving() { RNBreezSDKLiquid.hasListeners = true } - + override func stopObserving() { RNBreezSDKLiquid.hasListeners = false } - + @objc override static func requiresMainQueueSetup() -> Bool { return false } - + func getBindingLiquidSdk() throws -> BindingLiquidSdk { if bindingLiquidSdk != nil { return bindingLiquidSdk } - + throw SdkError.Generic(message: "Not initialized") } - + private func ensureWorkingDir(workingDir: String) throws { do { if !FileManager.default.fileExists(atPath: workingDir) { @@ -72,42 +71,41 @@ class RNBreezSDKLiquid: RCTEventEmitter { } } - @objc(defaultConfig:breezApiKey:resolve:reject:) - func defaultConfig(_ network: String, breezApiKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func defaultConfig(_ network: String, breezApiKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let networkTmp = try BreezSDKLiquidMapper.asLiquidNetwork(liquidNetwork: network) let breezApiKeyTmp = breezApiKey.isEmpty ? nil : breezApiKey - var res =try BreezSDKLiquid.defaultConfig(network: networkTmp, breezApiKey: breezApiKeyTmp) + var res = try BreezSDKLiquid.defaultConfig(network: networkTmp, breezApiKey: breezApiKeyTmp) res.workingDir = RNBreezSDKLiquid.breezSdkLiquidDirectory.path resolve(BreezSDKLiquidMapper.dictionaryOf(config: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(parse:resolve:reject:) - func parse(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func parse(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try BreezSDKLiquid.parse(input: input) + var res = try BreezSDKLiquid.parse(input: input) resolve(BreezSDKLiquidMapper.dictionaryOf(inputType: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(parseInvoice:resolve:reject:) - func parseInvoice(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func parseInvoice(_ input: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try BreezSDKLiquid.parseInvoice(input: input) + var res = try BreezSDKLiquid.parseInvoice(input: input) resolve(BreezSDKLiquidMapper.dictionaryOf(lnInvoice: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(setLogger:reject:) - func setLogger(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func setLogger(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { try BreezSDKLiquid.setLogger(logger: BreezSDKLiquidLogger()) resolve(["status": "ok"]) @@ -117,7 +115,7 @@ class RNBreezSDKLiquid: RCTEventEmitter { } @objc(connect:resolve:reject:) - func connect(_ req:[String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func connect(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { if bindingLiquidSdk != nil { reject("Generic", "Already initialized", nil) return @@ -133,7 +131,7 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(addEventListener:reject:) func addEventListener(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { @@ -147,9 +145,8 @@ class RNBreezSDKLiquid: RCTEventEmitter { } } - @objc(removeEventListener:resolve:reject:) - func removeEventListener(_ id: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func removeEventListener(_ id: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { try getBindingLiquidSdk().removeEventListener(id: id) resolve(["status": "ok"]) @@ -157,163 +154,163 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(getInfo:reject:) - func getInfo(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func getInfo(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try getBindingLiquidSdk().getInfo() + var res = try getBindingLiquidSdk().getInfo() resolve(BreezSDKLiquidMapper.dictionaryOf(getInfoResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(signMessage:resolve:reject:) - func signMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func signMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let signMessageRequest = try BreezSDKLiquidMapper.asSignMessageRequest(signMessageRequest: req) - var res =try getBindingLiquidSdk().signMessage(req: signMessageRequest) + var res = try getBindingLiquidSdk().signMessage(req: signMessageRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(signMessageResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(checkMessage:resolve:reject:) - func checkMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func checkMessage(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let checkMessageRequest = try BreezSDKLiquidMapper.asCheckMessageRequest(checkMessageRequest: req) - var res =try getBindingLiquidSdk().checkMessage(req: checkMessageRequest) + var res = try getBindingLiquidSdk().checkMessage(req: checkMessageRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(checkMessageResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareSendPayment:resolve:reject:) - func prepareSendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func prepareSendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let prepareSendRequest = try BreezSDKLiquidMapper.asPrepareSendRequest(prepareSendRequest: req) - var res =try getBindingLiquidSdk().prepareSendPayment(req: prepareSendRequest) + var res = try getBindingLiquidSdk().prepareSendPayment(req: prepareSendRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareSendResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(sendPayment:resolve:reject:) - func sendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func sendPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let sendPaymentRequest = try BreezSDKLiquidMapper.asSendPaymentRequest(sendPaymentRequest: req) - var res =try getBindingLiquidSdk().sendPayment(req: sendPaymentRequest) + var res = try getBindingLiquidSdk().sendPayment(req: sendPaymentRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(sendPaymentResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareReceivePayment:resolve:reject:) - func prepareReceivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func prepareReceivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let prepareReceiveRequest = try BreezSDKLiquidMapper.asPrepareReceiveRequest(prepareReceiveRequest: req) - var res =try getBindingLiquidSdk().prepareReceivePayment(req: prepareReceiveRequest) + var res = try getBindingLiquidSdk().prepareReceivePayment(req: prepareReceiveRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareReceiveResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(receivePayment:resolve:reject:) - func receivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func receivePayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let receivePaymentRequest = try BreezSDKLiquidMapper.asReceivePaymentRequest(receivePaymentRequest: req) - var res =try getBindingLiquidSdk().receivePayment(req: receivePaymentRequest) + var res = try getBindingLiquidSdk().receivePayment(req: receivePaymentRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(receivePaymentResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(fetchLightningLimits:reject:) - func fetchLightningLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func fetchLightningLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try getBindingLiquidSdk().fetchLightningLimits() + var res = try getBindingLiquidSdk().fetchLightningLimits() resolve(BreezSDKLiquidMapper.dictionaryOf(lightningPaymentLimitsResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(fetchOnchainLimits:reject:) - func fetchOnchainLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func fetchOnchainLimits(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try getBindingLiquidSdk().fetchOnchainLimits() + var res = try getBindingLiquidSdk().fetchOnchainLimits() resolve(BreezSDKLiquidMapper.dictionaryOf(onchainPaymentLimitsResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(preparePayOnchain:resolve:reject:) - func preparePayOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func preparePayOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let preparePayOnchainRequest = try BreezSDKLiquidMapper.asPreparePayOnchainRequest(preparePayOnchainRequest: req) - var res =try getBindingLiquidSdk().preparePayOnchain(req: preparePayOnchainRequest) + var res = try getBindingLiquidSdk().preparePayOnchain(req: preparePayOnchainRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(preparePayOnchainResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(payOnchain:resolve:reject:) - func payOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func payOnchain(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let payOnchainRequest = try BreezSDKLiquidMapper.asPayOnchainRequest(payOnchainRequest: req) - var res =try getBindingLiquidSdk().payOnchain(req: payOnchainRequest) + var res = try getBindingLiquidSdk().payOnchain(req: payOnchainRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(sendPaymentResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareBuyBitcoin:resolve:reject:) - func prepareBuyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func prepareBuyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let prepareBuyBitcoinRequest = try BreezSDKLiquidMapper.asPrepareBuyBitcoinRequest(prepareBuyBitcoinRequest: req) - var res =try getBindingLiquidSdk().prepareBuyBitcoin(req: prepareBuyBitcoinRequest) + var res = try getBindingLiquidSdk().prepareBuyBitcoin(req: prepareBuyBitcoinRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareBuyBitcoinResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(buyBitcoin:resolve:reject:) - func buyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func buyBitcoin(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let buyBitcoinRequest = try BreezSDKLiquidMapper.asBuyBitcoinRequest(buyBitcoinRequest: req) - var res =try getBindingLiquidSdk().buyBitcoin(req: buyBitcoinRequest) + var res = try getBindingLiquidSdk().buyBitcoin(req: buyBitcoinRequest) resolve(res) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(listPayments:resolve:reject:) - func listPayments(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func listPayments(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let listPaymentsRequest = try BreezSDKLiquidMapper.asListPaymentsRequest(listPaymentsRequest: req) - var res =try getBindingLiquidSdk().listPayments(req: listPaymentsRequest) + var res = try getBindingLiquidSdk().listPayments(req: listPaymentsRequest) resolve(BreezSDKLiquidMapper.arrayOf(paymentList: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(getPayment:resolve:reject:) - func getPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func getPayment(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let reqTmp = try BreezSDKLiquidMapper.asGetPaymentRequest(getPaymentRequest: req) - var res =try getBindingLiquidSdk().getPayment(req: reqTmp) + var res = try getBindingLiquidSdk().getPayment(req: reqTmp) if res != nil { resolve(BreezSDKLiquidMapper.dictionaryOf(payment: res!)) } else { @@ -323,41 +320,41 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(listRefundables:reject:) - func listRefundables(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func listRefundables(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try getBindingLiquidSdk().listRefundables() + var res = try getBindingLiquidSdk().listRefundables() resolve(BreezSDKLiquidMapper.arrayOf(refundableSwapList: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(prepareRefund:resolve:reject:) - func prepareRefund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func prepareRefund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let prepareRefundRequest = try BreezSDKLiquidMapper.asPrepareRefundRequest(prepareRefundRequest: req) - var res =try getBindingLiquidSdk().prepareRefund(req: prepareRefundRequest) + var res = try getBindingLiquidSdk().prepareRefund(req: prepareRefundRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareRefundResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(refund:resolve:reject:) - func refund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func refund(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let refundRequest = try BreezSDKLiquidMapper.asRefundRequest(refundRequest: req) - var res =try getBindingLiquidSdk().refund(req: refundRequest) + var res = try getBindingLiquidSdk().refund(req: refundRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(refundResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(rescanOnchainSwaps:reject:) - func rescanOnchainSwaps(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func rescanOnchainSwaps(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { try getBindingLiquidSdk().rescanOnchainSwaps() resolve(["status": "ok"]) @@ -365,9 +362,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(sync:reject:) - func sync(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func sync(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { try getBindingLiquidSdk().sync() resolve(["status": "ok"]) @@ -375,19 +372,19 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(recommendedFees:reject:) - func recommendedFees(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func recommendedFees(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try getBindingLiquidSdk().recommendedFees() + var res = try getBindingLiquidSdk().recommendedFees() resolve(BreezSDKLiquidMapper.dictionaryOf(recommendedFees: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(backup:resolve:reject:) - func backup(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func backup(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let backupRequest = try BreezSDKLiquidMapper.asBackupRequest(backupRequest: req) try getBindingLiquidSdk().backup(req: backupRequest) @@ -396,9 +393,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(restore:resolve:reject:) - func restore(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func restore(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let restoreRequest = try BreezSDKLiquidMapper.asRestoreRequest(restoreRequest: req) try getBindingLiquidSdk().restore(req: restoreRequest) @@ -407,9 +404,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(disconnect:reject:) - func disconnect(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func disconnect(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { try getBindingLiquidSdk().disconnect() bindingLiquidSdk = nil @@ -418,53 +415,53 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(prepareLnurlPay:resolve:reject:) - func prepareLnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func prepareLnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let prepareLnUrlPayRequest = try BreezSDKLiquidMapper.asPrepareLnUrlPayRequest(prepareLnUrlPayRequest: req) - var res =try getBindingLiquidSdk().prepareLnurlPay(req: prepareLnUrlPayRequest) + var res = try getBindingLiquidSdk().prepareLnurlPay(req: prepareLnUrlPayRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(prepareLnUrlPayResponse: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(lnurlPay:resolve:reject:) - func lnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func lnurlPay(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let lnUrlPayRequest = try BreezSDKLiquidMapper.asLnUrlPayRequest(lnUrlPayRequest: req) - var res =try getBindingLiquidSdk().lnurlPay(req: lnUrlPayRequest) + var res = try getBindingLiquidSdk().lnurlPay(req: lnUrlPayRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(lnUrlPayResult: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(lnurlWithdraw:resolve:reject:) - func lnurlWithdraw(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func lnurlWithdraw(_ req: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let lnUrlWithdrawRequest = try BreezSDKLiquidMapper.asLnUrlWithdrawRequest(lnUrlWithdrawRequest: req) - var res =try getBindingLiquidSdk().lnurlWithdraw(req: lnUrlWithdrawRequest) + var res = try getBindingLiquidSdk().lnurlWithdraw(req: lnUrlWithdrawRequest) resolve(BreezSDKLiquidMapper.dictionaryOf(lnUrlWithdrawResult: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(lnurlAuth:resolve:reject:) - func lnurlAuth(_ reqData: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func lnurlAuth(_ reqData: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { let lnUrlAuthRequestData = try BreezSDKLiquidMapper.asLnUrlAuthRequestData(lnUrlAuthRequestData: reqData) - var res =try getBindingLiquidSdk().lnurlAuth(reqData: lnUrlAuthRequestData) + var res = try getBindingLiquidSdk().lnurlAuth(reqData: lnUrlAuthRequestData) resolve(BreezSDKLiquidMapper.dictionaryOf(lnUrlCallbackStatus: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(registerWebhook:resolve:reject:) - func registerWebhook(_ webhookUrl: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func registerWebhook(_ webhookUrl: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { try getBindingLiquidSdk().registerWebhook(webhookUrl: webhookUrl) resolve(["status": "ok"]) @@ -472,9 +469,9 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(unregisterWebhook:reject:) - func unregisterWebhook(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func unregisterWebhook(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { try getBindingLiquidSdk().unregisterWebhook() resolve(["status": "ok"]) @@ -482,28 +479,27 @@ class RNBreezSDKLiquid: RCTEventEmitter { rejectErr(err: err, reject: reject) } } - + @objc(fetchFiatRates:reject:) - func fetchFiatRates(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func fetchFiatRates(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try getBindingLiquidSdk().fetchFiatRates() + var res = try getBindingLiquidSdk().fetchFiatRates() resolve(BreezSDKLiquidMapper.arrayOf(rateList: res)) } catch let err { rejectErr(err: err, reject: reject) } } - + @objc(listFiatCurrencies:reject:) - func listFiatCurrencies(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void { + func listFiatCurrencies(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { do { - var res =try getBindingLiquidSdk().listFiatCurrencies() + var res = try getBindingLiquidSdk().listFiatCurrencies() resolve(BreezSDKLiquidMapper.arrayOf(fiatCurrencyList: res)) } catch let err { rejectErr(err: err, reject: reject) } } - func rejectErr(err: Error, reject: @escaping RCTPromiseRejectBlock) { var errorName = "Generic" var message = "\(err)" @@ -516,4 +512,3 @@ class RNBreezSDKLiquid: RCTEventEmitter { reject(errorName, message, err) } } - diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 6157c8407..128db7ce7 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -19,22 +19,22 @@ const BreezSDKLiquid = NativeModules.RNBreezSDKLiquid const BreezSDKLiquidEmitter = new NativeEventEmitter(BreezSDKLiquid) -export type AesSuccessActionData = { +export interface AesSuccessActionData { description: string ciphertext: string iv: string } -export type AesSuccessActionDataDecrypted = { +export interface AesSuccessActionDataDecrypted { description: string plaintext: string } -export type BackupRequest = { +export interface BackupRequest { backupPath?: string } -export type BitcoinAddressData = { +export interface BitcoinAddressData { address: string network: Network amountSat?: number @@ -42,22 +42,22 @@ export type BitcoinAddressData = { message?: string } -export type BuyBitcoinRequest = { +export interface BuyBitcoinRequest { prepareResponse: PrepareBuyBitcoinResponse redirectUrl?: string } -export type CheckMessageRequest = { +export interface CheckMessageRequest { message: string pubkey: string signature: string } -export type CheckMessageResponse = { +export interface CheckMessageResponse { isValid: boolean } -export type Config = { +export interface Config { liquidElectrumUrl: string bitcoinElectrumUrl: string mempoolspaceUrl: string @@ -69,16 +69,16 @@ export type Config = { zeroConfMaxAmountSat?: number } -export type ConnectRequest = { +export interface ConnectRequest { config: Config mnemonic: string } -export type ConnectWithSignerRequest = { +export interface ConnectWithSignerRequest { config: Config } -export type CurrencyInfo = { +export interface CurrencyInfo { name: string fractionSize: number spacing?: number @@ -88,12 +88,12 @@ export type CurrencyInfo = { localeOverrides: LocaleOverrides[] } -export type FiatCurrency = { +export interface FiatCurrency { id: string info: CurrencyInfo } -export type GetInfoResponse = { +export interface GetInfoResponse { balanceSat: number pendingSendSat: number pendingReceiveSat: number @@ -101,7 +101,7 @@ export type GetInfoResponse = { pubkey: string } -export type LnInvoice = { +export interface LnInvoice { bolt11: string network: Network payeePubkey: string @@ -116,18 +116,18 @@ export type LnInvoice = { minFinalCltvExpiryDelta: number } -export type LightningPaymentLimitsResponse = { +export interface LightningPaymentLimitsResponse { send: Limits receive: Limits } -export type Limits = { +export interface Limits { minSat: number maxSat: number maxZeroConfSat: number } -export type LiquidAddressData = { +export interface LiquidAddressData { address: string network: Network assetId?: string @@ -136,7 +136,7 @@ export type LiquidAddressData = { message?: string } -export type ListPaymentsRequest = { +export interface ListPaymentsRequest { filters?: PaymentType[] fromTimestamp?: number toTimestamp?: number @@ -145,27 +145,27 @@ export type ListPaymentsRequest = { details?: ListPaymentDetails } -export type LnUrlAuthRequestData = { +export interface LnUrlAuthRequestData { k1: string domain: string url: string action?: string } -export type LnUrlErrorData = { +export interface LnUrlErrorData { reason: string } -export type LnUrlPayErrorData = { +export interface LnUrlPayErrorData { paymentHash: string reason: string } -export type LnUrlPayRequest = { +export interface LnUrlPayRequest { prepareResponse: PrepareLnUrlPayResponse } -export type LnUrlPayRequestData = { +export interface LnUrlPayRequestData { callback: string minSendable: number maxSendable: number @@ -177,18 +177,18 @@ export type LnUrlPayRequestData = { lnAddress?: string } -export type LnUrlPaySuccessData = { +export interface LnUrlPaySuccessData { successAction?: SuccessActionProcessed payment: Payment } -export type LnUrlWithdrawRequest = { +export interface LnUrlWithdrawRequest { data: LnUrlWithdrawRequestData amountMsat: number description?: string } -export type LnUrlWithdrawRequestData = { +export interface LnUrlWithdrawRequestData { callback: string k1: string defaultDescription: string @@ -196,41 +196,41 @@ export type LnUrlWithdrawRequestData = { maxWithdrawable: number } -export type LnUrlWithdrawSuccessData = { +export interface LnUrlWithdrawSuccessData { invoice: LnInvoice } -export type LocaleOverrides = { +export interface LocaleOverrides { locale: string spacing?: number symbol: SymbolType } -export type LocalizedName = { +export interface LocalizedName { locale: string name: string } -export type LogEntry = { +export interface LogEntry { line: string level: string } -export type MessageSuccessActionData = { +export interface MessageSuccessActionData { message: string } -export type OnchainPaymentLimitsResponse = { +export interface OnchainPaymentLimitsResponse { send: Limits receive: Limits } -export type PayOnchainRequest = { +export interface PayOnchainRequest { address: string prepareResponse: PreparePayOnchainResponse } -export type Payment = { +export interface Payment { timestamp: number amountSat: number feesSat: number @@ -241,47 +241,47 @@ export type Payment = { txId?: string } -export type PrepareBuyBitcoinRequest = { +export interface PrepareBuyBitcoinRequest { provider: BuyBitcoinProvider amountSat: number } -export type PrepareBuyBitcoinResponse = { +export interface PrepareBuyBitcoinResponse { provider: BuyBitcoinProvider amountSat: number feesSat: number } -export type PrepareLnUrlPayRequest = { +export interface PrepareLnUrlPayRequest { data: LnUrlPayRequestData amountMsat: number comment?: string validateSuccessActionUrl?: boolean } -export type PrepareLnUrlPayResponse = { +export interface PrepareLnUrlPayResponse { destination: SendDestination feesSat: number successAction?: SuccessAction } -export type PreparePayOnchainRequest = { +export interface PreparePayOnchainRequest { amount: PayOnchainAmount feeRateSatPerVbyte?: number } -export type PreparePayOnchainResponse = { +export interface PreparePayOnchainResponse { receiverAmountSat: number claimFeesSat: number totalFeesSat: number } -export type PrepareReceiveRequest = { +export interface PrepareReceiveRequest { paymentMethod: PaymentMethod payerAmountSat?: number } -export type PrepareReceiveResponse = { +export interface PrepareReceiveResponse { paymentMethod: PaymentMethod feesSat: number payerAmountSat?: number @@ -290,44 +290,44 @@ export type PrepareReceiveResponse = { zeroAmountServiceFeerate?: number } -export type PrepareRefundRequest = { +export interface PrepareRefundRequest { swapAddress: string refundAddress: string feeRateSatPerVbyte: number } -export type PrepareRefundResponse = { +export interface PrepareRefundResponse { txVsize: number txFeeSat: number refundTxId?: string } -export type PrepareSendRequest = { +export interface PrepareSendRequest { destination: string amountSat?: number } -export type PrepareSendResponse = { +export interface PrepareSendResponse { destination: SendDestination feesSat: number } -export type Rate = { +export interface Rate { coin: string value: number } -export type ReceivePaymentRequest = { +export interface ReceivePaymentRequest { prepareResponse: PrepareReceiveResponse description?: string useDescriptionHash?: boolean } -export type ReceivePaymentResponse = { +export interface ReceivePaymentResponse { destination: string } -export type RecommendedFees = { +export interface RecommendedFees { fastestFee: number halfHourFee: number hourFee: number @@ -335,31 +335,31 @@ export type RecommendedFees = { minimumFee: number } -export type RefundRequest = { +export interface RefundRequest { swapAddress: string refundAddress: string feeRateSatPerVbyte: number } -export type RefundResponse = { +export interface RefundResponse { refundTxId: string } -export type RefundableSwap = { +export interface RefundableSwap { swapAddress: string timestamp: number amountSat: number } -export type RestoreRequest = { +export interface RestoreRequest { backupPath?: string } -export type RouteHint = { +export interface RouteHint { hops: RouteHintHop[] } -export type RouteHintHop = { +export interface RouteHintHop { srcNodeId: string shortChannelId: string feesBaseMsat: number @@ -369,30 +369,30 @@ export type RouteHintHop = { htlcMaximumMsat?: number } -export type SendPaymentRequest = { +export interface SendPaymentRequest { prepareResponse: PrepareSendResponse } -export type SendPaymentResponse = { +export interface SendPaymentResponse { payment: Payment } -export type SignMessageRequest = { +export interface SignMessageRequest { message: string } -export type SignMessageResponse = { +export interface SignMessageResponse { signature: string } -export type SymbolType = { +export interface SymbolType { grapheme?: string template?: string rtl?: boolean position?: number } -export type UrlSuccessActionData = { +export interface UrlSuccessActionData { description: string url: string matchesCallbackDomain: boolean @@ -419,7 +419,7 @@ export enum GetPaymentRequestVariant { LIGHTNING = "lightning" } -export type GetPaymentRequest = { +export interface GetPaymentRequest { type: GetPaymentRequestVariant.LIGHTNING, paymentHash: string } @@ -687,7 +687,7 @@ export const connect = async (req: ConnectRequest): Promise => { export const addEventListener = async (listener: EventListener): Promise => { const response = await BreezSDKLiquid.addEventListener() BreezSDKLiquidEmitter.addListener(`event-${response}`, listener) - + return response } From 35cb343b7b310e15f32bde5202f49c7fa4109a11 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Sun, 10 Nov 2024 12:31:43 +0100 Subject: [PATCH 08/22] Update swap payer_amount when we know the quote --- lib/core/src/chain_swap.rs | 1 + lib/core/src/persist/chain.rs | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index c8baf2917..14c27154b 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -378,6 +378,7 @@ impl ChainSwapHandler { .and_then(|quote| { info!("Got quote of {quote} sat for swap {}", &swap.id); + self.persister.update_swap_payer_amount(&swap.id, quote)?; self.swapper .accept_zero_amount_chain_swap_quote(&swap.id, quote) }) diff --git a/lib/core/src/persist/chain.rs b/lib/core/src/persist/chain.rs index cf7be8c4d..387a9878b 100644 --- a/lib/core/src/persist/chain.rs +++ b/lib/core/src/persist/chain.rs @@ -263,6 +263,43 @@ impl Persister { Ok(()) } + /// Used for Zero-amount Receive Chain swaps, when we fetched the quote and we know how much + /// the sender locked up + pub(crate) fn update_swap_payer_amount( + &self, + swap_id: &str, + payer_amount_sat: u64, + ) -> Result<(), PaymentError> { + let swap = self + .fetch_chain_swap_by_id(swap_id)? + .ok_or_else(|| PaymentError::Generic { + err: format!("Cannot update non-existent chain swap with ID: {swap_id}"), + })?; + ensure_sdk!( + matches!(swap.direction, Direction::Incoming), + PaymentError::Generic { + err: format!( + "Can only update payer_amount_sat for incoming chain swaps. Swap ID: {swap_id}" + ) + } + ); + + log::info!("Updating chain swap {swap_id}: payer_amount_sat = {payer_amount_sat}"); + let con: Connection = self.get_connection()?; + con.execute( + "UPDATE chain_swaps + SET + payer_amount_sat = :payer_amount_sat + WHERE + id = :id", + named_params! { + ":id": swap_id, + ":payer_amount_sat": payer_amount_sat, + }, + )?; + Ok(()) + } + // Only set the Chain Swap claim_tx_id if not set, otherwise return an error pub(crate) fn set_chain_swap_claim_tx_id( &self, From d3f448819d81589e0a7b221880a419b54cebd9ca Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:17:27 +0100 Subject: [PATCH 09/22] Rename receive_onchain arg --- lib/core/src/sdk.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index d6d912d08..8e253d5d6 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -1992,13 +1992,13 @@ impl LiquidSdk { /// the service fees. async fn receive_onchain( &self, - payer_amount_sat: Option, + user_lockup_amount_sat: Option, fees_sat: u64, ) -> Result { self.ensure_is_started().await?; let swap = self - .create_receive_chain_swap(payer_amount_sat, fees_sat) + .create_receive_chain_swap(user_lockup_amount_sat, fees_sat) .await?; let create_response = swap.get_boltz_create_response()?; let address = create_response.lockup_details.lockup_address; From 1e18406e28ae4f16adff8cb4f9d525ce0a6aff55 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:14:20 +0100 Subject: [PATCH 10/22] Rename PrepareReceiveResponse fields --- .../include/breez_sdk_liquid.h | 6 +-- lib/bindings/src/breez_sdk_liquid.udl | 6 +-- lib/core/src/frb_generated.rs | 52 ++++++++----------- lib/core/src/model.rs | 12 ++--- lib/core/src/sdk.rs | 18 +++---- packages/dart/lib/src/frb_generated.dart | 24 ++++----- packages/dart/lib/src/frb_generated.io.dart | 14 +++-- packages/dart/lib/src/model.dart | 30 +++++------ ...utter_breez_liquid_bindings_generated.dart | 6 +-- .../breezsdkliquid/BreezSDKLiquidMapper.kt | 33 +++++------- .../ios/BreezSDKLiquidMapper.swift | 38 +++++++------- packages/react-native/src/index.ts | 6 +-- 12 files changed, 113 insertions(+), 132 deletions(-) diff --git a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h index 49511ef7c..6ae79baa0 100644 --- a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h +++ b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h @@ -367,9 +367,9 @@ typedef struct wire_cst_prepare_receive_response { int32_t payment_method; uint64_t *payer_amount_sat; uint64_t fees_sat; - uint64_t *zero_amount_min_payer_amount_sat; - uint64_t *zero_amount_max_payer_amount_sat; - double *zero_amount_service_feerate; + uint64_t *min_payer_amount_sat; + uint64_t *max_payer_amount_sat; + double *service_feerate; } wire_cst_prepare_receive_response; typedef struct wire_cst_receive_payment_request { diff --git a/lib/bindings/src/breez_sdk_liquid.udl b/lib/bindings/src/breez_sdk_liquid.udl index 6916f08e6..5ab5c409e 100644 --- a/lib/bindings/src/breez_sdk_liquid.udl +++ b/lib/bindings/src/breez_sdk_liquid.udl @@ -434,9 +434,9 @@ dictionary PrepareReceiveResponse { PaymentMethod payment_method; u64 fees_sat; u64? payer_amount_sat; - u64? zero_amount_min_payer_amount_sat; - u64? zero_amount_max_payer_amount_sat; - f64? zero_amount_service_feerate; + u64? min_payer_amount_sat; + u64? max_payer_amount_sat; + f64? service_feerate; }; dictionary ReceivePaymentRequest { diff --git a/lib/core/src/frb_generated.rs b/lib/core/src/frb_generated.rs index edc98ed24..3965ebff7 100644 --- a/lib/core/src/frb_generated.rs +++ b/lib/core/src/frb_generated.rs @@ -3756,16 +3756,16 @@ impl SseDecode for crate::model::PrepareReceiveResponse { let mut var_paymentMethod = ::sse_decode(deserializer); let mut var_payerAmountSat = >::sse_decode(deserializer); let mut var_feesSat = ::sse_decode(deserializer); - let mut var_zeroAmountMinPayerAmountSat = >::sse_decode(deserializer); - let mut var_zeroAmountMaxPayerAmountSat = >::sse_decode(deserializer); - let mut var_zeroAmountServiceFeerate = >::sse_decode(deserializer); + let mut var_minPayerAmountSat = >::sse_decode(deserializer); + let mut var_maxPayerAmountSat = >::sse_decode(deserializer); + let mut var_serviceFeerate = >::sse_decode(deserializer); return crate::model::PrepareReceiveResponse { payment_method: var_paymentMethod, payer_amount_sat: var_payerAmountSat, fees_sat: var_feesSat, - zero_amount_min_payer_amount_sat: var_zeroAmountMinPayerAmountSat, - zero_amount_max_payer_amount_sat: var_zeroAmountMaxPayerAmountSat, - zero_amount_service_feerate: var_zeroAmountServiceFeerate, + min_payer_amount_sat: var_minPayerAmountSat, + max_payer_amount_sat: var_maxPayerAmountSat, + service_feerate: var_serviceFeerate, }; } } @@ -5821,15 +5821,9 @@ impl flutter_rust_bridge::IntoDart for crate::model::PrepareReceiveResponse { self.payment_method.into_into_dart().into_dart(), self.payer_amount_sat.into_into_dart().into_dart(), self.fees_sat.into_into_dart().into_dart(), - self.zero_amount_min_payer_amount_sat - .into_into_dart() - .into_dart(), - self.zero_amount_max_payer_amount_sat - .into_into_dart() - .into_dart(), - self.zero_amount_service_feerate - .into_into_dart() - .into_dart(), + self.min_payer_amount_sat.into_into_dart().into_dart(), + self.max_payer_amount_sat.into_into_dart().into_dart(), + self.service_feerate.into_into_dart().into_dart(), ] .into_dart() } @@ -7712,9 +7706,9 @@ impl SseEncode for crate::model::PrepareReceiveResponse { ::sse_encode(self.payment_method, serializer); >::sse_encode(self.payer_amount_sat, serializer); ::sse_encode(self.fees_sat, serializer); - >::sse_encode(self.zero_amount_min_payer_amount_sat, serializer); - >::sse_encode(self.zero_amount_max_payer_amount_sat, serializer); - >::sse_encode(self.zero_amount_service_feerate, serializer); + >::sse_encode(self.min_payer_amount_sat, serializer); + >::sse_encode(self.max_payer_amount_sat, serializer); + >::sse_encode(self.service_feerate, serializer); } } @@ -9594,13 +9588,9 @@ mod io { payment_method: self.payment_method.cst_decode(), payer_amount_sat: self.payer_amount_sat.cst_decode(), fees_sat: self.fees_sat.cst_decode(), - zero_amount_min_payer_amount_sat: self - .zero_amount_min_payer_amount_sat - .cst_decode(), - zero_amount_max_payer_amount_sat: self - .zero_amount_max_payer_amount_sat - .cst_decode(), - zero_amount_service_feerate: self.zero_amount_service_feerate.cst_decode(), + min_payer_amount_sat: self.min_payer_amount_sat.cst_decode(), + max_payer_amount_sat: self.max_payer_amount_sat.cst_decode(), + service_feerate: self.service_feerate.cst_decode(), } } } @@ -10748,9 +10738,9 @@ mod io { payment_method: Default::default(), payer_amount_sat: core::ptr::null_mut(), fees_sat: Default::default(), - zero_amount_min_payer_amount_sat: core::ptr::null_mut(), - zero_amount_max_payer_amount_sat: core::ptr::null_mut(), - zero_amount_service_feerate: core::ptr::null_mut(), + min_payer_amount_sat: core::ptr::null_mut(), + max_payer_amount_sat: core::ptr::null_mut(), + service_feerate: core::ptr::null_mut(), } } } @@ -12893,9 +12883,9 @@ mod io { payment_method: i32, payer_amount_sat: *mut u64, fees_sat: u64, - zero_amount_min_payer_amount_sat: *mut u64, - zero_amount_max_payer_amount_sat: *mut u64, - zero_amount_service_feerate: *mut f64, + min_payer_amount_sat: *mut u64, + max_payer_amount_sat: *mut u64, + service_feerate: *mut f64, } #[repr(C)] #[derive(Clone, Copy)] diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index 9393acd3b..2f6ad2a93 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -306,18 +306,18 @@ pub struct PrepareReceiveResponse { /// The minimum amount the payer can send for this swap to succeed. /// - /// Only applicable to Zero-Amount Receive Chain Swaps. - pub zero_amount_min_payer_amount_sat: Option, + /// When the method is [PaymentMethod::LiquidAddress], this is empty. + pub min_payer_amount_sat: Option, /// The maximum amount the payer can send for this swap to succeed. /// - /// Only applicable to Zero-Amount Receive Chain Swaps. - pub zero_amount_max_payer_amount_sat: Option, + /// When the method is [PaymentMethod::LiquidAddress], this is empty. + pub max_payer_amount_sat: Option, /// The percentage of the sent amount that will count towards the service fee. /// - /// Only applicable to Zero-Amount Receive Chain Swaps. - pub zero_amount_service_feerate: Option, + /// When the method is [PaymentMethod::LiquidAddress], this is empty. + pub service_feerate: Option, } /// An argument when calling [crate::sdk::LiquidSdk::receive_payment]. diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index 8e253d5d6..cb3c514eb 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -1627,9 +1627,9 @@ impl LiquidSdk { ) -> Result { self.ensure_is_started().await?; - let mut zero_amount_min_payer_amount_sat = None; - let mut zero_amount_max_payer_amount_sat = None; - let mut zero_amount_service_feerate = None; + let mut min_payer_amount_sat = None; + let mut max_payer_amount_sat = None; + let mut service_feerate = None; let fees_sat; match req.payment_method { PaymentMethod::Lightning => { @@ -1665,9 +1665,9 @@ impl LiquidSdk { .unwrap_or_default(); if payer_amount_sat.is_none() { - zero_amount_min_payer_amount_sat = Some(pair.limits.minimal); - zero_amount_max_payer_amount_sat = Some(pair.limits.maximal); - zero_amount_service_feerate = Some(pair.fees.percentage); + min_payer_amount_sat = Some(pair.limits.minimal); + max_payer_amount_sat = Some(pair.limits.maximal); + service_feerate = Some(pair.fees.percentage); } fees_sat = service_fees_sat + claim_fees_sat + server_fees_sat; @@ -1684,9 +1684,9 @@ impl LiquidSdk { payer_amount_sat: req.payer_amount_sat, fees_sat, payment_method: req.payment_method.clone(), - zero_amount_min_payer_amount_sat, - zero_amount_max_payer_amount_sat, - zero_amount_service_feerate, + min_payer_amount_sat, + max_payer_amount_sat, + service_feerate, }) } diff --git a/packages/dart/lib/src/frb_generated.dart b/packages/dart/lib/src/frb_generated.dart index 18d52fab2..0addc28b1 100644 --- a/packages/dart/lib/src/frb_generated.dart +++ b/packages/dart/lib/src/frb_generated.dart @@ -2707,9 +2707,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { paymentMethod: dco_decode_payment_method(arr[0]), payerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[1]), feesSat: dco_decode_u_64(arr[2]), - zeroAmountMinPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[3]), - zeroAmountMaxPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[4]), - zeroAmountServiceFeerate: dco_decode_opt_box_autoadd_f_64(arr[5]), + minPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[3]), + maxPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[4]), + serviceFeerate: dco_decode_opt_box_autoadd_f_64(arr[5]), ); } @@ -4693,16 +4693,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_paymentMethod = sse_decode_payment_method(deserializer); var var_payerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); var var_feesSat = sse_decode_u_64(deserializer); - var var_zeroAmountMinPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); - var var_zeroAmountMaxPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); - var var_zeroAmountServiceFeerate = sse_decode_opt_box_autoadd_f_64(deserializer); + var var_minPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); + var var_maxPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); + var var_serviceFeerate = sse_decode_opt_box_autoadd_f_64(deserializer); return PrepareReceiveResponse( paymentMethod: var_paymentMethod, payerAmountSat: var_payerAmountSat, feesSat: var_feesSat, - zeroAmountMinPayerAmountSat: var_zeroAmountMinPayerAmountSat, - zeroAmountMaxPayerAmountSat: var_zeroAmountMaxPayerAmountSat, - zeroAmountServiceFeerate: var_zeroAmountServiceFeerate); + minPayerAmountSat: var_minPayerAmountSat, + maxPayerAmountSat: var_maxPayerAmountSat, + serviceFeerate: var_serviceFeerate); } @protected @@ -6546,9 +6546,9 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_payment_method(self.paymentMethod, serializer); sse_encode_opt_box_autoadd_u_64(self.payerAmountSat, serializer); sse_encode_u_64(self.feesSat, serializer); - sse_encode_opt_box_autoadd_u_64(self.zeroAmountMinPayerAmountSat, serializer); - sse_encode_opt_box_autoadd_u_64(self.zeroAmountMaxPayerAmountSat, serializer); - sse_encode_opt_box_autoadd_f_64(self.zeroAmountServiceFeerate, serializer); + sse_encode_opt_box_autoadd_u_64(self.minPayerAmountSat, serializer); + sse_encode_opt_box_autoadd_u_64(self.maxPayerAmountSat, serializer); + sse_encode_opt_box_autoadd_f_64(self.serviceFeerate, serializer); } @protected diff --git a/packages/dart/lib/src/frb_generated.io.dart b/packages/dart/lib/src/frb_generated.io.dart index f5049495c..c0e9eaafc 100644 --- a/packages/dart/lib/src/frb_generated.io.dart +++ b/packages/dart/lib/src/frb_generated.io.dart @@ -2918,11 +2918,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { wireObj.payment_method = cst_encode_payment_method(apiObj.paymentMethod); wireObj.payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.payerAmountSat); wireObj.fees_sat = cst_encode_u_64(apiObj.feesSat); - wireObj.zero_amount_min_payer_amount_sat = - cst_encode_opt_box_autoadd_u_64(apiObj.zeroAmountMinPayerAmountSat); - wireObj.zero_amount_max_payer_amount_sat = - cst_encode_opt_box_autoadd_u_64(apiObj.zeroAmountMaxPayerAmountSat); - wireObj.zero_amount_service_feerate = cst_encode_opt_box_autoadd_f_64(apiObj.zeroAmountServiceFeerate); + wireObj.min_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.minPayerAmountSat); + wireObj.max_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.maxPayerAmountSat); + wireObj.service_feerate = cst_encode_opt_box_autoadd_f_64(apiObj.serviceFeerate); } @protected @@ -5793,11 +5791,11 @@ final class wire_cst_prepare_receive_response extends ffi.Struct { @ffi.Uint64() external int fees_sat; - external ffi.Pointer zero_amount_min_payer_amount_sat; + external ffi.Pointer min_payer_amount_sat; - external ffi.Pointer zero_amount_max_payer_amount_sat; + external ffi.Pointer max_payer_amount_sat; - external ffi.Pointer zero_amount_service_feerate; + external ffi.Pointer service_feerate; } final class wire_cst_receive_payment_request extends ffi.Struct { diff --git a/packages/dart/lib/src/model.dart b/packages/dart/lib/src/model.dart index 4b9399987..255906e62 100644 --- a/packages/dart/lib/src/model.dart +++ b/packages/dart/lib/src/model.dart @@ -933,26 +933,26 @@ class PrepareReceiveResponse { /// The minimum amount the payer can send for this swap to succeed. /// - /// Only applicable to Zero-Amount Receive Chain Swaps. - final BigInt? zeroAmountMinPayerAmountSat; + /// When the method is [PaymentMethod::LiquidAddress], this is empty. + final BigInt? minPayerAmountSat; /// The maximum amount the payer can send for this swap to succeed. /// - /// Only applicable to Zero-Amount Receive Chain Swaps. - final BigInt? zeroAmountMaxPayerAmountSat; + /// When the method is [PaymentMethod::LiquidAddress], this is empty. + final BigInt? maxPayerAmountSat; /// The percentage of the sent amount that will count towards the service fee. /// - /// Only applicable to Zero-Amount Receive Chain Swaps. - final double? zeroAmountServiceFeerate; + /// When the method is [PaymentMethod::LiquidAddress], this is empty. + final double? serviceFeerate; const PrepareReceiveResponse({ required this.paymentMethod, this.payerAmountSat, required this.feesSat, - this.zeroAmountMinPayerAmountSat, - this.zeroAmountMaxPayerAmountSat, - this.zeroAmountServiceFeerate, + this.minPayerAmountSat, + this.maxPayerAmountSat, + this.serviceFeerate, }); @override @@ -960,9 +960,9 @@ class PrepareReceiveResponse { paymentMethod.hashCode ^ payerAmountSat.hashCode ^ feesSat.hashCode ^ - zeroAmountMinPayerAmountSat.hashCode ^ - zeroAmountMaxPayerAmountSat.hashCode ^ - zeroAmountServiceFeerate.hashCode; + minPayerAmountSat.hashCode ^ + maxPayerAmountSat.hashCode ^ + serviceFeerate.hashCode; @override bool operator ==(Object other) => @@ -972,9 +972,9 @@ class PrepareReceiveResponse { paymentMethod == other.paymentMethod && payerAmountSat == other.payerAmountSat && feesSat == other.feesSat && - zeroAmountMinPayerAmountSat == other.zeroAmountMinPayerAmountSat && - zeroAmountMaxPayerAmountSat == other.zeroAmountMaxPayerAmountSat && - zeroAmountServiceFeerate == other.zeroAmountServiceFeerate; + minPayerAmountSat == other.minPayerAmountSat && + maxPayerAmountSat == other.maxPayerAmountSat && + serviceFeerate == other.serviceFeerate; } /// An argument when calling [crate::sdk::LiquidSdk::prepare_refund]. diff --git a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart index 45420dcac..25b0abf49 100644 --- a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart +++ b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart @@ -4342,11 +4342,11 @@ final class wire_cst_prepare_receive_response extends ffi.Struct { @ffi.Uint64() external int fees_sat; - external ffi.Pointer zero_amount_min_payer_amount_sat; + external ffi.Pointer min_payer_amount_sat; - external ffi.Pointer zero_amount_max_payer_amount_sat; + external ffi.Pointer max_payer_amount_sat; - external ffi.Pointer zero_amount_service_feerate; + external ffi.Pointer service_feerate; } final class wire_cst_receive_payment_request extends ffi.Struct { diff --git a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt index d9256c489..b236ca96b 100644 --- a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt +++ b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt @@ -1697,44 +1697,37 @@ fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiv } else { null } - val zeroAmountMinPayerAmountSat = + val minPayerAmountSat = if (hasNonNullKey( prepareReceiveResponse, - "zeroAmountMinPayerAmountSat", + "minPayerAmountSat", ) ) { - prepareReceiveResponse.getDouble("zeroAmountMinPayerAmountSat").toULong() + prepareReceiveResponse.getDouble("minPayerAmountSat").toULong() } else { null } - val zeroAmountMaxPayerAmountSat = + val maxPayerAmountSat = if (hasNonNullKey( prepareReceiveResponse, - "zeroAmountMaxPayerAmountSat", + "maxPayerAmountSat", ) ) { - prepareReceiveResponse.getDouble("zeroAmountMaxPayerAmountSat").toULong() + prepareReceiveResponse.getDouble("maxPayerAmountSat").toULong() } else { null } - val zeroAmountServiceFeerate = + val serviceFeerate = if (hasNonNullKey( prepareReceiveResponse, - "zeroAmountServiceFeerate", + "serviceFeerate", ) ) { - prepareReceiveResponse.getDouble("zeroAmountServiceFeerate") + prepareReceiveResponse.getDouble("serviceFeerate") } else { null } - return PrepareReceiveResponse( - paymentMethod, - feesSat, - payerAmountSat, - zeroAmountMinPayerAmountSat, - zeroAmountMaxPayerAmountSat, - zeroAmountServiceFeerate, - ) + return PrepareReceiveResponse(paymentMethod, feesSat, payerAmountSat, minPayerAmountSat, maxPayerAmountSat, serviceFeerate) } fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap = @@ -1742,9 +1735,9 @@ fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap = "paymentMethod" to prepareReceiveResponse.paymentMethod.name.lowercase(), "feesSat" to prepareReceiveResponse.feesSat, "payerAmountSat" to prepareReceiveResponse.payerAmountSat, - "zeroAmountMinPayerAmountSat" to prepareReceiveResponse.zeroAmountMinPayerAmountSat, - "zeroAmountMaxPayerAmountSat" to prepareReceiveResponse.zeroAmountMaxPayerAmountSat, - "zeroAmountServiceFeerate" to prepareReceiveResponse.zeroAmountServiceFeerate, + "minPayerAmountSat" to prepareReceiveResponse.minPayerAmountSat, + "maxPayerAmountSat" to prepareReceiveResponse.maxPayerAmountSat, + "serviceFeerate" to prepareReceiveResponse.serviceFeerate, ) fun asPrepareReceiveResponseList(arr: ReadableArray): List { diff --git a/packages/react-native/ios/BreezSDKLiquidMapper.swift b/packages/react-native/ios/BreezSDKLiquidMapper.swift index 1f583c1bf..758da07fa 100644 --- a/packages/react-native/ios/BreezSDKLiquidMapper.swift +++ b/packages/react-native/ios/BreezSDKLiquidMapper.swift @@ -1979,29 +1979,29 @@ enum BreezSDKLiquidMapper { } payerAmountSat = payerAmountSatTmp } - var zeroAmountMinPayerAmountSat: UInt64? - if hasNonNilKey(data: prepareReceiveResponse, key: "zeroAmountMinPayerAmountSat") { - guard let zeroAmountMinPayerAmountSatTmp = prepareReceiveResponse["zeroAmountMinPayerAmountSat"] as? UInt64 else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "zeroAmountMinPayerAmountSat")) + var minPayerAmountSat: UInt64? + if hasNonNilKey(data: prepareReceiveResponse, key: "minPayerAmountSat") { + guard let minPayerAmountSatTmp = prepareReceiveResponse["minPayerAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "minPayerAmountSat")) } - zeroAmountMinPayerAmountSat = zeroAmountMinPayerAmountSatTmp + minPayerAmountSat = minPayerAmountSatTmp } - var zeroAmountMaxPayerAmountSat: UInt64? - if hasNonNilKey(data: prepareReceiveResponse, key: "zeroAmountMaxPayerAmountSat") { - guard let zeroAmountMaxPayerAmountSatTmp = prepareReceiveResponse["zeroAmountMaxPayerAmountSat"] as? UInt64 else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "zeroAmountMaxPayerAmountSat")) + var maxPayerAmountSat: UInt64? + if hasNonNilKey(data: prepareReceiveResponse, key: "maxPayerAmountSat") { + guard let maxPayerAmountSatTmp = prepareReceiveResponse["maxPayerAmountSat"] as? UInt64 else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "maxPayerAmountSat")) } - zeroAmountMaxPayerAmountSat = zeroAmountMaxPayerAmountSatTmp + maxPayerAmountSat = maxPayerAmountSatTmp } - var zeroAmountServiceFeerate: Double? - if hasNonNilKey(data: prepareReceiveResponse, key: "zeroAmountServiceFeerate") { - guard let zeroAmountServiceFeerateTmp = prepareReceiveResponse["zeroAmountServiceFeerate"] as? Double else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "zeroAmountServiceFeerate")) + var serviceFeerate: Double? + if hasNonNilKey(data: prepareReceiveResponse, key: "serviceFeerate") { + guard let serviceFeerateTmp = prepareReceiveResponse["serviceFeerate"] as? Double else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "serviceFeerate")) } - zeroAmountServiceFeerate = zeroAmountServiceFeerateTmp + serviceFeerate = serviceFeerateTmp } - return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, zeroAmountMinPayerAmountSat: zeroAmountMinPayerAmountSat, zeroAmountMaxPayerAmountSat: zeroAmountMaxPayerAmountSat, zeroAmountServiceFeerate: zeroAmountServiceFeerate) + return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, minPayerAmountSat: minPayerAmountSat, maxPayerAmountSat: maxPayerAmountSat, serviceFeerate: serviceFeerate) } static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [String: Any?] { @@ -2009,9 +2009,9 @@ enum BreezSDKLiquidMapper { "paymentMethod": valueOf(paymentMethod: prepareReceiveResponse.paymentMethod), "feesSat": prepareReceiveResponse.feesSat, "payerAmountSat": prepareReceiveResponse.payerAmountSat == nil ? nil : prepareReceiveResponse.payerAmountSat, - "zeroAmountMinPayerAmountSat": prepareReceiveResponse.zeroAmountMinPayerAmountSat == nil ? nil : prepareReceiveResponse.zeroAmountMinPayerAmountSat, - "zeroAmountMaxPayerAmountSat": prepareReceiveResponse.zeroAmountMaxPayerAmountSat == nil ? nil : prepareReceiveResponse.zeroAmountMaxPayerAmountSat, - "zeroAmountServiceFeerate": prepareReceiveResponse.zeroAmountServiceFeerate == nil ? nil : prepareReceiveResponse.zeroAmountServiceFeerate, + "minPayerAmountSat": prepareReceiveResponse.minPayerAmountSat == nil ? nil : prepareReceiveResponse.minPayerAmountSat, + "maxPayerAmountSat": prepareReceiveResponse.maxPayerAmountSat == nil ? nil : prepareReceiveResponse.maxPayerAmountSat, + "serviceFeerate": prepareReceiveResponse.serviceFeerate == nil ? nil : prepareReceiveResponse.serviceFeerate, ] } diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 1d49fc97f..a121f9221 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -301,9 +301,9 @@ export interface PrepareReceiveResponse { paymentMethod: PaymentMethod feesSat: number payerAmountSat?: number - zeroAmountMinPayerAmountSat?: number - zeroAmountMaxPayerAmountSat?: number - zeroAmountServiceFeerate?: number + minPayerAmountSat?: number + maxPayerAmountSat?: number + serviceFeerate?: number } export interface PrepareRefundRequest { From ab921c4df1b44aae6f7c2f5604fd03fca02abc59 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:17:06 +0100 Subject: [PATCH 11/22] Fix cargo clippy --- cli/src/commands.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 1863ee037..cc03ddcd5 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -275,9 +275,9 @@ pub(crate) async fn handle_command( let confirmation_msg = match payer_amount_sat { Some(_) => format!("Fees: {fees} sat. Are the fees acceptable? (y/N)"), None => { - let min = prepare_response.zero_amount_min_payer_amount_sat.unwrap(); - let max = prepare_response.zero_amount_max_payer_amount_sat.unwrap(); - let service_feerate = prepare_response.zero_amount_service_feerate.unwrap(); + let min = prepare_response.min_payer_amount_sat.unwrap(); + let max = prepare_response.max_payer_amount_sat.unwrap(); + let service_feerate = prepare_response.service_feerate.unwrap(); format!( "Fees: {fees} sat + {service_feerate}% of the sent amount. \ Sender should send between {min} sat and {max} sat. \ From 5a44cafb8be712244783f41c62b4318d1ba4937a Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:26:38 +0100 Subject: [PATCH 12/22] Improve error handling when accepting quote --- lib/core/src/chain_swap.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index 020d92110..7cba14075 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -440,7 +440,7 @@ impl ChainSwapHandler { let is_zero_amount = swap.payer_amount_sat == 0; if matches!(swap_state, ChainSwapStates::TransactionLockupFailed) && is_zero_amount { - if let Err(e) = self + let accept_quote_res = self .swapper .get_zero_amount_chain_swap_quote(&swap.id) .map(|quote| quote.to_sat()) @@ -450,13 +450,15 @@ impl ChainSwapHandler { self.persister.update_swap_payer_amount(&swap.id, quote)?; self.swapper .accept_zero_amount_chain_swap_quote(&swap.id, quote) - }) - { - warn!("Failed to accept the quote for swap {}: {e:?}", &swap.id); + }); + match accept_quote_res { + Ok(_) => { + // We successfully accepted the quote, the swap should continue as normal + return Ok(()); // Break from TxLockupFailed branch + } + // In case of error, we continue and mark it as refundable + Err(e) => error!("Failed to accept the quote for swap {}: {e:?}", &swap.id), } - - // We successfully accepted the quote, the swap should continue as normal - return Ok(()); // Break from TxLockupFailed branch } match swap.refund_tx_id.clone() { From c597ced3cde7ca833c26240ae9dcc1027fe731cb Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:51:21 +0100 Subject: [PATCH 13/22] Update zero-amount payer/receiver values in DB --- lib/core/src/chain_swap.rs | 3 ++- lib/core/src/persist/chain.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index 7cba14075..aa6f5614d 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -447,7 +447,8 @@ impl ChainSwapHandler { .and_then(|quote| { info!("Got quote of {quote} sat for swap {}", &swap.id); - self.persister.update_swap_payer_amount(&swap.id, quote)?; + self.persister + .update_zero_amount_swap_values(&swap.id, quote)?; self.swapper .accept_zero_amount_chain_swap_quote(&swap.id, quote) }); diff --git a/lib/core/src/persist/chain.rs b/lib/core/src/persist/chain.rs index 8e966305f..edf5c5d5e 100644 --- a/lib/core/src/persist/chain.rs +++ b/lib/core/src/persist/chain.rs @@ -265,10 +265,10 @@ impl Persister { /// Used for Zero-amount Receive Chain swaps, when we fetched the quote and we know how much /// the sender locked up - pub(crate) fn update_swap_payer_amount( + pub(crate) fn update_zero_amount_swap_values( &self, swap_id: &str, - payer_amount_sat: u64, + server_lockup_amount_sat: u64, ) -> Result<(), PaymentError> { let swap = self .fetch_chain_swap_by_id(swap_id)? @@ -279,22 +279,27 @@ impl Persister { matches!(swap.direction, Direction::Incoming), PaymentError::Generic { err: format!( - "Can only update payer_amount_sat for incoming chain swaps. Swap ID: {swap_id}" + "Only an incoming chain swap can be a zero-amount swap. Swap ID: {swap_id}" ) } ); - log::info!("Updating chain swap {swap_id}: payer_amount_sat = {payer_amount_sat}"); + let payer_amount_sat = server_lockup_amount_sat; + let receiver_amount_sat = server_lockup_amount_sat - swap.claim_fees_sat; + + log::info!("Updating chain swap {swap_id}: payer_amount_sat = {payer_amount_sat}, receiver_amount_sat = {receiver_amount_sat}"); let con: Connection = self.get_connection()?; con.execute( "UPDATE chain_swaps SET - payer_amount_sat = :payer_amount_sat + payer_amount_sat = :payer_amount_sat, + receiver_amount_sat = :receiver_amount_sat WHERE id = :id", named_params! { ":id": swap_id, ":payer_amount_sat": payer_amount_sat, + ":receiver_amount_sat": receiver_amount_sat, }, )?; Ok(()) From 98864c70a6055c74d5b60142548de8a9584b7b93 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:49:32 +0100 Subject: [PATCH 14/22] Set min/max/feerate in prepare response for both LN and Chain swaps --- lib/core/src/sdk.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index cb3c514eb..8753fb373 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -1650,6 +1650,10 @@ impl LiquidSdk { .within(payer_amount_sat) .map_err(|_| PaymentError::AmountOutOfRange)?; + min_payer_amount_sat = Some(reverse_pair.limits.minimal); + max_payer_amount_sat = Some(reverse_pair.limits.maximal); + service_feerate = Some(reverse_pair.fees.percentage); + debug!( "Preparing Lightning Receive Swap with: payer_amount_sat {payer_amount_sat} sat, fees_sat {fees_sat} sat" ); @@ -1664,11 +1668,9 @@ impl LiquidSdk { .map(|user_lockup_amount_sat| pair.fees.boltz(user_lockup_amount_sat)) .unwrap_or_default(); - if payer_amount_sat.is_none() { - min_payer_amount_sat = Some(pair.limits.minimal); - max_payer_amount_sat = Some(pair.limits.maximal); - service_feerate = Some(pair.fees.percentage); - } + min_payer_amount_sat = Some(pair.limits.minimal); + max_payer_amount_sat = Some(pair.limits.maximal); + service_feerate = Some(pair.fees.percentage); fees_sat = service_fees_sat + claim_fees_sat + server_fees_sat; debug!("Preparing Chain Receive Swap with: payer_amount_sat {payer_amount_sat:?}, fees_sat {fees_sat}"); From 2bfd81c26e14383a3275c2c177ab584828cdfc9e Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:31:08 +0100 Subject: [PATCH 15/22] Validate fees amountless swaps before accepting quote --- lib/core/src/chain_swap.rs | 90 ++++++++++++++++++++++++++++++----- lib/core/src/model.rs | 8 ++++ lib/core/src/persist/chain.rs | 20 +------- 3 files changed, 87 insertions(+), 31 deletions(-) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index aa6f5614d..5ee2af475 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -440,19 +440,7 @@ impl ChainSwapHandler { let is_zero_amount = swap.payer_amount_sat == 0; if matches!(swap_state, ChainSwapStates::TransactionLockupFailed) && is_zero_amount { - let accept_quote_res = self - .swapper - .get_zero_amount_chain_swap_quote(&swap.id) - .map(|quote| quote.to_sat()) - .and_then(|quote| { - info!("Got quote of {quote} sat for swap {}", &swap.id); - - self.persister - .update_zero_amount_swap_values(&swap.id, quote)?; - self.swapper - .accept_zero_amount_chain_swap_quote(&swap.id, quote) - }); - match accept_quote_res { + match self.handle_amountless_update(swap).await { Ok(_) => { // We successfully accepted the quote, the swap should continue as normal return Ok(()); // Break from TxLockupFailed branch @@ -492,6 +480,82 @@ impl ChainSwapHandler { } } + async fn handle_amountless_update(&self, swap: &ChainSwap) -> Result<(), PaymentError> { + let quote = self + .swapper + .get_zero_amount_chain_swap_quote(&swap.id) + .map(|quote| quote.to_sat())?; + info!("Got quote of {quote} sat for swap {}", &swap.id); + + self.validate_amountless_swap(swap, quote).await?; + + self.persister.update_zero_amount_swap_values( + &swap.id, + swap.payer_amount_sat, + swap.receiver_amount_sat, + )?; + self.swapper + .accept_zero_amount_chain_swap_quote(&swap.id, quote)?; + + Ok(()) + } + + async fn validate_amountless_swap( + &self, + swap: &ChainSwap, + quote_server_lockup_amount_sat: u64, + ) -> Result<(), PaymentError> { + debug!("Validating {swap:?}"); + + ensure_sdk!( + matches!(swap.direction, Direction::Incoming), + PaymentError::generic(&format!( + "Only an incoming chain swap can be a zero-amount swap. Swap ID: {}", + &swap.id + )) + ); + + let script_pubkey = swap.get_receive_lockup_swap_script_pubkey(self.config.network)?; + let script_balance = self + .bitcoin_chain_service + .lock() + .await + .script_get_balance(script_pubkey.as_script())?; + debug!("Found lockup balance {script_balance:?}"); + let user_lockup_amount_sat = match script_balance.confirmed > 0 { + true => script_balance.confirmed, + false => match script_balance.unconfirmed > 0 { + true => script_balance.unconfirmed.unsigned_abs(), + false => 0, + }, + }; + ensure_sdk!( + user_lockup_amount_sat > 0, + PaymentError::generic("Lockup address has no confirmed balance") + ); + + let pair = swap.get_boltz_pair()?; + let swapper_service_feerate = pair.fees.percentage; + let swapper_server_fees_sat = pair.fees.server(); + let service_fees_sat = + ((swapper_service_feerate / 100.0) * user_lockup_amount_sat as f64).ceil() as u64; + let fees_sat = swapper_server_fees_sat + service_fees_sat; + ensure_sdk!( + user_lockup_amount_sat > fees_sat, + PaymentError::generic(&format!("Invalid quote: fees ({fees_sat} sat) are higher than user lockup ({user_lockup_amount_sat} sat)")) + ); + + let expected_server_lockup_amount_sat = user_lockup_amount_sat - fees_sat; + debug!("user_lockup_amount_sat = {}, service_fees_sat = {}, server_fees_sat = {}, expected_server_lockup_amount_sat = {}, quote_server_lockup_amount_sat = {}", + user_lockup_amount_sat, service_fees_sat, swapper_server_fees_sat, expected_server_lockup_amount_sat, quote_server_lockup_amount_sat); + ensure_sdk!( + expected_server_lockup_amount_sat == quote_server_lockup_amount_sat, + PaymentError::generic(&format!("Invalid quote: expected {expected_server_lockup_amount_sat} sat, got {quote_server_lockup_amount_sat} sat")) + ); + + Ok(()) + } + async fn on_new_outgoing_status(&self, swap: &ChainSwap, update: &boltz::Update) -> Result<()> { let id = &update.id; let status = &update.status; diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index 351fe6134..697285edb 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use anyhow::{anyhow, Result}; +use boltz_client::boltz::ChainPair; use boltz_client::{ bitcoin::ScriptBuf, network::Chain, @@ -686,6 +687,13 @@ impl ChainSwap { }) } + pub(crate) fn get_boltz_pair(&self) -> Result { + let pair: ChainPair = serde_json::from_str(&self.pair_fees_json) + .map_err(|e| anyhow!("Failed to deserialize ChainPair: {e:?}"))?; + + Ok(pair) + } + pub(crate) fn get_claim_swap_script(&self) -> SdkResult { let chain_swap_details = self.get_boltz_create_response()?.claim_details; let our_pubkey = self.get_claim_keypair()?.public_key(); diff --git a/lib/core/src/persist/chain.rs b/lib/core/src/persist/chain.rs index 12a6895c7..4ec2a5fe3 100644 --- a/lib/core/src/persist/chain.rs +++ b/lib/core/src/persist/chain.rs @@ -272,25 +272,9 @@ impl Persister { pub(crate) fn update_zero_amount_swap_values( &self, swap_id: &str, - server_lockup_amount_sat: u64, + payer_amount_sat: u64, + receiver_amount_sat: u64, ) -> Result<(), PaymentError> { - let swap = self - .fetch_chain_swap_by_id(swap_id)? - .ok_or_else(|| PaymentError::Generic { - err: format!("Cannot update non-existent chain swap with ID: {swap_id}"), - })?; - ensure_sdk!( - matches!(swap.direction, Direction::Incoming), - PaymentError::Generic { - err: format!( - "Only an incoming chain swap can be a zero-amount swap. Swap ID: {swap_id}" - ) - } - ); - - let payer_amount_sat = server_lockup_amount_sat; - let receiver_amount_sat = server_lockup_amount_sat - swap.claim_fees_sat; - log::info!("Updating chain swap {swap_id}: payer_amount_sat = {payer_amount_sat}, receiver_amount_sat = {receiver_amount_sat}"); let con: Connection = self.get_connection()?; con.execute( From 842df7a708926c5971cdfcb28b04cd793ce57a2e Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:44:54 +0100 Subject: [PATCH 16/22] Fix CLI fee arg handling --- cli/src/commands.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index cc03ddcd5..ba8d6cf20 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -275,12 +275,12 @@ pub(crate) async fn handle_command( let confirmation_msg = match payer_amount_sat { Some(_) => format!("Fees: {fees} sat. Are the fees acceptable? (y/N)"), None => { - let min = prepare_response.min_payer_amount_sat.unwrap(); - let max = prepare_response.max_payer_amount_sat.unwrap(); - let service_feerate = prepare_response.service_feerate.unwrap(); + let min = prepare_response.min_payer_amount_sat; + let max = prepare_response.max_payer_amount_sat; + let service_feerate = prepare_response.service_feerate; format!( - "Fees: {fees} sat + {service_feerate}% of the sent amount. \ - Sender should send between {min} sat and {max} sat. \ + "Fees: {fees} sat + {service_feerate:?}% of the sent amount. \ + Sender should send between {min:?} sat and {max:?} sat. \ Are the fees acceptable? (y/N)" ) } From 183c828abc4be51f5ccd687d62c9b4f4d1ca1bde Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:55:55 +0100 Subject: [PATCH 17/22] Calculate, persist payer/receiver amounts when quote is accepted --- lib/core/src/chain_swap.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index 5ee2af475..c8c355d9e 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -487,20 +487,13 @@ impl ChainSwapHandler { .map(|quote| quote.to_sat())?; info!("Got quote of {quote} sat for swap {}", &swap.id); - self.validate_amountless_swap(swap, quote).await?; - - self.persister.update_zero_amount_swap_values( - &swap.id, - swap.payer_amount_sat, - swap.receiver_amount_sat, - )?; + self.validate_and_update_amountless_swap(swap, quote) + .await?; self.swapper - .accept_zero_amount_chain_swap_quote(&swap.id, quote)?; - - Ok(()) + .accept_zero_amount_chain_swap_quote(&swap.id, quote) } - async fn validate_amountless_swap( + async fn validate_and_update_amountless_swap( &self, swap: &ChainSwap, quote_server_lockup_amount_sat: u64, @@ -553,6 +546,13 @@ impl ChainSwapHandler { PaymentError::generic(&format!("Invalid quote: expected {expected_server_lockup_amount_sat} sat, got {quote_server_lockup_amount_sat} sat")) ); + let receiver_amount_sat = quote_server_lockup_amount_sat - swap.claim_fees_sat; + self.persister.update_zero_amount_swap_values( + &swap.id, + user_lockup_amount_sat, + receiver_amount_sat, + )?; + Ok(()) } From 618879d551b385f5d70b331725e217af196201c7 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:01:15 +0100 Subject: [PATCH 18/22] Update log comment --- lib/core/src/chain_swap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index c8c355d9e..96050d4de 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -524,7 +524,7 @@ impl ChainSwapHandler { }; ensure_sdk!( user_lockup_amount_sat > 0, - PaymentError::generic("Lockup address has no confirmed balance") + PaymentError::generic("Lockup address has no confirmed or unconfirmed balance") ); let pair = swap.get_boltz_pair()?; From e8ac979871dae459ff4cf0997f75cf916cf14322 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:33:01 +0100 Subject: [PATCH 19/22] Bump boltz-rust to latest trunk --- cli/Cargo.lock | 4 ++-- lib/Cargo.lock | 4 ++-- lib/core/Cargo.toml | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 8b5857bbd..27600a26f 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -609,7 +609,7 @@ dependencies = [ [[package]] name = "boltz-client" version = "0.1.3" -source = "git+https://github.com/ok300/boltz-rust?branch=ok300-support-quote#c718e53edf45b4746e820e8b503ddd73fcc57479" +source = "git+https://github.com/SatoshiPortal/boltz-rust?branch=trunk#68ff15b0f80abfa54d8dca4c11c8c2794e4b6921" dependencies = [ "bip39", "bitcoin 0.31.2", diff --git a/lib/Cargo.lock b/lib/Cargo.lock index e6a2106e2..cca4156df 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -723,7 +723,7 @@ dependencies = [ [[package]] name = "boltz-client" version = "0.1.3" -source = "git+https://github.com/ok300/boltz-rust?branch=ok300-support-quote#c718e53edf45b4746e820e8b503ddd73fcc57479" +source = "git+https://github.com/SatoshiPortal/boltz-rust?branch=trunk#68ff15b0f80abfa54d8dca4c11c8c2794e4b6921" dependencies = [ "bip39", "bitcoin 0.31.2", diff --git a/lib/core/Cargo.toml b/lib/core/Cargo.toml index 3a11691b6..7f0e20d9f 100644 --- a/lib/core/Cargo.toml +++ b/lib/core/Cargo.toml @@ -14,8 +14,7 @@ frb = ["dep:flutter_rust_bridge"] [dependencies] anyhow = { workspace = true } bip39 = "2.0.0" -#boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust", branch = "trunk" } -boltz-client = { git = "https://github.com/ok300/boltz-rust", branch = "ok300-support-quote" } +boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust", branch = "trunk" } chrono = "0.4" env_logger = "0.11" flutter_rust_bridge = { version = "=2.4.0", features = [ From addde46d2b65dea85420e467fd61a6f1d4271a57 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:44:43 +0100 Subject: [PATCH 20/22] PrepareReceiveResponse: rename service_feerate to swapper_feerate --- .../breez_sdk_liquid/include/breez_sdk_liquid.h | 2 +- lib/bindings/src/breez_sdk_liquid.udl | 2 +- lib/core/src/frb_generated.rs | 14 +++++++------- lib/core/src/model.rs | 2 +- lib/core/src/sdk.rs | 8 ++++---- packages/dart/lib/src/frb_generated.dart | 8 ++++---- packages/dart/lib/src/frb_generated.io.dart | 4 ++-- packages/dart/lib/src/model.dart | 8 ++++---- .../flutter_breez_liquid_bindings_generated.dart | 2 +- .../com/breezsdkliquid/BreezSDKLiquidMapper.kt | 10 +++++----- .../react-native/ios/BreezSDKLiquidMapper.swift | 14 +++++++------- packages/react-native/src/index.ts | 2 +- 12 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h index dd4d80397..c22c6c189 100644 --- a/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h +++ b/lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h @@ -369,7 +369,7 @@ typedef struct wire_cst_prepare_receive_response { uint64_t fees_sat; uint64_t *min_payer_amount_sat; uint64_t *max_payer_amount_sat; - double *service_feerate; + double *swapper_feerate; } wire_cst_prepare_receive_response; typedef struct wire_cst_receive_payment_request { diff --git a/lib/bindings/src/breez_sdk_liquid.udl b/lib/bindings/src/breez_sdk_liquid.udl index 81388bd41..d1975ceb5 100644 --- a/lib/bindings/src/breez_sdk_liquid.udl +++ b/lib/bindings/src/breez_sdk_liquid.udl @@ -436,7 +436,7 @@ dictionary PrepareReceiveResponse { u64? payer_amount_sat; u64? min_payer_amount_sat; u64? max_payer_amount_sat; - f64? service_feerate; + f64? swapper_feerate; }; dictionary ReceivePaymentRequest { diff --git a/lib/core/src/frb_generated.rs b/lib/core/src/frb_generated.rs index aba479989..289c91740 100644 --- a/lib/core/src/frb_generated.rs +++ b/lib/core/src/frb_generated.rs @@ -3760,14 +3760,14 @@ impl SseDecode for crate::model::PrepareReceiveResponse { let mut var_feesSat = ::sse_decode(deserializer); let mut var_minPayerAmountSat = >::sse_decode(deserializer); let mut var_maxPayerAmountSat = >::sse_decode(deserializer); - let mut var_serviceFeerate = >::sse_decode(deserializer); + let mut var_swapperFeerate = >::sse_decode(deserializer); return crate::model::PrepareReceiveResponse { payment_method: var_paymentMethod, payer_amount_sat: var_payerAmountSat, fees_sat: var_feesSat, min_payer_amount_sat: var_minPayerAmountSat, max_payer_amount_sat: var_maxPayerAmountSat, - service_feerate: var_serviceFeerate, + swapper_feerate: var_swapperFeerate, }; } } @@ -5826,7 +5826,7 @@ impl flutter_rust_bridge::IntoDart for crate::model::PrepareReceiveResponse { self.fees_sat.into_into_dart().into_dart(), self.min_payer_amount_sat.into_into_dart().into_dart(), self.max_payer_amount_sat.into_into_dart().into_dart(), - self.service_feerate.into_into_dart().into_dart(), + self.swapper_feerate.into_into_dart().into_dart(), ] .into_dart() } @@ -7712,7 +7712,7 @@ impl SseEncode for crate::model::PrepareReceiveResponse { ::sse_encode(self.fees_sat, serializer); >::sse_encode(self.min_payer_amount_sat, serializer); >::sse_encode(self.max_payer_amount_sat, serializer); - >::sse_encode(self.service_feerate, serializer); + >::sse_encode(self.swapper_feerate, serializer); } } @@ -9595,7 +9595,7 @@ mod io { fees_sat: self.fees_sat.cst_decode(), min_payer_amount_sat: self.min_payer_amount_sat.cst_decode(), max_payer_amount_sat: self.max_payer_amount_sat.cst_decode(), - service_feerate: self.service_feerate.cst_decode(), + swapper_feerate: self.swapper_feerate.cst_decode(), } } } @@ -10746,7 +10746,7 @@ mod io { fees_sat: Default::default(), min_payer_amount_sat: core::ptr::null_mut(), max_payer_amount_sat: core::ptr::null_mut(), - service_feerate: core::ptr::null_mut(), + swapper_feerate: core::ptr::null_mut(), } } } @@ -12892,7 +12892,7 @@ mod io { fees_sat: u64, min_payer_amount_sat: *mut u64, max_payer_amount_sat: *mut u64, - service_feerate: *mut f64, + swapper_feerate: *mut f64, } #[repr(C)] #[derive(Clone, Copy)] diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index 697285edb..e25547b82 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -318,7 +318,7 @@ pub struct PrepareReceiveResponse { /// The percentage of the sent amount that will count towards the service fee. /// /// When the method is [PaymentMethod::LiquidAddress], this is empty. - pub service_feerate: Option, + pub swapper_feerate: Option, } /// An argument when calling [crate::sdk::LiquidSdk::receive_payment]. diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index 9585eb55e..d6ad914ce 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -1635,7 +1635,7 @@ impl LiquidSdk { let mut min_payer_amount_sat = None; let mut max_payer_amount_sat = None; - let mut service_feerate = None; + let mut swapper_feerate = None; let fees_sat; match req.payment_method { PaymentMethod::Lightning => { @@ -1658,7 +1658,7 @@ impl LiquidSdk { min_payer_amount_sat = Some(reverse_pair.limits.minimal); max_payer_amount_sat = Some(reverse_pair.limits.maximal); - service_feerate = Some(reverse_pair.fees.percentage); + swapper_feerate = Some(reverse_pair.fees.percentage); debug!( "Preparing Lightning Receive Swap with: payer_amount_sat {payer_amount_sat} sat, fees_sat {fees_sat} sat" @@ -1676,7 +1676,7 @@ impl LiquidSdk { min_payer_amount_sat = Some(pair.limits.minimal); max_payer_amount_sat = Some(pair.limits.maximal); - service_feerate = Some(pair.fees.percentage); + swapper_feerate = Some(pair.fees.percentage); fees_sat = service_fees_sat + claim_fees_sat + server_fees_sat; debug!("Preparing Chain Receive Swap with: payer_amount_sat {payer_amount_sat:?}, fees_sat {fees_sat}"); @@ -1694,7 +1694,7 @@ impl LiquidSdk { payment_method: req.payment_method.clone(), min_payer_amount_sat, max_payer_amount_sat, - service_feerate, + swapper_feerate, }) } diff --git a/packages/dart/lib/src/frb_generated.dart b/packages/dart/lib/src/frb_generated.dart index 7cb921267..97887a9b2 100644 --- a/packages/dart/lib/src/frb_generated.dart +++ b/packages/dart/lib/src/frb_generated.dart @@ -2710,7 +2710,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { feesSat: dco_decode_u_64(arr[2]), minPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[3]), maxPayerAmountSat: dco_decode_opt_box_autoadd_u_64(arr[4]), - serviceFeerate: dco_decode_opt_box_autoadd_f_64(arr[5]), + swapperFeerate: dco_decode_opt_box_autoadd_f_64(arr[5]), ); } @@ -4698,14 +4698,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_feesSat = sse_decode_u_64(deserializer); var var_minPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); var var_maxPayerAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); - var var_serviceFeerate = sse_decode_opt_box_autoadd_f_64(deserializer); + var var_swapperFeerate = sse_decode_opt_box_autoadd_f_64(deserializer); return PrepareReceiveResponse( paymentMethod: var_paymentMethod, payerAmountSat: var_payerAmountSat, feesSat: var_feesSat, minPayerAmountSat: var_minPayerAmountSat, maxPayerAmountSat: var_maxPayerAmountSat, - serviceFeerate: var_serviceFeerate); + swapperFeerate: var_swapperFeerate); } @protected @@ -6552,7 +6552,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_u_64(self.feesSat, serializer); sse_encode_opt_box_autoadd_u_64(self.minPayerAmountSat, serializer); sse_encode_opt_box_autoadd_u_64(self.maxPayerAmountSat, serializer); - sse_encode_opt_box_autoadd_f_64(self.serviceFeerate, serializer); + sse_encode_opt_box_autoadd_f_64(self.swapperFeerate, serializer); } @protected diff --git a/packages/dart/lib/src/frb_generated.io.dart b/packages/dart/lib/src/frb_generated.io.dart index f2a498d7f..1b5e6b0b0 100644 --- a/packages/dart/lib/src/frb_generated.io.dart +++ b/packages/dart/lib/src/frb_generated.io.dart @@ -2921,7 +2921,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { wireObj.fees_sat = cst_encode_u_64(apiObj.feesSat); wireObj.min_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.minPayerAmountSat); wireObj.max_payer_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.maxPayerAmountSat); - wireObj.service_feerate = cst_encode_opt_box_autoadd_f_64(apiObj.serviceFeerate); + wireObj.swapper_feerate = cst_encode_opt_box_autoadd_f_64(apiObj.swapperFeerate); } @protected @@ -5796,7 +5796,7 @@ final class wire_cst_prepare_receive_response extends ffi.Struct { external ffi.Pointer max_payer_amount_sat; - external ffi.Pointer service_feerate; + external ffi.Pointer swapper_feerate; } final class wire_cst_receive_payment_request extends ffi.Struct { diff --git a/packages/dart/lib/src/model.dart b/packages/dart/lib/src/model.dart index 5c629ac35..ca943cd51 100644 --- a/packages/dart/lib/src/model.dart +++ b/packages/dart/lib/src/model.dart @@ -951,7 +951,7 @@ class PrepareReceiveResponse { /// The percentage of the sent amount that will count towards the service fee. /// /// When the method is [PaymentMethod::LiquidAddress], this is empty. - final double? serviceFeerate; + final double? swapperFeerate; const PrepareReceiveResponse({ required this.paymentMethod, @@ -959,7 +959,7 @@ class PrepareReceiveResponse { required this.feesSat, this.minPayerAmountSat, this.maxPayerAmountSat, - this.serviceFeerate, + this.swapperFeerate, }); @override @@ -969,7 +969,7 @@ class PrepareReceiveResponse { feesSat.hashCode ^ minPayerAmountSat.hashCode ^ maxPayerAmountSat.hashCode ^ - serviceFeerate.hashCode; + swapperFeerate.hashCode; @override bool operator ==(Object other) => @@ -981,7 +981,7 @@ class PrepareReceiveResponse { feesSat == other.feesSat && minPayerAmountSat == other.minPayerAmountSat && maxPayerAmountSat == other.maxPayerAmountSat && - serviceFeerate == other.serviceFeerate; + swapperFeerate == other.swapperFeerate; } /// An argument when calling [crate::sdk::LiquidSdk::prepare_refund]. diff --git a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart index 91fa3f4ec..7580437b8 100644 --- a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart +++ b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart @@ -4346,7 +4346,7 @@ final class wire_cst_prepare_receive_response extends ffi.Struct { external ffi.Pointer max_payer_amount_sat; - external ffi.Pointer service_feerate; + external ffi.Pointer swapper_feerate; } final class wire_cst_receive_payment_request extends ffi.Struct { diff --git a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt index a8de1060e..2959f6f6c 100644 --- a/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt +++ b/packages/react-native/android/src/main/java/com/breezsdkliquid/BreezSDKLiquidMapper.kt @@ -1719,17 +1719,17 @@ fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiv } else { null } - val serviceFeerate = + val swapperFeerate = if (hasNonNullKey( prepareReceiveResponse, - "serviceFeerate", + "swapperFeerate", ) ) { - prepareReceiveResponse.getDouble("serviceFeerate") + prepareReceiveResponse.getDouble("swapperFeerate") } else { null } - return PrepareReceiveResponse(paymentMethod, feesSat, payerAmountSat, minPayerAmountSat, maxPayerAmountSat, serviceFeerate) + return PrepareReceiveResponse(paymentMethod, feesSat, payerAmountSat, minPayerAmountSat, maxPayerAmountSat, swapperFeerate) } fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap = @@ -1739,7 +1739,7 @@ fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap = "payerAmountSat" to prepareReceiveResponse.payerAmountSat, "minPayerAmountSat" to prepareReceiveResponse.minPayerAmountSat, "maxPayerAmountSat" to prepareReceiveResponse.maxPayerAmountSat, - "serviceFeerate" to prepareReceiveResponse.serviceFeerate, + "swapperFeerate" to prepareReceiveResponse.swapperFeerate, ) fun asPrepareReceiveResponseList(arr: ReadableArray): List { diff --git a/packages/react-native/ios/BreezSDKLiquidMapper.swift b/packages/react-native/ios/BreezSDKLiquidMapper.swift index 886924091..12b0419a8 100644 --- a/packages/react-native/ios/BreezSDKLiquidMapper.swift +++ b/packages/react-native/ios/BreezSDKLiquidMapper.swift @@ -2001,15 +2001,15 @@ enum BreezSDKLiquidMapper { } maxPayerAmountSat = maxPayerAmountSatTmp } - var serviceFeerate: Double? - if hasNonNilKey(data: prepareReceiveResponse, key: "serviceFeerate") { - guard let serviceFeerateTmp = prepareReceiveResponse["serviceFeerate"] as? Double else { - throw SdkError.Generic(message: errUnexpectedValue(fieldName: "serviceFeerate")) + var swapperFeerate: Double? + if hasNonNilKey(data: prepareReceiveResponse, key: "swapperFeerate") { + guard let swapperFeerateTmp = prepareReceiveResponse["swapperFeerate"] as? Double else { + throw SdkError.Generic(message: errUnexpectedValue(fieldName: "swapperFeerate")) } - serviceFeerate = serviceFeerateTmp + swapperFeerate = swapperFeerateTmp } - return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, minPayerAmountSat: minPayerAmountSat, maxPayerAmountSat: maxPayerAmountSat, serviceFeerate: serviceFeerate) + return PrepareReceiveResponse(paymentMethod: paymentMethod, feesSat: feesSat, payerAmountSat: payerAmountSat, minPayerAmountSat: minPayerAmountSat, maxPayerAmountSat: maxPayerAmountSat, swapperFeerate: swapperFeerate) } static func dictionaryOf(prepareReceiveResponse: PrepareReceiveResponse) -> [String: Any?] { @@ -2019,7 +2019,7 @@ enum BreezSDKLiquidMapper { "payerAmountSat": prepareReceiveResponse.payerAmountSat == nil ? nil : prepareReceiveResponse.payerAmountSat, "minPayerAmountSat": prepareReceiveResponse.minPayerAmountSat == nil ? nil : prepareReceiveResponse.minPayerAmountSat, "maxPayerAmountSat": prepareReceiveResponse.maxPayerAmountSat == nil ? nil : prepareReceiveResponse.maxPayerAmountSat, - "serviceFeerate": prepareReceiveResponse.serviceFeerate == nil ? nil : prepareReceiveResponse.serviceFeerate, + "swapperFeerate": prepareReceiveResponse.swapperFeerate == nil ? nil : prepareReceiveResponse.swapperFeerate, ] } diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 16e6e1690..23d8c8549 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -304,7 +304,7 @@ export interface PrepareReceiveResponse { payerAmountSat?: number minPayerAmountSat?: number maxPayerAmountSat?: number - serviceFeerate?: number + swapperFeerate?: number } export interface PrepareRefundRequest { From 4576ad9f898f2ef586ab256452360e3ae2fcfb98 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:47:57 +0100 Subject: [PATCH 21/22] Tweak amountless swap quote validation --- lib/core/src/chain_swap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index 96050d4de..0ca54b7a6 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -542,8 +542,8 @@ impl ChainSwapHandler { debug!("user_lockup_amount_sat = {}, service_fees_sat = {}, server_fees_sat = {}, expected_server_lockup_amount_sat = {}, quote_server_lockup_amount_sat = {}", user_lockup_amount_sat, service_fees_sat, swapper_server_fees_sat, expected_server_lockup_amount_sat, quote_server_lockup_amount_sat); ensure_sdk!( - expected_server_lockup_amount_sat == quote_server_lockup_amount_sat, - PaymentError::generic(&format!("Invalid quote: expected {expected_server_lockup_amount_sat} sat, got {quote_server_lockup_amount_sat} sat")) + expected_server_lockup_amount_sat <= quote_server_lockup_amount_sat, + PaymentError::generic(&format!("Invalid quote: expected at least {expected_server_lockup_amount_sat} sat, got {quote_server_lockup_amount_sat} sat")) ); let receiver_amount_sat = quote_server_lockup_amount_sat - swap.claim_fees_sat; From 542dec789e748cae6da29c4ea516086ef8565785 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:14:20 +0100 Subject: [PATCH 22/22] Add docs for swapper_feerate handling in total fee --- lib/core/src/model.rs | 9 +++++++++ packages/dart/lib/src/model.dart | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index e25547b82..afeb4a177 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -303,6 +303,15 @@ pub struct PrepareReceiveRequest { pub struct PrepareReceiveResponse { pub payment_method: PaymentMethod, pub payer_amount_sat: Option, + + /// Generally represents the total fees that would be paid to send or receive this payment. + /// + /// In case of Zero-Amount Receive Chain swaps, the swapper service fee (`swapper_feerate` times + /// the amount) is paid in addition to `fees_sat`. The swapper service feerate is already known + /// in the beginning, but the exact swapper service fee will only be known when the + /// `payer_amount_sat` is known. + /// + /// In all other types of swaps, the swapper service fee is included in `fees_sat`. pub fees_sat: u64, /// The minimum amount the payer can send for this swap to succeed. diff --git a/packages/dart/lib/src/model.dart b/packages/dart/lib/src/model.dart index ca943cd51..3f17f444e 100644 --- a/packages/dart/lib/src/model.dart +++ b/packages/dart/lib/src/model.dart @@ -936,6 +936,15 @@ class PrepareReceiveRequest { class PrepareReceiveResponse { final PaymentMethod paymentMethod; final BigInt? payerAmountSat; + + /// Generally represents the total fees that would be paid to send or receive this payment. + /// + /// In case of Zero-Amount Receive Chain swaps, the swapper service fee (`swapper_feerate` times + /// the amount) is paid in addition to `fees_sat`. The swapper service feerate is already known + /// in the beginning, but the exact swapper service fee will only be known when the + /// `payer_amount_sat` is known. + /// + /// In all other types of swaps, the swapper service fee is included in `fees_sat`. final BigInt feesSat; /// The minimum amount the payer can send for this swap to succeed.