projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #2863 from benthecarman/breakup-coop-close
[rust-lightning]
/
lightning-invoice
/
src
/
payment.rs
diff --git
a/lightning-invoice/src/payment.rs
b/lightning-invoice/src/payment.rs
index e51638f5120c2247a28ec0033bc90429f4755454..8196fa9eb89a81d7df74300484ee96cddee5588f 100644
(file)
--- a/
lightning-invoice/src/payment.rs
+++ b/
lightning-invoice/src/payment.rs
@@
-10,16
+10,12
@@
//! Convenient utilities for paying Lightning invoices.
use crate::Bolt11Invoice;
//! Convenient utilities for paying Lightning invoices.
use crate::Bolt11Invoice;
-use crate::prelude::*;
-
-use bitcoin_hashes::Hash;
+use bitcoin::hashes::Hash;
use lightning::ln::PaymentHash;
use lightning::ln::channelmanager::RecipientOnionFields;
use lightning::routing::router::{PaymentParameters, RouteParameters};
use lightning::ln::PaymentHash;
use lightning::ln::channelmanager::RecipientOnionFields;
use lightning::routing::router::{PaymentParameters, RouteParameters};
-use core::time::Duration;
-
/// Builds the necessary parameters to pay or pre-flight probe the given zero-amount
/// [`Bolt11Invoice`] using [`ChannelManager::send_payment`] or
/// [`ChannelManager::send_preflight_probes`].
/// Builds the necessary parameters to pay or pre-flight probe the given zero-amount
/// [`Bolt11Invoice`] using [`ChannelManager::send_payment`] or
/// [`ChannelManager::send_preflight_probes`].
@@
-61,13
+57,9
@@
pub fn payment_parameters_from_invoice(invoice: &Bolt11Invoice)
}
}
}
}
-fn expiry_time_from_unix_epoch(invoice: &Bolt11Invoice) -> Duration {
- invoice.signed_invoice.raw_invoice.data.timestamp.0 + invoice.expiry_time()
-}
-
fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
-> (PaymentHash, RecipientOnionFields, RouteParameters) {
fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
-> (PaymentHash, RecipientOnionFields, RouteParameters) {
- let payment_hash = PaymentHash((*invoice.payment_hash()).
into_inner
());
+ let payment_hash = PaymentHash((*invoice.payment_hash()).
to_byte_array
());
let mut recipient_onion = RecipientOnionFields::secret_only(*invoice.payment_secret());
recipient_onion.payment_metadata = invoice.payment_metadata().map(|v| v.clone());
let mut recipient_onion = RecipientOnionFields::secret_only(*invoice.payment_secret());
recipient_onion.payment_metadata = invoice.payment_metadata().map(|v| v.clone());
@@
-76,8
+68,10
@@
fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
invoice.recover_payee_pub_key(),
invoice.min_final_cltv_expiry_delta() as u32
)
invoice.recover_payee_pub_key(),
invoice.min_final_cltv_expiry_delta() as u32
)
- .with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
.with_route_hints(invoice.route_hints()).unwrap();
.with_route_hints(invoice.route_hints()).unwrap();
+ if let Some(expiry) = invoice.expires_at() {
+ payment_params = payment_params.with_expiry_time(expiry.as_secs());
+ }
if let Some(features) = invoice.features() {
payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
}
if let Some(features) = invoice.features() {
payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
}
@@
-90,15
+84,13
@@
fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
mod tests {
use super::*;
use crate::{InvoiceBuilder, Currency};
mod tests {
use super::*;
use crate::{InvoiceBuilder, Currency};
- use bitcoin_hashes::sha256::Hash as Sha256;
- use lightning::events::Event;
- use lightning::ln::channelmanager::{Retry, PaymentId};
- use lightning::ln::msgs::ChannelMessageHandler;
+ use bitcoin::hashes::sha256::Hash as Sha256;
use lightning::ln::PaymentSecret;
use lightning::ln::PaymentSecret;
- use lightning::ln::functional_test_utils::*;
use lightning::routing::router::Payee;
use secp256k1::{SecretKey, PublicKey, Secp256k1};
use lightning::routing::router::Payee;
use secp256k1::{SecretKey, PublicKey, Secp256k1};
- use std::time::{SystemTime, Duration};
+ use core::time::Duration;
+ #[cfg(feature = "std")]
+ use std::time::SystemTime;
fn duration_since_epoch() -> Duration {
#[cfg(feature = "std")]
fn duration_since_epoch() -> Duration {
#[cfg(feature = "std")]
@@
-177,6
+169,10
@@
mod tests {
#[test]
#[cfg(feature = "std")]
fn payment_metadata_end_to_end() {
#[test]
#[cfg(feature = "std")]
fn payment_metadata_end_to_end() {
+ use lightning::events::Event;
+ use lightning::ln::channelmanager::{Retry, PaymentId};
+ use lightning::ln::msgs::ChannelMessageHandler;
+ use lightning::ln::functional_test_utils::*;
// Test that a payment metadata read from an invoice passed to `pay_invoice` makes it all
// the way out through the `PaymentClaimable` event.
let chanmon_cfgs = create_chanmon_cfgs(2);
// Test that a payment metadata read from an invoice passed to `pay_invoice` makes it all
// the way out through the `PaymentClaimable` event.
let chanmon_cfgs = create_chanmon_cfgs(2);