| 5706 | } |
| 5707 | |
| 5708 | const struct forwarding *forwarding_details(const tal_t *ctx, |
| 5709 | struct wallet *w, |
| 5710 | struct db_stmt *stmt) |
| 5711 | { |
| 5712 | struct forwarding *fwd = tal(ctx, struct forwarding); |
| 5713 | |
| 5714 | fwd->status = db_col_int(stmt, "state"); |
| 5715 | fwd->msat_in = db_col_amount_msat(stmt, "in_msatoshi"); |
| 5716 | fwd->created_index = db_col_u64(stmt, "rowid"); |
| 5717 | fwd->updated_index = db_col_u64(stmt, "updated_index"); |
| 5718 | |
| 5719 | if (!db_col_is_null(stmt, "out_msatoshi")) { |
| 5720 | fwd->msat_out = db_col_amount_msat(stmt, "out_msatoshi"); |
| 5721 | if (!amount_msat_sub(&fwd->fee, fwd->msat_in, fwd->msat_out)) { |
| 5722 | log_broken(w->log, "Forwarded in %s less than out %s!", |
| 5723 | fmt_amount_msat(tmpctx, fwd->msat_in), |
| 5724 | fmt_amount_msat(tmpctx, fwd->msat_out)); |
| 5725 | fwd->fee = AMOUNT_MSAT(0); |
| 5726 | } |
| 5727 | } |
| 5728 | else { |
| 5729 | assert(fwd->status == FORWARD_LOCAL_FAILED); |
| 5730 | fwd->msat_out = AMOUNT_MSAT(0); |
| 5731 | /* For this case, this forward_payment doesn't have out channel, |
| 5732 | * so the fee should be set as 0.*/ |
| 5733 | fwd->fee = AMOUNT_MSAT(0); |
| 5734 | } |
| 5735 | |
| 5736 | fwd->channel_in = db_col_short_channel_id(stmt, "in_channel_scid"); |
| 5737 | |
| 5738 | #ifdef COMPAT_V0121 |
| 5739 | /* This can happen due to migration! */ |
| 5740 | if (!db_col_is_null(stmt, "in_htlc_id")) |
| 5741 | fwd->htlc_id_in = db_col_u64(stmt, "in_htlc_id"); |
| 5742 | else |
| 5743 | fwd->htlc_id_in = HTLC_INVALID_ID; |
| 5744 | #else |
| 5745 | fwd->htlc_id_in = db_col_u64(stmt, "in_htlc_id"); |
| 5746 | #endif |
| 5747 | |
| 5748 | if (!db_col_is_null(stmt, "out_channel_scid")) { |
| 5749 | fwd->channel_out = db_col_short_channel_id(stmt, "out_channel_scid"); |
| 5750 | } else { |
| 5751 | assert(fwd->status == FORWARD_LOCAL_FAILED); |
| 5752 | fwd->channel_out.u64 = 0; |
| 5753 | } |
| 5754 | if (!db_col_is_null(stmt, "out_htlc_id")) { |
| 5755 | fwd->htlc_id_out = tal(fwd, u64); |
| 5756 | *fwd->htlc_id_out = db_col_u64(stmt, "out_htlc_id"); |
| 5757 | } else |
| 5758 | fwd->htlc_id_out = NULL; |
| 5759 | |
| 5760 | fwd->received_time = db_col_timeabs(stmt, "received_time"); |
| 5761 | |
| 5762 | if (!db_col_is_null(stmt, "resolved_time")) { |
| 5763 | fwd->resolved_time = tal(fwd, struct timeabs); |
| 5764 | *fwd->resolved_time |
| 5765 | = db_col_timeabs(stmt, "resolved_time"); |
no test coverage detected