@@ -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 } ;
@@ -603,6 +603,28 @@ impl<S: MutinyStorage> FederationClient<S> {
603603 }
604604 }
605605
606+ pub ( crate ) async fn reissue ( & self , oob_notes : OOBNotes ) -> Result < ( ) , MutinyError > {
607+ let logger = Arc :: clone ( & self . logger ) ;
608+
609+ // Get the `MintClientModule`
610+ let mint_module = self . fedimint_client . get_first_module :: < MintClientModule > ( ) ;
611+
612+ // Reissue `OOBNotes`
613+ let operation_id = mint_module. reissue_external_notes ( oob_notes, ( ) ) . await ?;
614+
615+ // TODO: (@leonardo) re-think about the results and errors that we need/want
616+ match process_reissue_outcome ( & mint_module, operation_id, logger. clone ( ) ) . await ? {
617+ ReissueExternalNotesState :: Created | ReissueExternalNotesState :: Failed ( _) => {
618+ log_trace ! ( logger, "re-issuance of OOBNotes failed!" ) ;
619+ Err ( MutinyError :: FedimintReissueFailed )
620+ }
621+ _ => {
622+ log_trace ! ( logger, "re-issuance of OOBNotes was successful!" ) ;
623+ Ok ( ( ) )
624+ }
625+ }
626+ }
627+
606628 pub async fn get_mutiny_federation_identity ( & self ) -> FederationIdentity {
607629 let gateway_fees = self . gateway_fee ( ) . await . ok ( ) ;
608630
@@ -860,6 +882,53 @@ where
860882 invoice
861883}
862884
885+ async fn process_reissue_outcome (
886+ mint_module : & MintClientModule ,
887+ operation_id : OperationId ,
888+ logger : Arc < MutinyLogger > ,
889+ ) -> Result < ReissueExternalNotesState , MutinyError > {
890+ // Subscribe/Process the outcome based on `ReissueExternalNotesState`
891+ let stream_or_outcome = mint_module
892+ . subscribe_reissue_external_notes ( operation_id)
893+ . await
894+ . map_err ( MutinyError :: Other ) ?;
895+
896+ match stream_or_outcome {
897+ UpdateStreamOrOutcome :: Outcome ( outcome) => {
898+ log_trace ! ( logger, "outcome received {:?}" , outcome) ;
899+ Ok ( outcome)
900+ }
901+ UpdateStreamOrOutcome :: UpdateStream ( mut stream) => {
902+ let timeout = DEFAULT_REISSUE_TIMEOUT * 1_000 ;
903+ let timeout_fut = sleep ( timeout as i32 ) ;
904+ pin_mut ! ( timeout_fut) ;
905+
906+ log_trace ! ( logger, "started timeout future {:?}" , timeout) ;
907+
908+ while let future:: Either :: Left ( ( outcome_opt, _) ) =
909+ future:: select ( stream. next ( ) , & mut timeout_fut) . await
910+ {
911+ if let Some ( outcome) = outcome_opt {
912+ log_trace ! ( logger, "streamed outcome received {:?}" , outcome) ;
913+
914+ match outcome {
915+ ReissueExternalNotesState :: Failed ( _) | ReissueExternalNotesState :: Done => {
916+ log_trace ! (
917+ logger,
918+ "streamed outcome received is final {:?}, returning" ,
919+ outcome
920+ ) ;
921+ return Ok ( outcome) ;
922+ }
923+ _ => { /* ignore and continue */ }
924+ }
925+ } ;
926+ }
927+ Err ( MutinyError :: FedimintReissueFailed )
928+ }
929+ }
930+ }
931+
863932#[ derive( Clone ) ]
864933pub struct FedimintStorage < S : MutinyStorage > {
865934 pub ( crate ) storage : S ,
0 commit comments