mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
common/json: move rest of bitcoin/lightning-specific json functions to json_helpers.
This dramatically reduces the linking requirements of lightning-cli. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
fda5f0b427
commit
f77d70d546
@@ -8,9 +8,18 @@
|
||||
|
||||
struct amount_msat;
|
||||
struct amount_sat;
|
||||
struct channel_id;
|
||||
struct pubkey;
|
||||
struct node_id;
|
||||
struct short_channel_id;
|
||||
struct wireaddr;
|
||||
struct wireaddr_internal;
|
||||
|
||||
/* Decode a hex-encoded payment preimage */
|
||||
bool json_to_preimage(const char *buffer, const jsmntok_t *tok, struct preimage *preimage);
|
||||
|
||||
/* Extract a secret from this. */
|
||||
bool json_to_secret(const char *buffer, const jsmntok_t *tok, struct secret *dest);
|
||||
|
||||
/* Extract a pubkey from this */
|
||||
bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,
|
||||
@@ -54,4 +63,76 @@ bool split_tok(const char *buffer, const jsmntok_t *tok,
|
||||
char split,
|
||||
jsmntok_t *a,
|
||||
jsmntok_t *b);
|
||||
|
||||
/* Helpers for outputting JSON results */
|
||||
|
||||
/* '"fieldname" : "0289abcdef..."' or "0289abcdef..." if fieldname is NULL */
|
||||
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,
|
||||
const struct node_id *id);
|
||||
|
||||
/* '"fieldname" : <hexrev>' or "<hexrev>" if fieldname is NULL */
|
||||
void json_add_txid(struct json_stream *result, const char *fieldname,
|
||||
const struct bitcoin_txid *txid);
|
||||
|
||||
/* '"fieldname" : "1234:5:6"' */
|
||||
void json_add_short_channel_id(struct json_stream *response,
|
||||
const char *fieldname,
|
||||
const struct short_channel_id *id);
|
||||
|
||||
/* JSON serialize a network address for a node */
|
||||
void json_add_address(struct json_stream *response, const char *fieldname,
|
||||
const struct wireaddr *addr);
|
||||
|
||||
/* JSON serialize a network address for a node. */
|
||||
void json_add_address_internal(struct json_stream *response,
|
||||
const char *fieldname,
|
||||
const struct wireaddr_internal *addr);
|
||||
|
||||
/* Adds both a 'raw' number field and an 'amount_msat' field */
|
||||
void json_add_amount_msat_compat(struct json_stream *result,
|
||||
struct amount_msat msat,
|
||||
const char *rawfieldname,
|
||||
const char *msatfieldname)
|
||||
NO_NULL_ARGS;
|
||||
|
||||
/* Adds both a 'raw' number field and an 'amount_msat' field */
|
||||
void json_add_amount_sat_compat(struct json_stream *result,
|
||||
struct amount_sat sat,
|
||||
const char *rawfieldname,
|
||||
const char *msatfieldname)
|
||||
NO_NULL_ARGS;
|
||||
|
||||
/* Adds an 'msat' field */
|
||||
void json_add_amount_msat_only(struct json_stream *result,
|
||||
const char *msatfieldname,
|
||||
struct amount_msat msat)
|
||||
NO_NULL_ARGS;
|
||||
|
||||
/* Adds an 'msat' field */
|
||||
void json_add_amount_sat_only(struct json_stream *result,
|
||||
const char *msatfieldname,
|
||||
struct amount_sat sat)
|
||||
NO_NULL_ARGS;
|
||||
|
||||
void json_add_sha256(struct json_stream *result, const char *fieldname,
|
||||
const struct sha256 *hash);
|
||||
|
||||
void json_add_preimage(struct json_stream *result, const char *fieldname,
|
||||
const struct preimage *preimage);
|
||||
|
||||
/* '"fieldname" : "010000000001..."' or "010000000001..." if fieldname is NULL */
|
||||
void json_add_tx(struct json_stream *result,
|
||||
const char *fieldname,
|
||||
const struct bitcoin_tx *tx);
|
||||
#endif /* LIGHTNING_COMMON_JSON_HELPERS_H */
|
||||
|
||||
Reference in New Issue
Block a user