+ let payment_id = PaymentId(payment_hash.0);
+ self.do_pay_pubkey(pubkey, payment_preimage, payment_hash, payment_id, amount_msats,
+ final_cltv_expiry_delta)
+ .map(|()| payment_id)
+ }
+
+ /// Pays `pubkey` an amount using the hash of the given preimage and a custom idempotency key,
+ /// caching the invoice for later use in case a retry is needed.
+ ///
+ /// Note that idempotency is only guaranteed as long as the payment is still pending. Once the
+ /// payment completes or fails, no idempotency guarantees are made.
+ ///
+ /// You should ensure that the [`PaymentPreimage`] is unique and the corresponding
+ /// [`PaymentHash`] has never been paid before.
+ pub fn pay_pubkey_with_id(
+ &self, pubkey: PublicKey, payment_preimage: PaymentPreimage, payment_id: PaymentId,
+ amount_msats: u64, final_cltv_expiry_delta: u32
+ ) -> Result<(), PaymentError> {
+ let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
+ self.do_pay_pubkey(pubkey, payment_preimage, payment_hash, payment_id, amount_msats,
+ final_cltv_expiry_delta)
+ }
+
+ fn do_pay_pubkey(
+ &self, pubkey: PublicKey, payment_preimage: PaymentPreimage, payment_hash: PaymentHash,
+ payment_id: PaymentId, amount_msats: u64, final_cltv_expiry_delta: u32
+ ) -> Result<(), PaymentError> {