Browse Source

json: Make payment_hash use `json_add_sha256`

pull/2938/head
trueptolemy 6 years ago
committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent
commit
4929034a40
  1. 13
      lightningd/invoice.c
  2. 2
      lightningd/jsonrpc.c
  3. 2
      lightningd/pay.c
  4. 6
      lightningd/peer_control.c
  5. 6
      lightningd/peer_htlcs.c
  6. 4
      lightningd/test/run-invoice-select-inchan.c
  7. 4
      wallet/test/run-wallet.c

13
lightningd/invoice.c

@ -49,7 +49,7 @@ static void json_add_invoice(struct json_stream *response,
{ {
json_add_escaped_string(response, "label", inv->label); json_add_escaped_string(response, "label", inv->label);
json_add_string(response, "bolt11", inv->bolt11); json_add_string(response, "bolt11", inv->bolt11);
json_add_hex(response, "payment_hash", &inv->rhash, sizeof(inv->rhash)); json_add_sha256(response, "payment_hash", &inv->rhash);
if (inv->msat) if (inv->msat)
json_add_amount_msat_compat(response, *inv->msat, json_add_amount_msat_compat(response, *inv->msat,
"msatoshi", "amount_msat"); "msatoshi", "amount_msat");
@ -514,8 +514,7 @@ static void gossipd_incoming_channels_reply(struct subd *gossipd,
details = wallet_invoice_details(info, wallet, invoice); details = wallet_invoice_details(info, wallet, invoice);
response = json_stream_success(info->cmd); response = json_stream_success(info->cmd);
json_add_hex(response, "payment_hash", &details->rhash, json_add_sha256(response, "payment_hash", &details->rhash);
sizeof(details->rhash));
json_add_u64(response, "expires_at", details->expiry_time); json_add_u64(response, "expires_at", details->expiry_time);
json_add_string(response, "bolt11", details->bolt11); json_add_string(response, "bolt11", details->bolt11);
@ -1083,9 +1082,8 @@ static struct command_result *json_decodepay(struct command *cmd,
json_add_escaped_string(response, "description", take(esc)); json_add_escaped_string(response, "description", take(esc));
} }
if (b11->description_hash) if (b11->description_hash)
json_add_hex(response, "description_hash", json_add_sha256(response, "description_hash",
b11->description_hash, b11->description_hash);
sizeof(*b11->description_hash));
json_add_num(response, "min_final_cltv_expiry", json_add_num(response, "min_final_cltv_expiry",
b11->min_final_cltv_expiry); b11->min_final_cltv_expiry);
if (tal_count(b11->fallbacks)) { if (tal_count(b11->fallbacks)) {
@ -1145,8 +1143,7 @@ static struct command_result *json_decodepay(struct command *cmd,
json_array_end(response); json_array_end(response);
} }
json_add_hex(response, "payment_hash", json_add_sha256(response, "payment_hash", &b11->payment_hash);
&b11->payment_hash, sizeof(b11->payment_hash));
json_add_string(response, "signature", json_add_string(response, "signature",
type_to_string(cmd, secp256k1_ecdsa_signature, type_to_string(cmd, secp256k1_ecdsa_signature,

2
lightningd/jsonrpc.c

@ -287,7 +287,7 @@ static struct command_result *json_dev(struct command *cmd UNUSED,
/* Hash in place. */ /* Hash in place. */
sha256(secret, secret, sizeof(*secret)); sha256(secret, secret, sizeof(*secret));
response = json_stream_success(cmd); response = json_stream_success(cmd);
json_add_hex(response, "rhash", secret, sizeof(*secret)); json_add_sha256(response, "rhash", secret);
return command_success(cmd, response); return command_success(cmd, response);
} }
} }

2
lightningd/pay.c

@ -76,7 +76,7 @@ json_add_payment_fields(struct json_stream *response,
const struct wallet_payment *t) const struct wallet_payment *t)
{ {
json_add_u64(response, "id", t->id); json_add_u64(response, "id", t->id);
json_add_hex(response, "payment_hash", &t->payment_hash, sizeof(t->payment_hash)); json_add_sha256(response, "payment_hash", &t->payment_hash);
json_add_node_id(response, "destination", &t->destination); json_add_node_id(response, "destination", &t->destination);
json_add_amount_msat_compat(response, t->msatoshi, json_add_amount_msat_compat(response, t->msatoshi,
"msatoshi", "amount_msat"); "msatoshi", "amount_msat");

6
lightningd/peer_control.c

@ -479,8 +479,7 @@ static void json_add_htlcs(struct lightningd *ld,
json_add_amount_msat_compat(response, hin->msat, json_add_amount_msat_compat(response, hin->msat,
"msatoshi", "amount_msat"); "msatoshi", "amount_msat");
json_add_u64(response, "expiry", hin->cltv_expiry); json_add_u64(response, "expiry", hin->cltv_expiry);
json_add_hex(response, "payment_hash", json_add_sha256(response, "payment_hash", &hin->payment_hash);
&hin->payment_hash, sizeof(hin->payment_hash));
json_add_string(response, "state", json_add_string(response, "state",
htlc_state_name(hin->hstate)); htlc_state_name(hin->hstate));
if (htlc_is_trimmed(REMOTE, hin->msat, local_feerate, if (htlc_is_trimmed(REMOTE, hin->msat, local_feerate,
@ -501,8 +500,7 @@ static void json_add_htlcs(struct lightningd *ld,
json_add_amount_msat_compat(response, hout->msat, json_add_amount_msat_compat(response, hout->msat,
"msatoshi", "amount_msat"); "msatoshi", "amount_msat");
json_add_u64(response, "expiry", hout->cltv_expiry); json_add_u64(response, "expiry", hout->cltv_expiry);
json_add_hex(response, "payment_hash", json_add_sha256(response, "payment_hash", &hout->payment_hash);
&hout->payment_hash, sizeof(hout->payment_hash));
json_add_string(response, "state", json_add_string(response, "state",
htlc_state_name(hout->hstate)); htlc_state_name(hout->hstate));
if (htlc_is_trimmed(LOCAL, hout->msat, local_feerate, if (htlc_is_trimmed(LOCAL, hout->msat, local_feerate,

6
lightningd/peer_htlcs.c

@ -734,7 +734,7 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p,
json_add_amount_msat_only(s, "amount", hin->msat); json_add_amount_msat_only(s, "amount", hin->msat);
json_add_u32(s, "cltv_expiry", expiry); json_add_u32(s, "cltv_expiry", expiry);
json_add_s32(s, "cltv_expiry_relative", expiry - blockheight); json_add_s32(s, "cltv_expiry_relative", expiry - blockheight);
json_add_hex(s, "payment_hash", hin->payment_hash.u.u8, sizeof(hin->payment_hash)); json_add_sha256(s, "payment_hash", &hin->payment_hash);
json_object_end(s); json_object_end(s);
} }
@ -2151,9 +2151,7 @@ void json_format_forwarding_object(struct json_stream *response,
/* See 6d333f16cc0f3aac7097269bf0985b5fa06d59b4: we may have deleted HTLC. */ /* See 6d333f16cc0f3aac7097269bf0985b5fa06d59b4: we may have deleted HTLC. */
if (cur->payment_hash) if (cur->payment_hash)
json_add_hex(response, "payment_hash", json_add_sha256(response, "payment_hash", cur->payment_hash);
cur->payment_hash,
sizeof(*cur->payment_hash));
json_add_short_channel_id(response, "in_channel", &cur->channel_in); json_add_short_channel_id(response, "in_channel", &cur->channel_in);
/* This can be unknown if we failed before channel lookup */ /* This can be unknown if we failed before channel lookup */

4
lightningd/test/run-invoice-select-inchan.c

@ -166,6 +166,10 @@ void json_add_escaped_string(struct json_stream *result UNNEEDED,
void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const void *data UNNEEDED, size_t len UNNEEDED) const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_add_hex called!\n"); abort(); } { fprintf(stderr, "json_add_hex called!\n"); abort(); }
/* Generated stub for json_add_sha256 */
void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct sha256 *hash UNNEEDED)
{ fprintf(stderr, "json_add_sha256 called!\n"); abort(); }
/* Generated stub for json_add_hex_talarr */ /* Generated stub for json_add_hex_talarr */
void json_add_hex_talarr(struct json_stream *result UNNEEDED, void json_add_hex_talarr(struct json_stream *result UNNEEDED,
const char *fieldname UNNEEDED, const char *fieldname UNNEEDED,

4
wallet/test/run-wallet.c

@ -243,6 +243,10 @@ void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UN
void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, void json_add_hex(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const void *data UNNEEDED, size_t len UNNEEDED) const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_add_hex called!\n"); abort(); } { fprintf(stderr, "json_add_hex called!\n"); abort(); }
/* Generated stub for json_add_sha256 */
void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct sha256 *hash UNNEEDED)
{ fprintf(stderr, "json_add_sha256 called!\n"); abort(); }
/* Generated stub for json_add_hex_talarr */ /* Generated stub for json_add_hex_talarr */
void json_add_hex_talarr(struct json_stream *result UNNEEDED, void json_add_hex_talarr(struct json_stream *result UNNEEDED,
const char *fieldname UNNEEDED, const char *fieldname UNNEEDED,

Loading…
Cancel
Save