To avoid multiple fetches, we represent directions as a bitmap * so we can do two at once. */
| 201 | /* To avoid multiple fetches, we represent directions as a bitmap |
| 202 | * so we can do two at once. */ |
| 203 | static void json_add_halfchan(struct json_stream *response, |
| 204 | struct gossmap *gossmap, |
| 205 | const struct gossmap_chan *c, |
| 206 | int dirbits) |
| 207 | { |
| 208 | struct short_channel_id scid; |
| 209 | struct node_id node_id[2]; |
| 210 | const u8 *chanfeatures; |
| 211 | struct amount_msat capacity_msat; |
| 212 | |
| 213 | /* These are channel (not per-direction) properties */ |
| 214 | chanfeatures = gossmap_chan_get_features(tmpctx, gossmap, c); |
| 215 | scid = gossmap_chan_scid(gossmap, c); |
| 216 | for (size_t i = 0; i < 2; i++) |
| 217 | gossmap_node_get_id(gossmap, gossmap_nth_node(gossmap, c, i), |
| 218 | &node_id[i]); |
| 219 | |
| 220 | capacity_msat = gossmap_chan_get_capacity(gossmap, c); |
| 221 | |
| 222 | for (int dir = 0; dir < 2; dir++) { |
| 223 | u32 timestamp; |
| 224 | u8 message_flags, channel_flags; |
| 225 | u32 fee_base_msat, fee_proportional_millionths; |
| 226 | struct amount_msat htlc_minimum_msat, htlc_maximum_msat; |
| 227 | |
| 228 | if (!((1 << dir) & dirbits)) |
| 229 | continue; |
| 230 | |
| 231 | if (!gossmap_chan_set(c, dir)) |
| 232 | continue; |
| 233 | |
| 234 | json_object_start(response, NULL); |
| 235 | json_add_node_id(response, "source", &node_id[dir]); |
| 236 | json_add_node_id(response, "destination", &node_id[!dir]); |
| 237 | json_add_short_channel_id(response, "short_channel_id", scid); |
| 238 | json_add_num(response, "direction", dir); |
| 239 | json_add_bool(response, "public", !gossmap_chan_is_localmod(gossmap, c)); |
| 240 | |
| 241 | gossmap_chan_get_update_details(gossmap, c, dir, |
| 242 | ×tamp, |
| 243 | &message_flags, |
| 244 | &channel_flags, |
| 245 | NULL, |
| 246 | &fee_base_msat, |
| 247 | &fee_proportional_millionths, |
| 248 | &htlc_minimum_msat, |
| 249 | &htlc_maximum_msat); |
| 250 | |
| 251 | json_add_amount_msat(response, "amount_msat", capacity_msat); |
| 252 | json_add_num(response, "message_flags", message_flags); |
| 253 | json_add_num(response, "channel_flags", channel_flags); |
| 254 | |
| 255 | json_add_bool(response, "active", c->half[dir].enabled); |
| 256 | json_add_num(response, "last_update", timestamp); |
| 257 | json_add_num(response, "base_fee_millisatoshi", fee_base_msat); |
| 258 | json_add_num(response, "fee_per_millionth", |
| 259 | fee_proportional_millionths); |
| 260 | json_add_num(response, "delay", c->half[dir].delay); |
no test coverage detected