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

Function gossmap_chan_get_capacity

common/gossmap.c:992–1027  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

990}
991
992bool 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
1029struct gossmap_chan *gossmap_nth_chan(const struct gossmap *map,
1030 const struct gossmap_node *node,

Callers 4

mainFunction · 0.85
mainFunction · 0.85
capacity_biasFunction · 0.85
json_add_halfchanFunction · 0.85

Calls 5

map_be64Function · 0.85
map_copyFunction · 0.85
be32_to_cpuFunction · 0.85
map_be16Function · 0.85
amount_satClass · 0.70

Tested by 2

mainFunction · 0.68
mainFunction · 0.68