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

Function forwarding_details

wallet/wallet.c:5768–5845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5766}
5767
5768const struct forwarding *forwarding_details(const tal_t *ctx,
5769 struct wallet *w,
5770 struct db_stmt *stmt)
5771{
5772 struct forwarding *fwd = tal(ctx, struct forwarding);
5773
5774 fwd->status = db_col_int(stmt, "state");
5775 fwd->msat_in = db_col_amount_msat(stmt, "in_msatoshi");
5776 fwd->created_index = db_col_u64(stmt, "rowid");
5777 fwd->updated_index = db_col_u64(stmt, "updated_index");
5778
5779 if (!db_col_is_null(stmt, "out_msatoshi")) {
5780 fwd->msat_out = db_col_amount_msat(stmt, "out_msatoshi");
5781 if (!amount_msat_sub(&fwd->fee, fwd->msat_in, fwd->msat_out)) {
5782 log_broken(w->log, "Forwarded in %s less than out %s!",
5783 fmt_amount_msat(tmpctx, fwd->msat_in),
5784 fmt_amount_msat(tmpctx, fwd->msat_out));
5785 fwd->fee = AMOUNT_MSAT(0);
5786 }
5787 }
5788 else {
5789 assert(fwd->status == FORWARD_LOCAL_FAILED);
5790 fwd->msat_out = AMOUNT_MSAT(0);
5791 /* For this case, this forward_payment doesn't have out channel,
5792 * so the fee should be set as 0.*/
5793 fwd->fee = AMOUNT_MSAT(0);
5794 }
5795
5796 fwd->channel_in = db_col_short_channel_id(stmt, "in_channel_scid");
5797
5798#ifdef COMPAT_V0121
5799 /* This can happen due to migration! */
5800 if (!db_col_is_null(stmt, "in_htlc_id"))
5801 fwd->htlc_id_in = db_col_u64(stmt, "in_htlc_id");
5802 else
5803 fwd->htlc_id_in = HTLC_INVALID_ID;
5804#else
5805 fwd->htlc_id_in = db_col_u64(stmt, "in_htlc_id");
5806#endif
5807
5808 if (!db_col_is_null(stmt, "out_channel_scid")) {
5809 fwd->channel_out = db_col_short_channel_id(stmt, "out_channel_scid");
5810 } else {
5811 assert(fwd->status == FORWARD_LOCAL_FAILED);
5812 fwd->channel_out.u64 = 0;
5813 }
5814 if (!db_col_is_null(stmt, "out_htlc_id")) {
5815 fwd->htlc_id_out = tal(fwd, u64);
5816 *fwd->htlc_id_out = db_col_u64(stmt, "out_htlc_id");
5817 } else
5818 fwd->htlc_id_out = NULL;
5819
5820 fwd->received_time = db_col_timeabs(stmt, "received_time");
5821
5822 if (!db_col_is_null(stmt, "resolved_time")) {
5823 fwd->resolved_time = tal(fwd, struct timeabs);
5824 *fwd->resolved_time
5825 = db_col_timeabs(stmt, "resolved_time");

Callers 1

Calls 9

db_col_intFunction · 0.85
db_col_amount_msatFunction · 0.85
db_col_u64Function · 0.85
db_col_is_nullFunction · 0.85
amount_msat_subFunction · 0.85
db_col_short_channel_idFunction · 0.85
db_col_timeabsFunction · 0.85
forward_style_in_dbFunction · 0.85
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected