File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1609,6 +1609,29 @@ impl Bolt11Invoice {
16091609 self . fallbacks ( ) . iter ( ) . filter_map ( filter_fn) . collect ( )
16101610 }
16111611
1612+ /// Returns the first fallback address as an [`Address`].
1613+ ///
1614+ /// See [`Self::fallback_addresses`] to fetch all addresses of known type.
1615+ pub fn first_fallback_address ( & self ) -> Option < Address > {
1616+ let filter_fn = |fallback : & & Fallback | {
1617+ let address = match fallback {
1618+ Fallback :: SegWitProgram { version, program } => {
1619+ match WitnessProgram :: new ( * version, & program) {
1620+ Ok ( witness_program) => {
1621+ Address :: from_witness_program ( witness_program, self . network ( ) )
1622+ } ,
1623+ Err ( _) => return None ,
1624+ }
1625+ } ,
1626+ Fallback :: PubKeyHash ( pkh) => Address :: p2pkh ( * pkh, self . network ( ) ) ,
1627+ Fallback :: ScriptHash ( sh) => Address :: p2sh_from_hash ( * sh, self . network ( ) ) ,
1628+ } ;
1629+
1630+ Some ( address)
1631+ } ;
1632+ self . fallbacks ( ) . iter ( ) . filter_map ( filter_fn) . next ( )
1633+ }
1634+
16121635 /// Returns a list of all routes included in the invoice
16131636 pub fn private_routes ( & self ) -> Vec < & PrivateRoute > {
16141637 self . signed_invoice . private_routes ( )
You can’t perform that action at this time.
0 commit comments