Browse Source

json: add channel_id helper

travis-experimental
niftynei 4 years ago
committed by Rusty Russell
parent
commit
3674de9865
  1. 7
      common/json_helpers.c
  2. 5
      common/json_helpers.h
  3. 3
      lightningd/notification.c

7
common/json_helpers.c

@ -142,6 +142,13 @@ void json_add_node_id(struct json_stream *response,
json_add_hex(response, fieldname, id->k, sizeof(id->k)); json_add_hex(response, fieldname, id->k, sizeof(id->k));
} }
void json_add_channel_id(struct json_stream *response,
const char *fieldname,
const struct channel_id *cid)
{
json_add_hex(response, fieldname, cid->id, sizeof(cid->id));
}
void json_add_pubkey(struct json_stream *response, void json_add_pubkey(struct json_stream *response,
const char *fieldname, const char *fieldname,
const struct pubkey *key) const struct pubkey *key)

5
common/json_helpers.h

@ -89,6 +89,11 @@ void json_add_node_id(struct json_stream *response,
const char *fieldname, const char *fieldname,
const struct node_id *id); const struct node_id *id);
/* '"fieldname" : "0289abcdef..."' or "0289abcdef..." if fieldname is NULL */
void json_add_channel_id(struct json_stream *response,
const char *fieldname,
const struct channel_id *cid);
/* '"fieldname" : <hexrev>' or "<hexrev>" if fieldname is NULL */ /* '"fieldname" : <hexrev>' or "<hexrev>" if fieldname is NULL */
void json_add_txid(struct json_stream *result, const char *fieldname, void json_add_txid(struct json_stream *result, const char *fieldname,
const struct bitcoin_txid *txid); const struct bitcoin_txid *txid);

3
lightningd/notification.c

@ -219,8 +219,7 @@ static void channel_state_changed_notification_serialize(struct json_stream *str
{ {
json_object_start(stream, "channel_state_changed"); json_object_start(stream, "channel_state_changed");
json_add_node_id(stream, "peer_id", peer_id); json_add_node_id(stream, "peer_id", peer_id);
json_add_string(stream, "channel_id", json_add_channel_id(stream, "channel_id", cid);
type_to_string(tmpctx, struct channel_id, cid));
if (scid) if (scid)
json_add_short_channel_id(stream, "short_channel_id", scid); json_add_short_channel_id(stream, "short_channel_id", scid);
else else

Loading…
Cancel
Save