From 8a4f44a58dd0f0514f9b05c8089cb5ac6f16f3a4 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 25 Oct 2022 14:47:56 +0200 Subject: [PATCH] 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 --- common/json_param.c | 6 +++++- tests/test_pay.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/json_param.c b/common/json_param.c index 0eecf4a49..7aa217464 100644 --- a/common/json_param.c +++ b/common/json_param.c @@ -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.", diff --git a/tests/test_pay.py b/tests/test_pay.py index 4cece70a0..db8cc5ac0 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -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')