From 6d07f4ed85be91d5af0bfffa75895d4b33fd4cc2 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 19 May 2022 13:51:49 +0200 Subject: [PATCH] json: Add parser for u32 params --- common/json_tok.c | 12 ++++++++++++ common/json_tok.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/common/json_tok.c b/common/json_tok.c index 5ae688014..a91eb63ed 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -122,6 +122,18 @@ struct command_result *param_sha256(struct command *cmd, const char *name, "should be a 32 byte hex value"); } +struct command_result *param_u32(struct command *cmd, const char *name, + const char *buffer, const jsmntok_t *tok, + uint32_t **num) +{ + *num = tal(cmd, uint32_t); + if (json_to_u32(buffer, tok, *num)) + return NULL; + + return command_fail_badparam(cmd, name, buffer, tok, + "should be an unsigned 32 bit integer"); +} + struct command_result *param_u64(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok, uint64_t **num) diff --git a/common/json_tok.h b/common/json_tok.h index e4c59d5ce..2b6f9e724 100644 --- a/common/json_tok.h +++ b/common/json_tok.h @@ -68,6 +68,11 @@ struct command_result *param_sha256(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok, struct sha256 **hash); +/* Extract number from this (may be a string, or a number literal) */ +struct command_result *param_u32(struct command *cmd, const char *name, + const char *buffer, const jsmntok_t *tok, + uint32_t **num); + /* Extract number from this (may be a string, or a number literal) */ struct command_result *param_u64(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok,