mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 08:34:31 +01:00
json: Add helper to decode sha256 hashes
This commit is contained in:
@@ -225,6 +225,15 @@ bool json_to_bool(const char *buffer, const jsmntok_t *tok, bool *b)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool json_to_sha256(const char *buffer, const jsmntok_t *tok, struct sha256 *dest)
|
||||
{
|
||||
if (tok->type != JSMN_STRING)
|
||||
return false;
|
||||
|
||||
return hex_decode(buffer + tok->start, tok->end - tok->start, dest,
|
||||
sizeof(struct sha256));
|
||||
}
|
||||
|
||||
u8 *json_tok_bin_from_hex(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
|
||||
{
|
||||
u8 *result;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef LIGHTNING_COMMON_JSON_H
|
||||
#define LIGHTNING_COMMON_JSON_H
|
||||
#include "config.h"
|
||||
#include <ccan/crypto/sha256/sha256.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <common/errcode.h>
|
||||
@@ -50,6 +51,7 @@ bool json_to_u32(const char *buffer, const jsmntok_t *tok,
|
||||
bool json_to_u16(const char *buffer, const jsmntok_t *tok,
|
||||
uint16_t *num);
|
||||
|
||||
bool json_to_sha256(const char *buffer, const jsmntok_t *tok, struct sha256 *dest);
|
||||
/*
|
||||
* Extract a non-negative (either 0 or positive) floating-point number from this
|
||||
* (must be a number literal), multiply it by 1 million and return it as an
|
||||
|
||||
Reference in New Issue
Block a user