Browse Source

common: json_to_msat and json_to_sat helpers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
confirmed-only
Rusty Russell 6 years ago
parent
commit
177cfd9edc
  1. 14
      common/json_helpers.c
  2. 10
      common/json_helpers.h
  3. 6
      common/test/run-json.c

14
common/json_helpers.c

@ -1,5 +1,6 @@
#include <bitcoin/pubkey.h> #include <bitcoin/pubkey.h>
#include <bitcoin/short_channel_id.h> #include <bitcoin/short_channel_id.h>
#include <common/amount.h>
#include <common/json_helpers.h> #include <common/json_helpers.h>
#include <errno.h> #include <errno.h>
@ -38,6 +39,19 @@ bool json_to_pubkey(const char *buffer, const jsmntok_t *tok,
tok->end - tok->start, pubkey); tok->end - tok->start, pubkey);
} }
bool json_to_msat(const char *buffer, const jsmntok_t *tok,
struct amount_msat *msat)
{
return parse_amount_msat(msat,
buffer + tok->start, tok->end - tok->start);
}
bool json_to_sat(const char *buffer, const jsmntok_t *tok,
struct amount_sat *sat)
{
return parse_amount_sat(sat, buffer + tok->start, tok->end - tok->start);
}
bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok, bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
struct short_channel_id *scid, struct short_channel_id *scid,
bool may_be_deprecated_form) bool may_be_deprecated_form)

10
common/json_helpers.h

@ -4,6 +4,8 @@
#include "config.h" #include "config.h"
#include <common/json.h> #include <common/json.h>
struct amount_msat;
struct amount_sat;
struct pubkey; struct pubkey;
struct short_channel_id; struct short_channel_id;
@ -20,4 +22,12 @@ bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
struct short_channel_id *scid, struct short_channel_id *scid,
bool may_be_deprecated_form); bool may_be_deprecated_form);
/* Extract a satoshis amount from this */
bool json_to_sat(const char *buffer, const jsmntok_t *tok,
struct amount_sat *sat);
/* Extract a millisatoshis amount from this */
bool json_to_msat(const char *buffer, const jsmntok_t *tok,
struct amount_msat *msat);
#endif /* LIGHTNING_COMMON_JSON_HELPERS_H */ #endif /* LIGHTNING_COMMON_JSON_HELPERS_H */

6
common/test/run-json.c

@ -5,6 +5,12 @@
#include <stdio.h> #include <stdio.h>
/* AUTOGENERATED MOCKS START */ /* AUTOGENERATED MOCKS START */
/* Generated stub for parse_amount_msat */
bool parse_amount_msat(struct amount_msat *msat UNNEEDED, const char *s UNNEEDED, size_t slen UNNEEDED)
{ fprintf(stderr, "parse_amount_msat called!\n"); abort(); }
/* Generated stub for parse_amount_sat */
bool parse_amount_sat(struct amount_sat *sat UNNEEDED, const char *s UNNEEDED, size_t slen UNNEEDED)
{ fprintf(stderr, "parse_amount_sat called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */ /* AUTOGENERATED MOCKS END */

Loading…
Cancel
Save