MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_forwarded_payment_update

Function wallet_forwarded_payment_update

wallet/wallet.c:4354–4413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4352}
4353
4354static bool wallet_forwarded_payment_update(struct wallet *w,
4355 const struct htlc_in *in,
4356 const struct htlc_out *out,
4357 enum forward_status state,
4358 enum onion_wire failcode,
4359 struct timeabs *resolved_time,
4360 enum forward_style forward_style)
4361{
4362 struct db_stmt *stmt;
4363 bool changed;
4364
4365 /* We update based solely on the htlc_in since an HTLC cannot be
4366 * associated with more than one forwarded payment. This saves us from
4367 * having to have two versions of the update statement (one with and
4368 * one without the htlc_out restriction).*/
4369 stmt = db_prepare_v2(w->db,
4370 SQL("UPDATE forwards SET"
4371 " in_msatoshi=?"
4372 ", out_msatoshi=?"
4373 ", state=?"
4374 ", resolved_time=?"
4375 ", failcode=?"
4376 ", forward_style=?"
4377 " WHERE in_htlc_id=? AND in_channel_scid=?"));
4378 db_bind_amount_msat(stmt, 0, &in->msat);
4379
4380 if (out) {
4381 db_bind_amount_msat(stmt, 1, &out->msat);
4382 } else {
4383 db_bind_null(stmt, 1);
4384 }
4385
4386 db_bind_int(stmt, 2, wallet_forward_status_in_db(state));
4387
4388 if (resolved_time != NULL) {
4389 db_bind_timeabs(stmt, 3, *resolved_time);
4390 } else {
4391 db_bind_null(stmt, 3);
4392 }
4393
4394 if (failcode != 0) {
4395 assert(state == FORWARD_FAILED || state == FORWARD_LOCAL_FAILED);
4396 db_bind_int(stmt, 4, (int)failcode);
4397 } else {
4398 db_bind_null(stmt, 4);
4399 }
4400
4401 /* This can happen for malformed onions, reload from db. */
4402 if (forward_style == FORWARD_STYLE_UNKNOWN)
4403 db_bind_null(stmt, 5);
4404 else
4405 db_bind_int(stmt, 5, forward_style_in_db(forward_style));
4406 db_bind_u64(stmt, 6, in->key.id);
4407 db_bind_scid(stmt, 7, channel_scid_or_local_alias(in->key.channel));
4408 db_exec_prepared_v2(stmt);
4409 changed = db_count_changes(stmt) != 0;
4410 tal_free(stmt);
4411

Callers 1

Calls 12

db_bind_amount_msatFunction · 0.85
db_bind_nullFunction · 0.85
db_bind_intFunction · 0.85
db_bind_timeabsFunction · 0.85
forward_style_in_dbFunction · 0.85
db_bind_u64Function · 0.85
db_bind_scidFunction · 0.85
db_exec_prepared_v2Function · 0.85
db_count_changesFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected