listchannels: allow source arg to list channels by their source node.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-01-15 14:39:27 +10:30
committed by Christian Decker
parent de682f5806
commit dc2ee9639b
8 changed files with 59 additions and 22 deletions

View File

@@ -43,6 +43,7 @@ gossip_getroute_reply,,hops,num_hops*struct route_hop
gossip_getchannels_request,3007
gossip_getchannels_request,,short_channel_id,?struct short_channel_id
gossip_getchannels_request,,source,?struct pubkey
gossip_getchannels_reply,3107
gossip_getchannels_reply,,num_channels,u16
1 #include <common/cryptomsg.h>
43 # Ping/pong test. Waits for a reply if it expects one. gossip_getchannels_reply,,nodes,num_channels*struct gossip_getchannels_entry
44 gossip_ping,3008 # Ping/pong test. Waits for a reply if it expects one.
45 gossip_ping,,id,struct pubkey gossip_ping,3008
46 gossip_ping,,id,struct pubkey
47 gossip_ping,,num_pong_bytes,u16
48 gossip_ping,,len,u16
49 gossip_ping_reply,3108

View File

@@ -1971,9 +1971,10 @@ static struct io_plan *getchannels_req(struct io_conn *conn,
struct gossip_getchannels_entry *entries;
struct chan *chan;
struct short_channel_id *scid;
struct pubkey *source;
/* Note: scid is marked optional in gossip_wire.csv */
if (!fromwire_gossip_getchannels_request(msg, msg, &scid))
if (!fromwire_gossip_getchannels_request(msg, msg, &scid, &source))
master_badmsg(WIRE_GOSSIP_GETCHANNELS_REQUEST, msg);
entries = tal_arr(tmpctx, struct gossip_getchannels_entry, 0);
@@ -1982,6 +1983,15 @@ static struct io_plan *getchannels_req(struct io_conn *conn,
chan = get_channel(daemon->rstate, scid);
if (chan)
append_channel(&entries, chan);
} else if (source) {
struct node *s = get_node(daemon->rstate, source);
if (s) {
for (size_t i = 0; i < tal_count(s->chans); i++)
append_half_channel(&entries,
s->chans[i],
!half_chan_to(s,
s->chans[i]));
}
} else {
u64 idx;