json: Add helper to serialize short_channel_id_dir

We'll need it in the next commit to exclude channels and their directions.
This commit is contained in:
Christian Decker 2020-05-22 17:39:25 +02:00
parent 5e3134083e
commit c2538392e9
2 changed files with 18 additions and 1 deletions

View File

@ -3,7 +3,6 @@
#include <bitcoin/privkey.h>
#include <bitcoin/psbt.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/short_channel_id.h>
#include <ccan/ccan/str/hex/hex.h>
#include <common/amount.h>
#include <common/channel_id.h>
@ -164,6 +163,18 @@ void json_add_short_channel_id(struct json_stream *response,
short_channel_id_outnum(scid));
}
void json_add_short_channel_id_dir(struct json_stream *response,
const char *fieldname,
const struct short_channel_id_dir *scidd)
{
json_add_member(response, fieldname, true, "%dx%dx%d/%d",
short_channel_id_blocknum(&scidd->scid),
short_channel_id_txnum(&scidd->scid),
short_channel_id_outnum(&scidd->scid),
scidd->dir
);
}
void json_add_address(struct json_stream *response, const char *fieldname,
const struct wireaddr *addr)
{

View File

@ -2,6 +2,7 @@
#ifndef LIGHTNING_COMMON_JSON_HELPERS_H
#define LIGHTNING_COMMON_JSON_HELPERS_H
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <bitcoin/tx.h>
#include <common/json.h>
#include <wire/wire.h>
@ -92,6 +93,11 @@ void json_add_short_channel_id(struct json_stream *response,
const char *fieldname,
const struct short_channel_id *id);
/* '"fieldname" : "1234:5:6/7"' */
void json_add_short_channel_id_dir(struct json_stream *response,
const char *fieldname,
const struct short_channel_id_dir *id);
/* JSON serialize a network address for a node */
void json_add_address(struct json_stream *response, const char *fieldname,
const struct wireaddr *addr);