| 4413 | } |
| 4414 | |
| 4415 | void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, |
| 4416 | enum forward_style forward_style, |
| 4417 | const struct short_channel_id *scid_out, |
| 4418 | const struct htlc_out *out, |
| 4419 | enum forward_status state, |
| 4420 | enum onion_wire failcode) |
| 4421 | { |
| 4422 | struct db_stmt *stmt; |
| 4423 | struct timeabs *resolved_time; |
| 4424 | |
| 4425 | if (state == FORWARD_SETTLED || state == FORWARD_FAILED) { |
| 4426 | resolved_time = tal(tmpctx, struct timeabs); |
| 4427 | *resolved_time = time_now(); |
| 4428 | } else { |
| 4429 | resolved_time = NULL; |
| 4430 | } |
| 4431 | |
| 4432 | if (wallet_forwarded_payment_update(w, in, out, state, failcode, resolved_time, forward_style)) |
| 4433 | goto notify; |
| 4434 | |
| 4435 | stmt = db_prepare_v2(w->db, |
| 4436 | SQL("INSERT INTO forwards (" |
| 4437 | " in_htlc_id" |
| 4438 | ", out_htlc_id" |
| 4439 | ", in_channel_scid" |
| 4440 | ", out_channel_scid" |
| 4441 | ", in_msatoshi" |
| 4442 | ", out_msatoshi" |
| 4443 | ", state" |
| 4444 | ", received_time" |
| 4445 | ", resolved_time" |
| 4446 | ", failcode" |
| 4447 | ", forward_style" |
| 4448 | ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); |
| 4449 | db_bind_u64(stmt, 0, in->key.id); |
| 4450 | |
| 4451 | /* FORWARD_LOCAL_FAILED may occur before we get htlc_out */ |
| 4452 | if (!out || !scid_out) { |
| 4453 | assert(failcode != 0); |
| 4454 | assert(state == FORWARD_LOCAL_FAILED); |
| 4455 | } |
| 4456 | |
| 4457 | if (out) |
| 4458 | db_bind_u64(stmt, 1, out->key.id); |
| 4459 | else |
| 4460 | db_bind_null(stmt, 1); |
| 4461 | |
| 4462 | /* We use the LOCAL alias, since that's under our control, and |
| 4463 | * we keep it stable, whereas the REMOTE alias is likely what |
| 4464 | * the sender used to specify the channel, but that's under |
| 4465 | * control of the remote end. */ |
| 4466 | assert(in->key.channel->scid != NULL || in->key.channel->alias[LOCAL]); |
| 4467 | db_bind_scid(stmt, 2, channel_scid_or_local_alias(in->key.channel)); |
| 4468 | |
| 4469 | if (scid_out) |
| 4470 | db_bind_scid(stmt, 3, scid_out); |
| 4471 | else |
| 4472 | db_bind_null(stmt, 3); |
no test coverage detected