Skip to content

Commit 464a8db

Browse files
committed
Ensure Option<Address> gets derived
This is used in bindings for the `Address` constructor, and needs to exist in the (public) source tree to ensure bindings derives it.
1 parent 5ced763 commit 464a8db

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lightning-invoice/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)