Browse Source

daemon: getpeers: list HTLCs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
17359279b2
  1. 46
      daemon/peer.c
  2. 14
      daemon/test/test.sh

46
daemon/peer.c

@ -254,6 +254,7 @@ static struct peer *new_peer(struct lightningd_state *dstate,
peer->current_htlc = NULL;
peer->num_htlcs = 0;
peer->close_tx = NULL;
peer->cstate = NULL;
/* If we free peer, conn should be closed, but can't be freed
* immediately so don't make peer a parent. */
@ -897,7 +898,42 @@ void make_commit_txs(const tal_t *ctx,
their_revocation_hash,
&their_cstate);
}
static void json_add_abstime(struct json_result *response,
const char *id,
const struct abs_locktime *t)
{
json_object_start(response, id);
if (abs_locktime_is_seconds(t))
json_add_num(response, "second", abs_locktime_to_seconds(t));
else
json_add_num(response, "block", abs_locktime_to_blocks(t));
json_object_end(response);
}
static void json_add_cstate(struct json_result *response,
const char *id,
const struct channel_oneside *side)
{
size_t i;
json_object_start(response, id);
json_add_num(response, "pay", side->pay_msat);
json_add_num(response, "fee", side->fee_msat);
json_array_start(response, "htlcs");
for (i = 0; i < tal_count(side->htlcs); i++) {
json_object_start(response, NULL);
json_add_u64(response, "msatoshis", side->htlcs[i].msatoshis);
json_add_abstime(response, "expiry", &side->htlcs[i].expiry);
json_add_hex(response, "rhash",
&side->htlcs[i].rhash,
sizeof(side->htlcs[i].rhash));
json_object_end(response);
}
json_array_end(response);
json_object_end(response);
}
/* FIXME: Somehow we should show running DNS lookups! */
/* FIXME: Show status of peers! */
static void json_getpeers(struct command *cmd,
@ -918,7 +954,13 @@ static void json_getpeers(struct command *cmd,
if (p->state != STATE_INIT)
json_add_hex(response, "id",
p->id.der, pubkey_derlen(&p->id));
if (p->cstate) {
json_object_start(response, "channel");
json_add_cstate(response, "us", &p->cstate->a);
json_add_cstate(response, "them", &p->cstate->b);
json_object_end(response);
}
json_object_end(response);
}
json_array_end(response);

14
daemon/test/test.sh

@ -74,11 +74,25 @@ sleep 2
$LCLI1 getpeers | grep STATE_NORMAL_HIGHPRIO
$LCLI2 getpeers | grep STATE_NORMAL_LOWPRIO
# Check channel status
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"us" : { "pay" : 949999000, "fee" : 50000000, "htlcs" : [ ]'
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"them" : { "pay" : 0, "fee" : 0, "htlcs" : [ ]'
$LCLI2 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"them" : { "pay" : 949999000, "fee" : 50000000, "htlcs" : [ ]'
$LCLI2 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"us" : { "pay" : 0, "fee" : 0, "htlcs" : [ ]'
EXPIRY=$(( $(date +%s) + 1000))
SECRET=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfd
RHASH=`$LCLI1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
$LCLI1 newhtlc $ID2 1000000 $EXPIRY $RHASH
# Check channel status
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"us" : { "pay" : 948999000, "fee" : 50000000, "htlcs" : [ { "msatoshis" : 1000000, "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ]'
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"them" : { "pay" : 0, "fee" : 0, "htlcs" : [ ]'
$LCLI2 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"them" : { "pay" : 948999000, "fee" : 50000000, "htlcs" : [ { "msatoshis" : 1000000, "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ]'
$LCLI2 getpeers | tr -s '\012\011 ' ' ' | fgrep -q '"us" : { "pay" : 0, "fee" : 0, "htlcs" : [ ]'
$LCLI1 stop
$LCLI2 stop
scripts/shutdown.sh

Loading…
Cancel
Save