L::Target: Logger,
{
use std::time::SystemTime;
- let duration = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)
+ let duration_since_epoch = SystemTime::now()
+ .duration_since(SystemTime::UNIX_EPOCH)
.expect("for the foreseeable future this shouldn't happen");
- create_invoice_from_channelmanager_and_duration_since_epoch(
+
+ _create_invoice_from_channelmanager_and_duration_since_epoch(
channelmanager, node_signer, logger, network, amt_msat,
- description, duration, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
+ Bolt11InvoiceDescription::Direct(
+ Description::new(description).map_err(SignOrCreationError::CreationError)?,
+ ),
+ duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
)
}
L::Target: Logger,
{
use std::time::SystemTime;
-
- let duration = SystemTime::now()
+ let duration_since_epoch = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("for the foreseeable future this shouldn't happen");
- create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(
- channelmanager, node_signer, logger, network, amt_msat,
- description_hash, duration, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
- )
-}
-
-/// Utility to construct an invoice. Generally, unless you want to do something like a custom
-/// `cltv_expiry`, this is what you should be using to create an invoice.
-#[cfg_attr(feature = "std", doc = "")]
-#[cfg_attr(feature = "std", doc = "See [`create_invoice_from_channelmanager_with_description_hash`] for more information.")]
-#[cfg_attr(feature = "std", doc = "")]
-#[cfg_attr(feature = "std", doc = "This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")]
-pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>(
- channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, MR, L>, node_signer: NS, logger: L,
- network: Currency, amt_msat: Option<u64>, description_hash: Sha256,
- duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Bolt11Invoice, SignOrCreationError<()>>
-where
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
- T::Target: BroadcasterInterface,
- ES::Target: EntropySource,
- NS::Target: NodeSigner,
- SP::Target: SignerProvider,
- F::Target: FeeEstimator,
- R::Target: Router,
- MR::Target: MessageRouter,
- L::Target: Logger,
-{
_create_invoice_from_channelmanager_and_duration_since_epoch(
channelmanager, node_signer, logger, network, amt_msat,
Bolt11InvoiceDescription::Hash(description_hash),
)
}
-/// Utility to construct an invoice. Generally, unless you want to do something like a custom
-/// `cltv_expiry`, this is what you should be using to create an invoice.
-#[cfg_attr(feature = "std", doc = "")]
-#[cfg_attr(feature = "std", doc = "See [`create_invoice_from_channelmanager`] for more information.")]
-#[cfg_attr(feature = "std", doc = "")]
-#[cfg_attr(feature = "std", doc = "This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")]
-pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>(
- channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, MR, L>, node_signer: NS, logger: L,
- network: Currency, amt_msat: Option<u64>, description: String, duration_since_epoch: Duration,
- invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Bolt11Invoice, SignOrCreationError<()>>
-where
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
- T::Target: BroadcasterInterface,
- ES::Target: EntropySource,
- NS::Target: NodeSigner,
- SP::Target: SignerProvider,
- F::Target: FeeEstimator,
- R::Target: Router,
- MR::Target: MessageRouter,
- L::Target: Logger,
-{
- _create_invoice_from_channelmanager_and_duration_since_epoch(
- channelmanager, node_signer, logger, network, amt_msat,
- Bolt11InvoiceDescription::Direct(
- Description::new(description).map_err(SignOrCreationError::CreationError)?,
- ),
- duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
- )
-}
-
fn _create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>(
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, MR, L>, node_signer: NS, logger: L,
network: Currency, amt_msat: Option<u64>, description: Bolt11InvoiceDescription,
invoice_expiry_delta_secs, payment_hash, payment_secret, min_final_cltv_expiry_delta)
}
-/// See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
+#[cfg(feature = "std")]
+/// See [`create_invoice_from_channelmanager`].
+///
/// This version allows for providing custom [`PaymentHash`] and description hash for the invoice.
///
/// This may be useful if you're building an on-chain swap or involving another protocol where
/// the payment hash is also involved outside the scope of lightning and want to set the
/// description hash.
-pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch_with_payment_hash<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>(
+pub fn create_invoice_from_channelmanager_with_description_hash_and_payment_hash<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>(
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, MR, L>, node_signer: NS, logger: L,
- network: Currency, amt_msat: Option<u64>, description_hash: Sha256, duration_since_epoch: Duration,
+ network: Currency, amt_msat: Option<u64>, description_hash: Sha256,
invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, min_final_cltv_expiry_delta: Option<u16>,
) -> Result<Bolt11Invoice, SignOrCreationError<()>>
where
MR::Target: MessageRouter,
L::Target: Logger,
{
+ use std::time::SystemTime;
+ let duration_since_epoch = SystemTime::now()
+ .duration_since(SystemTime::UNIX_EPOCH)
+ .expect("for the foreseeable future this shouldn't happen");
+
let payment_secret = channelmanager
.create_inbound_payment_for_hash(payment_hash, amt_msat, invoice_expiry_delta_secs,
min_final_cltv_expiry_delta)
)
}
-/// See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
+#[cfg(feature = "std")]
+/// See [`create_invoice_from_channelmanager`].
+///
/// This version allows for providing a custom [`PaymentHash`] for the invoice.
/// This may be useful if you're building an on-chain swap or involving another protocol where
/// the payment hash is also involved outside the scope of lightning.
-pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>(
+pub fn create_invoice_from_channelmanager_with_payment_hash<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>(
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, MR, L>, node_signer: NS, logger: L,
- network: Currency, amt_msat: Option<u64>, description: String, duration_since_epoch: Duration,
- invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, min_final_cltv_expiry_delta: Option<u16>,
+ network: Currency, amt_msat: Option<u64>, description: String, invoice_expiry_delta_secs: u32,
+ payment_hash: PaymentHash, min_final_cltv_expiry_delta: Option<u16>,
) -> Result<Bolt11Invoice, SignOrCreationError<()>>
where
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
MR::Target: MessageRouter,
L::Target: Logger,
{
+ use std::time::SystemTime;
+ let duration_since_epoch = SystemTime::now()
+ .duration_since(SystemTime::UNIX_EPOCH)
+ .expect("for the foreseeable future this shouldn't happen");
+
let payment_secret = channelmanager
.create_inbound_payment_for_hash(payment_hash, amt_msat, invoice_expiry_delta_secs,
min_final_cltv_expiry_delta)
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
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(
+ let invoice = create_invoice_from_channelmanager(
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();
+ Some(10_000), "test".to_string(), non_default_invoice_expiry_secs, None,
+ ).unwrap();
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
// If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let custom_min_final_cltv_expiry_delta = Some(50);
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
+ let invoice = create_invoice_from_channelmanager(
nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
- Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
+ Some(10_000), "".into(), 3600,
if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None },
).unwrap();
assert_eq!(invoice.min_final_cltv_expiry_delta(), if with_custom_delta {
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let custom_min_final_cltv_expiry_delta = Some(21);
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
+ let invoice = create_invoice_from_channelmanager(
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,
+ Some(10_000), "".into(), 3600, custom_min_final_cltv_expiry_delta,
).unwrap();
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
}
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let description_hash = Sha256(Hash::hash("Testing description_hash".as_bytes()));
- let invoice = create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(
+ let invoice = create_invoice_from_channelmanager_with_description_hash(
nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
- Some(10_000), description_hash, Duration::from_secs(1234567), 3600, None,
+ Some(10_000), description_hash, 3600, None,
).unwrap();
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let payment_hash = PaymentHash([0; 32]);
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
+ let invoice = create_invoice_from_channelmanager_with_payment_hash(
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,
+ Some(10_000), "test".to_string(), 3600, payment_hash, None,
).unwrap();
assert_eq!(invoice.amount_milli_satoshis(), Some(10_000));
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
invoice_node: &Node<'a, 'b, 'c>,
mut chan_ids_to_match: HashSet<u64>
) {
- let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
+ let invoice = create_invoice_from_channelmanager(
invoice_node.node, invoice_node.keys_manager, invoice_node.logger,
- Currency::BitcoinTestnet, invoice_amt, "test".to_string(), Duration::from_secs(1234567),
- 3600, None).unwrap();
+ Currency::BitcoinTestnet, invoice_amt, "test".to_string(), 3600, None,
+ ).unwrap();
let hints = invoice.private_routes();
for hint in hints {
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
- let result = create_invoice_from_channelmanager_and_duration_since_epoch(
+ let result = create_invoice_from_channelmanager(
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),
+ Some(10_000), "Some description".into(), 3600, Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4),
);
match result {
Err(SignOrCreationError::CreationError(CreationError::MinFinalCltvExpiryDeltaTooShort)) => {},