@@ -11,8 +11,6 @@ use ldk_node::lightning_invoice::Bolt11Invoice;
1111use bitcoin_payment_instructions:: PaymentMethod ;
1212use bitcoin_payment_instructions:: amount:: Amount ;
1313
14- use spark_wallet:: SparkWalletError ;
15-
1614use std:: future:: Future ;
1715use std:: sync:: Arc ;
1816use std:: time:: Duration ;
@@ -21,9 +19,6 @@ use std::time::Duration;
2119pub mod dummy;
2220pub mod spark;
2321
24- // todo generic error type
25- pub ( crate ) type Error = SparkWalletError ;
26-
2722/// Represents a payment with its associated details.
2823///
2924/// This struct contains information about a payment, including its unique ID,
@@ -57,29 +52,30 @@ pub trait TrustedWalletInterface: Sized + Send + Sync + private::Sealed {
5752 ) -> impl Future < Output = Result < Self , InitFailure > > + Send ;
5853
5954 /// Returns the current balance of the wallet.
60- fn get_balance ( & self ) -> impl Future < Output = Result < Amount , Error > > + Send ;
55+ fn get_balance ( & self ) -> impl Future < Output = Result < Amount , TrustedError > > + Send ;
6156
6257 /// Generates a new reusable address for receiving payments.
6358 /// Generally, this should be a BOLT 12 offer.
64- fn get_reusable_receive_uri ( & self ) -> impl Future < Output = Result < String , Error > > + Send ;
59+ fn get_reusable_receive_uri ( & self )
60+ -> impl Future < Output = Result < String , TrustedError > > + Send ;
6561
6662 /// Generates a Bolt11 invoice for the specified amount.
6763 fn get_bolt11_invoice (
6864 & self , amount : Option < Amount > ,
69- ) -> impl Future < Output = Result < Bolt11Invoice , Error > > + Send ;
65+ ) -> impl Future < Output = Result < Bolt11Invoice , TrustedError > > + Send ;
7066
7167 /// Lists all payments made through the wallet.
72- fn list_payments ( & self ) -> impl Future < Output = Result < Vec < Payment > , Error > > + Send ;
68+ fn list_payments ( & self ) -> impl Future < Output = Result < Vec < Payment > , TrustedError > > + Send ;
7369
7470 /// Estimates the fee for a payment to the given payment method with the specified amount.
7571 fn estimate_fee (
7672 & self , method : & PaymentMethod , amount : Amount ,
77- ) -> impl Future < Output = Result < Amount , Error > > + Send ;
73+ ) -> impl Future < Output = Result < Amount , TrustedError > > + Send ;
7874
7975 /// Pays to the given payment method with the specified amount.
8076 fn pay (
8177 & self , method : & PaymentMethod , amount : Amount ,
82- ) -> impl Future < Output = Result < [ u8 ; 32 ] , Error > > + Send ;
78+ ) -> impl Future < Output = Result < [ u8 ; 32 ] , TrustedError > > + Send ;
8379
8480 /// Stops the wallet, cleaning up any resources.
8581 /// This is typically used to gracefully shut down the wallet.
@@ -89,7 +85,7 @@ pub trait TrustedWalletInterface: Sized + Send + Sync + private::Sealed {
8985pub ( crate ) struct WalletTrusted < T : TrustedWalletInterface > ( pub ( crate ) Arc < T > ) ;
9086
9187impl < T : TrustedWalletInterface > graduated_rebalancer:: TrustedWallet for WalletTrusted < T > {
92- type Error = crate :: trusted_wallet :: Error ;
88+ type Error = TrustedError ;
9389
9490 fn get_balance ( & self ) -> impl Future < Output = Result < Amount , Self :: Error > > + Send {
9591 async move { self . 0 . get_balance ( ) . await }
@@ -127,3 +123,28 @@ mod private {
127123 #[ cfg( feature = "_test-utils" ) ]
128124 impl Sealed for super :: dummy:: DummyTrustedWallet { }
129125}
126+
127+ /// An error type for the Spark wallet implementation.
128+ #[ derive( Debug ) ]
129+ pub enum TrustedError {
130+ /// Not enough funds to complete the operation.
131+ InsufficientFunds ,
132+ /// The wallet operation failed with a specific message.
133+ WalletOperationFailed ( String ) ,
134+ /// The provided network is invalid.
135+ InvalidNetwork ,
136+ /// The spark wallet does not yet support the operation.
137+ UnsupportedOperation ( String ) ,
138+ /// Failed to convert an amount.
139+ AmountError ,
140+ /// An I/O error occurred.
141+ IOError ( ldk_node:: lightning:: io:: Error ) ,
142+ /// An unspecified error occurred.
143+ Other ( String ) ,
144+ }
145+
146+ impl From < ldk_node:: lightning:: io:: Error > for TrustedError {
147+ fn from ( e : ldk_node:: lightning:: io:: Error ) -> Self {
148+ TrustedError :: IOError ( e)
149+ }
150+ }
0 commit comments