Browse Source

JSONRPC: add optional short_channel_id argument to listchannels

In order to just list one (though it may return two entries, one for each
channel direction!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
06c4f6ddca
  1. 8
      gossipd/gossip.c
  2. 3
      gossipd/gossip_wire.csv
  3. 21
      lightningd/gossip_control.c
  4. 11
      tests/test_lightningd.py

8
gossipd/gossip.c

@ -1066,11 +1066,19 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem
struct gossip_getchannels_entry *entries;
struct node *n;
struct node_map_iter i;
struct short_channel_id *scid;
fromwire_gossip_getchannels_request(msg, msg, NULL, &scid);
entries = tal_arr(tmpctx, struct gossip_getchannels_entry, num_chans);
n = node_map_first(daemon->rstate->nodes, &i);
while (n != NULL) {
for (j=0; j<tal_count(n->out); j++){
if (scid &&
!short_channel_id_eq(scid,
&n->out[j]->short_channel_id)) {
continue;
}
tal_resize(&entries, num_chans + 1);
entries[num_chans].source = n->out[j]->src->id;
entries[num_chans].destination = n->out[j]->dst->id;

3
gossipd/gossip_wire.csv

@ -105,6 +105,9 @@ gossip_getroute_reply,,num_hops,u16
gossip_getroute_reply,,hops,num_hops*struct route_hop
gossip_getchannels_request,3007
# In practice, 0 or 1.
gossip_getchannels_request,,num,u16
gossip_getchannels_request,,short_channel_id,num*struct short_channel_id
gossip_getchannels_reply,3107
gossip_getchannels_reply,,num_channels,u16

Can't render this file because it has a wrong number of fields in line 5.

21
lightningd/gossip_control.c

@ -386,7 +386,26 @@ static void json_listchannels_reply(struct subd *gossip, const u8 *reply,
static void json_listchannels(struct command *cmd, const char *buffer,
const jsmntok_t *params)
{
u8 *req = towire_gossip_getchannels_request(cmd);
u8 *req;
jsmntok_t *idtok;
struct short_channel_id *id = NULL;
if (!json_get_params(buffer, params,
"?short_channel_id", &idtok,
NULL)) {
command_fail(cmd, "Invalid arguments");
return;
}
if (idtok) {
id = tal_arr(cmd, struct short_channel_id, 1);
if (!json_tok_short_channel_id(buffer, idtok, id)) {
command_fail(cmd, "Invalid short_channel_id");
return;
}
}
req = towire_gossip_getchannels_request(cmd, id);
subd_req(cmd->ld->gossip, cmd->ld->gossip,
req, -1, 0, json_listchannels_reply, cmd);
command_still_pending(cmd);

11
tests/test_lightningd.py

@ -1775,6 +1775,17 @@ class LightningDTests(BaseLightningDTests):
.format(bitcoind.rpc.getblockcount() + 9 + shadow_route))
assert l3.rpc.listinvoice('test_forward_different_fees_and_cltv')[0]['complete'] == True
# Check that we see all the channels
shortids = set(c['short_channel_id'] for c in l2.rpc.listchannels()['channels'])
for scid in shortids:
c = l1.rpc.listchannels(scid)['channels']
# We get one entry for each direction.
assert len(c) == 2
assert c[0]['short_channel_id'] == scid
assert c[1]['short_channel_id'] == scid
assert c[0]['source'] == c[1]['destination']
assert c[1]['source'] == c[0]['destination']
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1 for --dev-broadcast-interval")
def test_forward_pad_fees_and_cltv(self):
"""Test that we are allowed extra locktime delta, and fees"""

Loading…
Cancel
Save