Warp this process to ensure the consistent json object structure * between 'listforwards' API and 'forward_event' notification. */
| 87 | /* Warp this process to ensure the consistent json object structure |
| 88 | * between 'listforwards' API and 'forward_event' notification. */ |
| 89 | void json_add_forwarding_fields(struct json_stream *response, |
| 90 | const struct forwarding *cur, |
| 91 | const struct sha256 *payment_hash, |
| 92 | const struct preimage *preimage) |
| 93 | { |
| 94 | /* We don't bother grabbing id from db on update. */ |
| 95 | if (cur->created_index) |
| 96 | json_add_u64(response, "created_index", cur->created_index); |
| 97 | if (cur->updated_index) |
| 98 | json_add_u64(response, "updated_index", cur->updated_index); |
| 99 | |
| 100 | /* Only for forward_event */ |
| 101 | if (payment_hash) |
| 102 | json_add_sha256(response, "payment_hash", payment_hash); |
| 103 | json_add_short_channel_id(response, "in_channel", cur->channel_in); |
| 104 | |
| 105 | #ifdef COMPAT_V0121 |
| 106 | if (cur->htlc_id_in != HTLC_INVALID_ID) |
| 107 | #endif |
| 108 | json_add_u64(response, "in_htlc_id", cur->htlc_id_in); |
| 109 | |
| 110 | /* This can be unknown if we failed before channel lookup */ |
| 111 | if (cur->channel_out.u64 != 0) { |
| 112 | json_add_short_channel_id(response, "out_channel", |
| 113 | cur->channel_out); |
| 114 | if (cur->htlc_id_out) |
| 115 | json_add_u64(response, "out_htlc_id", *cur->htlc_id_out); |
| 116 | } |
| 117 | json_add_amount_msat(response, "in_msat", cur->msat_in); |
| 118 | |
| 119 | /* These can be unset (aka zero) if we failed before channel lookup */ |
| 120 | if (!amount_msat_is_zero(cur->msat_out)) { |
| 121 | json_add_amount_msat(response, "out_msat", cur->msat_out); |
| 122 | json_add_amount_msat(response, "fee_msat", cur->fee); |
| 123 | } |
| 124 | json_add_string(response, "status", forward_status_name(cur->status)); |
| 125 | |
| 126 | if (cur->failcode != 0) { |
| 127 | json_add_num(response, "failcode", cur->failcode); |
| 128 | json_add_string(response, "failreason", |
| 129 | onion_wire_name(cur->failcode)); |
| 130 | } |
| 131 | |
| 132 | /* Old forwards don't have this field */ |
| 133 | if (cur->forward_style != FORWARD_STYLE_UNKNOWN) |
| 134 | json_add_string(response, "style", |
| 135 | forward_style_name(cur->forward_style)); |
| 136 | |
| 137 | /* Forwards didn't originally have received_time. They should be 0 |
| 138 | in the database due to a previous migration. */ |
| 139 | json_add_timeabs(response, "received_time", cur->received_time); |
| 140 | if (cur->resolved_time) |
| 141 | json_add_timeabs(response, "resolved_time", *cur->resolved_time); |
| 142 | if (preimage) |
| 143 | json_add_preimage(response, "preimage", preimage); |
| 144 | } |
| 145 | |
| 146 | static void listforwardings_add_forwardings(struct json_stream *response, |
no test coverage detected