To avoid multiple fetches, we represent directions as a bitmap * so we can do two at once. */
| 209 | /* To avoid multiple fetches, we represent directions as a bitmap |
| 210 | * so we can do two at once. */ |
| 211 | static void json_add_halfchan(struct json_stream *response, |
| 212 | struct gossmap *gossmap, |
| 213 | const struct node_map *connected, |
| 214 | const struct gossmap_chan *c, |
| 215 | int dirbits) |
| 216 | { |
| 217 | struct short_channel_id scid; |
| 218 | struct node_id node_id[2]; |
| 219 | const u8 *chanfeatures; |
| 220 | struct amount_sat capacity; |
| 221 | bool local_disable; |
| 222 | |
| 223 | /* These are channel (not per-direction) properties */ |
| 224 | chanfeatures = gossmap_chan_get_features(tmpctx, gossmap, c); |
| 225 | scid = gossmap_chan_scid(gossmap, c); |
| 226 | for (size_t i = 0; i < 2; i++) |
| 227 | gossmap_node_get_id(gossmap, gossmap_nth_node(gossmap, c, i), |
| 228 | &node_id[i]); |
| 229 | |
| 230 | /* This can theoretically happen on partial write races. */ |
| 231 | if (!gossmap_chan_get_capacity(gossmap, c, &capacity)) |
| 232 | capacity = AMOUNT_SAT(0); |
| 233 | |
| 234 | /* Local channels are not "active" unless peer is connected. */ |
| 235 | if (node_id_eq(&node_id[0], &local_id)) |
| 236 | local_disable = !node_map_get(connected, &node_id[1]); |
| 237 | else if (node_id_eq(&node_id[1], &local_id)) |
| 238 | local_disable = !node_map_get(connected, &node_id[0]); |
| 239 | else |
| 240 | local_disable = false; |
| 241 | |
| 242 | for (int dir = 0; dir < 2; dir++) { |
| 243 | u32 timestamp; |
| 244 | u8 message_flags, channel_flags; |
| 245 | u32 fee_base_msat, fee_proportional_millionths; |
| 246 | struct amount_msat htlc_minimum_msat, htlc_maximum_msat; |
| 247 | |
| 248 | if (!((1 << dir) & dirbits)) |
| 249 | continue; |
| 250 | |
| 251 | if (!gossmap_chan_set(c, dir)) |
| 252 | continue; |
| 253 | |
| 254 | json_object_start(response, NULL); |
| 255 | json_add_node_id(response, "source", &node_id[dir]); |
| 256 | json_add_node_id(response, "destination", &node_id[!dir]); |
| 257 | json_add_short_channel_id(response, "short_channel_id", &scid); |
| 258 | json_add_bool(response, "public", !c->private); |
| 259 | |
| 260 | gossmap_chan_get_update_details(gossmap, c, dir, |
| 261 | ×tamp, |
| 262 | &message_flags, |
| 263 | &channel_flags, |
| 264 | &fee_base_msat, |
| 265 | &fee_proportional_millionths, |
| 266 | &htlc_minimum_msat, |
| 267 | &htlc_maximum_msat); |
| 268 |
no test coverage detected