From 5bd6b1ec25c814d6a0b40e43e7af981986aac261 Mon Sep 17 00:00:00 2001 From: Andrei <92177534+andrei-21@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:04:18 +0100 Subject: [PATCH 1/4] Bump uniffi to 0.28.0 (#1108) --- Cargo.lock | 61 +++++++++++++++++++++++------------------------------- Cargo.toml | 4 ++-- build.rs | 4 ++-- 3 files changed, 30 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15bcbded7..93c98bd97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1611,7 +1611,7 @@ checksum = "5e27ed0c2cf0c0cc52c6bcf3b45c907f433015e580879d14005386251842fb0a" dependencies = [ "graphql-introspection-query", "graphql-parser", - "heck", + "heck 0.4.1", "lazy_static", "proc-macro2", "quote", @@ -1691,6 +1691,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -2452,12 +2458,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d11de466f4a3006fe8a5e7ec84e93b79c70cb992ae0aa0eb631ad2df8abfe2" -[[package]] -name = "oneshot-uniffi" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c548d5c78976f6955d72d0ced18c48ca07030f7a1d4024529fedd7c1c01b29c" - [[package]] name = "opaque-debug" version = "0.3.1" @@ -2833,7 +2833,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", - "heck", + "heck 0.4.1", "itertools", "lazy_static", "log", @@ -3709,7 +3709,7 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -3796,8 +3796,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" dependencies = [ "smawk", - "unicode-linebreak", - "unicode-width", ] [[package]] @@ -4192,12 +4190,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-linebreak" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" - [[package]] name = "unicode-normalization" version = "0.1.22" @@ -4227,9 +4219,9 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "uniffi" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5566fae48a5cb017005bf9cd622af5236b2a203a13fb548afde3506d3c68277" +checksum = "f31bff6daf87277a9014bcdefbc2842b0553392919d1096843c5aad899ca4588" dependencies = [ "anyhow", "uniffi_core", @@ -4238,9 +4230,9 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a77bb514bcd4bf27c9bd404d7c3f2a6a8131b957eba9c22cfeb7751c4278e09" +checksum = "96061d7e01b185aa405f7c9b134741ab3e50cc6796a47d6fd8ab9a5364b5feed" dependencies = [ "anyhow", "askama", @@ -4249,7 +4241,7 @@ dependencies = [ "fs-err", "glob", "goblin", - "heck", + "heck 0.5.0", "once_cell", "paste", "serde", @@ -4262,9 +4254,9 @@ dependencies = [ [[package]] name = "uniffi_checksum_derive" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae7e5a6c33b1dec3f255f57ec0b6af0f0b2bb3021868be1d5eec7a38e2905ebc" +checksum = "2fcfa22f55829d3aaa7acfb1c5150224188fe0f27c59a8a3eddcaa24d1ffbe58" dependencies = [ "quote", "syn 2.0.58", @@ -4272,25 +4264,24 @@ dependencies = [ [[package]] name = "uniffi_core" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea3eb5474d50fc149b7e4d86b9c5bd4a61dcc167f0683902bf18ae7bbb3deef" +checksum = "3210d57d6ab6065ab47a2898dacdb7c606fd6a4156196831fa3bf82e34ac58a6" dependencies = [ "anyhow", "bytes", "camino", "log", "once_cell", - "oneshot-uniffi", "paste", "static_assertions", ] [[package]] name = "uniffi_macros" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18331d35003f46f0d04047fbe4227291815b83a937a8c32bc057f990962182c4" +checksum = "b58691741080935437dc862122e68d7414432a11824ac1137868de46181a0bd2" dependencies = [ "bincode", "camino", @@ -4306,9 +4297,9 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7224422c4cfd181c7ca9fca2154abca4d21db962f926f270f996edd38b0c4b8" +checksum = "7663eacdbd9fbf4a88907ddcfe2e6fa85838eb6dc2418a7d91eebb3786f8e20b" dependencies = [ "anyhow", "bytes", @@ -4318,9 +4309,9 @@ dependencies = [ [[package]] name = "uniffi_testing" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ce878d0bdfc288b58797044eaaedf748526c56eef3575380bb4d4b19d69eee" +checksum = "f922465f7566f25f8fe766920205fdfa9a3fcdc209c6bfb7557f0b5bf45b04dd" dependencies = [ "anyhow", "camino", @@ -4331,9 +4322,9 @@ dependencies = [ [[package]] name = "uniffi_udl" -version = "0.27.1" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c43c9ed40a8d20a5c3eae2d23031092db6b96dc8e571beb449ba9757484cea0" +checksum = "cef408229a3a407fafa4c36dc4f6ece78a6fb258ab28d2b64bddd49c8cb680f6" dependencies = [ "anyhow", "textwrap", diff --git a/Cargo.toml b/Cargo.toml index 624e8bb91..f24d20bf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ sha2 = { version = "0.10.8", features = [] } simplelog = { version = "0.12.2" } thiserror = "1.0.61" tokio = { version = "1.38.0", features = ["rt-multi-thread", "time", "sync"] } -uniffi = "0.27.0" +uniffi = "0.28.0" uuid = { version = "1.8.0", features = ["v5"] } # Bundle sqlite for all targets except iOS. @@ -86,7 +86,7 @@ lazy_static = "1.4.0" [build-dependencies] camino = "1.1.7" -uniffi_bindgen = "0.27.0" +uniffi_bindgen = "0.28.0" # Use some of the binary size reduction strategies from https://github.com/johnthagen/min-sized-rust [profile.release] diff --git a/build.rs b/build.rs index df80bb66d..27647cdfc 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,7 @@ use camino::Utf8Path; use std::env; -use uniffi_bindgen::bindings::kotlin::gen_kotlin::KotlinBindingGenerator; -use uniffi_bindgen::bindings::swift::gen_swift::SwiftBindingGenerator; +use uniffi_bindgen::bindings::KotlinBindingGenerator; +use uniffi_bindgen::bindings::SwiftBindingGenerator; fn main() { let udl_file = Utf8Path::new("src/lipalightninglib.udl"); From da6326eface5b36dcdec38c82f611e6049e38b4b Mon Sep 17 00:00:00 2001 From: Andrei <92177534+andrei-21@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:04:38 +0100 Subject: [PATCH 2/4] Move `ParseError` to errors (#1105) --- src/errors.rs | 26 ++++++++++++++++++++++++++ src/lib.rs | 32 +++----------------------------- src/symmetric_encryption.rs | 7 +++---- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index af19b4110..2c2ec7dd5 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -333,6 +333,32 @@ impl NotificationHandlingErrorCode { } } +/// Enum representing possible errors why parsing could fail. +#[derive(Debug, thiserror::Error)] +pub enum ParseError { + /// Parsing failed because parsed string was not complete. + /// Additional characters are needed to make the string valid. + /// It makes parsed string a valid prefix of a valid string. + #[error("Incomplete")] + Incomplete, + + /// Parsing failed because an unexpected character at position `at` was met. + /// The character **has to be removed**. + #[error("InvalidCharacter at {at}")] + InvalidCharacter { at: u32 }, +} + +impl From for ParseError { + fn from(error: parser::ParseError) -> Self { + match error { + parser::ParseError::Incomplete => ParseError::Incomplete, + parser::ParseError::UnexpectedCharacter(at) | parser::ParseError::ExcessSuffix(at) => { + ParseError::InvalidCharacter { at: at as u32 } + } + } + } +} + #[derive(Debug, PartialEq, Eq, thiserror::Error)] pub enum ParsePhoneNumberPrefixError { #[error("Incomplete")] diff --git a/src/lib.rs b/src/lib.rs index 7ef771fa9..2a571a03c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,9 +62,9 @@ use crate::errors::{ }; pub use crate::errors::{ DecodeDataError, Error as LnError, LnUrlPayError, LnUrlPayErrorCode, LnUrlPayResult, - MnemonicError, NotificationHandlingError, NotificationHandlingErrorCode, ParsePhoneNumberError, - ParsePhoneNumberPrefixError, PayError, PayErrorCode, PayResult, Result, RuntimeErrorCode, - SimpleError, UnsupportedDataType, + MnemonicError, NotificationHandlingError, NotificationHandlingErrorCode, ParseError, + ParsePhoneNumberError, ParsePhoneNumberPrefixError, PayError, PayErrorCode, PayResult, Result, + RuntimeErrorCode, SimpleError, UnsupportedDataType, }; use crate::event::LipaEventListener; pub use crate::exchange_rate_provider::ExchangeRate; @@ -2658,32 +2658,6 @@ pub fn accept_terms_and_conditions( .map_runtime_error_to(RuntimeErrorCode::AuthServiceUnavailable) } -/// Enum representing possible errors why parsing could fail. -#[derive(Debug, thiserror::Error)] -pub enum ParseError { - /// Parsing failed because parsed string was not complete. - /// Additional characters are needed to make the string valid. - /// It makes parsed string a valid prefix of a valid string. - #[error("Incomplete")] - Incomplete, - - /// Parsing failed because an unexpected character at position `at` was met. - /// The character **has to be removed**. - #[error("InvalidCharacter at {at}")] - InvalidCharacter { at: u32 }, -} - -impl From for ParseError { - fn from(error: parser::ParseError) -> Self { - match error { - parser::ParseError::Incomplete => ParseError::Incomplete, - parser::ParseError::UnexpectedCharacter(at) | parser::ParseError::ExcessSuffix(at) => { - ParseError::InvalidCharacter { at: at as u32 } - } - } - } -} - /// Try to parse the provided string as a lightning address, return [`ParseError`] /// precisely indicating why parsing failed. /// diff --git a/src/symmetric_encryption.rs b/src/symmetric_encryption.rs index f688e4a88..3ff05860d 100644 --- a/src/symmetric_encryption.rs +++ b/src/symmetric_encryption.rs @@ -1,13 +1,12 @@ use crate::errors::{Error, Result}; use crate::random; -use aes_gcm::Aes256Gcm; -use aes_gcm::{aead::Aead, Nonce as AesNonce}; +use aes_gcm::aead::Aead; +use aes_gcm::{Aes256Gcm, Nonce as AesNonce}; use cipher::consts::U12; use cipher::{KeyInit, Unsigned}; use perro::MapToError; -use sha2::Digest; -use sha2::Sha256; +use sha2::{Digest, Sha256}; type NonceLength = U12; type Nonce = AesNonce; From 01405061e038d6a685e46e1b94aad60cec8c6d1c Mon Sep 17 00:00:00 2001 From: Andrei <92177534+andrei-21@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:17:19 +0100 Subject: [PATCH 3/4] Migrate to the new pay on-chain API (#1102) --- examples/node/cli.rs | 12 ++-- src/lib.rs | 120 ++++++++++++++++++++++----------------- src/lipalightninglib.udl | 21 ++++++- 3 files changed, 92 insertions(+), 61 deletions(-) diff --git a/examples/node/cli.rs b/examples/node/cli.rs index efb2d0dac..ea6032a63 100644 --- a/examples/node/cli.rs +++ b/examples/node/cli.rs @@ -22,7 +22,7 @@ use uniffi_lipalightninglib::{ ExchangeRate, FailedSwapInfo, FiatValue, IncomingPaymentInfo, InvoiceCreationMetadata, InvoiceDetails, LightningNode, LiquidityLimit, LnUrlPayDetails, LnUrlWithdrawDetails, MaxRoutingFeeMode, OfferInfo, OfferKind, OutgoingPaymentInfo, PaymentInfo, PaymentMetadata, - Recipient, TzConfig, + RangeHit, Recipient, TzConfig, }; pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) { @@ -1346,11 +1346,11 @@ fn sweep(node: &LightningNode, address: String) -> Result { } fn clear_wallet_info(node: &LightningNode) -> Result<()> { - ensure!( - node.is_clear_wallet_feasible()?, - "Clearing the wallet isn't feasible at the moment due to the available funds being \ - either too low or too high" - ); + match node.check_clear_wallet_feasibility()? { + RangeHit::Below { min } => bail!("Balance is below min: {}", amount_to_string(&min)), + RangeHit::In => (), + RangeHit::Above { max } => bail!("Balance is above max: {}", amount_to_string(&max)), + }; let clear_wallet_info = node.prepare_clear_wallet()?; diff --git a/src/lib.rs b/src/lib.rs index 2a571a03c..0ac06210b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,10 +102,11 @@ use breez_sdk_core::{ ConnectRequest, EventListener, GreenlightCredentials, GreenlightNodeConfig, InputType, ListPaymentsRequest, LnUrlPayRequest, LnUrlPayRequestData, LnUrlWithdrawRequest, LnUrlWithdrawRequestData, Network, NodeConfig, OpenChannelFeeRequest, OpeningFeeParams, - PaymentDetails, PaymentStatus, PaymentTypeFilter, PrepareRedeemOnchainFundsRequest, + PayOnchainRequest, PaymentDetails, PaymentStatus, PaymentTypeFilter, + PrepareOnchainPaymentRequest, PrepareOnchainPaymentResponse, PrepareRedeemOnchainFundsRequest, PrepareRefundRequest, ReceiveOnchainRequest, RedeemOnchainFundsRequest, RefundRequest, - ReportIssueRequest, ReportPaymentFailureDetails, ReverseSwapFeesRequest, SendOnchainRequest, - SendPaymentRequest, SignMessageRequest, UnspentTransactionOutput, + ReportIssueRequest, ReportPaymentFailureDetails, ReverseSwapFeesRequest, SendPaymentRequest, + SignMessageRequest, UnspentTransactionOutput, }; use crow::{CountryCode, LanguageCode, OfferManager, TopupError, TopupInfo}; pub use crow::{PermanentFailureCode, TemporaryFailureCode}; @@ -137,6 +138,16 @@ const CLN_DUST_LIMIT_SAT: u64 = 546; pub(crate) const DB_FILENAME: &str = "db2.db3"; +/// Represent the result of comparision of a value with a given range. +pub enum RangeHit { + /// The value is below the left side of the range. + Below { min: Amount }, + /// The value is whithin the range. + In, + /// The value is above the right side of the range. + Above { max: Amount }, +} + /// The fee charged by the Lightning Service Provider (LSP) for opening a channel with the node. /// This fee is being charged at the time of the channel creation. /// The LSP simply subtracts this fee from an incoming payment (if this incoming payment leads to a channel creation). @@ -249,8 +260,7 @@ pub struct ClearWalletInfo { pub onchain_fee: Amount, /// Estimate for the fee paid to the swap service. pub swap_fee: Amount, - /// Hash that shouldn't be altered. - pub fees_hash: String, + prepare_response: PrepareOnchainPaymentResponse, } const MAX_FEE_PERMYRIAD: u16 = 150; @@ -2327,23 +2337,11 @@ impl LightningNode { /// Check if clearing the wallet is feasible. /// - /// If not feasible, it means the balance is either too high or too low for a reverse-swap to - /// be used. + /// Meaning that the balance is within the range of what can be reverse-swapped. /// /// Requires network: **yes** - pub fn is_clear_wallet_feasible(&self) -> Result { - #[allow(deprecated)] - let amount_sat = self - .rt - .handle() - .block_on(self.sdk.max_reverse_swap_amount()) - .map_to_runtime_error( - RuntimeErrorCode::NodeUnavailable, - "Failed to get max reverse swap amount", - )? - .total_sat; - - let reverse_swap_info = self + pub fn check_clear_wallet_feasibility(&self) -> Result { + let limits = self .rt .handle() .block_on( @@ -2354,59 +2352,78 @@ impl LightningNode { RuntimeErrorCode::NodeUnavailable, "Failed to fetch reverse swap fees", )?; - - Ok(amount_sat >= reverse_swap_info.min && amount_sat <= reverse_swap_info.max) + let balance_sat = self + .sdk + .node_info() + .map_to_runtime_error( + RuntimeErrorCode::NodeUnavailable, + "Failed to read node info", + )? + .channels_balance_msat + .as_msats() + .sats_round_down(); + let exchange_rate = self.get_exchange_rate(); + let range_hit = match balance_sat { + balance_sat if balance_sat < limits.min => RangeHit::Below { + min: limits.min.as_sats().to_amount_up(&exchange_rate), + }, + balance_sat if balance_sat <= limits.max => RangeHit::In, + balance_sat if limits.max < balance_sat => RangeHit::Above { + max: limits.max.as_sats().to_amount_down(&exchange_rate), + }, + _ => permanent_failure!("Unreachable code in check_clear_wallet_feasibility()"), + }; + Ok(range_hit) } /// Prepares a reverse swap that sends all funds in LN channels. This is possible because the /// route to the swap service is known, so fees can be known in advance. /// - /// The return includes fee estimates and must be provided to [`LightningNode::clear_wallet`] in - /// order to execute the clear operation. - /// /// This can fail if the balance is either too low or too high for it to be reverse-swapped. - /// The method [`LightningNode::is_clear_wallet_feasible`] can be used to check if the balance + /// The method [`LightningNode::check_clear_wallet_feasibility`] can be used to check if the balance /// is within the required range. /// /// Requires network: **yes** pub fn prepare_clear_wallet(&self) -> Result { - #[allow(deprecated)] - let amount_sat = self + let claim_tx_feerate = self.query_onchain_fee_rate()?; + let limits = self .rt .handle() - .block_on(self.sdk.max_reverse_swap_amount()) + .block_on(self.sdk.onchain_payment_limits()) .map_to_runtime_error( RuntimeErrorCode::NodeUnavailable, - "Failed to get max reverse swap amount", - )? - .total_sat; - - let reverse_swap_info = self + "Failed to get on-chain payment limits", + )?; + let prepare_response = self .rt .handle() - .block_on(self.sdk.fetch_reverse_swap_fees(ReverseSwapFeesRequest { - send_amount_sat: Some(amount_sat), - claim_tx_feerate: None, - })) + .block_on( + self.sdk + .prepare_onchain_payment(PrepareOnchainPaymentRequest { + amount_sat: limits.max_sat, + amount_type: breez_sdk_core::SwapAmountType::Send, + claim_tx_feerate, + }), + ) .map_to_runtime_error( RuntimeErrorCode::NodeUnavailable, - "Failed to fetch reverse swap fees", + "Failed to prepare on-chain payment", )?; - let total_fees_sat = reverse_swap_info.total_fees.ok_or_permanent_failure( - "No total reverse swap fee estimation provided when amount was present", - )?; - let onchain_fee_sat = reverse_swap_info.fees_claim + reverse_swap_info.fees_lockup; - let swap_fee_sat = - ((amount_sat as f64) * reverse_swap_info.fees_percentage / 100_f64) as u64; + let total_fees_sat = prepare_response.total_fees; + let onchain_fee_sat = prepare_response.fees_claim + prepare_response.fees_lockup; + let swap_fee_sat = total_fees_sat - onchain_fee_sat; let exchange_rate = self.get_exchange_rate(); Ok(ClearWalletInfo { - clear_amount: amount_sat.as_sats().to_amount_up(&exchange_rate), + clear_amount: prepare_response + .sender_amount_sat + .as_sats() + .to_amount_up(&exchange_rate), total_estimated_fees: total_fees_sat.as_sats().to_amount_up(&exchange_rate), onchain_fee: onchain_fee_sat.as_sats().to_amount_up(&exchange_rate), swap_fee: swap_fee_sat.as_sats().to_amount_up(&exchange_rate), - fees_hash: reverse_swap_info.fees_hash, + prepare_response, }) } @@ -2424,14 +2441,11 @@ impl LightningNode { clear_wallet_info: ClearWalletInfo, destination_onchain_address_data: BitcoinAddressData, ) -> Result<()> { - #[allow(deprecated)] self.rt .handle() - .block_on(self.sdk.send_onchain(SendOnchainRequest { - amount_sat: clear_wallet_info.clear_amount.sats, - onchain_recipient_address: destination_onchain_address_data.address, - pair_hash: clear_wallet_info.fees_hash, - sat_per_vbyte: self.query_onchain_fee_rate()?, + .block_on(self.sdk.pay_onchain(PayOnchainRequest { + recipient_address: destination_onchain_address_data.address, + prepare_res: clear_wallet_info.prepare_response, })) .map_to_runtime_error( RuntimeErrorCode::NodeUnavailable, diff --git a/src/lipalightninglib.udl b/src/lipalightninglib.udl index 504f3b30b..30c33c0e1 100644 --- a/src/lipalightninglib.udl +++ b/src/lipalightninglib.udl @@ -147,7 +147,7 @@ interface LightningNode { BreezHealthCheckStatus get_health_status(); [Throws=LnError] - boolean is_clear_wallet_feasible(); + RangeHit check_clear_wallet_feasibility(); [Throws=LnError] ClearWalletInfo prepare_clear_wallet(); @@ -207,6 +207,13 @@ enum Level { "Trace", }; +[Enum] +interface RangeHit { + Below(Amount min); + In(); + Above(Amount max); +}; + callback interface EventsCallback { void payment_received(string payment_hash); void payment_sent(string payment_hash, string payment_preimage); @@ -581,12 +588,22 @@ enum InvoiceAffordability { "Affordable", }; +dictionary PrepareOnchainPaymentResponse { + string fees_hash; + f64 fees_percentage; + u64 fees_lockup; + u64 fees_claim; + u64 sender_amount_sat; + u64 recipient_amount_sat; + u64 total_fees; +}; + dictionary ClearWalletInfo { Amount clear_amount; Amount total_estimated_fees; Amount onchain_fee; Amount swap_fee; - string fees_hash; + PrepareOnchainPaymentResponse prepare_response; }; dictionary ChannelCloseResolvingFees { From fb59134ee1c2a957c9d5d32a0594cb7fe893cfed Mon Sep 17 00:00:00 2001 From: Andrei <92177534+andrei-21@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:49:23 +0100 Subject: [PATCH 4/4] Accomodate routing fees while calculating min clear wallet amount (#1113) --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0ac06210b..75e9bfa93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2363,9 +2363,12 @@ impl LightningNode { .as_msats() .sats_round_down(); let exchange_rate = self.get_exchange_rate(); + + // Accomodating lightning network routing fees. + let min = limits.min + limits.min * (MAX_FEE_PERMYRIAD as u64) / 10000; let range_hit = match balance_sat { - balance_sat if balance_sat < limits.min => RangeHit::Below { - min: limits.min.as_sats().to_amount_up(&exchange_rate), + balance_sat if balance_sat < min => RangeHit::Below { + min: min.as_sats().to_amount_up(&exchange_rate), }, balance_sat if balance_sat <= limits.max => RangeHit::In, balance_sat if limits.max < balance_sat => RangeHit::Above {