keysend: Allow quoted numbers in extratlvs

This is because JSON technically does not allow numeric keys in maps.

Changelog-Added: JSON-RPC: The `extratlvs` argument for `keysend` now allows quoting the type numbers in string
This commit is contained in:
Christian Decker 2022-10-25 14:47:56 +02:00
parent 83beaa5396
commit 8a4f44a58d
2 changed files with 7 additions and 2 deletions

View File

@ -883,7 +883,11 @@ struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
temp = tal_arr(cmd, struct tlv_field, tok->size);
json_for_each_obj(i, curr, tok) {
f = &temp[i];
if (!json_to_u64(buffer, curr, &f->numtype)) {
/* Accept either bare ints as keys (not spec
* compliant, but simpler), or ints in strings, which
* are JSON spec compliant. */
if (!(json_str_to_u64(buffer, curr, &f->numtype) ||
json_to_u64(buffer, curr, &f->numtype))) {
return command_fail(
cmd, JSONRPC2_INVALID_PARAMS,
"\"%s\" is not a valid numeric TLV type.",

View File

@ -3627,7 +3627,8 @@ def test_keysend_strip_tlvs(node_factory):
ksinfo = """💕 ₿"'
More info
"""
l1.rpc.keysend(l2.info['id'], amt, extratlvs={133773310: bytes(ksinfo, encoding='utf8').hex()})
# Since we're at it, use this to test string-keyed TLVs
l1.rpc.keysend(l2.info['id'], amt, extratlvs={"133773310": bytes(ksinfo, encoding='utf8').hex()})
inv = only_one(l2.rpc.listinvoices()['invoices'])
assert inv['description'] == 'keysend: ' + ksinfo
l2.daemon.wait_for_log('Keysend payment uses illegal even field 133773310: stripping')