mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
param: upgraded json_tok_sha256
Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
committed by
Rusty Russell
parent
2a0c2601c0
commit
6254d15efd
@@ -126,14 +126,6 @@ bool json_tok_is_null(const char *buffer, const jsmntok_t *tok)
|
|||||||
return buffer[tok->start] == 'n';
|
return buffer[tok->start] == 'n';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool json_tok_sha256(const char *buffer, const jsmntok_t * tok,
|
|
||||||
struct sha256 *hash)
|
|
||||||
{
|
|
||||||
return hex_decode(buffer + tok->start,
|
|
||||||
tok->end - tok->start,
|
|
||||||
hash, sizeof(*hash));
|
|
||||||
}
|
|
||||||
|
|
||||||
const jsmntok_t *json_next(const jsmntok_t *tok)
|
const jsmntok_t *json_next(const jsmntok_t *tok)
|
||||||
{
|
{
|
||||||
const jsmntok_t *t;
|
const jsmntok_t *t;
|
||||||
|
|||||||
@@ -39,10 +39,6 @@ bool json_to_double(const char *buffer, const jsmntok_t *tok, double *num);
|
|||||||
bool json_tok_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
|
bool json_tok_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
|
||||||
uint64_t *satoshi);
|
uint64_t *satoshi);
|
||||||
|
|
||||||
/* Extract sha256 hash */
|
|
||||||
bool json_tok_sha256(const char *buffer, const jsmntok_t * tok,
|
|
||||||
struct sha256 *hash);
|
|
||||||
|
|
||||||
/* Is this the null primitive? */
|
/* Is this the null primitive? */
|
||||||
bool json_tok_is_null(const char *buffer, const jsmntok_t *tok);
|
bool json_tok_is_null(const char *buffer, const jsmntok_t *tok);
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,22 @@ bool json_tok_number(struct command *cmd, const char *name,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool json_tok_sha256(struct command *cmd, const char *name,
|
||||||
|
const char *buffer, const jsmntok_t *tok,
|
||||||
|
struct sha256 **hash)
|
||||||
|
{
|
||||||
|
*hash = tal(cmd, struct sha256);
|
||||||
|
if (hex_decode(buffer + tok->start,
|
||||||
|
tok->end - tok->start,
|
||||||
|
*hash, sizeof(**hash)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
"'%s' should be a 32 byte hex value, not '%.*s'",
|
||||||
|
name, tok->end - tok->start, buffer + tok->start);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool json_tok_u64(struct command *cmd, const char *name,
|
bool json_tok_u64(struct command *cmd, const char *name,
|
||||||
const char *buffer, const jsmntok_t *tok,
|
const char *buffer, const jsmntok_t *tok,
|
||||||
uint64_t **num)
|
uint64_t **num)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ struct command;
|
|||||||
struct json_result;
|
struct json_result;
|
||||||
struct pubkey;
|
struct pubkey;
|
||||||
struct route_hop;
|
struct route_hop;
|
||||||
|
struct sha256;
|
||||||
struct short_channel_id;
|
struct short_channel_id;
|
||||||
struct wallet_payment;
|
struct wallet_payment;
|
||||||
struct wireaddr;
|
struct wireaddr;
|
||||||
@@ -56,6 +57,11 @@ bool json_tok_number(struct command *cmd, const char *name,
|
|||||||
const char *buffer, const jsmntok_t *tok,
|
const char *buffer, const jsmntok_t *tok,
|
||||||
unsigned int **num);
|
unsigned int **num);
|
||||||
|
|
||||||
|
/* Extract sha256 hash */
|
||||||
|
bool json_tok_sha256(struct command *cmd, const char *name,
|
||||||
|
const char *buffer, const jsmntok_t *tok,
|
||||||
|
struct sha256 **hash);
|
||||||
|
|
||||||
/* Extract a pubkey from this */
|
/* Extract a pubkey from this */
|
||||||
bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok,
|
bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok,
|
||||||
struct pubkey *pubkey);
|
struct pubkey *pubkey);
|
||||||
|
|||||||
@@ -96,17 +96,17 @@ static void json_rhash(struct command *cmd,
|
|||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
struct json_result *response = new_json_result(cmd);
|
struct json_result *response = new_json_result(cmd);
|
||||||
struct sha256 secret;
|
struct sha256 *secret;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("secret", json_tok_sha256, &secret),
|
p_req_tal("secret", json_tok_sha256, &secret),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Hash in place. */
|
/* Hash in place. */
|
||||||
sha256(&secret, &secret, sizeof(secret));
|
sha256(secret, secret, sizeof(*secret));
|
||||||
json_object_start(response, NULL);
|
json_object_start(response, NULL);
|
||||||
json_add_hex(response, "rhash", &secret, sizeof(secret));
|
json_add_hex(response, "rhash", secret, sizeof(*secret));
|
||||||
json_object_end(response);
|
json_object_end(response);
|
||||||
command_success(cmd, response);
|
command_success(cmd, response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ static struct fail_format fail_formats[] = {
|
|||||||
{json_tok_wtx,
|
{json_tok_wtx,
|
||||||
"'%s' should be 'all' or a positive integer greater than "
|
"'%s' should be 'all' or a positive integer greater than "
|
||||||
"545, not '%.*s'"},
|
"545, not '%.*s'"},
|
||||||
{json_tok_sha256, "'%s' should be a 32 byte hex value, not '%.*s'"},
|
|
||||||
{NULL, "'%s' of '%.*s' is invalid'"}
|
{NULL, "'%s' of '%.*s' is invalid'"}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -948,7 +948,7 @@ static void json_sendpay(struct command *cmd,
|
|||||||
const jsmntok_t *routetok, *desctok;
|
const jsmntok_t *routetok, *desctok;
|
||||||
const jsmntok_t *t, *end;
|
const jsmntok_t *t, *end;
|
||||||
size_t n_hops;
|
size_t n_hops;
|
||||||
struct sha256 rhash;
|
struct sha256 *rhash;
|
||||||
struct route_hop *route;
|
struct route_hop *route;
|
||||||
u64 *msatoshi;
|
u64 *msatoshi;
|
||||||
const struct json_escaped *desc;
|
const struct json_escaped *desc;
|
||||||
@@ -956,7 +956,7 @@ static void json_sendpay(struct command *cmd,
|
|||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("route", json_tok_tok, &routetok),
|
p_req_tal("route", json_tok_tok, &routetok),
|
||||||
p_req("payment_hash", json_tok_sha256, &rhash),
|
p_req_tal("payment_hash", json_tok_sha256, &rhash),
|
||||||
p_opt_tal("description", json_tok_tok, &desctok),
|
p_opt_tal("description", json_tok_tok, &desctok),
|
||||||
p_opt_tal("msatoshi", json_tok_u64, &msatoshi),
|
p_opt_tal("msatoshi", json_tok_u64, &msatoshi),
|
||||||
NULL))
|
NULL))
|
||||||
@@ -1068,7 +1068,7 @@ static void json_sendpay(struct command *cmd,
|
|||||||
description = NULL;
|
description = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (send_payment(cmd, cmd->ld, &rhash, route,
|
if (send_payment(cmd, cmd->ld, rhash, route,
|
||||||
msatoshi ? *msatoshi : route[n_hops-1].amount,
|
msatoshi ? *msatoshi : route[n_hops-1].amount,
|
||||||
description,
|
description,
|
||||||
&json_sendpay_on_resolve, cmd))
|
&json_sendpay_on_resolve, cmd))
|
||||||
@@ -1090,16 +1090,16 @@ static void waitsendpay_timeout(struct command *cmd)
|
|||||||
static void json_waitsendpay(struct command *cmd, const char *buffer,
|
static void json_waitsendpay(struct command *cmd, const char *buffer,
|
||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
struct sha256 rhash;
|
struct sha256 *rhash;
|
||||||
unsigned int *timeout;
|
unsigned int *timeout;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("payment_hash", json_tok_sha256, &rhash),
|
p_req_tal("payment_hash", json_tok_sha256, &rhash),
|
||||||
p_opt_tal("timeout", json_tok_number, &timeout),
|
p_opt_tal("timeout", json_tok_number, &timeout),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!wait_payment(cmd, cmd->ld, &rhash, &json_waitsendpay_on_resolve, cmd))
|
if (!wait_payment(cmd, cmd->ld, rhash, &json_waitsendpay_on_resolve, cmd))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (timeout)
|
if (timeout)
|
||||||
|
|||||||
Reference in New Issue
Block a user