2018-03-22 11:36:25 +01:00
|
|
|
#ifndef LIGHTNING_WALLET_WALLET_H
|
|
|
|
#define LIGHTNING_WALLET_WALLET_H
|
2017-05-23 22:07:20 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "db.h"
|
2023-10-28 05:10:56 +02:00
|
|
|
#include <ccan/crypto/shachain/shachain.h>
|
2023-07-21 02:23:56 +02:00
|
|
|
#include <ccan/rune/rune.h>
|
2023-10-28 05:10:56 +02:00
|
|
|
#include <common/htlc.h>
|
|
|
|
#include <common/htlc_state.h>
|
2022-11-09 02:30:10 +01:00
|
|
|
#include <common/onion_encode.h>
|
2020-05-07 02:42:40 +02:00
|
|
|
#include <common/penalty_base.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/utxo.h>
|
2019-05-23 22:41:27 +02:00
|
|
|
#include <common/wallet.h>
|
2019-08-05 23:16:32 +02:00
|
|
|
#include <lightningd/bitcoind.h>
|
2023-10-02 00:59:50 +02:00
|
|
|
#include <lightningd/channel_state.h>
|
2023-10-28 05:10:56 +02:00
|
|
|
#include <lightningd/forwards.h>
|
2018-08-09 04:27:25 +02:00
|
|
|
#include <lightningd/log.h>
|
2023-07-22 09:51:47 +02:00
|
|
|
#include <lightningd/wait.h>
|
2017-05-23 22:07:20 +02:00
|
|
|
|
2019-02-21 03:38:35 +01:00
|
|
|
struct amount_msat;
|
2018-01-14 15:15:30 +01:00
|
|
|
struct invoices;
|
2018-02-12 11:12:55 +01:00
|
|
|
struct channel;
|
2021-02-04 22:14:44 +01:00
|
|
|
struct channel_inflight;
|
2023-10-28 05:10:56 +02:00
|
|
|
struct htlc_in;
|
|
|
|
struct htlc_in_map;
|
|
|
|
struct htlc_out;
|
|
|
|
struct htlc_out_map;
|
2023-07-11 21:42:17 +02:00
|
|
|
struct json_escape;
|
2017-06-25 04:33:13 +02:00
|
|
|
struct lightningd;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id;
|
2018-01-23 02:02:10 +01:00
|
|
|
struct oneshot;
|
2018-02-12 11:13:04 +01:00
|
|
|
struct peer;
|
2018-01-23 00:53:21 +01:00
|
|
|
struct timers;
|
2023-10-26 04:37:03 +02:00
|
|
|
struct local_anchor_info;
|
2017-06-25 04:33:13 +02:00
|
|
|
|
2017-05-23 22:07:20 +02:00
|
|
|
struct wallet {
|
2018-02-12 11:10:17 +01:00
|
|
|
struct lightningd *ld;
|
2017-05-23 22:07:20 +02:00
|
|
|
struct db *db;
|
2023-07-16 07:56:52 +02:00
|
|
|
struct logger *log;
|
2018-01-14 15:15:30 +01:00
|
|
|
struct invoices *invoices;
|
2018-02-18 13:53:46 +01:00
|
|
|
u64 max_channel_dbid;
|
2018-02-26 14:57:13 +01:00
|
|
|
|
|
|
|
/* Filter matching all outpoints corresponding to our owned outputs,
|
|
|
|
* including all spent ones */
|
|
|
|
struct outpointfilter *owned_outpoints;
|
2018-03-04 01:37:09 +01:00
|
|
|
|
2021-01-07 14:27:54 +01:00
|
|
|
/* Filter matching all outpoints that might be a funding transaction on
|
|
|
|
* the blockchain. This is currently all P2WSH outputs */
|
|
|
|
struct outpointfilter *utxoset_outpoints;
|
|
|
|
|
2020-04-14 15:36:58 +02:00
|
|
|
/* How many keys should we look ahead at most? */
|
|
|
|
u64 keyscan_gap;
|
2019-06-05 09:00:02 +02:00
|
|
|
};
|
|
|
|
|
2018-08-09 04:27:25 +02:00
|
|
|
static inline enum output_status output_status_in_db(enum output_status s)
|
|
|
|
{
|
|
|
|
switch (s) {
|
2020-08-28 05:56:34 +02:00
|
|
|
case OUTPUT_STATE_AVAILABLE:
|
|
|
|
BUILD_ASSERT(OUTPUT_STATE_AVAILABLE == 0);
|
2018-08-09 04:27:25 +02:00
|
|
|
return s;
|
2020-08-28 05:56:34 +02:00
|
|
|
case OUTPUT_STATE_RESERVED:
|
|
|
|
BUILD_ASSERT(OUTPUT_STATE_RESERVED == 1);
|
2018-08-09 04:27:25 +02:00
|
|
|
return s;
|
2020-08-28 05:56:34 +02:00
|
|
|
case OUTPUT_STATE_SPENT:
|
|
|
|
BUILD_ASSERT(OUTPUT_STATE_SPENT == 2);
|
2018-08-09 04:27:25 +02:00
|
|
|
return s;
|
|
|
|
/* This one doesn't go into db */
|
2020-08-28 05:56:34 +02:00
|
|
|
case OUTPUT_STATE_ANY:
|
2018-08-09 04:27:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, s);
|
|
|
|
}
|
|
|
|
|
2017-05-23 22:07:20 +02:00
|
|
|
/* Enumeration of all known output types. These include all types that
|
|
|
|
* could ever end up on-chain and we may need to react upon. Notice
|
|
|
|
* that `to_local`, `htlc_offer`, and `htlc_recv` may need immediate
|
|
|
|
* action since they are encumbered with a CSV. */
|
2018-08-09 04:27:25 +02:00
|
|
|
/* /!\ This is a DB ENUM, please do not change the numbering of any
|
|
|
|
* already defined elements (adding is ok) /!\ */
|
2017-05-23 22:07:20 +02:00
|
|
|
enum wallet_output_type {
|
|
|
|
p2sh_wpkh = 0,
|
|
|
|
to_local = 1,
|
|
|
|
htlc_offer = 3,
|
2017-09-12 13:50:47 +02:00
|
|
|
htlc_recv = 4,
|
2017-12-20 23:05:32 +01:00
|
|
|
our_change = 5,
|
|
|
|
p2wpkh = 6
|
2017-05-23 22:07:20 +02:00
|
|
|
};
|
|
|
|
|
2018-08-09 04:27:25 +02:00
|
|
|
static inline enum wallet_output_type wallet_output_type_in_db(enum wallet_output_type w)
|
|
|
|
{
|
|
|
|
switch (w) {
|
|
|
|
case p2sh_wpkh:
|
|
|
|
BUILD_ASSERT(p2sh_wpkh == 0);
|
|
|
|
return w;
|
|
|
|
case to_local:
|
|
|
|
BUILD_ASSERT(to_local == 1);
|
|
|
|
return w;
|
|
|
|
case htlc_offer:
|
|
|
|
BUILD_ASSERT(htlc_offer == 3);
|
|
|
|
return w;
|
|
|
|
case htlc_recv:
|
|
|
|
BUILD_ASSERT(htlc_recv == 4);
|
|
|
|
return w;
|
|
|
|
case our_change:
|
|
|
|
BUILD_ASSERT(our_change == 5);
|
|
|
|
return w;
|
|
|
|
case p2wpkh:
|
|
|
|
BUILD_ASSERT(p2wpkh == 6);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, w);
|
|
|
|
}
|
|
|
|
|
2018-10-16 19:48:09 +02:00
|
|
|
static inline enum forward_status wallet_forward_status_in_db(enum forward_status s)
|
|
|
|
{
|
|
|
|
switch (s) {
|
|
|
|
case FORWARD_OFFERED:
|
|
|
|
BUILD_ASSERT(FORWARD_OFFERED == 0);
|
|
|
|
return s;
|
|
|
|
case FORWARD_SETTLED:
|
|
|
|
BUILD_ASSERT(FORWARD_SETTLED == 1);
|
|
|
|
return s;
|
|
|
|
case FORWARD_FAILED:
|
|
|
|
BUILD_ASSERT(FORWARD_FAILED == 2);
|
|
|
|
return s;
|
2019-04-15 15:27:02 +02:00
|
|
|
case FORWARD_LOCAL_FAILED:
|
|
|
|
BUILD_ASSERT(FORWARD_LOCAL_FAILED == 3);
|
|
|
|
return s;
|
2021-01-23 18:18:34 +01:00
|
|
|
case FORWARD_ANY:
|
|
|
|
break;
|
2018-10-16 19:48:09 +02:00
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, s);
|
|
|
|
}
|
|
|
|
|
2022-03-31 05:14:27 +02:00
|
|
|
/* Wrapper to ensure types don't change, and we don't insert/extract
|
|
|
|
* invalid ones from db */
|
|
|
|
static inline enum forward_style forward_style_in_db(enum forward_style o)
|
|
|
|
{
|
|
|
|
switch (o) {
|
|
|
|
case FORWARD_STYLE_LEGACY:
|
|
|
|
BUILD_ASSERT(FORWARD_STYLE_LEGACY == 0);
|
|
|
|
return o;
|
|
|
|
case FORWARD_STYLE_TLV:
|
|
|
|
BUILD_ASSERT(FORWARD_STYLE_TLV == 1);
|
|
|
|
return o;
|
|
|
|
case FORWARD_STYLE_UNKNOWN:
|
|
|
|
/* Not recorded in DB! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, o);
|
|
|
|
}
|
|
|
|
|
2021-10-13 05:42:43 +02:00
|
|
|
/* DB wrapper to check htlc_state */
|
|
|
|
static inline enum htlc_state htlc_state_in_db(enum htlc_state s)
|
|
|
|
{
|
|
|
|
switch (s) {
|
|
|
|
case SENT_ADD_HTLC:
|
|
|
|
BUILD_ASSERT(SENT_ADD_HTLC == 0);
|
|
|
|
return s;
|
|
|
|
case SENT_ADD_COMMIT:
|
|
|
|
BUILD_ASSERT(SENT_ADD_COMMIT == 1);
|
|
|
|
return s;
|
|
|
|
case RCVD_ADD_REVOCATION:
|
|
|
|
BUILD_ASSERT(RCVD_ADD_REVOCATION == 2);
|
|
|
|
return s;
|
|
|
|
case RCVD_ADD_ACK_COMMIT:
|
|
|
|
BUILD_ASSERT(RCVD_ADD_ACK_COMMIT == 3);
|
|
|
|
return s;
|
|
|
|
case SENT_ADD_ACK_REVOCATION:
|
|
|
|
BUILD_ASSERT(SENT_ADD_ACK_REVOCATION == 4);
|
|
|
|
return s;
|
|
|
|
case RCVD_REMOVE_HTLC:
|
|
|
|
BUILD_ASSERT(RCVD_REMOVE_HTLC == 5);
|
|
|
|
return s;
|
|
|
|
case RCVD_REMOVE_COMMIT:
|
|
|
|
BUILD_ASSERT(RCVD_REMOVE_COMMIT == 6);
|
|
|
|
return s;
|
|
|
|
case SENT_REMOVE_REVOCATION:
|
|
|
|
BUILD_ASSERT(SENT_REMOVE_REVOCATION == 7);
|
|
|
|
return s;
|
|
|
|
case SENT_REMOVE_ACK_COMMIT:
|
|
|
|
BUILD_ASSERT(SENT_REMOVE_ACK_COMMIT == 8);
|
|
|
|
return s;
|
|
|
|
case RCVD_REMOVE_ACK_REVOCATION:
|
|
|
|
BUILD_ASSERT(RCVD_REMOVE_ACK_REVOCATION == 9);
|
|
|
|
return s;
|
|
|
|
case RCVD_ADD_HTLC:
|
|
|
|
BUILD_ASSERT(RCVD_ADD_HTLC == 10);
|
|
|
|
return s;
|
|
|
|
case RCVD_ADD_COMMIT:
|
|
|
|
BUILD_ASSERT(RCVD_ADD_COMMIT == 11);
|
|
|
|
return s;
|
|
|
|
case SENT_ADD_REVOCATION:
|
|
|
|
BUILD_ASSERT(SENT_ADD_REVOCATION == 12);
|
|
|
|
return s;
|
|
|
|
case SENT_ADD_ACK_COMMIT:
|
|
|
|
BUILD_ASSERT(SENT_ADD_ACK_COMMIT == 13);
|
|
|
|
return s;
|
|
|
|
case RCVD_ADD_ACK_REVOCATION:
|
|
|
|
BUILD_ASSERT(RCVD_ADD_ACK_REVOCATION == 14);
|
|
|
|
return s;
|
|
|
|
case SENT_REMOVE_HTLC:
|
|
|
|
BUILD_ASSERT(SENT_REMOVE_HTLC == 15);
|
|
|
|
return s;
|
|
|
|
case SENT_REMOVE_COMMIT:
|
|
|
|
BUILD_ASSERT(SENT_REMOVE_COMMIT == 16);
|
|
|
|
return s;
|
|
|
|
case RCVD_REMOVE_REVOCATION:
|
|
|
|
BUILD_ASSERT(RCVD_REMOVE_REVOCATION == 17);
|
|
|
|
return s;
|
|
|
|
case RCVD_REMOVE_ACK_COMMIT:
|
|
|
|
BUILD_ASSERT(RCVD_REMOVE_ACK_COMMIT == 18);
|
|
|
|
return s;
|
|
|
|
case SENT_REMOVE_ACK_REVOCATION:
|
|
|
|
BUILD_ASSERT(SENT_REMOVE_ACK_REVOCATION == 19);
|
|
|
|
return s;
|
|
|
|
case HTLC_STATE_INVALID:
|
|
|
|
/* Not in db! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, s);
|
|
|
|
}
|
|
|
|
|
2023-10-02 00:59:50 +02:00
|
|
|
/* DB wrapper to check channel_state */
|
|
|
|
static inline enum channel_state channel_state_in_db(enum channel_state s)
|
|
|
|
{
|
|
|
|
switch (s) {
|
|
|
|
case CHANNELD_AWAITING_LOCKIN:
|
|
|
|
BUILD_ASSERT(CHANNELD_AWAITING_LOCKIN == 2);
|
|
|
|
return s;
|
|
|
|
case CHANNELD_NORMAL:
|
|
|
|
BUILD_ASSERT(CHANNELD_NORMAL == 3);
|
|
|
|
return s;
|
|
|
|
case CHANNELD_SHUTTING_DOWN:
|
|
|
|
BUILD_ASSERT(CHANNELD_SHUTTING_DOWN == 4);
|
|
|
|
return s;
|
|
|
|
case CLOSINGD_SIGEXCHANGE:
|
|
|
|
BUILD_ASSERT(CLOSINGD_SIGEXCHANGE == 5);
|
|
|
|
return s;
|
|
|
|
case CLOSINGD_COMPLETE:
|
|
|
|
BUILD_ASSERT(CLOSINGD_COMPLETE == 6);
|
|
|
|
return s;
|
|
|
|
case AWAITING_UNILATERAL:
|
|
|
|
BUILD_ASSERT(AWAITING_UNILATERAL == 7);
|
|
|
|
return s;
|
|
|
|
case FUNDING_SPEND_SEEN:
|
|
|
|
BUILD_ASSERT(FUNDING_SPEND_SEEN == 8);
|
|
|
|
return s;
|
|
|
|
case ONCHAIN:
|
|
|
|
BUILD_ASSERT(ONCHAIN == 9);
|
|
|
|
return s;
|
|
|
|
case CLOSED:
|
|
|
|
BUILD_ASSERT(CLOSED == 10);
|
|
|
|
return s;
|
2023-10-02 00:59:51 +02:00
|
|
|
case DUALOPEND_OPEN_COMMITTED:
|
|
|
|
BUILD_ASSERT(DUALOPEND_OPEN_COMMITTED == 11);
|
2023-10-02 00:59:50 +02:00
|
|
|
return s;
|
2023-10-31 01:38:11 +01:00
|
|
|
case DUALOPEND_OPEN_COMMIT_READY:
|
|
|
|
BUILD_ASSERT(DUALOPEND_OPEN_COMMIT_READY == 14);
|
|
|
|
return s;
|
2023-10-02 00:59:50 +02:00
|
|
|
case DUALOPEND_AWAITING_LOCKIN:
|
|
|
|
BUILD_ASSERT(DUALOPEND_AWAITING_LOCKIN == 12);
|
|
|
|
return s;
|
|
|
|
case CHANNELD_AWAITING_SPLICE:
|
|
|
|
BUILD_ASSERT(CHANNELD_AWAITING_SPLICE == 13);
|
|
|
|
return s;
|
2023-10-02 00:59:51 +02:00
|
|
|
case DUALOPEND_OPEN_INIT:
|
|
|
|
/* Never appears in db! */
|
|
|
|
break;
|
2023-10-02 00:59:50 +02:00
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, s);
|
|
|
|
}
|
|
|
|
|
2024-11-10 04:04:47 +01:00
|
|
|
/* /!\ This is a DB ENUM, please do not change the numbering of any
|
|
|
|
* already defined elements (adding is ok) /!\ */
|
|
|
|
enum addrtype {
|
|
|
|
ADDR_BECH32 = 2,
|
|
|
|
ADDR_P2TR = 4,
|
|
|
|
ADDR_ALL = (ADDR_BECH32 + ADDR_P2TR)
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline enum addrtype wallet_addrtype_in_db(enum addrtype t)
|
|
|
|
{
|
|
|
|
switch (t) {
|
|
|
|
case ADDR_BECH32:
|
|
|
|
BUILD_ASSERT(ADDR_BECH32 == 2);
|
|
|
|
return t;
|
|
|
|
case ADDR_P2TR:
|
|
|
|
BUILD_ASSERT(ADDR_P2TR == 4);
|
|
|
|
return t;
|
|
|
|
case ADDR_ALL:
|
|
|
|
BUILD_ASSERT(ADDR_ALL == 6);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, t);
|
|
|
|
}
|
|
|
|
|
2017-07-18 19:01:26 +02:00
|
|
|
/* A database backed shachain struct. The datastructure is
|
|
|
|
* writethrough, reads are performed from an in-memory version, all
|
|
|
|
* writes are passed through to the DB. */
|
|
|
|
struct wallet_shachain {
|
|
|
|
u64 id;
|
|
|
|
struct shachain chain;
|
|
|
|
};
|
|
|
|
|
2023-07-11 21:41:17 +02:00
|
|
|
/* Possible states for a payment. Payments start in
|
2017-11-01 13:27:50 +01:00
|
|
|
* `PENDING`. Outgoing payments are set to `PAYMENT_COMPLETE` once we
|
|
|
|
* get the preimage matching the rhash, or to
|
2018-01-17 21:22:22 +01:00
|
|
|
* `PAYMENT_FAILED`. */
|
2017-11-01 13:27:50 +01:00
|
|
|
/* /!\ This is a DB ENUM, please do not change the numbering of any
|
2018-07-27 12:55:37 +02:00
|
|
|
* already defined elements (adding is ok but you should append the
|
2023-07-11 21:41:17 +02:00
|
|
|
* test case test_payment_status_enum() ) /!\ */
|
|
|
|
enum payment_status {
|
2017-11-01 13:27:50 +01:00
|
|
|
PAYMENT_PENDING = 0,
|
|
|
|
PAYMENT_COMPLETE = 1,
|
|
|
|
PAYMENT_FAILED = 2
|
|
|
|
};
|
|
|
|
|
2019-10-02 19:36:28 +02:00
|
|
|
struct tx_annotation {
|
|
|
|
enum wallet_tx_type type;
|
|
|
|
struct short_channel_id channel;
|
|
|
|
};
|
|
|
|
|
2023-07-11 21:41:17 +02:00
|
|
|
static inline enum payment_status payment_status_in_db(enum payment_status w)
|
2018-08-09 04:27:25 +02:00
|
|
|
{
|
|
|
|
switch (w) {
|
|
|
|
case PAYMENT_PENDING:
|
|
|
|
BUILD_ASSERT(PAYMENT_PENDING == 0);
|
|
|
|
return w;
|
|
|
|
case PAYMENT_COMPLETE:
|
|
|
|
BUILD_ASSERT(PAYMENT_COMPLETE == 1);
|
|
|
|
return w;
|
|
|
|
case PAYMENT_FAILED:
|
|
|
|
BUILD_ASSERT(PAYMENT_FAILED == 2);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, w);
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:22:22 +01:00
|
|
|
/* Outgoing payments. A simple persisted representation
|
|
|
|
* of a payment we initiated. This can be used by
|
|
|
|
* a UI (alongside invoices) to display the balance history.
|
2017-11-01 13:27:50 +01:00
|
|
|
*/
|
|
|
|
struct wallet_payment {
|
|
|
|
u64 id;
|
|
|
|
u32 timestamp;
|
2022-06-09 18:36:00 +02:00
|
|
|
u32 *completed_at;
|
2019-12-12 00:16:23 +01:00
|
|
|
|
2021-09-28 17:32:50 +02:00
|
|
|
/* The combination of these three fields is unique: */
|
2017-11-01 13:27:50 +01:00
|
|
|
struct sha256 payment_hash;
|
2019-12-12 00:16:23 +01:00
|
|
|
u64 partid;
|
2021-09-28 17:32:50 +02:00
|
|
|
u64 groupid;
|
2019-12-12 00:16:23 +01:00
|
|
|
|
2023-07-11 21:41:17 +02:00
|
|
|
enum payment_status status;
|
2019-11-07 23:13:29 +01:00
|
|
|
|
2023-10-28 05:09:15 +02:00
|
|
|
u64 updated_index;
|
2019-11-07 23:13:29 +01:00
|
|
|
/* The destination may not be known if we used `sendonion` */
|
|
|
|
struct node_id *destination;
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat msatoshi;
|
|
|
|
struct amount_msat msatoshi_sent;
|
2019-12-12 00:16:23 +01:00
|
|
|
struct amount_msat total_msat;
|
2018-01-29 05:46:54 +01:00
|
|
|
/* If and only if PAYMENT_COMPLETE */
|
2018-01-17 21:29:49 +01:00
|
|
|
struct preimage *payment_preimage;
|
2018-01-20 15:00:35 +01:00
|
|
|
/* Needed for recovering from routing failures. */
|
2018-01-17 21:29:49 +01:00
|
|
|
struct secret *path_secrets;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id *route_nodes;
|
2018-01-20 15:00:35 +01:00
|
|
|
struct short_channel_id *route_channels;
|
2020-12-14 02:24:37 +01:00
|
|
|
/* bolt11/bolt12 string; NULL for old payments. */
|
|
|
|
const char *invstring;
|
2018-07-20 15:10:01 +02:00
|
|
|
|
2019-02-23 04:11:14 +01:00
|
|
|
/* The label of the payment. Must support `tal_len` */
|
|
|
|
const char *label;
|
2019-11-11 19:38:27 +01:00
|
|
|
|
2022-04-02 04:33:35 +02:00
|
|
|
/* The description of the payment (used if invstring has hash). */
|
|
|
|
const char *description;
|
|
|
|
|
2019-11-11 19:38:27 +01:00
|
|
|
/* If we could not decode the fail onion, just add it here. */
|
|
|
|
const u8 *failonion;
|
2020-12-14 02:20:44 +01:00
|
|
|
|
2022-11-09 03:32:01 +01:00
|
|
|
/* If we are associated with an internal invoice_request */
|
|
|
|
struct sha256 *local_invreq_id;
|
2017-11-01 13:27:50 +01:00
|
|
|
};
|
|
|
|
|
2018-03-05 23:15:54 +01:00
|
|
|
struct outpoint {
|
2021-10-13 05:45:36 +02:00
|
|
|
struct bitcoin_outpoint outpoint;
|
2018-03-05 23:15:54 +01:00
|
|
|
u32 blockheight;
|
|
|
|
u32 txindex;
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat sat;
|
2018-03-05 23:15:54 +01:00
|
|
|
u8 *scriptpubkey;
|
|
|
|
u32 spendheight;
|
|
|
|
};
|
|
|
|
|
2018-04-03 16:57:28 +02:00
|
|
|
struct channeltx {
|
2018-04-03 16:45:06 +02:00
|
|
|
u32 channel_id;
|
|
|
|
int type;
|
|
|
|
u32 blockheight;
|
|
|
|
struct bitcoin_txid txid;
|
|
|
|
struct bitcoin_tx *tx;
|
|
|
|
u32 input_num;
|
|
|
|
u32 depth;
|
|
|
|
};
|
|
|
|
|
2019-05-28 22:36:15 +02:00
|
|
|
struct wallet_transaction {
|
|
|
|
struct bitcoin_txid id;
|
|
|
|
u32 blockheight;
|
|
|
|
u32 txindex;
|
|
|
|
u8 *rawtx;
|
2019-10-02 19:36:28 +02:00
|
|
|
|
|
|
|
/* Fully parsed transaction */
|
|
|
|
const struct bitcoin_tx *tx;
|
2019-05-28 22:36:15 +02:00
|
|
|
};
|
|
|
|
|
2017-05-23 22:07:20 +02:00
|
|
|
/**
|
2019-08-20 09:54:38 +02:00
|
|
|
* wallet_new - Constructor for a new DB based wallet
|
2017-05-23 22:07:20 +02:00
|
|
|
*
|
|
|
|
* This is guaranteed to either return a valid wallet, or abort with
|
|
|
|
* `fatal` if it cannot be initialized.
|
|
|
|
*/
|
2023-03-21 04:58:15 +01:00
|
|
|
struct wallet *wallet_new(struct lightningd *ld, struct timers *timers);
|
2017-05-23 22:07:20 +02:00
|
|
|
|
2018-08-13 05:03:08 +02:00
|
|
|
/**
|
|
|
|
* wallet_confirm_tx - Confirm a tx which contains a UTXO.
|
|
|
|
*/
|
|
|
|
void wallet_confirm_tx(struct wallet *w,
|
|
|
|
const struct bitcoin_txid *txid,
|
|
|
|
const u32 confirmation_height);
|
|
|
|
|
2017-05-31 16:16:59 +02:00
|
|
|
/**
|
|
|
|
* wallet_update_output_status - Perform an output state transition
|
|
|
|
*
|
|
|
|
* Change the current status of an output we are tracking in the
|
|
|
|
* database. Returns true if the output exists with the @oldstatus and
|
|
|
|
* was successfully updated to @newstatus. May fail if either the
|
|
|
|
* output does not exist, or it does not have the expected
|
|
|
|
* @oldstatus. In case we don't care about the previous state use
|
|
|
|
* `output_state_any` as @oldstatus.
|
|
|
|
*/
|
|
|
|
bool wallet_update_output_status(struct wallet *w,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *outpoint,
|
|
|
|
enum output_status oldstatus,
|
2017-05-31 16:16:59 +02:00
|
|
|
enum output_status newstatus);
|
|
|
|
|
2017-06-05 13:59:51 +02:00
|
|
|
/**
|
2023-10-30 06:19:59 +01:00
|
|
|
* wallet_get_all_utxos - Return all utxos, including spent ones.
|
2017-06-05 13:59:51 +02:00
|
|
|
*
|
|
|
|
* Returns a `tal_arr` of `utxo` structs. Double indirection in order
|
|
|
|
* to be able to steal individual elements onto something else.
|
|
|
|
*/
|
2023-10-30 06:19:59 +01:00
|
|
|
struct utxo **wallet_get_all_utxos(const tal_t *ctx, struct wallet *w);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_get_unspent_utxos - Return reserved and unreserved UTXOs.
|
|
|
|
*
|
|
|
|
* Returns a `tal_arr` of `utxo` structs. Double indirection in order
|
|
|
|
* to be able to steal individual elements onto something else.
|
|
|
|
*
|
|
|
|
* Use utxo_is_reserved() to test if it's reserved.
|
|
|
|
*/
|
|
|
|
struct utxo **wallet_get_unspent_utxos(const tal_t *ctx, struct wallet *w);
|
2017-06-05 13:59:51 +02:00
|
|
|
|
2018-08-13 05:02:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_get_unconfirmed_closeinfo_utxos - Retrieve any unconfirmed utxos w/ closeinfo
|
|
|
|
*
|
|
|
|
* Returns a `tal_arr` of `utxo` structs. Double indirection in order
|
|
|
|
* to be able to steal individual elements onto something else.
|
|
|
|
*/
|
|
|
|
struct utxo **wallet_get_unconfirmed_closeinfo_utxos(const tal_t *ctx,
|
|
|
|
struct wallet *w);
|
|
|
|
|
2020-07-15 07:30:49 +02:00
|
|
|
/**
|
|
|
|
* wallet_find_utxo - Select an available UTXO (does not reserve it!).
|
|
|
|
* @ctx: tal context
|
|
|
|
* @w: wallet
|
|
|
|
* @current_blockheight: current chain length.
|
|
|
|
* @amount_we_are_short: optional amount.
|
|
|
|
* @feerate_per_kw: feerate we are using.
|
|
|
|
* @maxheight: zero (if caller doesn't care) or maximum blockheight to accept.
|
2022-10-26 18:58:10 +02:00
|
|
|
* @nonwrapped: filter out p2sh-wrapped inputs
|
2020-07-15 07:30:49 +02:00
|
|
|
* @excludes: UTXOs not to consider.
|
|
|
|
*
|
|
|
|
* If @amount_we_are_short is not NULL, we try to get something very close
|
|
|
|
* (i.e. when we add this input, we will add => @amount_we_are_short, but
|
|
|
|
* less than @amount_we_are_short + dustlimit).
|
|
|
|
*
|
|
|
|
* Otherwise we give a random UTXO.
|
|
|
|
*/
|
|
|
|
struct utxo *wallet_find_utxo(const tal_t *ctx, struct wallet *w,
|
|
|
|
unsigned current_blockheight,
|
|
|
|
struct amount_sat *amount_we_are_short,
|
|
|
|
unsigned feerate_per_kw,
|
|
|
|
u32 maxheight,
|
2022-10-26 18:58:10 +02:00
|
|
|
bool nonwrapped,
|
2020-07-15 07:30:49 +02:00
|
|
|
const struct utxo **excludes);
|
|
|
|
|
2023-06-29 02:14:10 +02:00
|
|
|
/**
|
|
|
|
* wallet_has_funds: do we have sufficient other UTXOs for this amount?
|
|
|
|
* @w: the wallet
|
|
|
|
* @excludes: the utxos not to count (tal_arr or NULL)
|
|
|
|
* @current_blockheight: current chain length.
|
2024-02-04 17:18:01 +01:00
|
|
|
* @needed: the target, reduced if we find some funds
|
2023-06-29 02:14:10 +02:00
|
|
|
*
|
|
|
|
* This is a gross estimate, since it doesn't take into account the fees we
|
|
|
|
* would need to actually spend these utxos!
|
|
|
|
*/
|
|
|
|
bool wallet_has_funds(struct wallet *wallet,
|
|
|
|
const struct utxo **excludes,
|
|
|
|
u32 current_blockheight,
|
2024-02-04 17:18:01 +01:00
|
|
|
struct amount_sat *needed);
|
2023-10-19 07:59:35 +02:00
|
|
|
|
2020-07-06 07:28:43 +02:00
|
|
|
/**
|
|
|
|
* wallet_add_onchaind_utxo - Add a UTXO with spending info from onchaind.
|
|
|
|
*
|
|
|
|
* Usually we add UTXOs by looking at transactions, but onchaind tells
|
|
|
|
* us about other UTXOs we can spend with some extra metadata.
|
|
|
|
*
|
|
|
|
* Returns false if we already have it in db (that's fine).
|
|
|
|
*/
|
|
|
|
bool wallet_add_onchaind_utxo(struct wallet *w,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *outpoint,
|
2020-07-06 07:28:43 +02:00
|
|
|
const u8 *scriptpubkey,
|
|
|
|
u32 blockheight,
|
|
|
|
struct amount_sat amount,
|
|
|
|
const struct channel *chan,
|
|
|
|
/* NULL if option_static_remotekey */
|
2021-07-02 21:54:40 +02:00
|
|
|
const struct pubkey *commitment_point,
|
|
|
|
/* option_will_fund makes the csv_lock variable */
|
|
|
|
u32 csv_lock);
|
2020-07-06 07:28:43 +02:00
|
|
|
|
2020-07-14 21:30:26 +02:00
|
|
|
/**
|
|
|
|
* wallet_reserve_utxo - set a reservation on a UTXO.
|
|
|
|
*
|
2021-05-26 03:19:37 +02:00
|
|
|
* If the reservation is already reserved:
|
|
|
|
* refreshes the reservation by @reserve, return true.
|
|
|
|
* Otherwise if it's available:
|
|
|
|
* reserves until @current_height + @reserve, returns true.
|
|
|
|
* Otherwise:
|
|
|
|
* returns false.
|
2020-07-14 21:30:26 +02:00
|
|
|
*/
|
|
|
|
bool wallet_reserve_utxo(struct wallet *w,
|
|
|
|
struct utxo *utxo,
|
2021-05-26 03:19:37 +02:00
|
|
|
u32 current_height,
|
|
|
|
u32 reserve);
|
2020-07-14 21:30:26 +02:00
|
|
|
|
|
|
|
/* wallet_unreserve_utxo - make a reserved UTXO available again.
|
|
|
|
*
|
|
|
|
* Must be reserved.
|
|
|
|
*/
|
|
|
|
void wallet_unreserve_utxo(struct wallet *w, struct utxo *utxo,
|
2021-05-26 03:19:37 +02:00
|
|
|
u32 current_height, u32 unreserve);
|
2020-07-14 21:30:26 +02:00
|
|
|
|
2020-04-03 23:56:57 +02:00
|
|
|
/** wallet_utxo_get - Retrive a utxo.
|
|
|
|
*
|
|
|
|
* Returns a utxo, or NULL if not found.
|
|
|
|
*/
|
|
|
|
struct utxo *wallet_utxo_get(const tal_t *ctx, struct wallet *w,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *outpoint);
|
2020-04-03 23:56:57 +02:00
|
|
|
|
2023-10-30 06:21:59 +01:00
|
|
|
/**
|
|
|
|
* wallet_utxo_boost - get (unreserved) utxos to meet a given feerate.
|
|
|
|
* @ctx: context to tal return array from
|
|
|
|
* @w: the wallet
|
|
|
|
* @blockheight: current height (to determine reserved status)
|
|
|
|
* @fee_amount: amount already paying in fees
|
|
|
|
* @feerate_target: feerate we want, in perkw.
|
|
|
|
* @weight: (in)existing weight before any utxos added, (out)final weight with utxos added.
|
|
|
|
*
|
|
|
|
* May not meet the feerate, but will spend all available utxos to try.
|
|
|
|
* You may also need to create change, as it may exceed.
|
|
|
|
*/
|
|
|
|
struct utxo **wallet_utxo_boost(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
u32 blockheight,
|
|
|
|
struct amount_sat fee_amount,
|
|
|
|
u32 feerate_target,
|
|
|
|
size_t *weight);
|
|
|
|
|
2021-12-09 19:05:58 +01:00
|
|
|
/**
|
|
|
|
* wallet_can_spend - Do we have the private key matching this scriptpubkey?
|
|
|
|
*
|
|
|
|
* FIXME: This is very slow with lots of inputs!
|
|
|
|
*
|
|
|
|
* @w: (in) wallet holding the pubkeys to check against (privkeys are on HSM)
|
|
|
|
* @script: (in) the script to check
|
|
|
|
* @index: (out) the bip32 derivation index that matched the script
|
|
|
|
*/
|
2024-02-21 22:03:48 +01:00
|
|
|
bool wallet_can_spend(struct wallet *w,
|
|
|
|
const u8 *script,
|
|
|
|
u32 *index);
|
2021-12-09 19:05:58 +01:00
|
|
|
|
2017-06-25 04:33:13 +02:00
|
|
|
/**
|
|
|
|
* wallet_get_newindex - get a new index from the wallet.
|
|
|
|
* @ld: (in) lightning daemon
|
2024-11-10 04:04:47 +01:00
|
|
|
* @addrtype: (in) addess types we will publish for this
|
2017-06-25 04:33:13 +02:00
|
|
|
*
|
|
|
|
* Returns -1 on error (key exhaustion).
|
|
|
|
*/
|
2024-11-10 04:04:47 +01:00
|
|
|
s64 wallet_get_newindex(struct lightningd *ld, enum addrtype addrtype);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_get_addrtype - get the address types for this key.
|
|
|
|
* @wallet: (in) wallet
|
|
|
|
* @keyidx: what address types we've published.
|
|
|
|
*/
|
|
|
|
enum addrtype wallet_get_addrtype(struct wallet *w, u64 keyidx);
|
2017-06-25 04:33:13 +02:00
|
|
|
|
2017-07-18 19:01:26 +02:00
|
|
|
/**
|
|
|
|
* wallet_shachain_add_hash -- wallet wrapper around shachain_add_hash
|
|
|
|
*/
|
|
|
|
bool wallet_shachain_add_hash(struct wallet *wallet,
|
|
|
|
struct wallet_shachain *chain,
|
2017-08-18 06:43:53 +02:00
|
|
|
uint64_t index,
|
2018-07-09 13:17:58 +02:00
|
|
|
const struct secret *hash);
|
2017-07-18 19:01:26 +02:00
|
|
|
|
2018-02-18 13:53:46 +01:00
|
|
|
/**
|
|
|
|
* wallet_get_uncommitted_channel_dbid -- get a unique channel dbid
|
|
|
|
*
|
|
|
|
* @wallet: the wallet
|
|
|
|
*/
|
|
|
|
u64 wallet_get_channel_dbid(struct wallet *wallet);
|
|
|
|
|
2023-04-14 00:06:38 +02:00
|
|
|
void wallet_htlcsigs_confirm_inflight(struct wallet *w, struct channel *chan,
|
2023-07-27 23:37:52 +02:00
|
|
|
const struct bitcoin_outpoint *confirmed_outpoint);
|
2023-04-14 00:06:38 +02:00
|
|
|
|
2017-08-05 12:26:18 +02:00
|
|
|
/**
|
|
|
|
* wallet_channel_save -- Upsert the channel into the database
|
|
|
|
*
|
|
|
|
* @wallet: the wallet to save into
|
|
|
|
* @chan: the instance to store (not const so we can update the unique_id upon
|
|
|
|
* insert)
|
|
|
|
*/
|
2018-02-12 11:12:55 +01:00
|
|
|
void wallet_channel_save(struct wallet *w, struct channel *chan);
|
2017-08-05 14:45:42 +02:00
|
|
|
|
2024-04-14 11:43:15 +02:00
|
|
|
/**
|
|
|
|
* wallet_channels_by_dbid -- Check if an ID is preoccupied inside the `channels` table
|
|
|
|
*
|
|
|
|
* @wallet: the wallet
|
|
|
|
* @dbid: the ID at which we want to check the value.
|
|
|
|
*
|
|
|
|
* Returns `true` if it is occupied, false otherwise.
|
|
|
|
*/
|
|
|
|
bool channel_exists_by_id(struct wallet *w, u64 dbid);
|
|
|
|
|
2018-02-18 13:53:46 +01:00
|
|
|
/**
|
|
|
|
* wallet_channel_insert -- Insert the initial channel into the database
|
|
|
|
*
|
|
|
|
* @wallet: the wallet to save into
|
|
|
|
* @chan: the instance to store
|
|
|
|
*/
|
|
|
|
void wallet_channel_insert(struct wallet *w, struct channel *chan);
|
|
|
|
|
2021-02-04 22:14:44 +01:00
|
|
|
/**
|
|
|
|
* Save an inflight transaction for a channel
|
|
|
|
*/
|
|
|
|
void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight);
|
|
|
|
|
2024-01-22 23:33:47 +01:00
|
|
|
/**
|
|
|
|
* Delete an inflight transaction for a channel
|
|
|
|
*/
|
2024-02-10 18:36:54 +01:00
|
|
|
void wallet_inflight_del(struct wallet *w, const struct channel *chan,
|
|
|
|
const struct channel_inflight *inflight);
|
2024-01-22 23:33:47 +01:00
|
|
|
|
2021-02-04 22:14:44 +01:00
|
|
|
/**
|
|
|
|
* Update an existing inflight channel transaction
|
|
|
|
*/
|
|
|
|
void wallet_inflight_save(struct wallet *w,
|
|
|
|
struct channel_inflight *inflight);
|
|
|
|
|
2023-10-27 21:16:23 +02:00
|
|
|
/**
|
|
|
|
* Remove any channel inflights that are incomplete.
|
|
|
|
*/
|
|
|
|
void wallet_channel_inflight_cleanup_incomplete(struct wallet *w,
|
|
|
|
u64 wallet_id);
|
|
|
|
|
2021-05-20 23:52:42 +02:00
|
|
|
/**
|
|
|
|
* Remove all the inflights from a channel. Also cleans up
|
|
|
|
* the channel's inflight list
|
|
|
|
*/
|
|
|
|
void wallet_channel_clear_inflights(struct wallet *w,
|
|
|
|
struct channel *chan);
|
2018-01-23 14:48:09 +01:00
|
|
|
/**
|
2019-06-22 15:08:21 +02:00
|
|
|
* After fully resolving a channel, only keep a lightweight stub
|
2018-01-23 14:48:09 +01:00
|
|
|
*/
|
2019-06-22 15:08:21 +02:00
|
|
|
void wallet_channel_close(struct wallet *w, u64 wallet_id);
|
2018-02-14 02:53:04 +01:00
|
|
|
|
2020-10-28 11:46:22 +01:00
|
|
|
/**
|
|
|
|
* Adds a channel state change history entry into the database
|
|
|
|
*/
|
|
|
|
void wallet_state_change_add(struct wallet *w,
|
|
|
|
const u64 channel_id,
|
2023-10-02 00:59:50 +02:00
|
|
|
struct timeabs timestamp,
|
2020-10-28 11:46:22 +01:00
|
|
|
enum channel_state old_state,
|
|
|
|
enum channel_state new_state,
|
|
|
|
enum state_change cause,
|
2023-10-02 00:59:50 +02:00
|
|
|
const char *message);
|
2020-10-28 11:46:22 +01:00
|
|
|
|
2018-02-14 02:53:04 +01:00
|
|
|
/**
|
2023-03-20 01:15:35 +01:00
|
|
|
* wallet_delete_peer_if_unused -- After no more channels in peer, forget about it
|
2018-02-14 02:53:04 +01:00
|
|
|
*/
|
2023-03-20 01:15:35 +01:00
|
|
|
void wallet_delete_peer_if_unused(struct wallet *w, u64 peer_dbid);
|
2018-01-23 14:48:09 +01:00
|
|
|
|
2017-08-17 15:30:24 +02:00
|
|
|
/**
|
2019-08-09 18:01:31 +02:00
|
|
|
* wallet_init_channels -- Loads active channels into peers
|
|
|
|
* and inits the dbid counter for next channel.
|
2017-08-17 15:30:24 +02:00
|
|
|
*
|
2019-08-09 18:01:31 +02:00
|
|
|
* @w: wallet to load from
|
2017-08-17 15:30:24 +02:00
|
|
|
*
|
|
|
|
* Be sure to call this only once on startup since it'll append peers
|
|
|
|
* loaded from the database to the list without checking.
|
|
|
|
*/
|
2019-08-09 18:01:31 +02:00
|
|
|
bool wallet_init_channels(struct wallet *w);
|
2017-08-17 15:30:24 +02:00
|
|
|
|
2023-03-20 01:19:15 +01:00
|
|
|
/**
|
|
|
|
* wallet_load_closed_channels -- Loads dead channels.
|
|
|
|
* @ctx: context to allocate returned array from
|
|
|
|
* @w: wallet to load from
|
|
|
|
*
|
|
|
|
* These will be all state CLOSED.
|
|
|
|
*/
|
|
|
|
struct closed_channel **wallet_load_closed_channels(const tal_t *ctx,
|
|
|
|
struct wallet *w);
|
|
|
|
|
2018-03-24 09:26:08 +01:00
|
|
|
/**
|
|
|
|
* wallet_channel_stats_incr_* - Increase channel statistics.
|
|
|
|
*
|
|
|
|
* @w: wallet containing the channel
|
|
|
|
* @cdbid: channel database id
|
|
|
|
* @msatoshi: amount in msatoshi being transferred
|
|
|
|
*/
|
2019-02-21 04:45:55 +01:00
|
|
|
void wallet_channel_stats_incr_in_offered(struct wallet *w, u64 cdbid, struct amount_msat msatoshi);
|
|
|
|
void wallet_channel_stats_incr_in_fulfilled(struct wallet *w, u64 cdbid, struct amount_msat msatoshi);
|
|
|
|
void wallet_channel_stats_incr_out_offered(struct wallet *w, u64 cdbid, struct amount_msat msatoshi);
|
|
|
|
void wallet_channel_stats_incr_out_fulfilled(struct wallet *w, u64 cdbid, struct amount_msat msatoshi);
|
2018-03-24 09:26:08 +01:00
|
|
|
|
2018-01-03 06:26:30 +01:00
|
|
|
/**
|
2018-04-20 14:44:34 +02:00
|
|
|
* Retrieve the blockheight of the last block processed by lightningd.
|
|
|
|
*
|
2024-06-22 17:09:33 +02:00
|
|
|
* Will return the 0 if the wallet was never used before.
|
2018-01-03 06:26:30 +01:00
|
|
|
*
|
|
|
|
* @w: wallet to load from.
|
|
|
|
*/
|
2024-06-22 17:09:33 +02:00
|
|
|
u32 wallet_blocks_maxheight(struct wallet *w);
|
2018-01-03 06:26:30 +01:00
|
|
|
|
2017-09-01 14:33:21 +02:00
|
|
|
/**
|
|
|
|
* wallet_extract_owned_outputs - given a tx, extract all of our outputs
|
|
|
|
*/
|
2020-06-16 20:43:51 +02:00
|
|
|
int wallet_extract_owned_outputs(struct wallet *w, const struct wally_tx *tx,
|
2022-11-08 15:42:38 +01:00
|
|
|
bool is_coinbase,
|
2019-02-21 04:45:55 +01:00
|
|
|
const u32 *blockheight,
|
|
|
|
struct amount_sat *total);
|
2017-09-01 14:33:21 +02:00
|
|
|
|
2017-09-14 21:27:41 +02:00
|
|
|
/**
|
2018-02-08 22:43:01 +01:00
|
|
|
* wallet_htlc_save_in - store an htlc_in in the database
|
2017-09-14 21:27:41 +02:00
|
|
|
*
|
|
|
|
* @wallet: wallet to store the htlc into
|
2018-02-12 11:12:55 +01:00
|
|
|
* @chan: the channel this HTLC is associated with
|
2017-09-14 21:27:41 +02:00
|
|
|
* @in: the htlc_in to store
|
|
|
|
*
|
|
|
|
* This will store the contents of the `struct htlc_in` in the
|
|
|
|
* database. Since `struct htlc_in` commonly only change state after
|
|
|
|
* being created we do not support updating arbitrary fields and this
|
|
|
|
* function will fail when attempting to call it multiple times for
|
|
|
|
* the same `struct htlc_in`. Instead `wallet_htlc_update` may be used
|
|
|
|
* for state transitions or to set the `payment_key` for completed
|
|
|
|
* HTLCs.
|
|
|
|
*/
|
2017-11-01 02:10:48 +01:00
|
|
|
void wallet_htlc_save_in(struct wallet *wallet,
|
2018-02-12 11:12:55 +01:00
|
|
|
const struct channel *chan, struct htlc_in *in);
|
2017-09-14 21:27:41 +02:00
|
|
|
|
|
|
|
/**
|
2018-02-08 22:43:01 +01:00
|
|
|
* wallet_htlc_save_out - store an htlc_out in the database
|
2017-09-14 21:27:41 +02:00
|
|
|
*
|
|
|
|
* See comment for wallet_htlc_save_in.
|
|
|
|
*/
|
2017-11-01 02:10:48 +01:00
|
|
|
void wallet_htlc_save_out(struct wallet *wallet,
|
2018-02-12 11:12:55 +01:00
|
|
|
const struct channel *chan,
|
2017-09-14 21:27:41 +02:00
|
|
|
struct htlc_out *out);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_htlc_update - perform state transition or add payment_key
|
|
|
|
*
|
|
|
|
* @wallet: the wallet containing the HTLC to update
|
|
|
|
* @htlc_dbid: the database ID used to identify the HTLC
|
|
|
|
* @new_state: the state we should transition to
|
|
|
|
* @payment_key: the `payment_key` which hashes to the `payment_hash`,
|
|
|
|
* or NULL if unknown.
|
2021-10-13 05:45:30 +02:00
|
|
|
* @max_commit_num: maximum of local and remote commitment numbers.
|
2020-02-21 06:10:40 +01:00
|
|
|
* @badonion: the current BADONION failure code, or 0.
|
2020-02-18 01:00:58 +01:00
|
|
|
* @failonion: the current failure onion message (from peer), or NULL.
|
|
|
|
* @failmsg: the current local failure message, or NULL.
|
2020-03-19 00:28:29 +01:00
|
|
|
* @we_filled: for htlc-ins, true if we originated the preimage.
|
2017-09-14 21:27:41 +02:00
|
|
|
*
|
|
|
|
* Used to update the state of an HTLC, either a `struct htlc_in` or a
|
|
|
|
* `struct htlc_out` and optionally set the `payment_key` should the
|
2020-02-18 00:53:58 +01:00
|
|
|
* HTLC have been settled, or `failcode`/`failonion` if failed.
|
2017-09-14 21:27:41 +02:00
|
|
|
*/
|
2017-11-01 02:10:48 +01:00
|
|
|
void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
|
2017-09-14 21:27:41 +02:00
|
|
|
const enum htlc_state new_state,
|
2018-10-09 10:56:52 +02:00
|
|
|
const struct preimage *payment_key,
|
2021-10-13 05:45:30 +02:00
|
|
|
u64 max_commit_num,
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire badonion,
|
2020-02-18 01:00:58 +01:00
|
|
|
const struct onionreply *failonion,
|
2020-03-19 00:28:29 +01:00
|
|
|
const u8 *failmsg,
|
2020-04-14 21:02:46 +02:00
|
|
|
bool *we_filled);
|
2017-09-14 21:27:41 +02:00
|
|
|
|
2017-09-25 20:44:23 +02:00
|
|
|
/**
|
2019-12-12 00:39:10 +01:00
|
|
|
* wallet_htlcs_load_in_for_channel - Load incoming HTLCs associated with chan from DB.
|
2017-09-25 20:44:23 +02:00
|
|
|
*
|
|
|
|
* @wallet: wallet to load from
|
|
|
|
* @chan: load HTLCs associated with this channel
|
|
|
|
* @htlcs_in: htlc_in_map to store loaded htlc_in in
|
2019-12-12 00:39:10 +01:00
|
|
|
*
|
|
|
|
* This function looks for incoming HTLCs that are associated with the given
|
|
|
|
* channel and loads them into the provided map.
|
|
|
|
*/
|
|
|
|
bool wallet_htlcs_load_in_for_channel(struct wallet *wallet,
|
|
|
|
struct channel *chan,
|
|
|
|
struct htlc_in_map *htlcs_in);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_htlcs_load_out_for_channel - Load outgoing HTLCs associated with chan from DB.
|
|
|
|
*
|
|
|
|
* @wallet: wallet to load from
|
|
|
|
* @chan: load HTLCs associated with this channel
|
|
|
|
* @htlcs_out: htlc_out_map to store loaded htlc_out in.
|
|
|
|
* @remaining_htlcs_in: htlc_in_map with unconnected htlcs (removed as we progress)
|
|
|
|
*
|
|
|
|
* We populate htlc_out->in by looking up in remaining_htlcs_in. It's
|
|
|
|
* possible that it's still NULL, since we can have outgoing HTLCs
|
|
|
|
* outlive their corresponding incoming.
|
2017-09-25 20:44:23 +02:00
|
|
|
*/
|
2019-12-12 00:39:10 +01:00
|
|
|
bool wallet_htlcs_load_out_for_channel(struct wallet *wallet,
|
|
|
|
struct channel *chan,
|
|
|
|
struct htlc_out_map *htlcs_out,
|
|
|
|
struct htlc_in_map *remaining_htlcs_in);
|
2017-09-25 20:44:23 +02:00
|
|
|
|
2019-05-15 17:21:26 +02:00
|
|
|
/**
|
|
|
|
* wallet_announcement_save - Save remote announcement information with channel.
|
|
|
|
*
|
|
|
|
* @wallet: wallet to load from
|
|
|
|
* @id: channel database id
|
|
|
|
* @remote_ann_node_sig: location to load remote_ann_node_sig to
|
|
|
|
* @remote_ann_bitcoin_sig: location to load remote_ann_bitcoin_sig to
|
|
|
|
*
|
|
|
|
* This function is only used to save REMOTE announcement information into DB
|
|
|
|
* when the channel has set the announce_channel bit and don't send the shutdown
|
|
|
|
* message(BOLT#7).
|
|
|
|
*/
|
|
|
|
void wallet_announcement_save(struct wallet *wallet, u64 id,
|
|
|
|
secp256k1_ecdsa_signature *remote_ann_node_sig,
|
|
|
|
secp256k1_ecdsa_signature *remote_ann_bitcoin_sig);
|
2017-09-26 14:40:41 +02:00
|
|
|
|
2018-01-14 15:15:30 +01:00
|
|
|
/* /!\ This is a DB ENUM, please do not change the numbering of any
|
|
|
|
* already defined elements (adding is ok) /!\ */
|
|
|
|
enum invoice_status {
|
|
|
|
UNPAID,
|
|
|
|
PAID,
|
2018-01-23 02:02:10 +01:00
|
|
|
EXPIRED,
|
2018-01-14 15:15:30 +01:00
|
|
|
};
|
|
|
|
|
2018-08-09 04:27:25 +02:00
|
|
|
static inline enum invoice_status invoice_status_in_db(enum invoice_status s)
|
|
|
|
{
|
|
|
|
switch (s) {
|
|
|
|
case UNPAID:
|
|
|
|
BUILD_ASSERT(UNPAID == 0);
|
|
|
|
return s;
|
|
|
|
case PAID:
|
|
|
|
BUILD_ASSERT(PAID == 1);
|
|
|
|
return s;
|
|
|
|
case EXPIRED:
|
|
|
|
BUILD_ASSERT(EXPIRED == 2);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, s);
|
|
|
|
}
|
|
|
|
|
2017-10-10 13:04:32 +02:00
|
|
|
/**
|
|
|
|
* wallet_htlc_stubs - Retrieve HTLC stubs for the given channel
|
|
|
|
*
|
|
|
|
* Load minimal necessary information about HTLCs for the on-chain
|
|
|
|
* settlement. This returns a `tal_arr` allocated off of @ctx with the
|
|
|
|
* necessary size to hold all HTLCs.
|
|
|
|
*
|
|
|
|
* @ctx: Allocation context for the return value
|
|
|
|
* @wallet: Wallet to load from
|
|
|
|
* @chan: Channel to fetch stubs for
|
2021-10-13 05:45:36 +02:00
|
|
|
* @commit_num: The commitment number of the commit tx.
|
2017-10-10 13:04:32 +02:00
|
|
|
*/
|
2017-12-15 11:29:32 +01:00
|
|
|
struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
|
2021-10-13 05:45:36 +02:00
|
|
|
struct channel *chan, u64 commit_num);
|
2017-10-10 13:04:32 +02:00
|
|
|
|
2017-11-02 21:09:57 +01:00
|
|
|
/**
|
2023-10-28 05:08:17 +02:00
|
|
|
* wallet_add_payment - Store this payment in the db
|
|
|
|
* @ctx: context to allocate returned `struct wallet_payment` off.
|
2018-01-17 21:29:49 +01:00
|
|
|
* @wallet: wallet we're going to store it in.
|
2023-10-28 05:08:17 +02:00
|
|
|
* @...: the details
|
2018-01-17 21:29:49 +01:00
|
|
|
*/
|
2023-10-28 05:08:17 +02:00
|
|
|
struct wallet_payment *wallet_add_payment(const tal_t *ctx,
|
|
|
|
struct wallet *wallet,
|
|
|
|
u32 timestamp,
|
|
|
|
const u32 *completed_at,
|
|
|
|
const struct sha256 *payment_hash,
|
|
|
|
u64 partid,
|
|
|
|
u64 groupid,
|
|
|
|
enum payment_status status,
|
|
|
|
/* The destination may not be known if we used `sendonion` */
|
|
|
|
const struct node_id *destination TAKES,
|
|
|
|
struct amount_msat msatoshi,
|
|
|
|
struct amount_msat msatoshi_sent,
|
|
|
|
struct amount_msat total_msat,
|
|
|
|
/* If and only if PAYMENT_COMPLETE */
|
|
|
|
const struct preimage *payment_preimage TAKES,
|
|
|
|
const struct secret *path_secrets TAKES,
|
|
|
|
const struct node_id *route_nodes TAKES,
|
|
|
|
const struct short_channel_id *route_channels TAKES,
|
|
|
|
const char *invstring TAKES,
|
|
|
|
const char *label TAKES,
|
|
|
|
const char *description TAKES,
|
|
|
|
const u8 *failonion TAKES,
|
|
|
|
const struct sha256 *local_invreq_id);
|
2017-11-02 21:09:57 +01:00
|
|
|
|
2020-08-08 17:47:53 +02:00
|
|
|
/**
|
2022-09-19 02:54:26 +02:00
|
|
|
* wallet_payment_delete - Remove a payment
|
2020-08-08 17:47:53 +02:00
|
|
|
*
|
2022-09-19 02:54:26 +02:00
|
|
|
* Removes the payment from the database by hash; groupid and partid
|
|
|
|
* may both be NULL to delete all entries, otherwise deletes only that
|
|
|
|
* group/partid.
|
2020-08-08 17:47:53 +02:00
|
|
|
*/
|
2022-09-19 02:54:26 +02:00
|
|
|
void wallet_payment_delete(struct wallet *wallet,
|
|
|
|
const struct sha256 *payment_hash,
|
delpay: delete the payment by status from the db
There are cases (difficult to reproduce with a test) where
a payment will fail one time and succeed later.
As far I understand in this case the groupid field of the payment
is the same, and the only thing that change is the status, so
our logic inside the delpay is ambiguous where it is not
possible to delete a payment as described in https://github.com/ElementsProject/lightning/issues/6114
A sequence of commands that explain the problem is
```
$ lc -k listpays payment_hash=H
{
"pays": [
{
"bolt11": "I",
"destination": "redacted",
"payment_hash": "H",
"status": "complete",
"created_at": redacted,
"completed_at": redacted,
"preimage": "P",
"amount_msat": "redacted",
"amount_sent_msat": "redacted"
}
]
}
$ lc delpay H complete
{
"code": 211,
"message": "Payment with hash H has failed status but it should be complete"
}
```
In this case, the delpay is not able to delete a payment because the
listpays is returning only the succeeded one, so by running the
listsendpays we may see the following result where our delpay logic
will be stuck because it works to ensure that all the payments stored
in the database has the status specified by the user
```
➜ VincentSSD clightning --testnet listsendpays -k payment_hash=7fc74bedbb78f2f3330155d919a54e730cf19c11bc73e96c027f5cd4a34e53f4
{
"payments": [
{
"id": 322,
"payment_hash": "7fc74bedbb78f2f3330155d919a54e730cf19c11bc73e96c027f5cd4a34e53f4",
"groupid": 1,
"partid": 1,
"destination": "030b686a163aa2bba03cebb8bab7778fac251536498141df0a436d688352d426f6",
"amount_msat": 300,
"amount_sent_msat": 1664,
"created_at": 1679510203,
"completed_at": 1679510205,
"status": "failed",
"bolt11": "lntb1pjpkj4xsp52trda39rfpe7qtqahx8jjplhnj3tatxy8rh6sc6afgvmdz7n0llspp50lr5hmdm0re0xvcp2hv3nf2wwvx0r8q3h3e7jmqz0awdfg6w206qdp0w3jhxarfdenjqargv5sxgetvwpshjgrzw4njqun9wphhyaqxqyjw5qcqp2rzjqtp28uqy77te96ylt7ek703h4ayldljsf8rnlztgf3p8mg7pd0qzwf8a3yqqpdqqqyqqqqt2qqqqqqgqqc9qxpqysgqgeya2lguaj6sflc4hx2d89jvah8mw9uax4j77d8rzkut3rkm0554x37fc7gy92ws9l76yprdva2lalrs7fqjp9lcx40zuty8gca0g5spme3dup"
},
{
"id": 323,
"payment_hash": "7fc74bedbb78f2f3330155d919a54e730cf19c11bc73e96c027f5cd4a34e53f4",
"groupid": 1,
"partid": 2,
"destination": "030b686a163aa2bba03cebb8bab7778fac251536498141df0a436d688352d426f6",
"amount_msat": 300,
"amount_sent_msat": 3663,
"created_at": 1679510205,
"completed_at": 1679510207,
"status": "failed"
},
{
"id": 324,
"payment_hash": "7fc74bedbb78f2f3330155d919a54e730cf19c11bc73e96c027f5cd4a34e53f4",
"groupid": 1,
"partid": 3,
"destination": "030b686a163aa2bba03cebb8bab7778fac251536498141df0a436d688352d426f6",
"amount_msat": 300,
"amount_sent_msat": 3663,
"created_at": 1679510207,
"completed_at": 1679510209,
"status": "failed"
},
{
"id": 325,
"payment_hash": "7fc74bedbb78f2f3330155d919a54e730cf19c11bc73e96c027f5cd4a34e53f4",
"groupid": 1,
"partid": 4,
"destination": "030b686a163aa2bba03cebb8bab7778fac251536498141df0a436d688352d426f6",
"amount_msat": 300,
"amount_sent_msat": 4663,
"created_at": 1679510209,
"completed_at": 1679510221,
"status": "complete",
"payment_preimage": "43f746f2d28d4902489cbde9b3b8f3d04db5db7e973f8a55b7229ce774bf33a7"
}
]
}
```
This commit solves the problem by forcing the delete query in the
database to specify status too, and work around this kind of
ambiguous case.
Fixes: f52ff07558709bd1f7ed0cdca65c891d80b1a785 (lightningd: allow delpay to delete a specific payment.)
Reported-by: Antoine Poinsot <darosior@protonmail.com>
Link: https://github.com/ElementsProject/lightning/issues/6114
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Co-Developed-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: delpay be more pedantic about delete logic by allowing
delete payments by status directly on the database.
2023-03-22 20:22:25 +01:00
|
|
|
const u64 *groupid, const u64 *partid,
|
2023-07-11 21:41:17 +02:00
|
|
|
const enum payment_status *status);
|
2020-08-08 17:47:53 +02:00
|
|
|
|
2017-11-02 21:09:57 +01:00
|
|
|
/**
|
|
|
|
* wallet_payment_by_hash - Retrieve a specific payment
|
|
|
|
*
|
|
|
|
* Given the `payment_hash` retrieve the matching payment.
|
|
|
|
*/
|
|
|
|
struct wallet_payment *
|
|
|
|
wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
|
2019-12-12 00:16:23 +01:00
|
|
|
const struct sha256 *payment_hash,
|
2021-09-29 19:10:12 +02:00
|
|
|
u64 partid, u64 groupid);
|
2017-11-02 21:09:57 +01:00
|
|
|
|
2021-09-30 13:17:42 +02:00
|
|
|
/**
|
|
|
|
* Retrieve maximum groupid for a given payment_hash.
|
|
|
|
*
|
|
|
|
* Useful to either wait on the latest payment that was iniated with
|
|
|
|
* the hash or start a new one by incrementing the groupid.
|
|
|
|
*/
|
|
|
|
u64 wallet_payment_get_groupid(struct wallet *wallet,
|
|
|
|
const struct sha256 *payment_hash);
|
|
|
|
|
2017-11-02 21:09:57 +01:00
|
|
|
/**
|
|
|
|
* wallet_payment_set_status - Update the status of the payment
|
|
|
|
*
|
|
|
|
* Search for the payment with the given `payment_hash` and update
|
|
|
|
* its state.
|
|
|
|
*/
|
|
|
|
void wallet_payment_set_status(struct wallet *wallet,
|
2019-12-12 00:16:23 +01:00
|
|
|
const struct sha256 *payment_hash,
|
2021-09-29 12:33:57 +02:00
|
|
|
u64 partid, u64 groupid,
|
2023-07-11 21:41:17 +02:00
|
|
|
const enum payment_status newstatus,
|
2019-12-12 00:16:23 +01:00
|
|
|
const struct preimage *preimage);
|
2017-11-02 21:09:57 +01:00
|
|
|
|
2018-03-07 16:41:23 +01:00
|
|
|
/**
|
|
|
|
* wallet_payment_get_failinfo - Get failure information for a given
|
|
|
|
* `payment_hash`.
|
|
|
|
*
|
2019-01-15 05:02:27 +01:00
|
|
|
* Data is allocated as children of the given context. *faildirection
|
|
|
|
* is only set if *failchannel is set non-NULL.
|
2018-03-07 16:41:23 +01:00
|
|
|
*/
|
|
|
|
void wallet_payment_get_failinfo(const tal_t *ctx,
|
|
|
|
struct wallet *wallet,
|
|
|
|
const struct sha256 *payment_hash,
|
2019-12-12 00:16:23 +01:00
|
|
|
u64 partid,
|
2021-09-29 19:10:12 +02:00
|
|
|
u64 groupid,
|
2018-03-07 16:41:23 +01:00
|
|
|
/* outputs */
|
2020-01-23 00:38:04 +01:00
|
|
|
struct onionreply **failonionreply,
|
2018-03-07 16:41:23 +01:00
|
|
|
bool *faildestperm,
|
|
|
|
int *failindex,
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire *failcode,
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id **failnode,
|
2018-03-07 16:41:23 +01:00
|
|
|
struct short_channel_id **failchannel,
|
2018-04-16 15:29:40 +02:00
|
|
|
u8 **failupdate,
|
2019-01-15 05:02:27 +01:00
|
|
|
char **faildetail,
|
|
|
|
int *faildirection);
|
2018-03-07 16:41:23 +01:00
|
|
|
/**
|
|
|
|
* wallet_payment_set_failinfo - Set failure information for a given
|
|
|
|
* `payment_hash`.
|
|
|
|
*/
|
|
|
|
void wallet_payment_set_failinfo(struct wallet *wallet,
|
|
|
|
const struct sha256 *payment_hash,
|
2019-12-12 00:16:23 +01:00
|
|
|
u64 partid,
|
2020-01-23 00:38:04 +01:00
|
|
|
const struct onionreply *failonionreply,
|
2018-03-07 16:41:23 +01:00
|
|
|
bool faildestperm,
|
|
|
|
int failindex,
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire failcode,
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *failnode,
|
2018-03-07 16:41:23 +01:00
|
|
|
const struct short_channel_id *failchannel,
|
2018-04-16 15:29:40 +02:00
|
|
|
const u8 *failupdate,
|
2019-01-15 05:02:27 +01:00
|
|
|
const char *faildetail,
|
|
|
|
int faildirection);
|
2018-03-07 16:41:23 +01:00
|
|
|
|
2017-11-16 19:11:59 +01:00
|
|
|
/**
|
2023-10-28 05:09:15 +02:00
|
|
|
* payments_first: get first payment, optionally filtering by status
|
|
|
|
* @w: the wallet
|
2023-10-28 05:10:47 +02:00
|
|
|
* @listindex: what index order to use (if you care)
|
|
|
|
* @liststart: first index to return (0 == all).
|
|
|
|
* @listlimit: limit on number of entries to return (NULL == no limit).
|
2018-01-16 20:44:32 +01:00
|
|
|
*
|
2023-10-28 05:09:15 +02:00
|
|
|
* Returns NULL if none, otherwise you must call payments_next() or
|
|
|
|
* tal_free(stmt).
|
2017-11-16 19:11:59 +01:00
|
|
|
*/
|
2023-10-28 05:10:47 +02:00
|
|
|
struct db_stmt *payments_first(struct wallet *w,
|
|
|
|
const enum wait_index *listindex,
|
|
|
|
u64 liststart,
|
|
|
|
const u32 *listlimit);
|
2023-10-28 05:09:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* payments_next: get next payment
|
|
|
|
* @w: the wallet
|
|
|
|
* @stmt: the previous stmt from payments_first or payments_next.
|
|
|
|
*
|
|
|
|
* Returns NULL if none, otherwise you must call payments_next() or
|
|
|
|
* tal_free(stmt).
|
|
|
|
*/
|
|
|
|
struct db_stmt *payments_next(struct wallet *w,
|
|
|
|
struct db_stmt *stmt);
|
|
|
|
|
wallet: simplify payments lookup so sqlite3 uses index.
Filtering by status is rare, so we can do it in the caller; just let sqlite3
filter by payment_hash.
With ~650,000 payments in db:
Before:
```
129/300000 complete 5.60/sec (33078 invs, 169 pays, 0 retries) in 30 seconds. 19 hours-14 hours remaining.
201/300000 complete 7.20/sec (43519 invs, 241 pays, 0 retries) in 40 seconds. 16 hours-11 hours remaining.
257/300000 complete 5.60/sec (54568 invs, 289 pays, 0 retries) in 50 seconds. 16 hours-14 hours remaining.
305/300000 complete 4.80/sec (65772 invs, 337 pays, 0 retries) in 60 seconds. 16 hours-17 hours remaining.
361/300000 complete 5.60/sec (75875 invs, 401 pays, 0 retries) in 70 seconds. 16 hours-14 hours remaining.
```
After:
```
760/300000 complete 40.00/sec (19955 invs, 824 pays, 0 retries) in 20 seconds. 2 hours-2 hours remaining.
1176/300000 complete 41.60/sec (30082 invs, 1224 pays, 0 retries) in 30 seconds. 2 hours-119 minutes remaining.
1584/300000 complete 40.80/sec (40224 invs, 1640 pays, 0 retries) in 40 seconds. 2 hours-2 hours remaining.
1984/300000 complete 40.00/sec (49938 invs, 2048 pays, 0 retries) in 50 seconds. 2 hours-2 hours remaining.
```
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-09-19 02:49:53 +02:00
|
|
|
|
2023-10-28 05:09:15 +02:00
|
|
|
/**
|
|
|
|
* payments_by_hash: get the payment, if any, by payment_hash.
|
|
|
|
* @w: the wallet
|
|
|
|
* @payment_hash: the payment_hash.
|
|
|
|
*
|
|
|
|
* Returns NULL if none, otherwise call payments_get_details(),
|
|
|
|
* and then tal_free(stmt).
|
|
|
|
*/
|
|
|
|
struct db_stmt *payments_by_hash(struct wallet *w,
|
|
|
|
const struct sha256 *payment_hash);
|
2017-11-16 19:11:59 +01:00
|
|
|
|
2020-12-14 02:20:44 +01:00
|
|
|
/**
|
2023-10-28 05:09:15 +02:00
|
|
|
* payments_by_status: get the payments, if any, by status.
|
|
|
|
* @w: the wallet
|
|
|
|
* @status: the status.
|
2023-10-28 05:10:47 +02:00
|
|
|
* @listindex: what index order to use (if you care)
|
|
|
|
* @liststart: first index to return (0 == all).
|
|
|
|
* @listlimit: limit on number of entries to return (NULL == no limit).
|
2023-10-28 05:09:15 +02:00
|
|
|
*
|
|
|
|
* Returns NULL if none, otherwise call payments_get_details(),
|
|
|
|
* and then tal_free(stmt).
|
2020-12-14 02:20:44 +01:00
|
|
|
*/
|
2023-10-28 05:09:15 +02:00
|
|
|
struct db_stmt *payments_by_status(struct wallet *w,
|
2023-10-28 05:10:47 +02:00
|
|
|
enum payment_status status,
|
|
|
|
const enum wait_index *listindex,
|
|
|
|
u64 liststart,
|
|
|
|
const u32 *listlimit);
|
2023-10-28 05:09:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* payments_by_label: get the payment, if any, by label.
|
|
|
|
* @w: the wallet
|
|
|
|
* @label: the label.
|
|
|
|
*
|
|
|
|
* Returns NULL if none, otherwise call payments_get_details(),
|
|
|
|
* and then tal_free(stmt).
|
|
|
|
*/
|
|
|
|
struct db_stmt *payments_by_label(struct wallet *w,
|
|
|
|
const struct json_escape *label);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* payments_by_invoice_request: get payments, if any, for this local_invreq_id
|
|
|
|
* @w: the wallet
|
|
|
|
* @local_invreq_id: the local invreq_id.
|
|
|
|
*
|
|
|
|
* Returns NULL if none, otherwise you must call payments_next() or
|
|
|
|
* tal_free(stmt).
|
|
|
|
*/
|
|
|
|
struct db_stmt *payments_by_invoice_request(struct wallet *wallet,
|
|
|
|
const struct sha256 *local_invreq_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* payments_get_details: get the details of a payment.
|
|
|
|
*/
|
|
|
|
struct wallet_payment *payment_get_details(const tal_t *ctx,
|
|
|
|
struct db_stmt *stmt);
|
|
|
|
|
2020-12-14 02:20:44 +01:00
|
|
|
|
2018-02-09 15:44:39 +01:00
|
|
|
/**
|
2023-04-14 00:06:38 +02:00
|
|
|
* wallet_htlc_sigs_save - Delete all HTLC sigs (including inflights) for the
|
|
|
|
* channel and store `htlc_sigs` as the new values.
|
2018-02-09 15:44:39 +01:00
|
|
|
*/
|
|
|
|
void wallet_htlc_sigs_save(struct wallet *w, u64 channel_id,
|
2020-08-13 19:45:02 +02:00
|
|
|
const struct bitcoin_signature *htlc_sigs);
|
2018-02-16 17:55:33 +01:00
|
|
|
|
2023-04-14 00:06:38 +02:00
|
|
|
/**
|
|
|
|
* wallet_htlc_sigs_add - Appends `htlc_sigs` for the given inflight splice.
|
|
|
|
* `inflight_id` is the funding txid for the given splice.
|
|
|
|
*/
|
|
|
|
void wallet_htlc_sigs_add(struct wallet *w, u64 channel_id,
|
|
|
|
struct bitcoin_outpoint inflight_outpoint,
|
|
|
|
const struct bitcoin_signature *htlc_sigs);
|
|
|
|
|
2018-02-16 17:55:33 +01:00
|
|
|
/**
|
2022-07-20 04:28:25 +02:00
|
|
|
* wallet_sanity_check - Check that the wallet is setup for this node_id and chain
|
2018-02-16 17:55:33 +01:00
|
|
|
*
|
|
|
|
* Ensure that the genesis_hash from the chainparams matches the
|
2022-07-20 04:28:25 +02:00
|
|
|
* genesis_hash with which the DB was initialized, and that the HSM
|
|
|
|
* gave us the same node_id as the one is the db.
|
|
|
|
*
|
|
|
|
* Returns false if the checks failed.
|
2018-02-16 17:55:33 +01:00
|
|
|
*/
|
2022-07-20 04:28:25 +02:00
|
|
|
bool wallet_sanity_check(struct wallet *w);
|
2018-02-16 17:55:33 +01:00
|
|
|
|
2018-02-17 16:45:34 +01:00
|
|
|
/**
|
|
|
|
* wallet_block_add - Add a block to the blockchain tracked by this wallet
|
|
|
|
*/
|
|
|
|
void wallet_block_add(struct wallet *w, struct block *b);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_block_remove - Remove a block (and all its descendants) from the tracked blockchain
|
|
|
|
*/
|
|
|
|
void wallet_block_remove(struct wallet *w, struct block *b);
|
|
|
|
|
2018-02-19 14:01:42 +01:00
|
|
|
/**
|
|
|
|
* wallet_blocks_rollback - Roll the blockchain back to the given height
|
|
|
|
*/
|
|
|
|
void wallet_blocks_rollback(struct wallet *w, u32 height);
|
2018-02-17 16:45:34 +01:00
|
|
|
|
2019-08-05 23:16:32 +02:00
|
|
|
/**
|
|
|
|
* Return whether we have a block for the given height.
|
|
|
|
*/
|
|
|
|
bool wallet_have_block(struct wallet *w, u32 blockheight);
|
|
|
|
|
2018-03-28 11:13:43 +02:00
|
|
|
/**
|
|
|
|
* Mark an outpoint as spent, both in the owned as well as the UTXO set
|
|
|
|
*
|
|
|
|
* Given the outpoint (txid, outnum), and the blockheight, mark the
|
|
|
|
* corresponding DB entries as spent at the blockheight.
|
|
|
|
*
|
2020-09-04 17:50:17 +02:00
|
|
|
* @return true if found in our wallet's output set, false otherwise
|
|
|
|
*/
|
2024-03-20 01:47:55 +01:00
|
|
|
bool wallet_outpoint_spend(const tal_t *ctx, struct wallet *w,
|
2020-09-04 17:50:17 +02:00
|
|
|
const u32 blockheight,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *outpoint);
|
2018-03-02 15:07:13 +01:00
|
|
|
|
2024-03-20 01:47:55 +01:00
|
|
|
struct outpoint *wallet_outpoint_for_scid(const tal_t *ctx, struct wallet *w,
|
2024-03-20 02:59:51 +01:00
|
|
|
struct short_channel_id scid);
|
2018-03-05 23:15:54 +01:00
|
|
|
|
2021-10-13 05:45:36 +02:00
|
|
|
void wallet_utxoset_add(struct wallet *w,
|
|
|
|
const struct bitcoin_outpoint *outpoint,
|
2024-02-21 22:03:07 +01:00
|
|
|
const u32 blockheight, const u32 txindex,
|
|
|
|
const u8 *scriptpubkey, size_t scriptpubkey_len,
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat sat);
|
2018-04-07 14:39:11 +02:00
|
|
|
|
2020-09-08 12:34:36 +02:00
|
|
|
/**
|
|
|
|
* Retrieve all UTXO entries that were spent by the given blockheight.
|
|
|
|
*
|
|
|
|
* This allows us to retrieve any UTXO entries that were spent by a block,
|
|
|
|
* after the block has been processed. It's main use is to be able to tell
|
|
|
|
* `gossipd` about potential channel outpoints being spent, without having to
|
|
|
|
* track all outpoints in memory.
|
|
|
|
*
|
|
|
|
* In order to return correct results `blockheight` should not be called with
|
|
|
|
* a height below the UTXO set pruning height (see `UTXO_PRUNE_DEPTH` for the
|
|
|
|
* current value).
|
|
|
|
*/
|
|
|
|
const struct short_channel_id *
|
|
|
|
wallet_utxoset_get_spent(const tal_t *ctx, struct wallet *w, u32 blockheight);
|
|
|
|
|
2024-11-13 03:54:28 +01:00
|
|
|
/* Prune all UTXO entries spent (far) below this block height */
|
|
|
|
void wallet_utxoset_prune(struct wallet *w, u32 blockheight);
|
|
|
|
|
2024-11-13 03:54:28 +01:00
|
|
|
/* Get oldest spendheight (or 0 if none), to catch up */
|
|
|
|
u32 wallet_utxoset_oldest_spentheight(const tal_t *ctx, struct wallet *w);
|
|
|
|
|
2021-08-12 05:05:55 +02:00
|
|
|
/**
|
|
|
|
* Retrieve all UTXO entries that were created at a given blockheight.
|
|
|
|
*/
|
|
|
|
const struct short_channel_id *
|
|
|
|
wallet_utxoset_get_created(const tal_t *ctx, struct wallet *w, u32 blockheight);
|
|
|
|
|
2020-08-07 03:30:47 +02:00
|
|
|
void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx,
|
2018-04-07 14:39:11 +02:00
|
|
|
const u32 blockheight, const u32 txindex);
|
|
|
|
|
2021-10-13 05:45:36 +02:00
|
|
|
void wallet_annotate_txout(struct wallet *w,
|
|
|
|
const struct bitcoin_outpoint *outpoint,
|
|
|
|
enum wallet_tx_type type, u64 channel);
|
2019-09-30 22:24:04 +02:00
|
|
|
|
|
|
|
void wallet_annotate_txin(struct wallet *w, const struct bitcoin_txid *txid,
|
|
|
|
int innum, enum wallet_tx_type type, u64 channel);
|
|
|
|
|
2019-12-31 00:36:00 +01:00
|
|
|
/**
|
|
|
|
* Get the transaction from the database
|
|
|
|
*
|
|
|
|
* Looks up a transaction we have in the database and returns it, or NULL if
|
|
|
|
* not found.
|
|
|
|
*/
|
|
|
|
struct bitcoin_tx *wallet_transaction_get(const tal_t *ctx, struct wallet *w,
|
|
|
|
const struct bitcoin_txid *txid);
|
|
|
|
|
2018-04-09 15:18:09 +02:00
|
|
|
/**
|
|
|
|
* Get the confirmation height of a transaction we are watching by its
|
|
|
|
* txid. Returns 0 if the transaction was not part of any block.
|
|
|
|
*/
|
|
|
|
u32 wallet_transaction_height(struct wallet *w, const struct bitcoin_txid *txid);
|
|
|
|
|
2018-04-09 18:48:39 +02:00
|
|
|
/**
|
|
|
|
* Locate a transaction in the blockchain, returns NULL if the transaction is
|
|
|
|
* not tracked or is not yet confirmed.
|
|
|
|
*/
|
|
|
|
struct txlocator *wallet_transaction_locate(const tal_t *ctx, struct wallet *w,
|
|
|
|
const struct bitcoin_txid *txid);
|
|
|
|
|
2018-04-10 11:14:50 +02:00
|
|
|
/**
|
|
|
|
* Get transaction IDs for transactions that we are tracking.
|
|
|
|
*/
|
|
|
|
struct bitcoin_txid *wallet_transactions_by_height(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
const u32 blockheight);
|
|
|
|
|
2018-04-03 16:57:28 +02:00
|
|
|
/**
|
2024-11-13 03:54:28 +01:00
|
|
|
* Store funding txid spend to start replay on restart
|
|
|
|
* Note that tx should already be saved by wallet_transaction_add!
|
2018-04-03 16:57:28 +02:00
|
|
|
*/
|
2024-11-13 03:54:28 +01:00
|
|
|
void wallet_insert_funding_spend(struct wallet *w,
|
|
|
|
const struct channel *chan,
|
|
|
|
const struct bitcoin_txid *txid,
|
|
|
|
const u32 input_num, const u32 blockheight);
|
2018-04-03 16:57:28 +02:00
|
|
|
|
2024-11-13 03:54:27 +01:00
|
|
|
/**
|
|
|
|
* Get the transaction which spend funding for this channel, if any.
|
|
|
|
*/
|
|
|
|
struct bitcoin_tx *wallet_get_funding_spend(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
u64 channel_id,
|
|
|
|
u32 *blockheight);
|
|
|
|
|
2018-10-17 20:11:04 +02:00
|
|
|
/**
|
|
|
|
* Add of update a forwarded_payment
|
|
|
|
*/
|
2018-10-16 21:28:35 +02:00
|
|
|
void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
|
2022-03-31 05:14:27 +02:00
|
|
|
enum forward_style forward_style,
|
2020-02-13 03:11:01 +01:00
|
|
|
const struct short_channel_id *scid_out,
|
2018-10-16 21:28:35 +02:00
|
|
|
const struct htlc_out *out,
|
2019-04-15 15:47:37 +02:00
|
|
|
enum forward_status state,
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire failcode);
|
2018-10-16 21:28:35 +02:00
|
|
|
|
2018-10-17 20:11:04 +02:00
|
|
|
/**
|
2018-10-19 06:19:52 +02:00
|
|
|
* Retrieve summary of successful forwarded payments' fees
|
2018-10-17 20:11:04 +02:00
|
|
|
*/
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_msat wallet_total_forward_fees(struct wallet *w);
|
2018-10-17 20:11:04 +02:00
|
|
|
|
|
|
|
/**
|
2024-06-19 08:27:22 +02:00
|
|
|
* Retrieve forwarded_payments
|
|
|
|
*/
|
|
|
|
struct db_stmt *forwarding_first(struct wallet *w,
|
|
|
|
enum forward_status status,
|
|
|
|
const struct short_channel_id *chan_in,
|
|
|
|
const struct short_channel_id *chan_out,
|
|
|
|
const enum wait_index *listindex,
|
|
|
|
u64 liststart,
|
|
|
|
const u32 *listlimit);
|
|
|
|
|
|
|
|
struct db_stmt *forwarding_next(struct wallet *w,
|
|
|
|
struct db_stmt *stmt);
|
|
|
|
|
|
|
|
const struct forwarding *forwarding_details(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
struct db_stmt *stmt);
|
2019-05-15 17:21:26 +02:00
|
|
|
|
2022-09-19 02:52:58 +02:00
|
|
|
/**
|
|
|
|
* Delete a particular forward entry
|
|
|
|
* Returns false if not found
|
|
|
|
*/
|
|
|
|
bool wallet_forward_delete(struct wallet *w,
|
2024-03-20 02:59:51 +01:00
|
|
|
struct short_channel_id chan_in,
|
2022-09-27 01:43:36 +02:00
|
|
|
const u64 *htlc_id,
|
2022-09-19 02:52:58 +02:00
|
|
|
enum forward_status state);
|
|
|
|
|
2019-05-15 17:21:26 +02:00
|
|
|
/**
|
|
|
|
* Load remote_ann_node_sig and remote_ann_bitcoin_sig
|
|
|
|
*
|
|
|
|
* @w: wallet containing the channel
|
2024-01-31 04:16:17 +01:00
|
|
|
* @chan: channel (must be in db)
|
2019-05-15 17:21:26 +02:00
|
|
|
* @remote_ann_node_sig: location to load remote_ann_node_sig to
|
|
|
|
* @remote_ann_bitcoin_sig: location to load remote_ann_bitcoin_sig to
|
2024-01-31 04:16:17 +01:00
|
|
|
*
|
|
|
|
* Returns false if the signatures were null.
|
|
|
|
*/
|
|
|
|
bool wallet_remote_ann_sigs_load(struct wallet *w,
|
|
|
|
const struct channel *chan,
|
|
|
|
secp256k1_ecdsa_signature *remote_ann_node_sig,
|
|
|
|
secp256k1_ecdsa_signature *remote_ann_bitcoin_sig);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Null out remote_ann_node_sig and remote_ann_bitcoin_sig
|
|
|
|
*
|
|
|
|
* @w: wallet containing the channel
|
|
|
|
* @id: channel database id
|
2019-05-15 17:21:26 +02:00
|
|
|
*/
|
2024-01-31 04:16:17 +01:00
|
|
|
void wallet_remote_ann_sigs_clear(struct wallet *w, const struct channel *chan);
|
2019-06-05 09:00:02 +02:00
|
|
|
|
2019-05-28 22:36:15 +02:00
|
|
|
/**
|
|
|
|
* Get a list of transactions that we track in the wallet.
|
|
|
|
*
|
|
|
|
* @param ctx: allocation context for the returned list
|
|
|
|
* @param wallet: Wallet to load from.
|
2019-10-02 19:36:28 +02:00
|
|
|
* @return A tal_arr of wallet annotated transactions
|
2019-05-28 22:36:15 +02:00
|
|
|
*/
|
2024-03-20 01:47:55 +01:00
|
|
|
struct wallet_transaction *wallet_transactions_get(const tal_t *ctx, struct wallet *w);
|
2019-05-28 22:36:15 +02:00
|
|
|
|
2019-08-05 23:16:32 +02:00
|
|
|
/**
|
|
|
|
* Add a filteredblock to the blocks and utxoset tables.
|
|
|
|
*
|
|
|
|
* This can be used to backfill the blocks and still unspent UTXOs that were before our wallet birth height.
|
|
|
|
*/
|
2019-08-08 06:24:33 +02:00
|
|
|
void wallet_filteredblock_add(struct wallet *w, const struct filteredblock *fb);
|
2019-08-05 23:16:32 +02:00
|
|
|
|
2020-05-07 02:42:40 +02:00
|
|
|
/**
|
|
|
|
* Store a penalty base in the database.
|
|
|
|
*
|
|
|
|
* Required to eventually create a penalty transaction when we get a
|
|
|
|
* revocation.
|
|
|
|
*/
|
|
|
|
void wallet_penalty_base_add(struct wallet *w, u64 chan_id,
|
|
|
|
const struct penalty_base *pb);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve all pending penalty bases for a given channel.
|
|
|
|
*
|
|
|
|
* This list should stay relatively small since we remove items from it as we
|
|
|
|
* get revocations. We retrieve this list whenever we start a new `channeld`.
|
|
|
|
*/
|
|
|
|
struct penalty_base *wallet_penalty_base_load_for_channel(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
u64 chan_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a penalty_base, after we created and delivered it to the hook.
|
|
|
|
*/
|
|
|
|
void wallet_penalty_base_delete(struct wallet *w, u64 chan_id, u64 commitnum);
|
|
|
|
|
2020-12-14 02:17:58 +01:00
|
|
|
/* /!\ This is a DB ENUM, please do not change the numbering of any
|
|
|
|
* already defined elements (adding is ok) /!\ */
|
|
|
|
#define OFFER_STATUS_ACTIVE_F 0x1
|
|
|
|
#define OFFER_STATUS_SINGLE_F 0x2
|
|
|
|
#define OFFER_STATUS_USED_F 0x4
|
|
|
|
enum offer_status {
|
2021-02-18 05:15:54 +01:00
|
|
|
OFFER_MULTIPLE_USE_UNUSED = OFFER_STATUS_ACTIVE_F,
|
|
|
|
OFFER_MULTIPLE_USE_USED = OFFER_STATUS_ACTIVE_F|OFFER_STATUS_USED_F,
|
|
|
|
OFFER_SINGLE_USE_UNUSED = OFFER_STATUS_ACTIVE_F|OFFER_STATUS_SINGLE_F,
|
|
|
|
OFFER_SINGLE_USE_USED = OFFER_STATUS_SINGLE_F|OFFER_STATUS_USED_F,
|
2020-12-14 02:17:58 +01:00
|
|
|
OFFER_SINGLE_DISABLED = OFFER_STATUS_SINGLE_F,
|
2021-07-21 07:37:44 +02:00
|
|
|
OFFER_MULTIPLE_USED_DISABLED = OFFER_STATUS_USED_F,
|
2020-12-14 02:17:58 +01:00
|
|
|
OFFER_MULTIPLE_DISABLED = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline enum offer_status offer_status_in_db(enum offer_status s)
|
|
|
|
{
|
|
|
|
switch (s) {
|
2021-02-18 05:15:54 +01:00
|
|
|
case OFFER_MULTIPLE_USE_UNUSED:
|
|
|
|
BUILD_ASSERT(OFFER_MULTIPLE_USE_UNUSED == 1);
|
2020-12-14 02:17:58 +01:00
|
|
|
return s;
|
2021-02-18 05:15:54 +01:00
|
|
|
case OFFER_MULTIPLE_USE_USED:
|
|
|
|
BUILD_ASSERT(OFFER_MULTIPLE_USE_USED == 5);
|
2020-12-14 02:17:58 +01:00
|
|
|
return s;
|
2021-02-18 05:15:54 +01:00
|
|
|
case OFFER_SINGLE_USE_UNUSED:
|
|
|
|
BUILD_ASSERT(OFFER_SINGLE_USE_UNUSED == 3);
|
|
|
|
return s;
|
|
|
|
case OFFER_SINGLE_USE_USED:
|
|
|
|
BUILD_ASSERT(OFFER_SINGLE_USE_USED == 6);
|
2020-12-14 02:17:58 +01:00
|
|
|
return s;
|
|
|
|
case OFFER_SINGLE_DISABLED:
|
|
|
|
BUILD_ASSERT(OFFER_SINGLE_DISABLED == 2);
|
|
|
|
return s;
|
2021-07-21 07:37:44 +02:00
|
|
|
case OFFER_MULTIPLE_USED_DISABLED:
|
|
|
|
BUILD_ASSERT(OFFER_MULTIPLE_USED_DISABLED == 4);
|
|
|
|
return s;
|
2020-12-14 02:17:58 +01:00
|
|
|
case OFFER_MULTIPLE_DISABLED:
|
|
|
|
BUILD_ASSERT(OFFER_MULTIPLE_DISABLED == 0);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
fatal("%s: %u is invalid", __func__, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool offer_status_active(enum offer_status s)
|
|
|
|
{
|
|
|
|
return s & OFFER_STATUS_ACTIVE_F;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool offer_status_single(enum offer_status s)
|
|
|
|
{
|
|
|
|
return s & OFFER_STATUS_SINGLE_F;
|
|
|
|
}
|
|
|
|
|
2021-02-18 05:15:54 +01:00
|
|
|
static inline bool offer_status_used(enum offer_status s)
|
|
|
|
{
|
|
|
|
return s & OFFER_STATUS_USED_F;
|
|
|
|
}
|
|
|
|
|
2020-12-14 02:17:58 +01:00
|
|
|
/**
|
|
|
|
* Store an offer in the database.
|
|
|
|
* @w: the wallet
|
|
|
|
* @offer_id: the merkle root, as used for signing (must be unique)
|
|
|
|
* @bolt12: offer as text.
|
|
|
|
* @label: optional label for this offer.
|
|
|
|
* @status: OFFER_SINGLE_USE or OFFER_MULTIPLE_USE
|
|
|
|
*/
|
|
|
|
bool wallet_offer_create(struct wallet *w,
|
|
|
|
const struct sha256 *offer_id,
|
|
|
|
const char *bolt12,
|
|
|
|
const struct json_escape *label,
|
|
|
|
enum offer_status status)
|
|
|
|
NON_NULL_ARGS(1,2,3);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve an offer from the database.
|
|
|
|
* @ctx: the tal context to allocate return from.
|
|
|
|
* @w: the wallet
|
|
|
|
* @offer_id: the merkle root, as used for signing (must be unique)
|
|
|
|
* @label: the label of the offer, set to NULL if none (or NULL)
|
|
|
|
* @status: set if succeeds (or NULL)
|
|
|
|
*
|
|
|
|
* If @offer_id is found, returns the bolt12 text, sets @label and
|
|
|
|
* @state. Otherwise returns NULL.
|
|
|
|
*/
|
|
|
|
char *wallet_offer_find(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
const struct sha256 *offer_id,
|
|
|
|
const struct json_escape **label,
|
|
|
|
enum offer_status *status)
|
|
|
|
NON_NULL_ARGS(1,2,3);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate through all the offers.
|
|
|
|
* @w: the wallet
|
|
|
|
* @offer_id: the first offer id (if returns non-NULL)
|
|
|
|
*
|
2021-12-04 12:27:06 +01:00
|
|
|
* Returns pointer to hand as @stmt to wallet_offer_id_next(), or NULL.
|
2020-12-15 00:43:42 +01:00
|
|
|
* If you choose not to call wallet_offer_id_next() you must free it!
|
2020-12-14 02:17:58 +01:00
|
|
|
*/
|
2020-12-15 00:43:42 +01:00
|
|
|
struct db_stmt *wallet_offer_id_first(struct wallet *w,
|
|
|
|
struct sha256 *offer_id);
|
2020-12-14 02:17:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate through all the offers.
|
|
|
|
* @w: the wallet
|
2020-12-15 00:43:42 +01:00
|
|
|
* @stmt: return from wallet_offer_id_first() or previous wallet_offer_id_next()
|
2020-12-14 02:17:58 +01:00
|
|
|
* @offer_id: the next offer id (if returns non-NULL)
|
|
|
|
*
|
|
|
|
* Returns NULL once we're out of offers. If you choose not to call
|
2020-12-15 00:43:42 +01:00
|
|
|
* wallet_offer_id_next() again you must free return.
|
2020-12-14 02:17:58 +01:00
|
|
|
*/
|
2020-12-15 00:43:42 +01:00
|
|
|
struct db_stmt *wallet_offer_id_next(struct wallet *w,
|
|
|
|
struct db_stmt *stmt,
|
|
|
|
struct sha256 *offer_id);
|
2020-12-14 02:17:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable an offer in the database.
|
|
|
|
* @w: the wallet
|
|
|
|
* @offer_id: the merkle root, as used for signing (must be unique)
|
|
|
|
* @s: the current status (must be active).
|
|
|
|
*
|
|
|
|
* Must exist. Returns new status. */
|
|
|
|
enum offer_status wallet_offer_disable(struct wallet *w,
|
|
|
|
const struct sha256 *offer_id,
|
|
|
|
enum offer_status s)
|
|
|
|
NO_NULL_ARGS;
|
|
|
|
|
2024-06-02 11:38:12 +02:00
|
|
|
/**
|
|
|
|
* Enable an offer in the database.
|
|
|
|
* @w: the wallet
|
|
|
|
* @offer_id: the merkle root, as used for signing (must be unique)
|
|
|
|
* @s: the current status (must be active).
|
|
|
|
*
|
|
|
|
* Must exist. Returns new status. */
|
|
|
|
enum offer_status wallet_offer_enable(struct wallet *w,
|
|
|
|
const struct sha256 *offer_id,
|
|
|
|
enum offer_status s)
|
|
|
|
NO_NULL_ARGS;
|
|
|
|
|
2020-12-14 02:17:58 +01:00
|
|
|
/**
|
|
|
|
* Mark an offer in the database used.
|
|
|
|
* @w: the wallet
|
|
|
|
* @offer_id: the merkle root, as used for signing (must be unique)
|
|
|
|
*
|
|
|
|
* Must exist and be active.
|
|
|
|
*/
|
|
|
|
void wallet_offer_mark_used(struct db *db, const struct sha256 *offer_id)
|
|
|
|
NO_NULL_ARGS;
|
2021-08-25 04:50:12 +02:00
|
|
|
|
2022-11-09 03:32:01 +01:00
|
|
|
/**
|
|
|
|
* Store an offer in the database.
|
|
|
|
* @w: the wallet
|
|
|
|
* @invreq_id: the hash of the invoice_request.
|
|
|
|
* @bolt12: invoice_request as text.
|
|
|
|
* @label: optional label for this invoice_request.
|
|
|
|
* @status: OFFER_SINGLE_USE or OFFER_MULTIPLE_USE
|
|
|
|
*/
|
|
|
|
bool wallet_invoice_request_create(struct wallet *w,
|
|
|
|
const struct sha256 *invreq_id,
|
|
|
|
const char *bolt12,
|
|
|
|
const struct json_escape *label,
|
|
|
|
enum offer_status status)
|
|
|
|
NON_NULL_ARGS(1,2,3);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve an invoice_request from the database.
|
|
|
|
* @ctx: the tal context to allocate return from.
|
|
|
|
* @w: the wallet
|
|
|
|
* @invreq_id: the merkle root, as used for signing (must be unique)
|
|
|
|
* @label: the label of the invoice_request, set to NULL if none (or NULL)
|
|
|
|
* @status: set if succeeds (or NULL)
|
|
|
|
*
|
|
|
|
* If @invreq_id is found, returns the bolt12 text, sets @label and
|
|
|
|
* @state. Otherwise returns NULL.
|
|
|
|
*/
|
|
|
|
char *wallet_invoice_request_find(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
const struct sha256 *invreq_id,
|
|
|
|
const struct json_escape **label,
|
|
|
|
enum offer_status *status)
|
|
|
|
NON_NULL_ARGS(1,2,3);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate through all the invoice_requests.
|
|
|
|
* @w: the wallet
|
|
|
|
* @invreq_id: the first invoice_request id (if returns non-NULL)
|
|
|
|
*
|
|
|
|
* Returns pointer to hand as @stmt to wallet_invreq_id_next(), or NULL.
|
|
|
|
* If you choose not to call wallet_invreq_id_next() you must free it!
|
|
|
|
*/
|
|
|
|
struct db_stmt *wallet_invreq_id_first(struct wallet *w,
|
|
|
|
struct sha256 *invreq_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate through all the invoice_requests.
|
|
|
|
* @w: the wallet
|
|
|
|
* @stmt: return from wallet_invreq_id_first() or previous wallet_invreq_id_next()
|
|
|
|
* @invreq_id: the next invoice_request id (if returns non-NULL)
|
|
|
|
*
|
|
|
|
* Returns NULL once we're out of invoice_requests. If you choose not to call
|
|
|
|
* wallet_invreq_id_next() again you must free return.
|
|
|
|
*/
|
|
|
|
struct db_stmt *wallet_invreq_id_next(struct wallet *w,
|
|
|
|
struct db_stmt *stmt,
|
|
|
|
struct sha256 *invreq_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable an invoice_request in the database.
|
|
|
|
* @w: the wallet
|
|
|
|
* @invreq_id: the merkle root, as used for signing (must be unique)
|
|
|
|
* @s: the current status (must be active).
|
|
|
|
*
|
|
|
|
* Must exist. Returns new status. */
|
|
|
|
enum offer_status wallet_invoice_request_disable(struct wallet *w,
|
|
|
|
const struct sha256 *invreq_id,
|
|
|
|
enum offer_status s)
|
|
|
|
NO_NULL_ARGS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark an invoice_request in the database used.
|
|
|
|
* @w: the wallet
|
|
|
|
* @invreq_id: the merkle root, as used for signing (must be unique)
|
|
|
|
*
|
|
|
|
* Must exist and be active.
|
|
|
|
*/
|
|
|
|
void wallet_invoice_request_mark_used(struct db *db, const struct sha256 *invreq_id)
|
|
|
|
NO_NULL_ARGS;
|
|
|
|
|
2021-08-25 04:50:12 +02:00
|
|
|
/**
|
2021-08-25 04:51:04 +02:00
|
|
|
* Add an new key/value to the datastore (generation 0)
|
2021-08-25 04:50:37 +02:00
|
|
|
* @w: the wallet
|
2021-08-25 04:51:34 +02:00
|
|
|
* @key: the new key (if returns non-NULL)
|
|
|
|
* @data: the new data (if returns non-NULL)
|
2021-08-25 04:50:37 +02:00
|
|
|
*/
|
2021-08-25 04:51:34 +02:00
|
|
|
void wallet_datastore_create(struct wallet *w, const char **key, const u8 *data);
|
2021-08-25 04:50:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an existing key/value to the datastore.
|
2021-08-25 04:50:12 +02:00
|
|
|
* @w: the wallet
|
|
|
|
* @key: the first key (if returns non-NULL)
|
|
|
|
* @data: the first data (if returns non-NULL)
|
|
|
|
*/
|
2021-08-25 04:51:34 +02:00
|
|
|
void wallet_datastore_update(struct wallet *w,
|
|
|
|
const char **key,
|
|
|
|
const u8 *data);
|
2021-08-25 04:50:12 +02:00
|
|
|
|
|
|
|
/**
|
2021-08-25 04:51:34 +02:00
|
|
|
* Remove a key from the datastore
|
2021-08-25 04:50:12 +02:00
|
|
|
* @w: the wallet
|
|
|
|
* @key: the key
|
|
|
|
*/
|
2021-08-25 04:51:34 +02:00
|
|
|
void wallet_datastore_remove(struct wallet *w, const char **key);
|
2021-08-25 04:50:12 +02:00
|
|
|
|
lightningd: simplify datastore internal db API.
The wallet_datastore_first() SELECT statement only iterates from the
given key (if any), relying on the caller to notice when the key no
longer applies. (e.g. startkey = ["foo", "bar"] will return key
["foo", "bar"] then ["foo", "bar", "child" ], then ["foo", "baz"]).
The only caller (listdatastore) would notice the keychange and stop
looping, but reallly wallet_datastore_next() should do this. When I
tried to use it for migrations, I got very confused!
Also, several places want a simple "wallet_datastore_get()" function,
so provide that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 03:51:43 +02:00
|
|
|
/**
|
|
|
|
* Get a single entry from the datastore
|
|
|
|
* @ctx: the tal ctx to allocate off
|
|
|
|
* @w: the wallet
|
|
|
|
* @key: the key
|
|
|
|
* @generation: the generation or NULL (set if returns non-NULL)
|
|
|
|
*/
|
|
|
|
u8 *wallet_datastore_get(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
const char **key,
|
|
|
|
u64 *generation);
|
|
|
|
|
2021-08-25 04:50:12 +02:00
|
|
|
/**
|
|
|
|
* Iterate through the datastore.
|
|
|
|
* @ctx: the tal ctx to allocate off
|
|
|
|
* @w: the wallet
|
lightningd: simplify datastore internal db API.
The wallet_datastore_first() SELECT statement only iterates from the
given key (if any), relying on the caller to notice when the key no
longer applies. (e.g. startkey = ["foo", "bar"] will return key
["foo", "bar"] then ["foo", "bar", "child" ], then ["foo", "baz"]).
The only caller (listdatastore) would notice the keychange and stop
looping, but reallly wallet_datastore_next() should do this. When I
tried to use it for migrations, I got very confused!
Also, several places want a simple "wallet_datastore_get()" function,
so provide that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 03:51:43 +02:00
|
|
|
* @startkey: NULL, or the subkey to iterate
|
2021-08-25 04:50:12 +02:00
|
|
|
* @key: the first key (if returns non-NULL)
|
|
|
|
* @data: the first data (if returns non-NULL)
|
2021-08-25 04:51:04 +02:00
|
|
|
* @generation: the first generation (if returns non-NULL)
|
2021-08-25 04:50:12 +02:00
|
|
|
*
|
|
|
|
* Returns pointer to hand as @stmt to wallet_datastore_next(), or NULL.
|
|
|
|
* If you choose not to call wallet_datastore_next() you must free it!
|
|
|
|
*/
|
|
|
|
struct db_stmt *wallet_datastore_first(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
2021-08-25 04:51:34 +02:00
|
|
|
const char **startkey,
|
|
|
|
const char ***key,
|
2021-08-25 04:51:04 +02:00
|
|
|
const u8 **data,
|
|
|
|
u64 *generation);
|
2021-08-25 04:50:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate through the datastore.
|
|
|
|
* @ctx: the tal ctx to allocate off
|
lightningd: simplify datastore internal db API.
The wallet_datastore_first() SELECT statement only iterates from the
given key (if any), relying on the caller to notice when the key no
longer applies. (e.g. startkey = ["foo", "bar"] will return key
["foo", "bar"] then ["foo", "bar", "child" ], then ["foo", "baz"]).
The only caller (listdatastore) would notice the keychange and stop
looping, but reallly wallet_datastore_next() should do this. When I
tried to use it for migrations, I got very confused!
Also, several places want a simple "wallet_datastore_get()" function,
so provide that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 03:51:43 +02:00
|
|
|
* @startkey: NULL, or the subkey to iterate
|
2021-08-25 04:50:12 +02:00
|
|
|
* @stmt: the previous statement.
|
2021-08-25 04:51:04 +02:00
|
|
|
* @key: the key (if returns non-NULL)
|
|
|
|
* @data: the data (if returns non-NULL)
|
|
|
|
* @generation: the generation (if returns non-NULL)
|
2021-08-25 04:50:12 +02:00
|
|
|
*
|
|
|
|
* Returns pointer to hand as @stmt to wallet_datastore_next(), or NULL.
|
|
|
|
* If you choose not to call wallet_datastore_next() you must free it!
|
|
|
|
*/
|
|
|
|
struct db_stmt *wallet_datastore_next(const tal_t *ctx,
|
lightningd: simplify datastore internal db API.
The wallet_datastore_first() SELECT statement only iterates from the
given key (if any), relying on the caller to notice when the key no
longer applies. (e.g. startkey = ["foo", "bar"] will return key
["foo", "bar"] then ["foo", "bar", "child" ], then ["foo", "baz"]).
The only caller (listdatastore) would notice the keychange and stop
looping, but reallly wallet_datastore_next() should do this. When I
tried to use it for migrations, I got very confused!
Also, several places want a simple "wallet_datastore_get()" function,
so provide that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 03:51:43 +02:00
|
|
|
const char **startkey,
|
2021-08-25 04:50:12 +02:00
|
|
|
struct db_stmt *stmt,
|
2021-08-25 04:51:34 +02:00
|
|
|
const char ***key,
|
2021-08-25 04:51:04 +02:00
|
|
|
const u8 **data,
|
|
|
|
u64 *generation);
|
2021-08-25 04:50:12 +02:00
|
|
|
|
lightningd: simplify datastore internal db API.
The wallet_datastore_first() SELECT statement only iterates from the
given key (if any), relying on the caller to notice when the key no
longer applies. (e.g. startkey = ["foo", "bar"] will return key
["foo", "bar"] then ["foo", "bar", "child" ], then ["foo", "baz"]).
The only caller (listdatastore) would notice the keychange and stop
looping, but reallly wallet_datastore_next() should do this. When I
tried to use it for migrations, I got very confused!
Also, several places want a simple "wallet_datastore_get()" function,
so provide that.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 03:51:43 +02:00
|
|
|
/* Does k1 match k2 as far as k2 goes? */
|
|
|
|
bool datastore_key_startswith(const char **k1, const char **k2);
|
|
|
|
/* Does k1 match k2? */
|
|
|
|
bool datastore_key_eq(const char **k1, const char **k2);
|
|
|
|
|
2022-09-19 02:49:53 +02:00
|
|
|
/**
|
|
|
|
* Iterate through the htlcs table.
|
|
|
|
* @w: the wallet
|
|
|
|
* @chan: optional channel to filter by
|
|
|
|
*
|
|
|
|
* Returns pointer to hand as @iter to wallet_htlcs_next(), or NULL.
|
|
|
|
* If you choose not to call wallet_htlcs_next() you must free it!
|
|
|
|
*/
|
|
|
|
struct wallet_htlc_iter *wallet_htlcs_first(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
const struct channel *chan,
|
|
|
|
struct short_channel_id *scid,
|
|
|
|
u64 *htlc_id,
|
|
|
|
int *cltv_expiry,
|
|
|
|
enum side *owner,
|
|
|
|
struct amount_msat *msat,
|
|
|
|
struct sha256 *payment_hash,
|
|
|
|
enum htlc_state *hstate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate through the htlcs table.
|
|
|
|
* @w: the wallet
|
|
|
|
* @iter: the previous iter.
|
|
|
|
*
|
|
|
|
* Returns pointer to hand as @iter to wallet_htlcs_next(), or NULL.
|
|
|
|
* If you choose not to call wallet_htlcs_next() you must free it!
|
|
|
|
*/
|
|
|
|
struct wallet_htlc_iter *wallet_htlcs_next(struct wallet *w,
|
|
|
|
struct wallet_htlc_iter *iter,
|
|
|
|
struct short_channel_id *scid,
|
|
|
|
u64 *htlc_id,
|
|
|
|
int *cltv_expiry,
|
|
|
|
enum side *owner,
|
|
|
|
struct amount_msat *msat,
|
|
|
|
struct sha256 *payment_hash,
|
|
|
|
enum htlc_state *hstate);
|
2023-04-10 02:19:56 +02:00
|
|
|
|
|
|
|
/* Make a PSBT from these utxos, or enhance @base if non-NULL. */
|
|
|
|
struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
|
|
|
|
struct wallet *wallet,
|
|
|
|
struct utxo **utxos,
|
|
|
|
u32 nlocktime,
|
|
|
|
u32 nsequence,
|
|
|
|
struct wally_psbt *base);
|
2023-07-21 02:15:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a particular runestring from the db
|
|
|
|
* @ctx: tal ctx for return to be tallocated from
|
|
|
|
* @wallet: the wallet
|
|
|
|
* @unique_id: the id of the rune.
|
2023-09-14 03:18:17 +02:00
|
|
|
* @last_used: absolute time rune was last used
|
2023-07-21 02:15:19 +02:00
|
|
|
*
|
|
|
|
* Returns NULL if it's not found.
|
|
|
|
*/
|
2023-09-14 03:18:17 +02:00
|
|
|
const char *wallet_get_rune(const tal_t *ctx, struct wallet *wallet, u64 unique_id, struct timeabs *last_used);
|
2023-07-21 02:15:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get every runestring from the db
|
|
|
|
* @ctx: tal ctx for return to be tallocated from
|
|
|
|
* @wallet: the wallet
|
2023-09-14 03:18:17 +02:00
|
|
|
* @last_used: absolute time rune was last used
|
2023-07-21 02:15:19 +02:00
|
|
|
*/
|
2023-09-14 03:18:17 +02:00
|
|
|
const char **wallet_get_runes(const tal_t *ctx, struct wallet *wallet, struct timeabs **last_used);
|
2023-07-21 02:15:19 +02:00
|
|
|
|
2023-07-21 02:23:56 +02:00
|
|
|
/**
|
|
|
|
* wallet_rune_insert -- Insert the newly created rune into the database
|
|
|
|
*
|
|
|
|
* @wallet: the wallet to save into
|
|
|
|
* @rune: the instance to store
|
|
|
|
*/
|
2023-08-30 05:12:55 +02:00
|
|
|
void wallet_rune_insert(struct wallet *wallet, const struct rune *rune);
|
2023-07-21 02:23:56 +02:00
|
|
|
|
2023-09-14 03:20:31 +02:00
|
|
|
/**
|
|
|
|
* wallet_rune_update_last_used -- Update the timestamp on an existing rune
|
|
|
|
*
|
|
|
|
* @wallet: the wallet to save into
|
|
|
|
* @rune: the instance to store
|
|
|
|
* @last_used: now
|
|
|
|
*/
|
|
|
|
void wallet_rune_update_last_used(struct wallet *wallet, const struct rune *rune, struct timeabs last_used);
|
|
|
|
|
2023-07-21 02:15:19 +02:00
|
|
|
/* Load the runes blacklist */
|
|
|
|
struct rune_blacklist {
|
|
|
|
u64 start, end;
|
|
|
|
};
|
|
|
|
|
2023-09-23 03:21:32 +02:00
|
|
|
/**
|
|
|
|
* Load the next unique id for rune from the db.
|
|
|
|
* @ctx: tal ctx for return to be tallocated from
|
|
|
|
* @wallet: the wallet
|
|
|
|
*/
|
|
|
|
u64 wallet_get_rune_next_unique_id(const tal_t *ctx, struct wallet *wallet);
|
|
|
|
|
2023-07-21 02:15:19 +02:00
|
|
|
/**
|
|
|
|
* Load the blacklist from the db.
|
|
|
|
* @ctx: tal ctx for return to be tallocated from
|
|
|
|
* @wallet: the wallet
|
|
|
|
*/
|
|
|
|
struct rune_blacklist *wallet_get_runes_blacklist(const tal_t *ctx, struct wallet *wallet);
|
|
|
|
|
2023-07-21 03:25:38 +02:00
|
|
|
/**
|
|
|
|
* wallet_insert_blacklist -- Insert rune into blacklist
|
|
|
|
*
|
|
|
|
* @wallet: the wallet to save into
|
|
|
|
* @entry: the new entry to insert
|
|
|
|
*/
|
|
|
|
void wallet_insert_blacklist(struct wallet *wallet, const struct rune_blacklist *entry);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_delete_blacklist -- Delete row from blacklist
|
|
|
|
*
|
|
|
|
* @wallet: the wallet to delete from
|
|
|
|
* @entry: the entry to delete
|
|
|
|
*/
|
|
|
|
void wallet_delete_blacklist(struct wallet *wallet, const struct rune_blacklist *entry);
|
|
|
|
|
2023-10-26 04:37:03 +02:00
|
|
|
/**
|
|
|
|
* wallet_set_local_anchor -- Set local anchor point for a remote commitment tx
|
|
|
|
* @w: wallet containing the channel
|
|
|
|
* @channel_id: channel database id
|
|
|
|
* @anchor: the local_anchor_info describing the remote commitment tx.
|
|
|
|
* @remote_index: the (remote) commitment index
|
|
|
|
*/
|
|
|
|
void wallet_set_local_anchor(struct wallet *w,
|
|
|
|
u64 channel_id,
|
|
|
|
const struct local_anchor_info *anchor,
|
|
|
|
u64 remote_index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_remove_local_anchors -- Remove old local anchor points
|
|
|
|
* @w: wallet containing the channel
|
|
|
|
* @channel_id: channel database id
|
|
|
|
* @old_remote_index: the (remote) commitment index to remove
|
|
|
|
*
|
|
|
|
* Since we only have to keep the last two, we use this to remove the
|
|
|
|
* old entries for the channel.
|
|
|
|
*/
|
|
|
|
void wallet_remove_local_anchors(struct wallet *w,
|
|
|
|
u64 channel_id,
|
|
|
|
u64 old_remote_index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wallet_get_local_anchors -- Get all local anchor points for remote commitment txs
|
|
|
|
* @ctx: tal context for returned array
|
|
|
|
* @w: wallet containing the channel
|
|
|
|
* @channel_id: channel database id
|
|
|
|
*/
|
|
|
|
struct local_anchor_info *wallet_get_local_anchors(const tal_t *ctx,
|
|
|
|
struct wallet *w,
|
|
|
|
u64 channel_id);
|
2018-03-22 11:36:25 +01:00
|
|
|
#endif /* LIGHTNING_WALLET_WALLET_H */
|