Browse Source

param: upgraded json_tok_sha256

Signed-off-by: Mark Beckwith <wythe@intrig.com>
ppa-0.6.1
Mark Beckwith 7 years ago
committed by Rusty Russell
parent
commit
6254d15efd
  1. 8
      common/json.c
  2. 4
      common/json.h
  3. 16
      lightningd/json.c
  4. 6
      lightningd/json.h
  5. 8
      lightningd/jsonrpc.c
  6. 1
      lightningd/param.c
  7. 12
      lightningd/pay.c

8
common/json.c

@ -126,14 +126,6 @@ bool json_tok_is_null(const char *buffer, const jsmntok_t *tok)
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 *t;

4
common/json.h

@ -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,
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? */
bool json_tok_is_null(const char *buffer, const jsmntok_t *tok);

16
lightningd/json.c

@ -142,6 +142,22 @@ bool json_tok_number(struct command *cmd, const char *name,
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,
const char *buffer, const jsmntok_t *tok,
uint64_t **num)

6
lightningd/json.h

@ -18,6 +18,7 @@ struct command;
struct json_result;
struct pubkey;
struct route_hop;
struct sha256;
struct short_channel_id;
struct wallet_payment;
struct wireaddr;
@ -56,6 +57,11 @@ bool json_tok_number(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
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 */
bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok,
struct pubkey *pubkey);

8
lightningd/jsonrpc.c

@ -96,17 +96,17 @@ static void json_rhash(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
struct json_result *response = new_json_result(cmd);
struct sha256 secret;
struct sha256 *secret;
if (!param(cmd, buffer, params,
p_req("secret", json_tok_sha256, &secret),
p_req_tal("secret", json_tok_sha256, &secret),
NULL))
return;
/* Hash in place. */
sha256(&secret, &secret, sizeof(secret));
sha256(secret, secret, sizeof(*secret));
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);
command_success(cmd, response);
}

1
lightningd/param.c

@ -53,7 +53,6 @@ static struct fail_format fail_formats[] = {
{json_tok_wtx,
"'%s' should be 'all' or a positive integer greater than "
"545, not '%.*s'"},
{json_tok_sha256, "'%s' should be a 32 byte hex value, not '%.*s'"},
{NULL, "'%s' of '%.*s' is invalid'"}
};

12
lightningd/pay.c

@ -948,7 +948,7 @@ static void json_sendpay(struct command *cmd,
const jsmntok_t *routetok, *desctok;
const jsmntok_t *t, *end;
size_t n_hops;
struct sha256 rhash;
struct sha256 *rhash;
struct route_hop *route;
u64 *msatoshi;
const struct json_escaped *desc;
@ -956,7 +956,7 @@ static void json_sendpay(struct command *cmd,
if (!param(cmd, buffer, params,
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("msatoshi", json_tok_u64, &msatoshi),
NULL))
@ -1068,7 +1068,7 @@ static void json_sendpay(struct command *cmd,
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,
description,
&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,
const jsmntok_t *params)
{
struct sha256 rhash;
struct sha256 *rhash;
unsigned int *timeout;
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),
NULL))
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;
if (timeout)

Loading…
Cancel
Save