| 990 | } |
| 991 | |
| 992 | bool gossmap_chan_get_capacity(const struct gossmap *map, |
| 993 | const struct gossmap_chan *c, |
| 994 | struct amount_sat *amount) |
| 995 | { |
| 996 | struct gossip_hdr ghdr; |
| 997 | size_t off; |
| 998 | u16 type; |
| 999 | |
| 1000 | /* Fail for local channels */ |
| 1001 | if (c->cann_off >= map->map_size) |
| 1002 | return false; |
| 1003 | |
| 1004 | /* For private, we need to go back WIRE_GOSSIP_STORE_PRIVATE_CHANNEL, |
| 1005 | * which is 8 (satoshis) + 2 (len) */ |
| 1006 | if (c->private) { |
| 1007 | *amount = amount_sat(map_be64(map, c->cann_off - 8 - 2)); |
| 1008 | return true; |
| 1009 | } |
| 1010 | |
| 1011 | /* Skip over this record to next; expect a gossip_store_channel_amount */ |
| 1012 | off = c->cann_off - sizeof(ghdr); |
| 1013 | map_copy(map, off, &ghdr, sizeof(ghdr)); |
| 1014 | off += sizeof(ghdr) + (be32_to_cpu(ghdr.len) & GOSSIP_STORE_LEN_MASK); |
| 1015 | |
| 1016 | /* Partial write, this can happen. */ |
| 1017 | if (off + sizeof(ghdr) + 2 > map->map_size) |
| 1018 | return false; |
| 1019 | |
| 1020 | /* Get type of next field. */ |
| 1021 | type = map_be16(map, off + sizeof(ghdr)); |
| 1022 | if (type != WIRE_GOSSIP_STORE_CHANNEL_AMOUNT) |
| 1023 | return false; |
| 1024 | |
| 1025 | *amount = amount_sat(map_be64(map, off + sizeof(ghdr) + sizeof(be16))); |
| 1026 | return true; |
| 1027 | } |
| 1028 | |
| 1029 | struct gossmap_chan *gossmap_nth_chan(const struct gossmap *map, |
| 1030 | const struct gossmap_node *node, |