wallet: Correctly handle forwards when channels or htlcs are deleted

The left join should make sure we still get the results but
referencing the fields and/or attempting to write them to the JSON-RPC
result will cause unforeseen problems. So just omit if we forgot
something.
This commit is contained in:
Christian Decker 2018-10-17 23:28:43 +02:00 committed by Rusty Russell
parent facd7d16aa
commit 6d333f16cc
3 changed files with 12 additions and 4 deletions

View File

@ -1880,6 +1880,7 @@ static void listforwardings_add_forwardings(struct json_result *response, struct
for (size_t i=0; i<tal_count(forwardings); i++) {
const struct forwarding *cur = &forwardings[i];
json_object_start(response, NULL);
json_add_short_channel_id(response, "in_channel", &cur->channel_in);
json_add_short_channel_id(response, "out_channel", &cur->channel_out);
json_add_num(response, "in_msatoshi", cur->msatoshi_in);

View File

@ -2481,9 +2481,16 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,
cur->msatoshi_in = sqlite3_column_int64(stmt, 1);
cur->msatoshi_out = sqlite3_column_int64(stmt, 2);
cur->fee = cur->msatoshi_in - cur->msatoshi_out;
sqlite3_column_sha256_double(stmt, 3, &cur->payment_hash);
sqlite3_column_short_channel_id(stmt, 4, &cur->channel_in);
sqlite3_column_short_channel_id(stmt, 5, &cur->channel_out);
if (sqlite3_column_type(stmt, 3) != SQLITE_NULL) {
cur->payment_hash = tal(ctx, struct sha256_double);
sqlite3_column_sha256_double(stmt, 3, cur->payment_hash);
} else {
cur->payment_hash = NULL;
}
cur->channel_in.u64 = sqlite3_column_int64(stmt, 4);
cur->channel_out.u64 = sqlite3_column_int64(stmt, 5);
}
db_stmt_done(stmt);

View File

@ -162,7 +162,7 @@ static inline const char* forward_status_name(enum forward_status status)
struct forwarding {
struct short_channel_id channel_in, channel_out;
u64 msatoshi_in, msatoshi_out, fee;
struct sha256_double payment_hash;
struct sha256_double *payment_hash;
enum forward_status status;
};