X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-invoice%2Fsrc%2Futils.rs;h=1d6b9210afd967f58c79e7453f53a3eda856a9ee;hb=e74f24332f76beb21d20f9989244db1c57956d3b;hp=3a337a9a4b964dea101ee04ea5f6346b4b68fe27;hpb=ef2156ae8b8af8efaf44379aa8382d91c9f0f8d7;p=rust-lightning diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index 3a337a9a..1d6b9210 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -16,8 +16,10 @@ use lightning::routing::gossip::RoutingFees; use lightning::routing::router::{RouteHint, RouteHintHop, Router}; use lightning::util::logger::{Logger, Record}; use secp256k1::PublicKey; +use alloc::collections::{btree_map, BTreeMap}; use core::ops::Deref; use core::time::Duration; +#[cfg(not(feature = "std"))] use core::iter::Iterator; /// Utility to create an invoice that can be paid to one of multiple nodes, or a "phantom invoice." @@ -603,7 +605,7 @@ fn sort_and_filter_channels( where L::Target: Logger, { - let mut filtered_channels: HashMap = HashMap::new(); + let mut filtered_channels: BTreeMap = BTreeMap::new(); let min_inbound_capacity = min_inbound_capacity_msat.unwrap_or(0); let mut min_capacity_channel_exists = false; let mut online_channel_exists = false; @@ -664,7 +666,7 @@ where } match filtered_channels.entry(channel.counterparty.node_id) { - hash_map::Entry::Occupied(mut entry) => { + btree_map::Entry::Occupied(mut entry) => { let current_max_capacity = entry.get().inbound_capacity_msat; // If this channel is public and the previous channel is not, ensure we replace the // previous channel to avoid announcing non-public channels. @@ -697,7 +699,7 @@ where channel.inbound_capacity_msat); } } - hash_map::Entry::Vacant(entry) => { + btree_map::Entry::Vacant(entry) => { entry.insert(channel); } } @@ -816,14 +818,15 @@ impl<'a, 'b, L: Deref> WithChannelDetails<'a, 'b, L> where L::Target: Logger { #[cfg(test)] mod test { - use core::cell::RefCell; use core::time::Duration; use crate::{Currency, Description, Bolt11InvoiceDescription, SignOrCreationError, CreationError}; use bitcoin::hashes::{Hash, sha256}; use bitcoin::hashes::sha256::Hash as Sha256; use lightning::sign::PhantomKeysManager; - use lightning::events::{MessageSendEvent, MessageSendEventsProvider, Event, EventsProvider}; - use lightning::ln::{PaymentPreimage, PaymentHash}; + use lightning::events::{MessageSendEvent, MessageSendEventsProvider}; + use lightning::ln::PaymentHash; + #[cfg(feature = "std")] + use lightning::ln::PaymentPreimage; use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry}; use lightning::ln::functional_test_utils::*; use lightning::ln::msgs::ChannelMessageHandler; @@ -1294,6 +1297,9 @@ mod test { #[cfg(feature = "std")] fn do_test_multi_node_receive(user_generated_pmt_hash: bool) { + use lightning::events::{Event, EventsProvider}; + use core::cell::RefCell; + let mut chanmon_cfgs = create_chanmon_cfgs(3); let seed_1 = [42u8; 32]; let seed_2 = [43u8; 32];