}).collect::<Vec<_>>();
let data = RawDataPart {
- timestamp: timestamp,
- tagged_fields: tagged_fields,
+ timestamp,
+ tagged_fields,
};
Ok(RawInvoice {
- hrp: hrp,
- data: data,
+ hrp,
+ data,
})
}
}
recovered_pub_key = Some(recovered);
}
- let pub_key = included_pub_key.or_else(|| recovered_pub_key.as_ref())
+ let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
.expect("One is always present");
let hash = Message::from_slice(&self.hash[..])
}
#[cfg(feature = "std")]
-impl Into<SystemTime> for PositiveTimestamp {
- fn into(self) -> SystemTime {
- SystemTime::UNIX_EPOCH + self.0
+impl From<PositiveTimestamp> for SystemTime {
+ fn from(val: PositiveTimestamp) -> Self {
+ SystemTime::UNIX_EPOCH + val.0
}
}
/// ```
pub fn from_signed(signed_invoice: SignedRawInvoice) -> Result<Self, SemanticError> {
let invoice = Invoice {
- signed_invoice: signed_invoice,
+ signed_invoice,
};
invoice.check_field_counts()?;
invoice.check_feature_bits()?;
///
/// (C-not exported) because we don't yet export InvoiceDescription
pub fn description(&self) -> InvoiceDescription {
- if let Some(ref direct) = self.signed_invoice.description() {
+ if let Some(direct) = self.signed_invoice.description() {
return InvoiceDescription::Direct(direct);
- } else if let Some(ref hash) = self.signed_invoice.description_hash() {
+ } else if let Some(hash) = self.signed_invoice.description_hash() {
return InvoiceDescription::Hash(hash);
}
unreachable!("ensured by constructor");
}
}
-impl Into<String> for Description {
- fn into(self) -> String {
- self.into_inner()
+impl From<Description> for String {
+ fn from(val: Description) -> Self {
+ val.into_inner()
}
}
}
}
-impl Into<RouteHint> for PrivateRoute {
- fn into(self) -> RouteHint {
- self.into_inner()
+impl From<PrivateRoute> for RouteHint {
+ fn from(val: PrivateRoute) -> Self {
+ val.into_inner()
}
}
// Multiple payment secrets
let invoice = {
- let mut invoice = invoice_template.clone();
+ let mut invoice = invoice_template;
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
assert_eq!(invoice.hrp.raw_amount, Some(15));
- let invoice = builder.clone()
+ let invoice = builder
.amount_milli_satoshis(150)
.build_raw()
.unwrap();
.build_raw();
assert_eq!(long_route_res, Err(CreationError::RouteTooLong));
- let sign_error_res = builder.clone()
+ let sign_error_res = builder
.description("Test".into())
.payment_secret(PaymentSecret([0; 32]))
.try_build_signed(|_| {
let route_1 = RouteHint(vec![
RouteHintHop {
- src_node_id: public_key.clone(),
+ src_node_id: public_key,
short_channel_id: de::parse_int_be(&[123; 8], 256).expect("short chan ID slice too big?"),
fees: RoutingFees {
base_msat: 2,
htlc_maximum_msat: None,
},
RouteHintHop {
- src_node_id: public_key.clone(),
+ src_node_id: public_key,
short_channel_id: de::parse_int_be(&[42; 8], 256).expect("short chan ID slice too big?"),
fees: RoutingFees {
base_msat: 3,
let route_2 = RouteHint(vec![
RouteHintHop {
- src_node_id: public_key.clone(),
+ src_node_id: public_key,
short_channel_id: 0,
fees: RoutingFees {
base_msat: 4,
htlc_maximum_msat: None,
},
RouteHintHop {
- src_node_id: public_key.clone(),
+ src_node_id: public_key,
short_channel_id: de::parse_int_be(&[1; 8], 256).expect("short chan ID slice too big?"),
fees: RoutingFees {
base_msat: 5,
let builder = InvoiceBuilder::new(Currency::BitcoinTestnet)
.amount_milli_satoshis(123)
.duration_since_epoch(Duration::from_secs(1234567))
- .payee_pub_key(public_key.clone())
+ .payee_pub_key(public_key)
.expiry_time(Duration::from_secs(54321))
.min_final_cltv_expiry_delta(144)
.fallback(Fallback::PubKeyHash([0;20]))
L::Target: Logger,
{
- if phantom_route_hints.len() == 0 {
+ if phantom_route_hints.is_empty() {
return Err(SignOrCreationError::CreationError(
CreationError::MissingRouteHints,
));
}
}
- if channel.is_usable {
- if !online_channel_exists {
- log_trace!(logger, "Channel with connected peer exists for invoice route hints");
- online_channel_exists = true;
- }
+ if channel.is_usable && !online_channel_exists {
+ log_trace!(logger, "Channel with connected peer exists for invoice route hints");
+ online_channel_exists = true;
}
match filtered_channels.entry(channel.counterparty.node_id) {
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
let non_default_invoice_expiry_secs = 4200;
let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
- &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
Some(10_000), "test".to_string(), Duration::from_secs(1234567),
non_default_invoice_expiry_secs, None).unwrap();
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
let scorer = test_utils::TestScorer::new();
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
let route = find_route(
- &nodes[0].node.get_our_node_id(), &route_params, &network_graph,
+ &nodes[0].node.get_our_node_id(), &route_params, network_graph,
Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
).unwrap();
let payment_event = {
let mut payment_hash = PaymentHash([0; 32]);
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
- nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
+ nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
assert_eq!(added_monitors.len(), 1);
added_monitors.clear();
let custom_min_final_cltv_expiry_delta = Some(50);
let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
- &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None },
).unwrap();
let custom_min_final_cltv_expiry_delta = Some(21);
let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
- &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
custom_min_final_cltv_expiry_delta,
).unwrap();
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let description_hash = crate::Sha256(Hash::hash("Testing description_hash".as_bytes()));
let invoice = crate::utils::create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(
- &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
Some(10_000), description_hash, Duration::from_secs(1234567), 3600, None,
).unwrap();
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let payment_hash = PaymentHash([0; 32]);
let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
- &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
Some(10_000), "test".to_string(), Duration::from_secs(1234567), 3600,
payment_hash, None,
).unwrap();
mut chan_ids_to_match: HashSet<u64>
) {
let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
- &invoice_node.node, invoice_node.keys_manager, invoice_node.logger,
+ invoice_node.node, invoice_node.keys_manager, invoice_node.logger,
Currency::BitcoinTestnet, invoice_amt, "test".to_string(), Duration::from_secs(1234567),
3600, None).unwrap();
let hints = invoice.private_routes();
#[cfg(feature = "std")]
fn do_test_multi_node_receive(user_generated_pmt_hash: bool) {
let mut chanmon_cfgs = create_chanmon_cfgs(3);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
let invoice =
crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestLogger>(
Some(payment_amt), payment_hash, "test".to_string(), non_default_invoice_expiry_secs,
- route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager, &nodes[1].logger,
+ route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
Currency::BitcoinTestnet, None, Duration::from_secs(1234567)
).unwrap();
let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().into_inner()), *invoice.payment_secret());
let scorer = test_utils::TestScorer::new();
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
let route = find_route(
- &nodes[0].node.get_our_node_id(), ¶ms, &network_graph,
+ &nodes[0].node.get_our_node_id(), ¶ms, network_graph,
Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
).unwrap();
let (payment_event, fwd_idx) = {
let mut payment_hash = PaymentHash([0; 32]);
payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
- nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
+ nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
assert_eq!(added_monitors.len(), 1);
added_monitors.clear();
let payment_preimage_opt = if user_generated_pmt_hash { None } else { Some(payment_preimage) };
expect_payment_claimable!(&nodes[fwd_idx], payment_hash, payment_secret, payment_amt, payment_preimage_opt, route.paths[0].last().unwrap().pubkey);
- do_claim_payment_along_route(&nodes[0], &vec!(&vec!(&nodes[fwd_idx])[..]), false, payment_preimage);
+ do_claim_payment_along_route(&nodes[0], &[&vec!(&nodes[fwd_idx])[..]], false, payment_preimage);
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 2);
match events[0] {
#[cfg(feature = "std")]
fn test_multi_node_hints_has_htlc_min_max_values() {
let mut chanmon_cfgs = create_chanmon_cfgs(3);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
&test_utils::TestKeysInterface, &test_utils::TestLogger>(Some(payment_amt), Some(payment_hash),
- "test".to_string(), 3600, route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager,
- &nodes[1].logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
+ "test".to_string(), 3600, route_hints, nodes[1].keys_manager, nodes[1].keys_manager,
+ nodes[1].logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
let chan_0_1 = &nodes[1].node.list_usable_channels()[0];
assert_eq!(invoice.route_hints()[0].0[0].htlc_minimum_msat, chan_0_1.inbound_htlc_minimum_msat);
&test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestLogger,
>(
Some(payment_amt), None, non_default_invoice_expiry_secs, description_hash,
- route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager, &nodes[1].logger,
+ route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
Currency::BitcoinTestnet, None, Duration::from_secs(1234567),
)
.unwrap();
let duration_since_epoch = Duration::from_secs(1234567);
let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
&test_utils::TestKeysInterface, &test_utils::TestLogger>(Some(payment_amt), payment_hash,
- "".to_string(), non_default_invoice_expiry_secs, route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager,
- &nodes[1].logger, Currency::BitcoinTestnet, min_final_cltv_expiry_delta, duration_since_epoch).unwrap();
+ "".to_string(), non_default_invoice_expiry_secs, route_hints, nodes[1].keys_manager, nodes[1].keys_manager,
+ nodes[1].logger, Currency::BitcoinTestnet, min_final_cltv_expiry_delta, duration_since_epoch).unwrap();
assert_eq!(invoice.amount_pico_btc(), Some(200_000));
assert_eq!(invoice.min_final_cltv_expiry_delta(), (min_final_cltv_expiry_delta.unwrap() + 3) as u64);
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
#[cfg(feature = "std")]
fn test_multi_node_hints_includes_single_channels_to_participating_nodes() {
let mut chanmon_cfgs = create_chanmon_cfgs(3);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
#[cfg(feature = "std")]
fn test_multi_node_hints_includes_one_channel_of_each_counterparty_nodes_per_participating_node() {
let mut chanmon_cfgs = create_chanmon_cfgs(4);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
#[cfg(feature = "std")]
fn test_multi_node_forwarding_info_not_assigned_channel_excluded_from_hints() {
let mut chanmon_cfgs = create_chanmon_cfgs(4);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
#[cfg(feature = "std")]
fn test_multi_node_with_only_public_channels_hints_includes_only_phantom_route() {
let mut chanmon_cfgs = create_chanmon_cfgs(3);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
#[cfg(feature = "std")]
fn test_multi_node_with_mixed_public_and_private_channel_hints_includes_only_phantom_route() {
let mut chanmon_cfgs = create_chanmon_cfgs(4);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
#[cfg(feature = "std")]
fn test_multi_node_hints_has_only_highest_inbound_capacity_channel() {
let mut chanmon_cfgs = create_chanmon_cfgs(3);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
#[cfg(feature = "std")]
fn test_multi_node_channels_inbound_capacity_lower_than_invoice_amt_filtering() {
let mut chanmon_cfgs = create_chanmon_cfgs(4);
- let seed_1 = [42 as u8; 32];
- let seed_2 = [43 as u8; 32];
- let cross_node_seed = [44 as u8; 32];
+ let seed_1 = [42u8; 32];
+ let seed_2 = [43u8; 32];
+ let cross_node_seed = [44u8; 32];
chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
&test_utils::TestKeysInterface, &test_utils::TestLogger>(invoice_amt, None, "test".to_string(),
- 3600, phantom_route_hints, &invoice_node.keys_manager, &invoice_node.keys_manager,
- &invoice_node.logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
+ 3600, phantom_route_hints, invoice_node.keys_manager, invoice_node.keys_manager,
+ invoice_node.logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
let invoice_hints = invoice.private_routes();
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let result = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
- &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+ nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
Some(10_000), "Some description".into(), Duration::from_secs(1234567), 3600, Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4),
);
match result {