diff --git a/plugins/bkpr/chain_event.h b/plugins/bkpr/chain_event.h index 764c85410..9359de8f8 100644 --- a/plugins/bkpr/chain_event.h +++ b/plugins/bkpr/chain_event.h @@ -16,6 +16,9 @@ struct chain_event { /* db_id of account this event belongs to */ u64 acct_db_id; + /* Name of the account this belongs to */ + char *acct_name; + /* Tag describing the event */ const char *tag; diff --git a/plugins/bkpr/channel_event.h b/plugins/bkpr/channel_event.h index c64c21d4b..7e231dce2 100644 --- a/plugins/bkpr/channel_event.h +++ b/plugins/bkpr/channel_event.h @@ -15,6 +15,9 @@ struct channel_event { /* db_id of account this event belongs to */ u64 acct_db_id; + /* Name of the account this belongs to */ + char *acct_name; + /* Tag describing the event */ const char *tag; diff --git a/plugins/bkpr/onchain_fee.h b/plugins/bkpr/onchain_fee.h index 0d31e4d59..b57c9f18a 100644 --- a/plugins/bkpr/onchain_fee.h +++ b/plugins/bkpr/onchain_fee.h @@ -12,6 +12,9 @@ struct onchain_fee { /* db_id of account this event belongs to */ u64 acct_db_id; + /* Name of the account this belongs to */ + char *acct_name; + /* Transaction that we're recording fees for */ struct bitcoin_txid txid; diff --git a/plugins/bkpr/recorder.c b/plugins/bkpr/recorder.c index 57e38e388..f7cc03093 100644 --- a/plugins/bkpr/recorder.c +++ b/plugins/bkpr/recorder.c @@ -21,31 +21,32 @@ static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *stmt) { struct chain_event *e = tal(ctx, struct chain_event); - e->db_id = db_col_u64(stmt, "id"); - e->acct_db_id = db_col_u64(stmt, "account_id"); + e->db_id = db_col_u64(stmt, "e.id"); + e->acct_db_id = db_col_u64(stmt, "e.account_id"); + e->acct_name = db_col_strdup(e, stmt, "a.name"); - e->tag = db_col_strdup(e, stmt, "tag"); + e->tag = db_col_strdup(e, stmt, "e.tag"); - db_col_amount_msat(stmt, "credit", &e->credit); - db_col_amount_msat(stmt, "debit", &e->debit); - db_col_amount_msat(stmt, "output_value", &e->output_value); + db_col_amount_msat(stmt, "e.credit", &e->credit); + db_col_amount_msat(stmt, "e.debit", &e->debit); + db_col_amount_msat(stmt, "e.output_value", &e->output_value); - e->currency = db_col_strdup(e, stmt, "currency"); - e->timestamp = db_col_u64(stmt, "timestamp"); - e->blockheight = db_col_int(stmt, "blockheight"); + e->currency = db_col_strdup(e, stmt, "e.currency"); + e->timestamp = db_col_u64(stmt, "e.timestamp"); + e->blockheight = db_col_int(stmt, "e.blockheight"); - db_col_txid(stmt, "utxo_txid", &e->outpoint.txid); - e->outpoint.n = db_col_int(stmt, "outnum"); + db_col_txid(stmt, "e.utxo_txid", &e->outpoint.txid); + e->outpoint.n = db_col_int(stmt, "e.outnum"); - if (!db_col_is_null(stmt, "payment_id")) { + if (!db_col_is_null(stmt, "e.payment_id")) { e->payment_id = tal(e, struct sha256); - db_col_sha256(stmt, "payment_id", e->payment_id); + db_col_sha256(stmt, "e.payment_id", e->payment_id); } else e->payment_id = NULL; - if (!db_col_is_null(stmt, "spending_txid")) { + if (!db_col_is_null(stmt, "e.spending_txid")) { e->spending_txid = tal(e, struct bitcoin_txid); - db_col_txid(stmt, "spending_txid", e->spending_txid); + db_col_txid(stmt, "e.spending_txid", e->spending_txid); } else e->spending_txid = NULL; @@ -74,23 +75,24 @@ static struct channel_event *stmt2channel_event(const tal_t *ctx, struct db_stmt { struct channel_event *e = tal(ctx, struct channel_event); - e->db_id = db_col_u64(stmt, "id"); - e->acct_db_id = db_col_u64(stmt, "account_id"); + e->db_id = db_col_u64(stmt, "e.id"); + e->acct_db_id = db_col_u64(stmt, "e.account_id"); + e->acct_name = db_col_strdup(e, stmt, "a.name"); - e->tag = db_col_strdup(e, stmt, "tag"); + e->tag = db_col_strdup(e, stmt, "e.tag"); - db_col_amount_msat(stmt, "credit", &e->credit); - db_col_amount_msat(stmt, "debit", &e->debit); - db_col_amount_msat(stmt, "fees", &e->fees); + db_col_amount_msat(stmt, "e.credit", &e->credit); + db_col_amount_msat(stmt, "e.debit", &e->debit); + db_col_amount_msat(stmt, "e.fees", &e->fees); - e->currency = db_col_strdup(e, stmt, "currency"); - if (!db_col_is_null(stmt, "payment_id")) { + e->currency = db_col_strdup(e, stmt, "e.currency"); + if (!db_col_is_null(stmt, "e.payment_id")) { e->payment_id = tal(e, struct sha256); - db_col_sha256(stmt, "payment_id", e->payment_id); + db_col_sha256(stmt, "e.payment_id", e->payment_id); } else e->payment_id = NULL; - e->part_id = db_col_int(stmt, "part_id"); - e->timestamp = db_col_u64(stmt, "timestamp"); + e->part_id = db_col_int(stmt, "e.part_id"); + e->timestamp = db_col_u64(stmt, "e.timestamp"); return e; } @@ -102,21 +104,25 @@ struct chain_event **account_get_chain_events(const tal_t *ctx, struct db_stmt *stmt; stmt = db_prepare_v2(db, SQL("SELECT" - " id" - ", account_id" - ", tag" - ", credit" - ", debit" - ", output_value" - ", currency" - ", timestamp" - ", blockheight" - ", utxo_txid" - ", outnum" - ", spending_txid" - ", payment_id" - " FROM chain_events" - " WHERE account_id = ?;")); + " e.id" + ", e.account_id" + ", a.name" + ", e.tag" + ", e.credit" + ", e.debit" + ", e.output_value" + ", e.currency" + ", e.timestamp" + ", e.blockheight" + ", e.utxo_txid" + ", e.outnum" + ", e.spending_txid" + ", e.payment_id" + " FROM chain_events e" + " LEFT OUTER JOIN accounts a" + " ON e.account_id = a.id" + " WHERE e.account_id = ?" + " ORDER BY e.timestamp, e.id")); db_bind_int(stmt, 0, acct->db_id); return find_chain_events(ctx, take(stmt)); @@ -134,47 +140,53 @@ static struct chain_event *find_chain_event(const tal_t *ctx, if (spending_txid) { stmt = db_prepare_v2(db, SQL("SELECT" - " id" - ", account_id" - ", tag" - ", credit" - ", debit" - ", output_value" - ", currency" - ", timestamp" - ", blockheight" - ", utxo_txid" - ", outnum" - ", spending_txid" - ", payment_id" - " FROM chain_events" + " e.id" + ", e.account_id" + ", a.name" + ", e.tag" + ", e.credit" + ", e.debit" + ", e.output_value" + ", e.currency" + ", e.timestamp" + ", e.blockheight" + ", e.utxo_txid" + ", e.outnum" + ", e.spending_txid" + ", e.payment_id" + " FROM chain_events e" + " LEFT OUTER JOIN accounts a" + " ON e.account_id = a.id" " WHERE " - " account_id = ?" - " AND utxo_txid = ?" - " AND outnum = ?" - " AND spending_txid = ?")); + " e.account_id = ?" + " AND e.utxo_txid = ?" + " AND e.outnum = ?" + " AND e.spending_txid = ?")); db_bind_txid(stmt, 3, spending_txid); } else { stmt = db_prepare_v2(db, SQL("SELECT" - " id" - ", account_id" - ", tag" - ", credit" - ", debit" - ", output_value" - ", currency" - ", timestamp" - ", blockheight" - ", utxo_txid" - ", outnum" - ", spending_txid" - ", payment_id" - " FROM chain_events" + " e.id" + ", e.account_id" + ", a.name" + ", e.tag" + ", e.credit" + ", e.debit" + ", e.output_value" + ", e.currency" + ", e.timestamp" + ", e.blockheight" + ", e.utxo_txid" + ", e.outnum" + ", e.spending_txid" + ", e.payment_id" + " FROM chain_events e" + " LEFT OUTER JOIN accounts a" + " ON e.account_id = a.id" " WHERE " - " account_id = ?" - " AND utxo_txid = ?" - " AND outnum = ?" - " AND spending_txid IS NULL")); + " e.account_id = ?" + " AND e.utxo_txid = ?" + " AND e.outnum = ?" + " AND e.spending_txid IS NULL")); } db_bind_u64(stmt, 0, acct->db_id); @@ -296,18 +308,22 @@ struct channel_event **account_get_channel_events(const tal_t *ctx, struct channel_event **results; stmt = db_prepare_v2(db, SQL("SELECT" - " id" - ", account_id" - ", tag" - ", credit" - ", debit" - ", fees" - ", currency" - ", payment_id" - ", part_id" - ", timestamp" - " FROM channel_events" - " WHERE account_id = ?;")); + " e.id" + ", a.name" + ", e.account_id" + ", e.tag" + ", e.credit" + ", e.debit" + ", e.fees" + ", e.currency" + ", e.payment_id" + ", e.part_id" + ", e.timestamp" + " FROM channel_events e" + " LEFT OUTER JOIN accounts a" + " ON a.id = e.account_id" + " WHERE e.account_id = ?" + " ORDER BY e.timestamp, e.id")); db_bind_u64(stmt, 0, acct->db_id); db_query_prepared(stmt); @@ -327,13 +343,14 @@ static struct onchain_fee *stmt2onchain_fee(const tal_t *ctx, { struct onchain_fee *of = tal(ctx, struct onchain_fee); - of->acct_db_id = db_col_u64(stmt, "account_id"); - db_col_txid(stmt, "txid", &of->txid); - db_col_amount_msat(stmt, "credit", &of->credit); - db_col_amount_msat(stmt, "debit", &of->debit); - of->currency = db_col_strdup(of, stmt, "currency"); - of->timestamp = db_col_u64(stmt, "timestamp"); - of->update_count = db_col_int(stmt, "update_count"); + of->acct_db_id = db_col_u64(stmt, "of.account_id"); + of->acct_name = db_col_strdup(of, stmt, "a.name"); + db_col_txid(stmt, "of.txid", &of->txid); + db_col_amount_msat(stmt, "of.credit", &of->credit); + db_col_amount_msat(stmt, "of.debit", &of->debit); + of->currency = db_col_strdup(of, stmt, "of.currency"); + of->timestamp = db_col_u64(stmt, "of.timestamp"); + of->update_count = db_col_int(stmt, "of.update_count"); return of; } @@ -344,17 +361,22 @@ struct onchain_fee **list_chain_fees(const tal_t *ctx, struct db *db) struct onchain_fee **results; stmt = db_prepare_v2(db, SQL("SELECT" - " account_id" - ", txid" - ", credit" - ", debit" - ", currency" - ", timestamp" - ", update_count" - " FROM onchain_fees" - " ORDER BY account_id" - ", txid" - ", update_count")); + " of.account_id" + ", a.name" + ", of.txid" + ", of.credit" + ", of.debit" + ", of.currency" + ", of.timestamp" + ", of.update_count" + " FROM onchain_fees of" + " LEFT OUTER JOIN accounts a" + " ON a.id = of.account_id" + " ORDER BY " + " of.timestamp" + ", of.account_id" + ", of.txid" + ", of.update_count")); db_query_prepared(stmt); results = tal_arr(ctx, struct onchain_fee *, 0); @@ -444,15 +466,18 @@ struct onchain_fee **account_onchain_fees(const tal_t *ctx, struct onchain_fee **results; stmt = db_prepare_v2(db, SQL("SELECT" - " account_id" - ", txid" - ", credit" - ", debit" - ", currency" - ", timestamp" - ", update_count" - " FROM onchain_fees" - " WHERE account_id = ?;")); + " of.account_id" + ", a.name" + ", of.txid" + ", of.credit" + ", of.debit" + ", of.currency" + ", of.timestamp" + ", of.update_count" + " FROM onchain_fees of" + " LEFT OUTER JOIN accounts a" + " ON a.id = of.account_id" + " WHERE of.account_id = ?;")); db_bind_u64(stmt, 0, acct->db_id); db_query_prepared(stmt); @@ -643,6 +668,7 @@ void log_channel_event(struct db *db, db_exec_prepared_v2(stmt); e->db_id = db_last_insert_id_v2(stmt); e->acct_db_id = acct->db_id; + e->acct_name = tal_strdup(e, acct->name); tal_free(stmt); } @@ -652,23 +678,26 @@ static struct chain_event **find_chain_events_bytxid(const tal_t *ctx, struct db struct db_stmt *stmt; stmt = db_prepare_v2(db, SQL("SELECT " - " id" - ", account_id" - ", tag" - ", credit" - ", debit" - ", output_value" - ", currency" - ", timestamp" - ", blockheight" - ", utxo_txid" - ", outnum" - ", spending_txid" - ", payment_id" - " FROM chain_events" - " WHERE spending_txid = ?" - " OR (utxo_txid = ? AND spending_txid IS NULL)" - " ORDER BY account_id")); + " e.id" + ", a.name" + ", e.account_id" + ", e.tag" + ", e.credit" + ", e.debit" + ", e.output_value" + ", e.currency" + ", e.timestamp" + ", e.blockheight" + ", e.utxo_txid" + ", e.outnum" + ", e.spending_txid" + ", e.payment_id" + " FROM chain_events e" + " LEFT OUTER JOIN accounts a" + " ON a.id = e.account_id" + " WHERE e.spending_txid = ?" + " OR (e.utxo_txid = ? AND e.spending_txid IS NULL)" + " ORDER BY e.account_id")); db_bind_txid(stmt, 0, txid); db_bind_txid(stmt, 1, txid); @@ -977,5 +1006,6 @@ void log_chain_event(struct db *db, db_exec_prepared_v2(stmt); e->db_id = db_last_insert_id_v2(stmt); e->acct_db_id = acct->db_id; + e->acct_name = tal_strdup(e, acct->name); tal_free(stmt); } diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c index 06140746d..ad55c6eca 100644 --- a/plugins/bkpr/test/run-recorder.c +++ b/plugins/bkpr/test/run-recorder.c @@ -698,7 +698,7 @@ static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p) struct db *db = db_setup(ctx, p, tmp_dsn(ctx)); struct node_id peer_id; struct account *acct, *acct2; - struct channel_event ev1, ev2, ev3, **chan_evs; + struct channel_event *ev1, *ev2, *ev3, **chan_evs; memset(&peer_id, 3, sizeof(struct node_id)); @@ -710,48 +710,51 @@ static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p) db_commit_transaction(db); CHECK_MSG(!db_err, db_err); - ev1.payment_id = tal(ctx, struct sha256); - memset(ev1.payment_id, 'B', sizeof(struct sha256)); - ev1.credit = AMOUNT_MSAT(100); - ev1.debit = AMOUNT_MSAT(102); - ev1.fees = AMOUNT_MSAT(104); - ev1.currency = "btc"; - ev1.timestamp = 11111; - ev1.part_id = 19; + ev1 = tal(ctx, struct channel_event); + ev1->payment_id = tal(ev1, struct sha256); + memset(ev1->payment_id, 'B', sizeof(struct sha256)); + ev1->credit = AMOUNT_MSAT(100); + ev1->debit = AMOUNT_MSAT(102); + ev1->fees = AMOUNT_MSAT(104); + ev1->currency = "btc"; + ev1->timestamp = 11111; + ev1->part_id = 19; /* Passing unknown tags in should be ok */ - ev1.tag = "hello"; + ev1->tag = "hello"; - ev2.payment_id = tal(ctx, struct sha256); - memset(ev2.payment_id, 'C', sizeof(struct sha256)); - ev2.credit = AMOUNT_MSAT(200); - ev2.debit = AMOUNT_MSAT(202); - ev2.fees = AMOUNT_MSAT(204); - ev2.currency = "brct"; - ev2.timestamp = 22222; - ev2.part_id = 0; - ev2.tag = tal_fmt(ctx, "deposit"); + ev2 = tal(ctx, struct channel_event); + ev2->payment_id = tal(ev2, struct sha256); + memset(ev2->payment_id, 'C', sizeof(struct sha256)); + ev2->credit = AMOUNT_MSAT(200); + ev2->debit = AMOUNT_MSAT(202); + ev2->fees = AMOUNT_MSAT(204); + ev2->currency = "brct"; + ev2->timestamp = 22222; + ev2->part_id = 0; + ev2->tag = tal_fmt(ev2, "deposit"); - ev3.payment_id = tal(ctx, struct sha256); - memset(ev3.payment_id, 'D', sizeof(struct sha256)); - ev3.credit = AMOUNT_MSAT(300); - ev3.debit = AMOUNT_MSAT(302); - ev3.fees = AMOUNT_MSAT(304); - ev3.currency = "brct"; - ev3.timestamp = 33333; - ev3.part_id = 5; - ev3.tag = tal_fmt(ctx, "routed"); + ev3 = tal(ctx, struct channel_event); + ev3->payment_id = tal(ev3, struct sha256); + memset(ev3->payment_id, 'D', sizeof(struct sha256)); + ev3->credit = AMOUNT_MSAT(300); + ev3->debit = AMOUNT_MSAT(302); + ev3->fees = AMOUNT_MSAT(304); + ev3->currency = "brct"; + ev3->timestamp = 33333; + ev3->part_id = 5; + ev3->tag = tal_fmt(ev3, "routed"); db_begin_transaction(db); - log_channel_event(db, acct, &ev1); - log_channel_event(db, acct, &ev2); + log_channel_event(db, acct, ev1); + log_channel_event(db, acct, ev2); /* log a channel event to a different acct */ - log_channel_event(db, acct2, &ev3); + log_channel_event(db, acct2, ev3); /* log a channel event without a payment id */ - ev3.payment_id = NULL; - log_channel_event(db, acct2, &ev3); + ev3->payment_id = NULL; + log_channel_event(db, acct2, ev3); db_commit_transaction(db); CHECK_MSG(!db_err, db_err); @@ -762,9 +765,12 @@ static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p) CHECK_MSG(!db_err, db_err); CHECK_MSG(!db_err, db_err); + CHECK(streq(acct->name, chan_evs[0]->acct_name)); + CHECK(streq(acct->name, chan_evs[1]->acct_name)); + CHECK(tal_count(chan_evs) == 2); - channel_events_eq(&ev1, chan_evs[0]); - channel_events_eq(&ev2, chan_evs[1]); + channel_events_eq(ev1, chan_evs[0]); + channel_events_eq(ev2, chan_evs[1]); return true; } @@ -774,7 +780,7 @@ static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p) struct db *db = db_setup(ctx, p, tmp_dsn(ctx)); struct node_id peer_id; struct account *acct, *acct2; - struct chain_event ev1, *ev2, ev3, **chain_evs; + struct chain_event *ev1, *ev2, *ev3, **chain_evs; char *name = tal_fmt(ctx, "example"); ev2 = tal(ctx, struct chain_event); @@ -789,21 +795,22 @@ static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p) CHECK_MSG(!db_err, db_err); /* This event spends the second inserted event */ - ev1.tag = tal_fmt(ctx, "withdrawal"); - ev1.credit = AMOUNT_MSAT(100); - ev1.debit = AMOUNT_MSAT(102); - ev1.output_value = AMOUNT_MSAT(104); - ev1.currency = "btc"; - ev1.timestamp = 1919191; - ev1.blockheight = 1919191; - memset(&ev1.outpoint.txid, 'D', sizeof(struct bitcoin_txid)); - ev1.outpoint.n = 1; - ev1.spending_txid = tal(ctx, struct bitcoin_txid); - memset(ev1.spending_txid, 'C', sizeof(struct bitcoin_txid)); - ev1.payment_id = NULL; + ev1 = tal(ctx, struct chain_event); + ev1->tag = tal_fmt(ev1, "withdrawal"); + ev1->credit = AMOUNT_MSAT(100); + ev1->debit = AMOUNT_MSAT(102); + ev1->output_value = AMOUNT_MSAT(104); + ev1->currency = "btc"; + ev1->timestamp = 1919191; + ev1->blockheight = 1919191; + memset(&ev1->outpoint.txid, 'D', sizeof(struct bitcoin_txid)); + ev1->outpoint.n = 1; + ev1->spending_txid = tal(ctx, struct bitcoin_txid); + memset(ev1->spending_txid, 'C', sizeof(struct bitcoin_txid)); + ev1->payment_id = NULL; db_begin_transaction(db); - log_chain_event(db, acct, &ev1); + log_chain_event(db, acct, ev1); db_commit_transaction(db); CHECK_MSG(!db_err, db_err); @@ -821,24 +828,25 @@ static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p) memset(ev2->payment_id, 'B', sizeof(struct sha256)); /* Dummy event, logged to separate account */ - ev3.tag = tal_fmt(ctx, "deposit"); - ev3.credit = AMOUNT_MSAT(300); - ev3.debit = AMOUNT_MSAT(302); - ev3.output_value = AMOUNT_MSAT(304); - ev3.currency = "btc"; - ev3.timestamp = 3939393; - ev3.blockheight = 3939393; - memset(&ev3.outpoint.txid, 'E', sizeof(struct bitcoin_txid)); - ev3.outpoint.n = 1; - ev3.spending_txid = tal(ctx, struct bitcoin_txid); - memset(ev3.spending_txid, 'D', sizeof(struct bitcoin_txid)); - ev3.payment_id = NULL; + ev3 = tal(ctx, struct chain_event); + ev3->tag = tal_fmt(ev3, "deposit"); + ev3->credit = AMOUNT_MSAT(300); + ev3->debit = AMOUNT_MSAT(302); + ev3->output_value = AMOUNT_MSAT(304); + ev3->currency = "btc"; + ev3->timestamp = 3939393; + ev3->blockheight = 3939393; + memset(&ev3->outpoint.txid, 'E', sizeof(struct bitcoin_txid)); + ev3->outpoint.n = 1; + ev3->spending_txid = tal(ctx, struct bitcoin_txid); + memset(ev3->spending_txid, 'D', sizeof(struct bitcoin_txid)); + ev3->payment_id = NULL; db_begin_transaction(db); log_chain_event(db, acct, ev2); /* log new event to a different account.. */ - log_chain_event(db, acct2, &ev3); + log_chain_event(db, acct2, ev3); db_commit_transaction(db); CHECK_MSG(!db_err, db_err); @@ -855,14 +863,16 @@ static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p) CHECK_MSG(!db_err, db_err); CHECK(tal_count(chain_evs) == 2); - chain_events_eq(&ev1, chain_evs[0]); + CHECK(streq(acct->name, chain_evs[0]->acct_name)); + CHECK(streq(acct->name, chain_evs[1]->acct_name)); + chain_events_eq(ev1, chain_evs[0]); chain_events_eq(ev2, chain_evs[1]); /* Now insert a utxo create and spend, in that order */ - ev1.db_id = 0; - memset(&ev1.outpoint.txid, 'A', sizeof(struct bitcoin_txid)); - ev1.outpoint.n = 10; - ev1.spending_txid = tal_free(ev1.spending_txid); + ev1->db_id = 0; + memset(&ev1->outpoint.txid, 'A', sizeof(struct bitcoin_txid)); + ev1->outpoint.n = 10; + ev1->spending_txid = tal_free(ev1->spending_txid); ev2->db_id = 0; memset(&ev2->outpoint.txid, 'A', sizeof(struct bitcoin_txid)); @@ -872,7 +882,7 @@ static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p) db_begin_transaction(db); - log_chain_event(db, acct, &ev1); + log_chain_event(db, acct, ev1); log_chain_event(db, acct, ev2); chain_evs = account_get_chain_events(ctx, db, acct); db_commit_transaction(db); @@ -881,7 +891,7 @@ static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p) /* There should be four now */ CHECK(tal_count(chain_evs) == 4); - chain_events_eq(&ev1, chain_evs[2]); + chain_events_eq(ev1, chain_evs[2]); chain_events_eq(ev2, chain_evs[3]); return true; @@ -978,7 +988,7 @@ static bool test_account_crud(const tal_t *ctx, struct plugin *p) struct db *db = db_setup(ctx, p, tmp_dsn(ctx)); struct node_id peer_id; struct account *acct, *acct2, **acct_list; - struct chain_event ev1; + struct chain_event *ev1; enum mvt_tag *tags; char *name = tal_fmt(ctx, "example"); @@ -1022,29 +1032,29 @@ static bool test_account_crud(const tal_t *ctx, struct plugin *p) /* Will we update an account's properties * correctly, given an event and tag list? */ - ev1.tag = tal_fmt(ctx, "withdrawal"); - ev1.credit = AMOUNT_MSAT(100); - ev1.debit = AMOUNT_MSAT(102); - ev1.output_value = AMOUNT_MSAT(104); - ev1.currency = "btc"; - ev1.timestamp = 1919191; - ev1.blockheight = 1919191; - memset(&ev1.outpoint.txid, 'D', sizeof(struct bitcoin_txid)); - ev1.outpoint.n = 1; - ev1.spending_txid = tal(ctx, struct bitcoin_txid); - memset(ev1.spending_txid, 'C', sizeof(struct bitcoin_txid)); - ev1.payment_id = NULL; + ev1 = tal(ctx, struct chain_event); + ev1->tag = tal_fmt(ctx, "withdrawal"); + ev1->credit = AMOUNT_MSAT(100); + ev1->debit = AMOUNT_MSAT(102); + ev1->output_value = AMOUNT_MSAT(104); + ev1->currency = "btc"; + ev1->timestamp = 1919191; + ev1->blockheight = 1919191; + memset(&ev1->outpoint.txid, 'D', sizeof(struct bitcoin_txid)); + ev1->outpoint.n = 1; + ev1->spending_txid = tal(ctx, struct bitcoin_txid); + memset(ev1->spending_txid, 'C', sizeof(struct bitcoin_txid)); + ev1->payment_id = NULL; db_begin_transaction(db); - log_chain_event(db, acct, &ev1); + log_chain_event(db, acct, ev1); tags = tal_arr(ctx, enum mvt_tag, 2); /* should not update the account info */ tags[0] = PUSHED; tags[1] = PENALTY; - maybe_update_account(db, acct, &ev1, tags); - acct2 = find_account(ctx, db, "wallet"); + maybe_update_account(db, acct, ev1, tags); accountseq(acct, acct2); /* channel_open -> open event db updated */ @@ -1052,7 +1062,7 @@ static bool test_account_crud(const tal_t *ctx, struct plugin *p) CHECK(acct->open_event_db_id == NULL); tags[0] = CHANNEL_OPEN; tags[1] = LEASED; - maybe_update_account(db, acct, &ev1, tags); + maybe_update_account(db, acct, ev1, tags); acct2 = find_account(ctx, db, "wallet"); accountseq(acct, acct2); CHECK(acct->leased); @@ -1062,7 +1072,7 @@ static bool test_account_crud(const tal_t *ctx, struct plugin *p) tags[1] = OPENER; CHECK(acct->closed_event_db_id == NULL); CHECK(!acct->we_opened); - maybe_update_account(db, acct, &ev1, tags); + maybe_update_account(db, acct, ev1, tags); acct2 = find_account(ctx, db, "wallet"); accountseq(acct, acct2); CHECK(acct->closed_event_db_id != NULL);