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