mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
json: move bitcoin/lightning specific helpers into common/json_helpers.
We don't need them in common/json, since lightning-cli doesn't need these, but plugins want them. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
ea7e13b5a7
commit
e65b680807
@@ -1,6 +1,7 @@
|
||||
/* JSON core and helpers */
|
||||
#include "json.h"
|
||||
#include <assert.h>
|
||||
#include <bitcoin/pubkey.h>
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
@@ -127,34 +128,6 @@ bool json_to_bool(const char *buffer, const jsmntok_t *tok, bool *b)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
|
||||
uint64_t *satoshi)
|
||||
{
|
||||
char *end;
|
||||
unsigned long btc, sat;
|
||||
|
||||
btc = strtoul(buffer + tok->start, &end, 10);
|
||||
if (btc == ULONG_MAX && errno == ERANGE)
|
||||
return false;
|
||||
if (end != buffer + tok->end) {
|
||||
/* Expect always 8 decimal places. */
|
||||
if (*end != '.' || buffer + tok->end - end != 9)
|
||||
return false;
|
||||
sat = strtoul(end+1, &end, 10);
|
||||
if (sat == ULONG_MAX && errno == ERANGE)
|
||||
return false;
|
||||
if (end != buffer + tok->end)
|
||||
return false;
|
||||
} else
|
||||
sat = 0;
|
||||
|
||||
*satoshi = btc * (uint64_t)100000000 + sat;
|
||||
if (*satoshi != btc * (uint64_t)100000000 + sat)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool json_tok_is_num(const char *buffer, const jsmntok_t *tok)
|
||||
{
|
||||
if (tok->type != JSMN_PRIMITIVE)
|
||||
|
||||
Reference in New Issue
Block a user