bkpr: use the in-memory event descriptions, not the database ones.
The new access APIs are more symmetrical: 1. edit_utxo_description -> add_utxo_description 2. add_payment_hash_desc -> add_payment_hash_description And to read it, instead of accessing ->ev_desc (now removed) we use chain_event_description() & channel_event_description(), threading bkpr though as needed. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -366,6 +366,7 @@ static struct command_result *json_inspect(struct command *cmd,
|
||||
}
|
||||
|
||||
static void json_add_events(struct json_stream *res,
|
||||
const struct bkpr *bkpr,
|
||||
struct channel_event **channel_events,
|
||||
struct chain_event **chain_events,
|
||||
struct onchain_fee **onchain_fees)
|
||||
@@ -406,13 +407,13 @@ static void json_add_events(struct json_stream *res,
|
||||
|
||||
/* chain events first, then channel events, then fees. */
|
||||
if (chain && chain->timestamp == lowest) {
|
||||
json_add_chain_event(res, chain);
|
||||
json_add_chain_event(res, bkpr, chain);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (chan && chan->timestamp == lowest) {
|
||||
json_add_channel_event(res, chan);
|
||||
json_add_channel_event(res, bkpr, chan);
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
@@ -483,7 +484,7 @@ static struct command_result *json_list_account_events(struct command *cmd,
|
||||
|
||||
res = jsonrpc_stream_success(cmd);
|
||||
json_array_start(res, "events");
|
||||
json_add_events(res, channel_events, chain_events, onchain_fees);
|
||||
json_add_events(res, bkpr, channel_events, chain_events, onchain_fees);
|
||||
json_array_end(res);
|
||||
return command_finished(cmd, res);
|
||||
}
|
||||
@@ -518,13 +519,13 @@ static struct command_result *json_edit_desc_utxo(struct command *cmd,
|
||||
return command_param_failed();
|
||||
|
||||
db_begin_transaction(bkpr->db);
|
||||
edit_utxo_description(bkpr->db, outpoint, new_desc);
|
||||
add_utxo_description(cmd, bkpr, outpoint, new_desc);
|
||||
chain_events = get_chain_events_by_outpoint(cmd, bkpr->db, outpoint, true);
|
||||
db_commit_transaction(bkpr->db);
|
||||
|
||||
res = jsonrpc_stream_success(cmd);
|
||||
json_array_start(res, "updated");
|
||||
json_add_events(res, NULL, chain_events, NULL);
|
||||
json_add_events(res, bkpr, NULL, chain_events, NULL);
|
||||
json_array_end(res);
|
||||
|
||||
return command_finished(cmd, res);
|
||||
@@ -548,7 +549,7 @@ static struct command_result *json_edit_desc_payment_id(struct command *cmd,
|
||||
return command_param_failed();
|
||||
|
||||
db_begin_transaction(bkpr->db);
|
||||
add_payment_hash_desc(bkpr->db, identifier, new_desc);
|
||||
add_payment_hash_description(cmd, bkpr, identifier, new_desc);
|
||||
|
||||
chain_events = get_chain_events_by_id(cmd, bkpr->db, identifier);
|
||||
channel_events = get_channel_events_by_id(cmd, bkpr->db, identifier);
|
||||
@@ -556,7 +557,7 @@ static struct command_result *json_edit_desc_payment_id(struct command *cmd,
|
||||
|
||||
res = jsonrpc_stream_success(cmd);
|
||||
json_array_start(res, "updated");
|
||||
json_add_events(res, channel_events, chain_events, NULL);
|
||||
json_add_events(res, bkpr, channel_events, chain_events, NULL);
|
||||
json_array_end(res);
|
||||
|
||||
return command_finished(cmd, res);
|
||||
@@ -783,7 +784,6 @@ static bool new_missed_channel_account(struct command *cmd,
|
||||
chain_ev->payment_id = NULL;
|
||||
chain_ev->stealable = false;
|
||||
chain_ev->splice_close = false;
|
||||
chain_ev->desc = NULL;
|
||||
|
||||
/* Update the account info too */
|
||||
tags = tal_arr(chain_ev, enum mvt_tag, 1);
|
||||
@@ -1290,11 +1290,10 @@ listinvoices_done(struct command *cmd,
|
||||
}
|
||||
|
||||
if (desc) {
|
||||
db_begin_transaction(bkpr->db);
|
||||
add_payment_hash_desc(bkpr->db, payment_hash,
|
||||
add_payment_hash_description(cmd, bkpr, payment_hash,
|
||||
json_escape_unescape(cmd,
|
||||
(struct json_escape *)desc));
|
||||
db_commit_transaction(bkpr->db);
|
||||
|
||||
} else
|
||||
plugin_log(cmd->plugin, LOG_DBG,
|
||||
"listinvoices:"
|
||||
@@ -1335,9 +1334,7 @@ listsendpays_done(struct command *cmd,
|
||||
}
|
||||
|
||||
if (desc) {
|
||||
db_begin_transaction(bkpr->db);
|
||||
add_payment_hash_desc(bkpr->db, payment_hash, desc);
|
||||
db_commit_transaction(bkpr->db);
|
||||
add_payment_hash_description(cmd, bkpr, payment_hash, desc);
|
||||
} else
|
||||
plugin_log(cmd->plugin, LOG_DBG,
|
||||
"listpays: bolt11/bolt12 not found:"
|
||||
@@ -1436,8 +1433,7 @@ parse_and_log_chain_move(struct command *cmd,
|
||||
const struct amount_msat debit,
|
||||
const char *coin_type STEALS,
|
||||
const u64 timestamp,
|
||||
const enum mvt_tag *tags,
|
||||
const char *desc)
|
||||
const enum mvt_tag *tags)
|
||||
{
|
||||
struct chain_event *e = tal(cmd, struct chain_event);
|
||||
struct sha256 *payment_hash = tal(cmd, struct sha256);
|
||||
@@ -1529,7 +1525,6 @@ parse_and_log_chain_move(struct command *cmd,
|
||||
e->debit = debit;
|
||||
e->timestamp = timestamp;
|
||||
e->tag = mvt_tag_str(tags[0]);
|
||||
e->desc = tal_steal(e, desc);
|
||||
|
||||
e->stealable = false;
|
||||
e->splice_close = false;
|
||||
@@ -1645,8 +1640,7 @@ parse_and_log_channel_move(struct command *cmd,
|
||||
const struct amount_msat debit,
|
||||
const char *coin_type STEALS,
|
||||
const u64 timestamp,
|
||||
const enum mvt_tag *tags,
|
||||
const char *desc)
|
||||
const enum mvt_tag *tags)
|
||||
{
|
||||
struct channel_event *e = tal(cmd, struct channel_event);
|
||||
struct account *acct;
|
||||
@@ -1682,7 +1676,6 @@ parse_and_log_channel_move(struct command *cmd,
|
||||
e->debit = debit;
|
||||
e->timestamp = timestamp;
|
||||
e->tag = mvt_tag_str(tags[0]);
|
||||
e->desc = tal_steal(e, desc);
|
||||
e->rebalance_id = NULL;
|
||||
|
||||
/* Go find the account for this event */
|
||||
@@ -1784,7 +1777,6 @@ static struct command_result *json_utxo_deposit(struct command *cmd, const char
|
||||
ev->output_value = ev->credit;
|
||||
ev->spending_txid = NULL;
|
||||
ev->payment_id = NULL;
|
||||
ev->desc = NULL;
|
||||
ev->splice_close = false;
|
||||
|
||||
plugin_log(cmd->plugin, LOG_DBG, "%s (%s|%s) %s -%s %"PRIu64" %d %s",
|
||||
@@ -1855,7 +1847,6 @@ static struct command_result *json_utxo_spend(struct command *cmd, const char *b
|
||||
ev->credit = AMOUNT_MSAT(0);
|
||||
ev->output_value = ev->debit;
|
||||
ev->payment_id = NULL;
|
||||
ev->desc = NULL;
|
||||
|
||||
plugin_log(cmd->plugin, LOG_DBG, "%s (%s|%s) %s -%s %"PRIu64" %d %s %s",
|
||||
move_tag, ev->tag, acct_name,
|
||||
@@ -1954,15 +1945,13 @@ static struct command_result *json_coin_moved(struct command *cmd,
|
||||
if (streq(mvt_type, CHAIN_MOVE))
|
||||
return parse_and_log_chain_move(cmd, buf, params,
|
||||
acct_name, credit, debit,
|
||||
coin_type, timestamp, tags,
|
||||
NULL);
|
||||
coin_type, timestamp, tags);
|
||||
|
||||
|
||||
assert(streq(mvt_type, CHANNEL_MOVE));
|
||||
return parse_and_log_channel_move(cmd, buf, params,
|
||||
acct_name, credit, debit,
|
||||
coin_type, timestamp, tags,
|
||||
NULL);
|
||||
coin_type, timestamp, tags);
|
||||
}
|
||||
|
||||
const struct plugin_notification notifs[] = {
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
#include <common/json_stream.h>
|
||||
#include <plugins/bkpr/chain_event.h>
|
||||
#include <plugins/bkpr/descriptions.h>
|
||||
|
||||
void json_add_chain_event(struct json_stream *out, struct chain_event *ev)
|
||||
void json_add_chain_event(struct json_stream *out,
|
||||
const struct bkpr *bkpr,
|
||||
struct chain_event *ev)
|
||||
{
|
||||
const char *desc;
|
||||
json_object_start(out, NULL);
|
||||
json_add_string(out, "account", ev->acct_name);
|
||||
if (ev->origin_acct)
|
||||
@@ -15,14 +19,16 @@ void json_add_chain_event(struct json_stream *out, struct chain_event *ev)
|
||||
json_add_amount_msat(out, "debit_msat", ev->debit);
|
||||
json_add_string(out, "currency", chainparams->lightning_hrp);
|
||||
json_add_outpoint(out, "outpoint", &ev->outpoint);
|
||||
desc = chain_event_description(bkpr, ev);
|
||||
|
||||
if (ev->spending_txid)
|
||||
json_add_txid(out, "txid", ev->spending_txid);
|
||||
if (ev->payment_id)
|
||||
if (ev->payment_id) {
|
||||
json_add_sha256(out, "payment_id", ev->payment_id);
|
||||
}
|
||||
json_add_u64(out, "timestamp", ev->timestamp);
|
||||
json_add_u32(out, "blockheight", ev->blockheight);
|
||||
if (ev->desc)
|
||||
json_add_string(out, "description", ev->desc);
|
||||
if (desc)
|
||||
json_add_string(out, "description", desc);
|
||||
json_object_end(out);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <ccan/short_types/short_types.h>
|
||||
|
||||
struct amount_msat;
|
||||
struct bkpr;
|
||||
struct bitcoin_outpoint;
|
||||
struct bitcoin_txid;
|
||||
struct json_stream;
|
||||
@@ -58,12 +59,10 @@ struct chain_event {
|
||||
|
||||
/* Sometimes chain events resolve payments */
|
||||
struct sha256 *payment_id;
|
||||
|
||||
/* Desc of event (maybe useful for printing notes) */
|
||||
const char *desc;
|
||||
};
|
||||
|
||||
void json_add_chain_event(struct json_stream *out,
|
||||
const struct bkpr *bkpr,
|
||||
struct chain_event *ev);
|
||||
|
||||
#endif /* LIGHTNING_PLUGINS_BKPR_CHAIN_EVENT_H */
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <common/amount.h>
|
||||
#include <common/json_stream.h>
|
||||
#include <plugins/bkpr/channel_event.h>
|
||||
#include <plugins/bkpr/descriptions.h>
|
||||
|
||||
struct channel_event *new_channel_event(const tal_t *ctx,
|
||||
const char *tag,
|
||||
@@ -25,13 +26,13 @@ struct channel_event *new_channel_event(const tal_t *ctx,
|
||||
ev->payment_id = tal_steal(ev, payment_id);
|
||||
ev->part_id = part_id;
|
||||
ev->timestamp = timestamp;
|
||||
ev->desc = NULL;
|
||||
ev->rebalance_id = NULL;
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
void json_add_channel_event(struct json_stream *out,
|
||||
const struct bkpr *bkpr,
|
||||
struct channel_event *ev)
|
||||
{
|
||||
json_object_start(out, NULL);
|
||||
@@ -44,12 +45,13 @@ void json_add_channel_event(struct json_stream *out,
|
||||
json_add_amount_msat(out, "fees_msat", ev->fees);
|
||||
json_add_string(out, "currency", chainparams->lightning_hrp);
|
||||
if (ev->payment_id) {
|
||||
const char *desc = channel_event_description(bkpr, ev);
|
||||
json_add_sha256(out, "payment_id", ev->payment_id);
|
||||
json_add_u32(out, "part_id", ev->part_id);
|
||||
if (desc)
|
||||
json_add_string(out, "description", desc);
|
||||
}
|
||||
json_add_u64(out, "timestamp", ev->timestamp);
|
||||
if (ev->desc)
|
||||
json_add_string(out, "description", ev->desc);
|
||||
json_add_bool(out, "is_rebalance", ev->rebalance_id != NULL);
|
||||
json_object_end(out);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <common/utils.h>
|
||||
|
||||
struct amount_msat;
|
||||
struct bkpr;
|
||||
struct json_stream;
|
||||
struct sha256;
|
||||
|
||||
@@ -38,9 +39,6 @@ struct channel_event {
|
||||
/* What time did the event happen */
|
||||
u64 timestamp;
|
||||
|
||||
/* Description, usually from invoice */
|
||||
const char *desc;
|
||||
|
||||
/* ID of paired event, iff is a rebalance */
|
||||
u64 *rebalance_id;
|
||||
};
|
||||
@@ -55,6 +53,7 @@ struct channel_event *new_channel_event(const tal_t *ctx,
|
||||
u64 timestamp);
|
||||
|
||||
void json_add_channel_event(struct json_stream *out,
|
||||
const struct bkpr *bkpr,
|
||||
struct channel_event *ev);
|
||||
|
||||
#endif /* LIGHTNING_PLUGINS_BKPR_CHANNEL_EVENT_H */
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <plugins/bkpr/bookkeeper.h>
|
||||
#include <plugins/bkpr/chain_event.h>
|
||||
#include <plugins/bkpr/channel_event.h>
|
||||
#include <plugins/bkpr/descriptions.h>
|
||||
#include <plugins/bkpr/incomestmt.h>
|
||||
#include <plugins/bkpr/onchain_fee.h>
|
||||
#include <plugins/bkpr/recorder.h>
|
||||
@@ -23,6 +24,7 @@
|
||||
#define ONCHAIN_FEE "onchain_fee"
|
||||
|
||||
static struct income_event *chain_to_income(const tal_t *ctx,
|
||||
const struct bkpr *bkpr,
|
||||
struct chain_event *ev,
|
||||
const char *acct_to_attribute,
|
||||
struct amount_msat credit,
|
||||
@@ -37,7 +39,7 @@ static struct income_event *chain_to_income(const tal_t *ctx,
|
||||
inc->fees = AMOUNT_MSAT(0);
|
||||
inc->timestamp = ev->timestamp;
|
||||
inc->outpoint = tal_dup(inc, struct bitcoin_outpoint, &ev->outpoint);
|
||||
inc->desc = tal_strdup_or_null(inc, ev->desc);
|
||||
inc->desc = tal_strdup_or_null(inc, chain_event_description(bkpr, ev));
|
||||
inc->txid = tal_dup_or_null(inc, struct bitcoin_txid, ev->spending_txid);
|
||||
inc->payment_id = tal_dup_or_null(inc, struct sha256, ev->payment_id);
|
||||
|
||||
@@ -45,6 +47,7 @@ static struct income_event *chain_to_income(const tal_t *ctx,
|
||||
}
|
||||
|
||||
static struct income_event *channel_to_income(const tal_t *ctx,
|
||||
const struct bkpr *bkpr,
|
||||
struct channel_event *ev,
|
||||
struct amount_msat credit,
|
||||
struct amount_msat debit)
|
||||
@@ -59,7 +62,7 @@ static struct income_event *channel_to_income(const tal_t *ctx,
|
||||
inc->timestamp = ev->timestamp;
|
||||
inc->outpoint = NULL;
|
||||
inc->txid = NULL;
|
||||
inc->desc = tal_strdup_or_null(inc, ev->desc);
|
||||
inc->desc = tal_strdup_or_null(inc, channel_event_description(bkpr, ev));
|
||||
inc->payment_id = tal_dup_or_null(inc, struct sha256, ev->payment_id);
|
||||
|
||||
return inc;
|
||||
@@ -106,19 +109,19 @@ static char *csv_safe_str(const tal_t *ctx, const char *input TAKES)
|
||||
}
|
||||
|
||||
static struct income_event *maybe_chain_income(const tal_t *ctx,
|
||||
struct db *db,
|
||||
const struct bkpr *bkpr,
|
||||
struct account *acct,
|
||||
struct chain_event *ev)
|
||||
{
|
||||
if (streq(ev->tag, "htlc_fulfill")) {
|
||||
if (is_external_account(ev->acct_name))
|
||||
/* Swap the credit/debit as it went to external */
|
||||
return chain_to_income(ctx, ev,
|
||||
return chain_to_income(ctx, bkpr, ev,
|
||||
ev->origin_acct,
|
||||
ev->debit,
|
||||
ev->credit);
|
||||
/* Normal credit/debit as it originated from external */
|
||||
return chain_to_income(ctx, ev,
|
||||
return chain_to_income(ctx, bkpr, ev,
|
||||
ev->acct_name,
|
||||
ev->credit, ev->debit);
|
||||
}
|
||||
@@ -127,7 +130,7 @@ static struct income_event *maybe_chain_income(const tal_t *ctx,
|
||||
if (streq(ev->tag, "anchor")) {
|
||||
if (acct->we_opened)
|
||||
/* for now, we count all anchors as expenses */
|
||||
return chain_to_income(ctx, ev,
|
||||
return chain_to_income(ctx, bkpr, ev,
|
||||
ev->acct_name,
|
||||
ev->debit,
|
||||
ev->credit);
|
||||
@@ -148,7 +151,7 @@ static struct income_event *maybe_chain_income(const tal_t *ctx,
|
||||
if (ev->blockheight == 0)
|
||||
return NULL;
|
||||
|
||||
iev = chain_to_income(ctx, ev,
|
||||
iev = chain_to_income(ctx, bkpr, ev,
|
||||
ev->origin_acct,
|
||||
ev->debit,
|
||||
ev->credit);
|
||||
@@ -164,7 +167,7 @@ static struct income_event *maybe_chain_income(const tal_t *ctx,
|
||||
* into a tx that included funds from a 3rd party
|
||||
* coming to us... eg. a splice out from the peer
|
||||
* to our onchain wallet */
|
||||
stmt = db_prepare_v2(db, SQL("SELECT"
|
||||
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
|
||||
" 1"
|
||||
" FROM chain_events e"
|
||||
" WHERE "
|
||||
@@ -176,7 +179,7 @@ static struct income_event *maybe_chain_income(const tal_t *ctx,
|
||||
tal_free(stmt);
|
||||
/* no matching withdrawal from internal,
|
||||
* so must be new deposit (external) */
|
||||
return chain_to_income(ctx, ev,
|
||||
return chain_to_income(ctx, bkpr, ev,
|
||||
ev->acct_name,
|
||||
ev->credit,
|
||||
ev->debit);
|
||||
@@ -191,26 +194,29 @@ static struct income_event *maybe_chain_income(const tal_t *ctx,
|
||||
}
|
||||
|
||||
static struct income_event *paid_invoice_fee(const tal_t *ctx,
|
||||
const struct bkpr *bkpr,
|
||||
struct channel_event *ev)
|
||||
{
|
||||
struct income_event *iev;
|
||||
iev = channel_to_income(ctx, ev, AMOUNT_MSAT(0), ev->fees);
|
||||
iev = channel_to_income(ctx, bkpr, ev, AMOUNT_MSAT(0), ev->fees);
|
||||
iev->tag = tal_free(ev->tag);
|
||||
iev->tag = (char *)account_entry_tag_str(INVOICEFEE);
|
||||
return iev;
|
||||
}
|
||||
|
||||
static struct income_event *rebalance_fee(const tal_t *ctx,
|
||||
const struct bkpr *bkpr,
|
||||
struct channel_event *ev)
|
||||
{
|
||||
struct income_event *iev;
|
||||
iev = channel_to_income(ctx, ev, AMOUNT_MSAT(0), ev->fees);
|
||||
iev = channel_to_income(ctx, bkpr, ev, AMOUNT_MSAT(0), ev->fees);
|
||||
iev->tag = tal_free(ev->tag);
|
||||
iev->tag = (char *)account_entry_tag_str(REBALANCEFEE);
|
||||
return iev;
|
||||
}
|
||||
|
||||
static struct income_event *maybe_channel_income(const tal_t *ctx,
|
||||
const struct bkpr *bkpr,
|
||||
struct channel_event *ev)
|
||||
{
|
||||
if (amount_msat_is_zero(ev->credit)
|
||||
@@ -220,7 +226,7 @@ static struct income_event *maybe_channel_income(const tal_t *ctx,
|
||||
/* We record a +/- penalty adj, but we only count the credit */
|
||||
if (streq(ev->tag, "penalty_adj")) {
|
||||
if (!amount_msat_is_zero(ev->credit))
|
||||
return channel_to_income(ctx, ev,
|
||||
return channel_to_income(ctx, bkpr, ev,
|
||||
ev->credit,
|
||||
ev->debit);
|
||||
return NULL;
|
||||
@@ -237,12 +243,12 @@ static struct income_event *maybe_channel_income(const tal_t *ctx,
|
||||
bool ok;
|
||||
ok = amount_msat_sub(&paid, ev->debit, ev->fees);
|
||||
assert(ok);
|
||||
return channel_to_income(ctx, ev,
|
||||
return channel_to_income(ctx, bkpr, ev,
|
||||
ev->credit,
|
||||
paid);
|
||||
}
|
||||
|
||||
return channel_to_income(ctx, ev,
|
||||
return channel_to_income(ctx, bkpr, ev,
|
||||
ev->credit,
|
||||
ev->debit);
|
||||
}
|
||||
@@ -251,7 +257,7 @@ static struct income_event *maybe_channel_income(const tal_t *ctx,
|
||||
* debiting side -- the side the $$ was made on! */
|
||||
if (streq(ev->tag, "routed")) {
|
||||
if (!amount_msat_is_zero(ev->debit))
|
||||
return channel_to_income(ctx, ev,
|
||||
return channel_to_income(ctx, bkpr, ev,
|
||||
ev->fees,
|
||||
AMOUNT_MSAT(0));
|
||||
return NULL;
|
||||
@@ -259,7 +265,7 @@ static struct income_event *maybe_channel_income(const tal_t *ctx,
|
||||
|
||||
/* For everything else, it's straight forward */
|
||||
/* (lease_fee, pushed, journal_entry) */
|
||||
return channel_to_income(ctx, ev, ev->credit, ev->debit);
|
||||
return channel_to_income(ctx, bkpr, ev, ev->credit, ev->debit);
|
||||
}
|
||||
|
||||
static struct onchain_fee **find_consolidated_fees(const tal_t *ctx,
|
||||
@@ -364,7 +370,7 @@ struct income_event **list_income_events(const tal_t *ctx,
|
||||
struct account *acct =
|
||||
find_account(bkpr, chain->acct_name);
|
||||
|
||||
ev = maybe_chain_income(evs, db, acct, chain);
|
||||
ev = maybe_chain_income(evs, bkpr, acct, chain);
|
||||
if (ev)
|
||||
tal_arr_expand(&evs, ev);
|
||||
i++;
|
||||
@@ -373,7 +379,7 @@ struct income_event **list_income_events(const tal_t *ctx,
|
||||
|
||||
if (chan && chan->timestamp == lowest) {
|
||||
struct income_event *ev;
|
||||
ev = maybe_channel_income(evs, chan);
|
||||
ev = maybe_channel_income(evs, bkpr, chan);
|
||||
if (ev)
|
||||
tal_arr_expand(&evs, ev);
|
||||
|
||||
@@ -382,9 +388,9 @@ struct income_event **list_income_events(const tal_t *ctx,
|
||||
&& !amount_msat_is_zero(chan->debit)
|
||||
&& !amount_msat_is_zero(chan->fees)) {
|
||||
if (!chan->rebalance_id)
|
||||
ev = paid_invoice_fee(evs, chan);
|
||||
ev = paid_invoice_fee(evs, bkpr, chan);
|
||||
else
|
||||
ev = rebalance_fee(evs, chan);
|
||||
ev = rebalance_fee(evs, bkpr, chan);
|
||||
tal_arr_expand(&evs, ev);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,12 +55,6 @@ static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *st
|
||||
e->spending_txid = NULL;
|
||||
|
||||
e->stealable = db_col_int(stmt, "e.stealable") == 1;
|
||||
|
||||
if (!db_col_is_null(stmt, "e.ev_desc"))
|
||||
e->desc = db_col_strdup(e, stmt, "e.ev_desc");
|
||||
else
|
||||
e->desc = NULL;
|
||||
|
||||
e->splice_close = db_col_int(stmt, "e.spliced") == 1;
|
||||
|
||||
return e;
|
||||
@@ -107,11 +101,6 @@ static struct channel_event *stmt2channel_event(const tal_t *ctx, struct db_stmt
|
||||
e->part_id = db_col_int(stmt, "e.part_id");
|
||||
e->timestamp = db_col_u64(stmt, "e.timestamp");
|
||||
|
||||
if (!db_col_is_null(stmt, "e.ev_desc"))
|
||||
e->desc = db_col_strdup(e, stmt, "e.ev_desc");
|
||||
else
|
||||
e->desc = NULL;
|
||||
|
||||
if (!db_col_is_null(stmt, "e.rebalance_id")) {
|
||||
e->rebalance_id = tal(e, u64);
|
||||
*e->rebalance_id = db_col_u64(stmt, "e.rebalance_id");
|
||||
@@ -177,7 +166,6 @@ struct chain_event **list_chain_events_timebox(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE e.timestamp > ?"
|
||||
@@ -215,7 +203,6 @@ struct chain_event **account_get_chain_events(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE e.account_name = ?"
|
||||
@@ -246,7 +233,6 @@ static struct chain_event **find_txos_for_tx(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE e.utxo_txid = ?"
|
||||
@@ -504,51 +490,6 @@ u64 account_onchain_closeheight(struct db *db, const struct account *acct)
|
||||
return height;
|
||||
}
|
||||
|
||||
void edit_utxo_description(struct db *db,
|
||||
struct bitcoin_outpoint *outpoint,
|
||||
const char *desc)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
|
||||
/* Ok, now we update the account with this blockheight */
|
||||
stmt = db_prepare_v2(db, SQL("UPDATE chain_events SET"
|
||||
" ev_desc = ?"
|
||||
" WHERE"
|
||||
" utxo_txid = ?"
|
||||
" AND outnum = ?"
|
||||
" AND credit > 0"));
|
||||
db_bind_text(stmt, desc);
|
||||
db_bind_txid(stmt, &outpoint->txid);
|
||||
db_bind_int(stmt, outpoint->n);
|
||||
|
||||
db_exec_prepared_v2(take(stmt));
|
||||
}
|
||||
|
||||
void add_payment_hash_desc(struct db *db,
|
||||
struct sha256 *payment_hash,
|
||||
const char *desc)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
|
||||
/* Ok, now we update the account with this blockheight */
|
||||
stmt = db_prepare_v2(db, SQL("UPDATE channel_events SET"
|
||||
" ev_desc = ?"
|
||||
" WHERE"
|
||||
" payment_id = ?"));
|
||||
db_bind_text(stmt, desc);
|
||||
db_bind_sha256(stmt, payment_hash);
|
||||
db_exec_prepared_v2(take(stmt));
|
||||
|
||||
/* Ok, now we update the account with this blockheight */
|
||||
stmt = db_prepare_v2(db, SQL("UPDATE chain_events SET"
|
||||
" ev_desc = ?"
|
||||
" WHERE"
|
||||
" payment_id = ?"));
|
||||
db_bind_text(stmt, desc);
|
||||
db_bind_sha256(stmt, payment_hash);
|
||||
db_exec_prepared_v2(take(stmt));
|
||||
}
|
||||
|
||||
struct chain_event *find_chain_event_by_id(const tal_t *ctx,
|
||||
struct db *db,
|
||||
u64 event_db_id)
|
||||
@@ -571,7 +512,6 @@ struct chain_event *find_chain_event_by_id(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE "
|
||||
@@ -610,7 +550,6 @@ struct chain_event **get_chain_events_by_outpoint(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE "
|
||||
@@ -633,7 +572,6 @@ struct chain_event **get_chain_events_by_outpoint(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE "
|
||||
@@ -665,7 +603,6 @@ struct chain_event **get_chain_events_by_id(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE "
|
||||
@@ -702,7 +639,6 @@ static struct chain_event *find_chain_event(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE "
|
||||
@@ -727,7 +663,6 @@ static struct chain_event *find_chain_event(const tal_t *ctx,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE "
|
||||
@@ -836,7 +771,6 @@ struct channel_event **list_channel_events_timebox(const tal_t *ctx,
|
||||
", e.payment_id"
|
||||
", e.part_id"
|
||||
", e.timestamp"
|
||||
", e.ev_desc"
|
||||
", e.rebalance_id"
|
||||
" FROM channel_events e"
|
||||
" WHERE e.timestamp > ?"
|
||||
@@ -879,7 +813,6 @@ struct channel_event **account_get_channel_events(const tal_t *ctx,
|
||||
", e.payment_id"
|
||||
", e.part_id"
|
||||
", e.timestamp"
|
||||
", e.ev_desc"
|
||||
", e.rebalance_id"
|
||||
" FROM channel_events e"
|
||||
" WHERE e.account_name = ?"
|
||||
@@ -905,7 +838,6 @@ struct channel_event **get_channel_events_by_id(const tal_t *ctx,
|
||||
", e.payment_id"
|
||||
", e.part_id"
|
||||
", e.timestamp"
|
||||
", e.ev_desc"
|
||||
", e.rebalance_id"
|
||||
" FROM channel_events e"
|
||||
" WHERE e.payment_id = ?"
|
||||
@@ -931,11 +863,10 @@ void log_channel_event(struct db *db,
|
||||
", payment_id"
|
||||
", part_id"
|
||||
", timestamp"
|
||||
", ev_desc"
|
||||
", rebalance_id"
|
||||
")"
|
||||
" VALUES"
|
||||
" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||
" (?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||
|
||||
db_bind_text(stmt, acct->name);
|
||||
db_bind_text(stmt, e->tag);
|
||||
@@ -948,10 +879,6 @@ void log_channel_event(struct db *db,
|
||||
db_bind_null(stmt);
|
||||
db_bind_int(stmt, e->part_id);
|
||||
db_bind_u64(stmt, e->timestamp);
|
||||
if (e->desc)
|
||||
db_bind_text(stmt, e->desc);
|
||||
else
|
||||
db_bind_null(stmt);
|
||||
|
||||
if (e->rebalance_id)
|
||||
db_bind_u64(stmt, *e->rebalance_id);
|
||||
@@ -984,7 +911,6 @@ struct chain_event **find_chain_events_bytxid(const tal_t *ctx, struct db *db,
|
||||
", e.spending_txid"
|
||||
", e.payment_id"
|
||||
", e.stealable"
|
||||
", e.ev_desc"
|
||||
", e.spliced"
|
||||
" FROM chain_events e"
|
||||
" WHERE e.spending_txid = ?"
|
||||
@@ -1143,11 +1069,10 @@ bool log_chain_event(struct db *db,
|
||||
", payment_id"
|
||||
", spending_txid"
|
||||
", stealable"
|
||||
", ev_desc"
|
||||
", spliced"
|
||||
")"
|
||||
" VALUES "
|
||||
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||
|
||||
db_bind_text(stmt, acct->name);
|
||||
if (e->origin_acct)
|
||||
@@ -1174,10 +1099,6 @@ bool log_chain_event(struct db *db,
|
||||
db_bind_null(stmt);
|
||||
|
||||
db_bind_int(stmt, e->stealable ? 1 : 0);
|
||||
if (e->desc)
|
||||
db_bind_text(stmt, e->desc);
|
||||
else
|
||||
db_bind_null(stmt);
|
||||
db_bind_int(stmt, e->splice_close ? 1 : 0);
|
||||
db_exec_prepared_v2(stmt);
|
||||
e->db_id = db_last_insert_id_v2(stmt);
|
||||
|
||||
@@ -137,20 +137,6 @@ const char *find_close_account_name(const tal_t *ctx,
|
||||
* The point of this is to allow us to prune data, eventually */
|
||||
u64 account_onchain_closeheight(struct db *db, const struct account *acct);
|
||||
|
||||
/* We fetch invoice desc data after the fact and then update it
|
||||
* Updates both the chain_event and channel_event tables for all
|
||||
* matching payment_hashes
|
||||
* */
|
||||
void add_payment_hash_desc(struct db *db,
|
||||
struct sha256 *payment_hash,
|
||||
const char *desc);
|
||||
|
||||
/* Set the description for all events on this outpoint to
|
||||
* the provided one */
|
||||
void edit_utxo_description(struct db *db,
|
||||
struct bitcoin_outpoint *outpoint,
|
||||
const char *desc);
|
||||
|
||||
/* When we make external deposits from the wallet, we don't
|
||||
* count them until any output that was spent *into* them is
|
||||
* confirmed onchain.
|
||||
|
||||
@@ -181,10 +181,6 @@ static bool channel_events_eq(struct channel_event *e1, struct channel_event *e2
|
||||
CHECK(e1->part_id == e2->part_id);
|
||||
CHECK(e1->timestamp == e2->timestamp);
|
||||
|
||||
CHECK((e1->desc != NULL) == (e2->desc != NULL));
|
||||
if (e1->desc)
|
||||
CHECK(streq(e1->desc, e2->desc));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -212,10 +208,6 @@ static bool chain_events_eq(struct chain_event *e1, struct chain_event *e2)
|
||||
if (e1->payment_id)
|
||||
CHECK(sha256_eq(e1->payment_id, e2->payment_id));
|
||||
|
||||
CHECK((e1->desc != NULL) == (e2->desc != NULL));
|
||||
if (e1->desc)
|
||||
CHECK(streq(e1->desc, e2->desc));
|
||||
|
||||
CHECK(e1->splice_close == e2->splice_close);
|
||||
|
||||
return true;
|
||||
@@ -237,7 +229,6 @@ static struct channel_event *make_channel_event(const tal_t *ctx,
|
||||
ev->timestamp = 1919191;
|
||||
ev->part_id = 19;
|
||||
ev->tag = tag;
|
||||
ev->desc = tal_fmt(ev, "description");
|
||||
ev->rebalance_id = NULL;
|
||||
return ev;
|
||||
}
|
||||
@@ -267,7 +258,6 @@ static struct chain_event *make_chain_event(const tal_t *ctx,
|
||||
ev->blockheight = blockheight;
|
||||
ev->stealable = false;
|
||||
ev->splice_close = false;
|
||||
ev->desc = tal_fmt(ev, "hello hello");
|
||||
memset(&ev->outpoint.txid, outpoint_char, sizeof(struct bitcoin_txid));
|
||||
ev->outpoint.n = outnum;
|
||||
|
||||
@@ -861,12 +851,10 @@ static bool test_channel_event_crud(const tal_t *ctx)
|
||||
ev1->fees = AMOUNT_MSAT(104);
|
||||
ev1->timestamp = 11111;
|
||||
ev1->part_id = 19;
|
||||
ev1->desc = tal_strdup(ev1, "hello desc1");
|
||||
ev1->rebalance_id = NULL;
|
||||
|
||||
/* Passing unknown tags in should be ok */
|
||||
ev1->tag = "hello";
|
||||
ev1->desc = tal_fmt(ev1, "desc");
|
||||
|
||||
ev2 = tal(ctx, struct channel_event);
|
||||
ev2->payment_id = tal(ev2, struct sha256);
|
||||
@@ -877,7 +865,6 @@ static bool test_channel_event_crud(const tal_t *ctx)
|
||||
ev2->timestamp = 22222;
|
||||
ev2->part_id = 0;
|
||||
ev2->tag = tal_fmt(ev2, "deposit");
|
||||
ev2->desc = NULL;
|
||||
ev2->rebalance_id = tal(ev2, u64);
|
||||
*ev2->rebalance_id = 1;
|
||||
|
||||
@@ -890,7 +877,6 @@ static bool test_channel_event_crud(const tal_t *ctx)
|
||||
ev3->timestamp = 33333;
|
||||
ev3->part_id = 5;
|
||||
ev3->tag = tal_fmt(ev3, "routed");
|
||||
ev3->desc = NULL;
|
||||
ev3->rebalance_id = NULL;
|
||||
|
||||
db_begin_transaction(db);
|
||||
@@ -957,7 +943,6 @@ static bool test_chain_event_crud(const tal_t *ctx)
|
||||
ev1->spending_txid = tal(ctx, struct bitcoin_txid);
|
||||
memset(ev1->spending_txid, 'C', sizeof(struct bitcoin_txid));
|
||||
ev1->payment_id = NULL;
|
||||
ev1->desc = tal_fmt(ev1, "description");
|
||||
|
||||
db_begin_transaction(db);
|
||||
log_chain_event(db, acct, ev1);
|
||||
@@ -976,7 +961,6 @@ static bool test_chain_event_crud(const tal_t *ctx)
|
||||
ev2->outpoint.n = 1;
|
||||
ev2->spending_txid = NULL;
|
||||
ev2->payment_id = tal(ctx, struct sha256);
|
||||
ev2->desc = NULL;
|
||||
memset(ev2->payment_id, 'B', sizeof(struct sha256));
|
||||
|
||||
/* Dummy event, logged to separate account */
|
||||
@@ -995,7 +979,6 @@ static bool test_chain_event_crud(const tal_t *ctx)
|
||||
ev3->spending_txid = tal(ctx, struct bitcoin_txid);
|
||||
memset(ev3->spending_txid, 'D', sizeof(struct bitcoin_txid));
|
||||
ev3->payment_id = NULL;
|
||||
ev3->desc = NULL;
|
||||
|
||||
db_begin_transaction(db);
|
||||
log_chain_event(db, acct, ev2);
|
||||
@@ -1197,7 +1180,6 @@ static bool test_account_crud(const tal_t *ctx)
|
||||
ev1->spending_txid = tal(ctx, struct bitcoin_txid);
|
||||
memset(ev1->spending_txid, 'C', sizeof(struct bitcoin_txid));
|
||||
ev1->payment_id = NULL;
|
||||
ev1->desc = tal_fmt(ev1, "oh hello");
|
||||
|
||||
db_begin_transaction(db);
|
||||
log_chain_event(db, acct, ev1);
|
||||
|
||||
Reference in New Issue
Block a user