diff --git a/lib/ls-sdk-bindings/src/uniffi_bindings.rs b/lib/ls-sdk-bindings/src/uniffi_bindings.rs index d7a6780..313d280 100644 --- a/lib/ls-sdk-bindings/src/uniffi_bindings.rs +++ b/lib/ls-sdk-bindings/src/uniffi_bindings.rs @@ -2,8 +2,9 @@ use std::sync::Arc; use anyhow::{Error, Result}; use ls_sdk::{ + error::PaymentError, model::{ - Network, PaymentError, PrepareReceiveRequest, PrepareReceiveResponse, PrepareSendResponse, + Network, PrepareReceiveRequest, PrepareReceiveResponse, PrepareSendResponse, ReceivePaymentResponse, SendPaymentResponse, WalletInfo, }, wallet::Wallet, diff --git a/lib/ls-sdk-core/src/bindings.rs b/lib/ls-sdk-core/src/bindings.rs index bd367a6..6095d6c 100644 --- a/lib/ls-sdk-core/src/bindings.rs +++ b/lib/ls-sdk-core/src/bindings.rs @@ -3,8 +3,9 @@ pub(crate) use boltz_client::util::secrets::LBtcReverseRecovery; use std::sync::{Arc, OnceLock}; use crate::{ + error::PaymentError, model::{ - Network, PaymentError, PrepareReceiveRequest, PrepareReceiveResponse, PrepareSendResponse, + Network, PrepareReceiveRequest, PrepareReceiveResponse, PrepareSendResponse, ReceivePaymentResponse, SendPaymentResponse, WalletInfo, }, wallet::Wallet, diff --git a/lib/ls-sdk-core/src/error.rs b/lib/ls-sdk-core/src/error.rs index 0e5e7dd..cbe806a 100644 --- a/lib/ls-sdk-core/src/error.rs +++ b/lib/ls-sdk-core/src/error.rs @@ -21,3 +21,91 @@ impl From for LsSdkError { LsSdkError::Generic { err: e.to_string() } } } + +#[derive(thiserror::Error, Debug)] +pub enum PaymentError { + #[error("Invoice amount is out of range")] + AmountOutOfRange, + + #[error("The specified funds have already been claimed")] + AlreadyClaimed, + + #[error("Generic error: {err}")] + Generic { err: String }, + + #[error("The specified invoice is not valid")] + InvalidInvoice, + + #[error("The generated preimage is not valid")] + InvalidPreimage, + + #[error("Lwk error: {err}")] + LwkError { err: String }, + + #[error("Boltz did not return any pairs from the request")] + PairsNotFound, + + #[error("Could not store the swap details locally")] + PersistError, + + #[error("Could not sign/send the transaction: {err}")] + SendError { err: String }, + + #[error("Could not sign the transaction: {err}")] + SignerError { err: String }, +} + +impl From for PaymentError { + fn from(err: boltz_client::error::Error) -> Self { + match err { + boltz_client::error::Error::Protocol(msg) => { + if msg == "Could not find utxos for script" { + return PaymentError::AlreadyClaimed; + } + + PaymentError::Generic { err: msg } + } + _ => PaymentError::Generic { + err: format!("{err:?}"), + }, + } + } +} + +#[allow(clippy::match_single_binding)] +impl From for PaymentError { + fn from(err: lwk_wollet::Error) -> Self { + match err { + _ => PaymentError::LwkError { + err: format!("{err:?}"), + }, + } + } +} + +#[allow(clippy::match_single_binding)] +impl From for PaymentError { + fn from(err: lwk_signer::SignerError) -> Self { + match err { + _ => PaymentError::SignerError { + err: format!("{err:?}"), + }, + } + } +} + +impl From for PaymentError { + fn from(err: anyhow::Error) -> Self { + Self::Generic { + err: err.to_string(), + } + } +} + +impl From for PaymentError { + fn from(err: LsSdkError) -> Self { + Self::Generic { + err: err.to_string(), + } + } +} diff --git a/lib/ls-sdk-core/src/model.rs b/lib/ls-sdk-core/src/model.rs index 744844e..89b2de8 100644 --- a/lib/ls-sdk-core/src/model.rs +++ b/lib/ls-sdk-core/src/model.rs @@ -6,8 +6,6 @@ use serde::Serialize; use crate::get_invoice_amount; -use super::error::LsSdkError; - #[derive(Debug, Copy, Clone, PartialEq)] pub enum Network { Liquid, @@ -95,94 +93,6 @@ pub struct SendPaymentResponse { pub txid: String, } -#[derive(thiserror::Error, Debug)] -pub enum PaymentError { - #[error("Invoice amount is out of range")] - AmountOutOfRange, - - #[error("The specified funds have already been claimed")] - AlreadyClaimed, - - #[error("Generic error: {err}")] - Generic { err: String }, - - #[error("The specified invoice is not valid")] - InvalidInvoice, - - #[error("The generated preimage is not valid")] - InvalidPreimage, - - #[error("Lwk error: {err}")] - LwkError { err: String }, - - #[error("Boltz did not return any pairs from the request")] - PairsNotFound, - - #[error("Could not store the swap details locally")] - PersistError, - - #[error("Could not sign/send the transaction: {err}")] - SendError { err: String }, - - #[error("Could not sign the transaction: {err}")] - SignerError { err: String }, -} - -impl From for PaymentError { - fn from(err: boltz_client::error::Error) -> Self { - match err { - boltz_client::error::Error::Protocol(msg) => { - if msg == "Could not find utxos for script" { - return PaymentError::AlreadyClaimed; - } - - PaymentError::Generic { err: msg } - } - _ => PaymentError::Generic { - err: format!("{err:?}"), - }, - } - } -} - -#[allow(clippy::match_single_binding)] -impl From for PaymentError { - fn from(err: lwk_wollet::Error) -> Self { - match err { - _ => PaymentError::LwkError { - err: format!("{err:?}"), - }, - } - } -} - -#[allow(clippy::match_single_binding)] -impl From for PaymentError { - fn from(err: lwk_signer::SignerError) -> Self { - match err { - _ => PaymentError::SignerError { - err: format!("{err:?}"), - }, - } - } -} - -impl From for PaymentError { - fn from(err: anyhow::Error) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for PaymentError { - fn from(err: LsSdkError) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} - #[derive(Debug, Serialize)] pub struct WalletInfo { pub balance_sat: u64, diff --git a/lib/ls-sdk-core/src/wallet.rs b/lib/ls-sdk-core/src/wallet.rs index de4d472..5361b51 100644 --- a/lib/ls-sdk-core/src/wallet.rs +++ b/lib/ls-sdk-core/src/wallet.rs @@ -29,12 +29,16 @@ use lwk_wollet::{ ElementsNetwork, FsPersister, Wollet as LwkWollet, WolletDescriptor, }; -use crate::{ensure_sdk, get_invoice_amount, persist::Persister}; - -use crate::model::{ - Network, OngoingSwap, Payment, PaymentData, PaymentError, PaymentType, PrepareReceiveRequest, - PrepareReceiveResponse, PrepareSendResponse, ReceivePaymentResponse, SendPaymentResponse, - WalletInfo, WalletOptions, +use crate::{ + ensure_sdk, + error::PaymentError, + get_invoice_amount, + model::{ + Network, OngoingSwap, Payment, PaymentData, PaymentType, PrepareReceiveRequest, + PrepareReceiveResponse, PrepareSendResponse, ReceivePaymentResponse, SendPaymentResponse, + WalletInfo, WalletOptions, + }, + persist::Persister, }; /// Claim tx feerate for Receive, in sats per vbyte.