wallet_payment: Make msatoshi field nullable.

This commit is contained in:
ZmnSCPxj 2018-01-10 01:13:00 +00:00 committed by Rusty Russell
parent 50471bf4fe
commit caab95b922
5 changed files with 20 additions and 6 deletions

View File

@ -259,7 +259,10 @@ static void json_invoice(struct command *cmd,
payment.payment_hash = invoice->rhash;
payment.destination = NULL;
payment.status = PAYMENT_PENDING;
payment.msatoshi = *invoice->msatoshi;
if (invoice->msatoshi)
payment.msatoshi = tal_dup(cmd, u64, invoice->msatoshi);
else
payment.msatoshi = NULL;
payment.timestamp = b11->timestamp;
if (!wallet_payment_add(cmd->ld->wallet, &payment)) {

View File

@ -247,7 +247,8 @@ static bool send_payment(struct command *cmd,
payment->payment_hash = *rhash;
payment->destination = &ids[n_hops - 1];
payment->status = PAYMENT_PENDING;
payment->msatoshi = route[n_hops-1].amount;
payment->msatoshi = tal(payment, u64);
*payment->msatoshi = route[n_hops-1].amount;
payment->timestamp = time_now().ts.tv_sec;
}
pc->cmd = cmd;
@ -503,7 +504,8 @@ static void json_listpayments(struct command *cmd, const char *buffer,
json_add_hex(response, "payment_hash", &t->payment_hash, sizeof(t->payment_hash));
if (!t->incoming)
json_add_pubkey(response, "destination", t->destination);
json_add_u64(response, "msatoshi", t->msatoshi);
if (t->msatoshi)
json_add_u64(response, "msatoshi", *t->msatoshi);
json_add_u64(response, "timestamp", t->timestamp);
switch (t->status) {

View File

@ -557,6 +557,7 @@ static bool test_payment_crud(const tal_t *ctx)
t.id = 0;
t.destination = NULL;
t.msatoshi = NULL;
db_begin_transaction(w->db);
CHECK(wallet_payment_add(w, &t));

View File

@ -1403,7 +1403,10 @@ bool wallet_payment_add(struct wallet *wallet,
else
sqlite3_bind_null(stmt, 4);
sqlite3_bind_int64(stmt, 5, payment->msatoshi);
if (payment->msatoshi)
sqlite3_bind_int64(stmt, 5, *payment->msatoshi);
else
sqlite3_bind_null(stmt, 5);
sqlite3_bind_int(stmt, 6, payment->timestamp);
@ -1427,7 +1430,12 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
payment->destination = NULL;
}
payment->msatoshi = sqlite3_column_int64(stmt, 4);
if (sqlite3_column_type(stmt, 4) != SQLITE_NULL) {
payment->msatoshi = tal(payment, u64);
*payment->msatoshi = sqlite3_column_int64(stmt, 4);
} else {
payment->msatoshi = NULL;
}
sqlite3_column_sha256(stmt, 5, &payment->payment_hash);
payment->timestamp = sqlite3_column_int(stmt, 6);

View File

@ -89,7 +89,7 @@ struct wallet_payment {
struct sha256 payment_hash;
enum wallet_payment_status status;
struct pubkey *destination;
u64 msatoshi;
u64 *msatoshi;
};
/**