@@ -9,7 +9,7 @@ use crate::{
9
9
get_payment_info, list_payment_info, persist_payment_info, MutinyStorage , VersionedValue ,
10
10
} ,
11
11
utils:: sleep,
12
- HTLCStatus , MutinyInvoice , DEFAULT_PAYMENT_TIMEOUT ,
12
+ HTLCStatus , MutinyInvoice , DEFAULT_PAYMENT_TIMEOUT , DEFAULT_REISSUE_TIMEOUT ,
13
13
} ;
14
14
use async_trait:: async_trait;
15
15
use bip39:: Mnemonic ;
@@ -52,7 +52,7 @@ use fedimint_ln_client::{
52
52
} ;
53
53
use fedimint_ln_common:: lightning_invoice:: RoutingFees ;
54
54
use fedimint_ln_common:: LightningCommonInit ;
55
- use fedimint_mint_client:: MintClientInit ;
55
+ use fedimint_mint_client:: { MintClientInit , MintClientModule , OOBNotes , ReissueExternalNotesState } ;
56
56
use fedimint_wallet_client:: { WalletClientInit , WalletClientModule } ;
57
57
use futures:: future:: { self } ;
58
58
use futures_util:: { pin_mut, StreamExt } ;
@@ -609,6 +609,28 @@ impl<S: MutinyStorage> FederationClient<S> {
609
609
}
610
610
}
611
611
612
+ pub ( crate ) async fn reissue ( & self , oob_notes : OOBNotes ) -> Result < ( ) , MutinyError > {
613
+ let logger = Arc :: clone ( & self . logger ) ;
614
+
615
+ // Get the `MintClientModule`
616
+ let mint_module = self . fedimint_client . get_first_module :: < MintClientModule > ( ) ;
617
+
618
+ // Reissue `OOBNotes`
619
+ let operation_id = mint_module. reissue_external_notes ( oob_notes, ( ) ) . await ?;
620
+
621
+ // TODO: (@leonardo) re-think about the results and errors that we need/want
622
+ match process_reissue_outcome ( & mint_module, operation_id, logger. clone ( ) ) . await ? {
623
+ ReissueExternalNotesState :: Created | ReissueExternalNotesState :: Failed ( _) => {
624
+ log_trace ! ( logger, "re-issuance of OOBNotes failed!" ) ;
625
+ Err ( MutinyError :: FedimintReissueFailed )
626
+ }
627
+ _ => {
628
+ log_trace ! ( logger, "re-issuance of OOBNotes was successful!" ) ;
629
+ Ok ( ( ) )
630
+ }
631
+ }
632
+ }
633
+
612
634
pub async fn get_mutiny_federation_identity ( & self ) -> FederationIdentity {
613
635
let gateway_fees = self . gateway_fee ( ) . await . ok ( ) ;
614
636
@@ -866,6 +888,53 @@ where
866
888
invoice
867
889
}
868
890
891
+ async fn process_reissue_outcome (
892
+ mint_module : & MintClientModule ,
893
+ operation_id : OperationId ,
894
+ logger : Arc < MutinyLogger > ,
895
+ ) -> Result < ReissueExternalNotesState , MutinyError > {
896
+ // Subscribe/Process the outcome based on `ReissueExternalNotesState`
897
+ let stream_or_outcome = mint_module
898
+ . subscribe_reissue_external_notes ( operation_id)
899
+ . await
900
+ . map_err ( MutinyError :: Other ) ?;
901
+
902
+ match stream_or_outcome {
903
+ UpdateStreamOrOutcome :: Outcome ( outcome) => {
904
+ log_trace ! ( logger, "outcome received {:?}" , outcome) ;
905
+ Ok ( outcome)
906
+ }
907
+ UpdateStreamOrOutcome :: UpdateStream ( mut stream) => {
908
+ let timeout = DEFAULT_REISSUE_TIMEOUT * 1_000 ;
909
+ let timeout_fut = sleep ( timeout as i32 ) ;
910
+ pin_mut ! ( timeout_fut) ;
911
+
912
+ log_trace ! ( logger, "started timeout future {:?}" , timeout) ;
913
+
914
+ while let future:: Either :: Left ( ( outcome_opt, _) ) =
915
+ future:: select ( stream. next ( ) , & mut timeout_fut) . await
916
+ {
917
+ if let Some ( outcome) = outcome_opt {
918
+ log_trace ! ( logger, "streamed outcome received {:?}" , outcome) ;
919
+
920
+ match outcome {
921
+ ReissueExternalNotesState :: Failed ( _) | ReissueExternalNotesState :: Done => {
922
+ log_trace ! (
923
+ logger,
924
+ "streamed outcome received is final {:?}, returning" ,
925
+ outcome
926
+ ) ;
927
+ return Ok ( outcome) ;
928
+ }
929
+ _ => { /* ignore and continue */ }
930
+ }
931
+ } ;
932
+ }
933
+ Err ( MutinyError :: FedimintReissueFailed )
934
+ }
935
+ }
936
+ }
937
+
869
938
#[ derive( Clone ) ]
870
939
pub struct FedimintStorage < S : MutinyStorage > {
871
940
pub ( crate ) storage : S ,
0 commit comments