Skip to content

Commit

Permalink
json: Add wrapper to add a secret to a JSON result
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Decker <[email protected]>
  • Loading branch information
cdecker authored and rustyrussell committed Jun 9, 2019
1 parent 6f015b6 commit c91483f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lightningd/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,9 @@ void json_add_time(struct json_stream *result, const char *fieldname,
(unsigned)ts.tv_nsec);
json_add_string(result, fieldname, timebuf);
}

void json_add_secret(struct json_stream *response, const char *fieldname,
const struct secret *secret)
{
json_add_hex(response, fieldname, secret, sizeof(struct secret));
}
6 changes: 6 additions & 0 deletions lightningd/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef LIGHTNING_LIGHTNINGD_JSON_H
#define LIGHTNING_LIGHTNINGD_JSON_H
#include "config.h"
#include <bitcoin/privkey.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <ccan/time/time.h>
Expand Down Expand Up @@ -42,6 +43,11 @@ void json_add_pubkey(struct json_stream *response,
const char *fieldname,
const struct pubkey *key);

/* '"fieldname" : "89abcdef..."' or "89abcdef..." if fieldname is NULL */
void json_add_secret(struct json_stream *response,
const char *fieldname,
const struct secret *secret);

/* '"fieldname" : "0289abcdef..."' or "0289abcdef..." if fieldname is NULL */
void json_add_node_id(struct json_stream *response,
const char *fieldname,
Expand Down

0 comments on commit c91483f

Please sign in to comment.