common/json: add a helper for json to u16

As Rusty pointed out to me, the gossip protocol restricts cltvs to u16
so at least we'll use this helper for them.
This commit is contained in:
darosior
2019-11-06 14:46:55 +01:00
committed by Rusty Russell
parent 5766231d98
commit 16f5af00c7
3 changed files with 24 additions and 7 deletions

View File

@@ -90,6 +90,21 @@ bool json_to_number(const char *buffer, const jsmntok_t *tok,
return true;
}
bool json_to_u16(const char *buffer, const jsmntok_t *tok,
short unsigned int *num)
{
uint64_t u64;
if (!json_to_u64(buffer, tok, &u64))
return false;
*num = u64;
/* Just in case it doesn't fit. */
if (*num != u64)
return false;
return true;
}
bool json_to_int(const char *buffer, const jsmntok_t *tok, int *num)
{
char *end;