X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-invoice%2Fsrc%2Flib.rs;h=20eaf7a82d27a7970872883536f7edce1da55c69;hb=b3f8470996fe1e29a881a37584984104670172cd;hp=610f739e57ad9d294610103edd36bbd5155d7109;hpb=f98a652f11f598aa828acfff64e5b0df8de80f4f;p=rust-lightning diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 610f739e..20eaf7a8 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -31,7 +31,6 @@ pub mod utils; extern crate bech32; #[macro_use] extern crate lightning; -extern crate num_traits; extern crate secp256k1; extern crate alloc; #[cfg(any(test, feature = "std"))] @@ -79,14 +78,7 @@ mod tb; #[allow(unused_imports)] mod prelude { - #[cfg(feature = "hashbrown")] - extern crate hashbrown; - pub use alloc::{vec, vec::Vec, string::String}; - #[cfg(not(feature = "hashbrown"))] - pub use std::collections::{HashMap, hash_map}; - #[cfg(feature = "hashbrown")] - pub use self::hashbrown::{HashMap, HashSet, hash_map}; pub use alloc::string::ToString; } @@ -1355,6 +1347,15 @@ impl Bolt11Invoice { self.signed_invoice.recover_payee_pub_key().expect("was checked by constructor").0 } + /// Recover the payee's public key if one was included in the invoice, otherwise return the + /// recovered public key from the signature + pub fn get_payee_pub_key(&self) -> PublicKey { + match self.payee_pub_key() { + Some(pk) => *pk, + None => self.recover_payee_pub_key() + } + } + /// Returns the Duration since the Unix epoch at which the invoice expires. /// Returning None if overflow occurred. pub fn expires_at(&self) -> Option { @@ -2062,7 +2063,7 @@ mod test { let route_1 = RouteHint(vec![ RouteHintHop { src_node_id: public_key, - short_channel_id: de::parse_int_be(&[123; 8], 256).expect("short chan ID slice too big?"), + short_channel_id: u64::from_be_bytes([123; 8]), fees: RoutingFees { base_msat: 2, proportional_millionths: 1, @@ -2073,7 +2074,7 @@ mod test { }, RouteHintHop { src_node_id: public_key, - short_channel_id: de::parse_int_be(&[42; 8], 256).expect("short chan ID slice too big?"), + short_channel_id: u64::from_be_bytes([42; 8]), fees: RoutingFees { base_msat: 3, proportional_millionths: 2, @@ -2098,7 +2099,7 @@ mod test { }, RouteHintHop { src_node_id: public_key, - short_channel_id: de::parse_int_be(&[1; 8], 256).expect("short chan ID slice too big?"), + short_channel_id: u64::from_be_bytes([1; 8]), fees: RoutingFees { base_msat: 5, proportional_millionths: 4,