mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
lightningd: add json_add_amount_msat and json_add_amount_sat helpers.
These create two fields, one old one which is purely numeric, and a modern on with a suffix, eg "msatoshi" and "amount_msat". Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
177cfd9edc
commit
28ec65fd79
@ -328,3 +328,25 @@ void json_add_escaped_string(struct json_stream *result, const char *fieldname,
|
||||
if (taken(esc))
|
||||
tal_free(esc);
|
||||
}
|
||||
|
||||
void json_add_amount_msat(struct json_stream *result,
|
||||
struct amount_msat msat,
|
||||
const char *rawfieldname,
|
||||
const char *msatfieldname)
|
||||
{
|
||||
json_add_u64(result, rawfieldname, msat.millisatoshis);
|
||||
json_add_member(result, msatfieldname, "\"%s\"",
|
||||
type_to_string(tmpctx, struct amount_msat, &msat));
|
||||
}
|
||||
|
||||
void json_add_amount_sat(struct json_stream *result,
|
||||
struct amount_sat sat,
|
||||
const char *rawfieldname,
|
||||
const char *msatfieldname)
|
||||
{
|
||||
struct amount_msat msat;
|
||||
json_add_u64(result, rawfieldname, sat.satoshis);
|
||||
if (amount_sat_to_msat(&msat, sat))
|
||||
json_add_member(result, msatfieldname, "\"%s\"",
|
||||
type_to_string(tmpctx, struct amount_msat, &msat));
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <common/amount.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@ -127,6 +128,20 @@ void json_add_hex_talarr(struct json_stream *result,
|
||||
const char *fieldname,
|
||||
const tal_t *data);
|
||||
|
||||
/* Adds both a 'raw' number field and an 'amount_msat' field */
|
||||
void json_add_amount_msat(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(struct json_stream *result,
|
||||
struct amount_sat sat,
|
||||
const char *rawfieldname,
|
||||
const char *msatfieldname)
|
||||
NO_NULL_ARGS;
|
||||
|
||||
enum address_parse_result {
|
||||
/* Not recognized as an onchain address */
|
||||
ADDRESS_PARSE_UNRECOGNIZED,
|
||||
|
@ -3,6 +3,10 @@
|
||||
#include "../json.c"
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for amount_sat_to_msat */
|
||||
bool amount_sat_to_msat(struct amount_msat *msat UNNEEDED,
|
||||
struct amount_sat sat UNNEEDED)
|
||||
{ fprintf(stderr, "amount_sat_to_msat called!\n"); abort(); }
|
||||
/* Generated stub for db_begin_transaction_ */
|
||||
void db_begin_transaction_(struct db *db UNNEEDED, const char *location UNNEEDED)
|
||||
{ fprintf(stderr, "db_begin_transaction_ called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user