diff --git a/lib/bindings/src/breez_sdk_liquid.udl b/lib/bindings/src/breez_sdk_liquid.udl index 63e999c45..ada8a2ca8 100644 --- a/lib/bindings/src/breez_sdk_liquid.udl +++ b/lib/bindings/src/breez_sdk_liquid.udl @@ -564,6 +564,7 @@ enum PaymentState { "TimedOut", "Refundable", "RefundPending", + "Recoverable", }; dictionary RefundableSwap { diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index d55f7fbf0..b5d4468a6 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -1149,6 +1149,11 @@ impl ChainSwapHandler { to_state: PaymentState, ) -> Result<(), PaymentError> { match (from_state, to_state) { + (Recoverable, Pending | Refundable | RefundPending | Failed | Complete) => Ok(()), + (_, Recoverable) => Err(PaymentError::Generic { + err: format!("Cannot transition from {from_state:?} to Recoverable state"), + }), + (_, Created) => Err(PaymentError::Generic { err: "Cannot transition to Created state".to_string(), }), diff --git a/lib/core/src/frb_generated.rs b/lib/core/src/frb_generated.rs index 1a6d710b3..e4fdda9bf 100644 --- a/lib/core/src/frb_generated.rs +++ b/lib/core/src/frb_generated.rs @@ -2063,6 +2063,7 @@ impl CstDecode for i32 { 4 => crate::model::PaymentState::TimedOut, 5 => crate::model::PaymentState::Refundable, 6 => crate::model::PaymentState::RefundPending, + 7 => crate::model::PaymentState::Recoverable, _ => unreachable!("Invalid variant for PaymentState: {}", self), } } @@ -3629,6 +3630,7 @@ impl SseDecode for crate::model::PaymentState { 4 => crate::model::PaymentState::TimedOut, 5 => crate::model::PaymentState::Refundable, 6 => crate::model::PaymentState::RefundPending, + 7 => crate::model::PaymentState::Recoverable, _ => unreachable!("Invalid variant for PaymentState: {}", inner), }; } @@ -5620,6 +5622,7 @@ impl flutter_rust_bridge::IntoDart for crate::model::PaymentState { Self::TimedOut => 4.into_dart(), Self::Refundable => 5.into_dart(), Self::RefundPending => 6.into_dart(), + Self::Recoverable => 7.into_dart(), _ => unreachable!(), } } @@ -7588,6 +7591,7 @@ impl SseEncode for crate::model::PaymentState { crate::model::PaymentState::TimedOut => 4, crate::model::PaymentState::Refundable => 5, crate::model::PaymentState::RefundPending => 6, + crate::model::PaymentState::Recoverable => 7, _ => { unimplemented!(""); } diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index 9e59fd285..49ddf8950 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -1018,6 +1018,12 @@ pub enum PaymentState { /// /// When the refund tx is broadcast, `refund_tx_id` is set in the swap. RefundPending = 6, + + /// ## Recoverable Swaps + /// + /// The status for swaps that have been synced in, and whose information is recoverable from + /// chain + Recoverable = 7, } impl ToSql for PaymentState { fn to_sql(&self) -> rusqlite::Result> { @@ -1035,6 +1041,7 @@ impl FromSql for PaymentState { 4 => Ok(PaymentState::TimedOut), 5 => Ok(PaymentState::Refundable), 6 => Ok(PaymentState::RefundPending), + 7 => Ok(PaymentState::Recoverable), _ => Err(FromSqlError::OutOfRange(i)), }, _ => Err(FromSqlError::InvalidType), diff --git a/lib/core/src/persist/sync.rs b/lib/core/src/persist/sync.rs index edb59f06f..f53ddad2d 100644 --- a/lib/core/src/persist/sync.rs +++ b/lib/core/src/persist/sync.rs @@ -479,7 +479,7 @@ impl Persister { :description, :state )", - [params, &[(":state", &PaymentState::Created)]] + [params, &[(":state", &PaymentState::Recoverable)]] .concat() .as_slice(), )?; @@ -572,7 +572,7 @@ impl Persister { :description, :state )", - [params, &[(":state", &PaymentState::Created)]] + [params, &[(":state", &PaymentState::Recoverable)]] .concat() .as_slice(), )?; @@ -684,7 +684,7 @@ impl Persister { :server_lockup_tx_id, :state )", - [params, &[(":state", &PaymentState::Created)]] + [params, &[(":state", &PaymentState::Recoverable)]] .concat() .as_slice(), )?; diff --git a/lib/core/src/receive_swap.rs b/lib/core/src/receive_swap.rs index fd87c5558..730befc9e 100644 --- a/lib/core/src/receive_swap.rs +++ b/lib/core/src/receive_swap.rs @@ -9,9 +9,7 @@ use lwk_wollet::hashes::hex::DisplayHex; use tokio::sync::{broadcast, Mutex}; use crate::chain::liquid::LiquidChainService; -use crate::model::PaymentState::{ - Complete, Created, Failed, Pending, RefundPending, Refundable, TimedOut, -}; +use crate::model::PaymentState::*; use crate::model::{Config, PaymentTxData, PaymentType, ReceiveSwap}; use crate::prelude::{Swap, Transaction}; use crate::{ensure_sdk, utils}; @@ -372,6 +370,11 @@ impl ReceiveSwapHandler { to_state: PaymentState, ) -> Result<(), PaymentError> { match (from_state, to_state) { + (Recoverable, Pending | Refundable | RefundPending | Failed | Complete) => Ok(()), + (_, Recoverable) => Err(PaymentError::Generic { + err: format!("Cannot transition from {from_state:?} to Recoverable state"), + }), + (_, Created) => Err(PaymentError::Generic { err: "Cannot transition to Created state".to_string(), }), diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index b7e1405a7..85ef01bd2 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -562,12 +562,12 @@ impl LiquidSdk { None => pending_send_sat += p.amount_sat, }, Created => pending_send_sat += p.amount_sat, - Refundable | RefundPending | TimedOut => {} + Refundable | RefundPending | TimedOut | Recoverable => {} }, PaymentType::Receive => match p.status { Complete => confirmed_received_sat += p.amount_sat, Pending => pending_receive_sat += p.amount_sat, - Created | Refundable | RefundPending | Failed | TimedOut => {} + Created | Refundable | RefundPending | Failed | TimedOut | Recoverable => {} }, } } @@ -1241,7 +1241,7 @@ impl LiquidSdk { } Pending => return Err(PaymentError::PaymentInProgress), Complete => return Err(PaymentError::AlreadyPaid), - RefundPending | Refundable | Failed => { + RefundPending | Refundable | Failed | Recoverable => { return Err(PaymentError::invalid_invoice( "Payment has already failed. Please try with another invoice", )) diff --git a/lib/core/src/send_swap.rs b/lib/core/src/send_swap.rs index dcf71cda5..f6d370bab 100644 --- a/lib/core/src/send_swap.rs +++ b/lib/core/src/send_swap.rs @@ -496,6 +496,11 @@ impl SendSwapHandler { to_state: PaymentState, ) -> Result<(), PaymentError> { match (from_state, to_state) { + (Recoverable, Pending | Refundable | RefundPending | Failed | Complete) => Ok(()), + (_, Recoverable) => Err(PaymentError::Generic { + err: format!("Cannot transition from {from_state:?} to Recoverable state"), + }), + (TimedOut, Created) => Ok(()), (_, Created) => Err(PaymentError::Generic { err: "Cannot transition from {from_state:?} to Created state".to_string(), diff --git a/packages/dart/lib/src/model.dart b/packages/dart/lib/src/model.dart index d6f87cfe8..16c963862 100644 --- a/packages/dart/lib/src/model.dart +++ b/packages/dart/lib/src/model.dart @@ -736,6 +736,12 @@ enum PaymentState { /// /// When the refund tx is broadcast, `refund_tx_id` is set in the swap. refundPending, + + /// ## Recoverable Swaps + /// + /// The status for swaps that have been synced in, and whose information is recoverable from + /// chain + recoverable, ; } diff --git a/packages/react-native/ios/BreezSDKLiquidMapper.swift b/packages/react-native/ios/BreezSDKLiquidMapper.swift index d39694fa2..1803382bf 100644 --- a/packages/react-native/ios/BreezSDKLiquidMapper.swift +++ b/packages/react-native/ios/BreezSDKLiquidMapper.swift @@ -3733,6 +3733,9 @@ enum BreezSDKLiquidMapper { case "refundPending": return PaymentState.refundPending + case "recoverable": + return PaymentState.recoverable + default: throw SdkError.Generic(message: "Invalid variant \(paymentState) for enum PaymentState") } } @@ -3759,6 +3762,9 @@ enum BreezSDKLiquidMapper { case .refundPending: return "refundPending" + + case .recoverable: + return "recoverable" } } diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 42afd7d15..431289ea9 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -621,7 +621,8 @@ export enum PaymentState { FAILED = "failed", TIMED_OUT = "timedOut", REFUNDABLE = "refundable", - REFUND_PENDING = "refundPending" + REFUND_PENDING = "refundPending", + RECOVERABLE = "recoverable" } export enum PaymentType {