diff --git a/common/json_parse_simple.c b/common/json_parse_simple.c index f7ce964ca..9fe94229c 100644 --- a/common/json_parse_simple.c +++ b/common/json_parse_simple.c @@ -88,6 +88,19 @@ bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num) return true; } +bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num) +{ + jsmntok_t temp; + if (tok->type != JSMN_STRING) + return false; + + temp = *tok; + temp.start += 1; + temp.end -= 1; + + return json_to_u64(buffer, &temp, num); +} + bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num) { uint64_t u64; diff --git a/common/json_parse_simple.h b/common/json_parse_simple.h index 4188a4eb4..4092dad75 100644 --- a/common/json_parse_simple.h +++ b/common/json_parse_simple.h @@ -35,6 +35,10 @@ char *json_strdup(const tal_t *ctx, const char *buffer, const jsmntok_t *tok); /* Extract number from this (may be a string, or a number literal) */ bool json_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num); +/* Extract number from string. The number must be the entirety of the + * string between the '"' */ +bool json_str_to_u64(const char *buffer, const jsmntok_t *tok, u64 *num); + /* Extract number from this (may be a string, or a number literal) */ bool json_to_u32(const char *buffer, const jsmntok_t *tok, u32 *num);