Browse Source

wallet: store failcode by adding failcode field in wallet_forwarded_payment_add()

htlc_accepted_hook
trueptolemy 6 years ago
committed by Christian Decker
parent
commit
3a8fe5bf31
  1. 32
      wallet/wallet.c
  2. 3
      wallet/wallet.h

32
wallet/wallet.c

@ -2488,7 +2488,8 @@ struct channeltx *wallet_channeltxs_get(struct wallet *w, const tal_t *ctx,
void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
const struct htlc_out *out, const struct htlc_out *out,
enum forward_status state) enum forward_status state,
enum onion_type failcode)
{ {
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
stmt = db_prepare( stmt = db_prepare(
@ -2503,13 +2504,27 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
", state" ", state"
", received_time" ", received_time"
", resolved_time" ", resolved_time"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"); ", failcode"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
sqlite3_bind_int64(stmt, 1, in->dbid); sqlite3_bind_int64(stmt, 1, in->dbid);
sqlite3_bind_int64(stmt, 2, out->dbid);
if(out) {
sqlite3_bind_int64(stmt, 2, out->dbid);
sqlite3_bind_int64(stmt, 4, out->key.channel->scid->u64);
sqlite3_bind_amount_msat(stmt, 6, out->msat);
} else {
/* FORWARD_LOCAL_FAILED may occur before we get htlc_out */
assert(failcode != 0);
assert(state == FORWARD_LOCAL_FAILED);
sqlite3_bind_null(stmt, 2);
sqlite3_bind_null(stmt, 4);
sqlite3_bind_null(stmt, 6);
}
sqlite3_bind_int64(stmt, 3, in->key.channel->scid->u64); sqlite3_bind_int64(stmt, 3, in->key.channel->scid->u64);
sqlite3_bind_int64(stmt, 4, out->key.channel->scid->u64);
sqlite3_bind_amount_msat(stmt, 5, in->msat); sqlite3_bind_amount_msat(stmt, 5, in->msat);
sqlite3_bind_amount_msat(stmt, 6, out->msat);
sqlite3_bind_int(stmt, 7, wallet_forward_status_in_db(state)); sqlite3_bind_int(stmt, 7, wallet_forward_status_in_db(state));
sqlite3_bind_timeabs(stmt, 8, in->received_time); sqlite3_bind_timeabs(stmt, 8, in->received_time);
@ -2518,6 +2533,13 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
else else
sqlite3_bind_null(stmt, 9); sqlite3_bind_null(stmt, 9);
if(failcode != 0) {
assert(state == FORWARD_FAILED || state == FORWARD_LOCAL_FAILED);
sqlite3_bind_int(stmt, 10, (int)failcode);
} else {
sqlite3_bind_null(stmt, 10);
}
db_exec_prepared(w->db, stmt); db_exec_prepared(w->db, stmt);
} }

3
wallet/wallet.h

@ -1040,7 +1040,8 @@ struct channeltx *wallet_channeltxs_get(struct wallet *w, const tal_t *ctx,
*/ */
void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
const struct htlc_out *out, const struct htlc_out *out,
enum forward_status state); enum forward_status state,
enum onion_type failcode);
/** /**
* Retrieve summary of successful forwarded payments' fees * Retrieve summary of successful forwarded payments' fees

Loading…
Cancel
Save