common: implement op_return test.

Since we included the spec for it, this is a good time to implement
it.

I also asked chatgpt to write some unit tests.  I had to mangle them a
bit, but it probably saved me a few minutes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-03-15 21:51:35 +10:30
parent 733efcf7dd
commit 71eb04064c
8 changed files with 232 additions and 8 deletions

View File

@@ -1227,7 +1227,7 @@ static void peer_got_shutdown(struct channel *channel, const u8 *msg)
* - if the `scriptpubkey` is not in one of the above forms:
* - SHOULD send a `warning`.
*/
if (!valid_shutdown_scriptpubkey(scriptpubkey, anysegwit, !anchors)) {
if (!valid_shutdown_scriptpubkey(scriptpubkey, anysegwit, !anchors, false)) {
u8 *warning = towire_warningfmt(NULL,
&channel->cid,
"Bad shutdown scriptpubkey %s",

View File

@@ -759,10 +759,10 @@ static struct command_result *json_close(struct command *cmd,
/* In theory, this could happen if the peer had anysegwit when channel was
* established, and doesn't now. Doesn't happen, and if it did we could
* provide a new address manually. */
if (!valid_shutdown_scriptpubkey(close_to_script, anysegwit, false)) {
if (!valid_shutdown_scriptpubkey(close_to_script, anysegwit, false, false)) {
/* Explicit check for future segwits. */
if (!anysegwit &&
valid_shutdown_scriptpubkey(close_to_script, true, false)) {
valid_shutdown_scriptpubkey(close_to_script, true, false, false)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Peer does not allow v1+ shutdown addresses");
}

View File

@@ -1588,7 +1588,7 @@ static void handle_peer_wants_to_close(struct subd *dualopend,
* - if the `scriptpubkey` is not in one of the above forms:
* - SHOULD send a `warning`
*/
if (!valid_shutdown_scriptpubkey(scriptpubkey, anysegwit, !anchors)) {
if (!valid_shutdown_scriptpubkey(scriptpubkey, anysegwit, !anchors, false)) {
u8 *warning = towire_warningfmt(NULL,
&channel->cid,
"Bad shutdown scriptpubkey %s",