From 8e74a507d7e5ae877616a00d584621d680818c6d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 9 Jun 2021 12:40:00 +0930 Subject: [PATCH] common/json_tok: allow non-v0 segwit addresses. Only v0 has specific length restrictions: taproot is v1 32 bytes long, but explicitly other lengths remain undefined. I noticed that I added option_shutdown_anysegwit as EXPERIMENTAL in the last release, but didn't CHANGELOG it. Then I changed it to non-experimental as a spec update, but didn't CHANGELOG it then either, so let's do that now! Changelog-Added: Protocol: We now send and accept `option_shutdown_anysegwit` so you can close channels to v1+ segwit addresses. Signed-off-by: Rusty Russell Changelog-Added: JSON-RPC: `withdraw`, `close` (and others) now accept taproot (and other future) segwit addresses. --- common/json_tok.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/json_tok.c b/common/json_tok.c index e30dfc35b..d6e292cc3 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -433,14 +433,15 @@ json_to_address_scriptpubkey(const tal_t *ctx, bip173 = segwit_addr_net_decode(&witness_version, witness_program, &witness_program_len, addrz, chainparams); - if (bip173) { - bool witness_ok = false; - if (witness_version == 0 && (witness_program_len == 20 || - witness_program_len == 32)) { + bool witness_ok; + + /* We know the rules for v0, rest remain undefined */ + if (witness_version == 0) { + witness_ok = (witness_program_len == 20 || + witness_program_len == 32); + } else witness_ok = true; - } - /* Insert other witness versions here. */ if (witness_ok) { *scriptpubkey = scriptpubkey_witness_raw(ctx, witness_version,