diff --git a/common/json_helpers.c b/common/json_helpers.c index df4f5cd09..d9c20527c 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -38,6 +39,19 @@ bool json_to_pubkey(const char *buffer, const jsmntok_t *tok, 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, struct short_channel_id *scid, bool may_be_deprecated_form) diff --git a/common/json_helpers.h b/common/json_helpers.h index 5659fe856..5683bcdde 100644 --- a/common/json_helpers.h +++ b/common/json_helpers.h @@ -4,6 +4,8 @@ #include "config.h" #include +struct amount_msat; +struct amount_sat; struct pubkey; 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, 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 */ diff --git a/common/test/run-json.c b/common/test/run-json.c index e44e64c9a..42a1e79d4 100644 --- a/common/test/run-json.c +++ b/common/test/run-json.c @@ -5,6 +5,12 @@ #include /* 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 */