@@ -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 , DEFAULT_REISSUE_TIMEOUT ,
12+ HTLCStatus , MutinyInvoice , DEFAULT_PAYMENT_TIMEOUT ,
1313} ;
1414use async_trait:: async_trait;
1515use bip39:: Mnemonic ;
@@ -72,6 +72,12 @@ use std::{
7272 sync:: atomic:: { AtomicU32 , Ordering } ,
7373} ;
7474
75+ // The amount of time in milliseconds to wait for
76+ // checking the status of a fedimint OOB re-issuance. This
77+ // is to work around their stream status checking
78+ // when wanting just the current status.
79+ const FEDIMINT_OOB_REISSUE_TIMEOUT_CHECK_MS : u64 = 30 ;
80+
7581// The amount of time in milliseconds to wait for
7682// checking the status of a fedimint payment. This
7783// is to work around their stream status checking
@@ -616,15 +622,31 @@ impl<S: MutinyStorage> FederationClient<S> {
616622 // Reissue `OOBNotes`
617623 let operation_id = mint_module. reissue_external_notes ( oob_notes, ( ) ) . await ?;
618624
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!" ) ;
625+ match process_reissue_outcome (
626+ & mint_module,
627+ operation_id,
628+ FEDIMINT_OOB_REISSUE_TIMEOUT_CHECK_MS ,
629+ self . logger . clone ( ) ,
630+ )
631+ . await ?
632+ {
633+ ReissueExternalNotesState :: Done => {
634+ log_trace ! ( self . logger, "re-issuance of OOBNotes was successful!" ) ;
635+ Ok ( ( ) )
636+ }
637+ ReissueExternalNotesState :: Failed ( reason) => {
638+ log_trace ! (
639+ self . logger,
640+ "re-issuance of OOBNotes failed explicitly, reason: {reason}"
641+ ) ;
623642 Err ( MutinyError :: FedimintReissueFailed )
624643 }
625644 _ => {
626- log_trace ! ( self . logger, "re-issuance of OOBNotes was successful!" ) ;
627- Ok ( ( ) )
645+ log_trace ! (
646+ self . logger,
647+ "re-issuance of OOBNotes explicitly failed, due to outcome with a stale state!"
648+ ) ;
649+ Err ( MutinyError :: FedimintReissueStaleState )
628650 }
629651 }
630652 }
@@ -889,21 +911,22 @@ where
889911async fn process_reissue_outcome (
890912 mint_module : & MintClientModule ,
891913 operation_id : OperationId ,
914+ timeout : u64 ,
892915 logger : Arc < MutinyLogger > ,
893916) -> Result < ReissueExternalNotesState , MutinyError > {
894- // Subscribe/Process the outcome based on `ReissueExternalNotesState`
917+ // Subscribe to the outcome based on `ReissueExternalNotesState`
895918 let stream_or_outcome = mint_module
896919 . subscribe_reissue_external_notes ( operation_id)
897920 . await
898921 . map_err ( MutinyError :: Other ) ?;
899922
923+ // Process the outcome based on `ReissueExternalNotesState`
900924 match stream_or_outcome {
901925 UpdateStreamOrOutcome :: Outcome ( outcome) => {
902926 log_trace ! ( logger, "outcome received {:?}" , outcome) ;
903927 Ok ( outcome)
904928 }
905929 UpdateStreamOrOutcome :: UpdateStream ( mut stream) => {
906- let timeout = DEFAULT_REISSUE_TIMEOUT ;
907930 let timeout_fut = sleep ( timeout as i32 ) ;
908931 pin_mut ! ( timeout_fut) ;
909932
@@ -924,7 +947,13 @@ async fn process_reissue_outcome(
924947 ) ;
925948 return Ok ( outcome) ;
926949 }
927- _ => { /* ignore and continue */ }
950+ _ => {
951+ log_trace ! (
952+ logger,
953+ "streamed outcome received is not final {:?}, skipping" ,
954+ outcome
955+ ) ;
956+ }
928957 }
929958 } ;
930959 }
0 commit comments