2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_INVOICE_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_INVOICE_H
|
2016-09-06 09:17:49 +02:00
|
|
|
#include "config.h"
|
2023-07-11 21:40:17 +02:00
|
|
|
#include <wallet/wallet.h>
|
2020-09-07 23:06:50 +02:00
|
|
|
#include <wire/onion_wire.h>
|
2019-04-11 02:08:55 +02:00
|
|
|
|
|
|
|
struct amount_msat;
|
2019-12-12 00:55:45 +01:00
|
|
|
struct htlc_set;
|
2023-07-22 09:46:17 +02:00
|
|
|
struct json_escape;
|
2019-04-11 02:08:55 +02:00
|
|
|
struct lightningd;
|
|
|
|
struct sha256;
|
|
|
|
|
2023-07-11 21:42:17 +02:00
|
|
|
/* The information about an invoice */
|
|
|
|
struct invoice_details {
|
|
|
|
/* Current invoice state */
|
|
|
|
enum invoice_status state;
|
|
|
|
/* Preimage for this invoice */
|
|
|
|
struct preimage r;
|
|
|
|
/* Hash of preimage r */
|
|
|
|
struct sha256 rhash;
|
|
|
|
/* Label assigned by user */
|
|
|
|
const struct json_escape *label;
|
|
|
|
/* NULL if they specified "any" */
|
|
|
|
struct amount_msat *msat;
|
|
|
|
/* Absolute UNIX epoch time this will expire */
|
|
|
|
u64 expiry_time;
|
|
|
|
/* Set if state == PAID; order to be returned by waitanyinvoice */
|
|
|
|
u64 pay_index;
|
|
|
|
/* Set if state == PAID; amount received */
|
|
|
|
struct amount_msat received;
|
|
|
|
/* Set if state == PAID; time paid */
|
|
|
|
u64 paid_timestamp;
|
2023-10-26 05:32:13 +02:00
|
|
|
/* Set if state == PAID and invoice paid on chain; outpoint containing the payment */
|
|
|
|
const struct bitcoin_outpoint *paid_outpoint;
|
2023-07-11 21:42:17 +02:00
|
|
|
/* BOLT11 or BOLT12 encoding for this invoice */
|
|
|
|
const char *invstring;
|
|
|
|
|
|
|
|
/* The description of the payment. */
|
|
|
|
char *description;
|
|
|
|
/* The features, if any (tal_arr) */
|
|
|
|
u8 *features;
|
|
|
|
/* The offer this refers to, if any. */
|
|
|
|
struct sha256 *local_offer_id;
|
2023-07-22 12:59:17 +02:00
|
|
|
/* Index values */
|
|
|
|
u64 created_index, updated_index;
|
2023-07-11 21:42:17 +02:00
|
|
|
};
|
2019-12-12 00:55:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* invoice_check_payment - check if this payment would be valid
|
|
|
|
* @ctx: tal context to allocate return off
|
|
|
|
* @ld: lightningd
|
|
|
|
* @payment_hash: hash of preimage they want.
|
|
|
|
* @msat: amount they offer to pay.
|
|
|
|
* @payment_secret: they payment secret they sent, if any.
|
2023-07-22 13:26:16 +02:00
|
|
|
* @err: error string if it returns NULL.
|
2019-12-12 00:55:45 +01:00
|
|
|
*
|
|
|
|
* Returns NULL if there's a problem, otherwise returns the invoice details.
|
|
|
|
*/
|
2023-10-28 02:38:09 +02:00
|
|
|
const struct invoice_details *invoice_check_payment(const tal_t *ctx,
|
|
|
|
struct lightningd *ld,
|
|
|
|
const struct sha256 *payment_hash,
|
|
|
|
const struct amount_msat msat,
|
|
|
|
const struct secret *payment_secret,
|
|
|
|
const char **err);
|
2019-12-12 00:55:45 +01:00
|
|
|
|
2023-10-26 05:32:13 +02:00
|
|
|
/**
|
|
|
|
* invoice_check_onchain_payment - check if this on-chain payment would be valid
|
|
|
|
* @ld: the lightning context
|
|
|
|
* @scriptPubKey: fallback script with which to search for invoices
|
|
|
|
* @sat: output amount
|
|
|
|
* @outpoint: the outpoint which paid it.
|
|
|
|
*/
|
|
|
|
void invoice_check_onchain_payment(struct lightningd *ld,
|
|
|
|
const u8 *scriptPubKey,
|
|
|
|
struct amount_sat sat,
|
|
|
|
const struct bitcoin_outpoint *outpoint);
|
|
|
|
|
2019-04-11 02:08:55 +02:00
|
|
|
/**
|
2019-12-12 00:55:45 +01:00
|
|
|
* invoice_try_pay - process payment for these incoming payments.
|
2019-04-11 02:08:55 +02:00
|
|
|
* @ld: lightningd
|
2023-10-26 05:32:13 +02:00
|
|
|
* @set: the htlc_set used to pay this (NULL if onchain)
|
2019-12-12 00:55:45 +01:00
|
|
|
* @details: returned from successful invoice_check_payment.
|
2023-10-26 05:32:13 +02:00
|
|
|
* @msat: the amount of the output or htlc_set
|
|
|
|
* @outpoint: the onchain outpoint (iff onchain).
|
2019-04-11 02:08:55 +02:00
|
|
|
*
|
2023-10-26 05:32:13 +02:00
|
|
|
* If @set is not NULL, either calls fulfill_htlc_set() or fail_htlc_set().
|
2019-04-11 02:08:55 +02:00
|
|
|
*/
|
|
|
|
void invoice_try_pay(struct lightningd *ld,
|
2019-12-12 00:55:45 +01:00
|
|
|
struct htlc_set *set,
|
2023-10-26 05:32:13 +02:00
|
|
|
const struct invoice_details *details,
|
|
|
|
struct amount_msat msat,
|
|
|
|
const struct bitcoin_outpoint *outpoint);
|
2016-09-06 09:17:49 +02:00
|
|
|
|
2023-07-11 21:40:17 +02:00
|
|
|
/* Simple enum -> string converter for JSON fields */
|
|
|
|
const char *invoice_status_str(enum invoice_status state);
|
|
|
|
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_INVOICE_H */
|