From c36be4f5b9d51ef90753ba458033e830fc525bd6 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Sat, 1 Feb 2025 17:46:41 +1300 Subject: [PATCH] script: make scriptpubkey_is_p2tr available internally For use by a later commit. --- src/script.c | 5 +++-- src/script.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/script.c b/src/script.c index 7ad6c7b0a..c48d5395d 100644 --- a/src/script.c +++ b/src/script.c @@ -361,9 +361,10 @@ static bool scriptpubkey_is_p2wsh(const unsigned char *bytes, size_t bytes_len) bytes[1] == 32; /* SHA256 */ } -static bool scriptpubkey_is_p2tr(const unsigned char *bytes, size_t bytes_len) +bool scriptpubkey_is_p2tr(const unsigned char *bytes, size_t bytes_len) { - return bytes_len == WALLY_SCRIPTPUBKEY_P2TR_LEN && + /* Note this is called from elsewhere hence we check 'bytes' for NULL */ + return bytes && bytes_len == WALLY_SCRIPTPUBKEY_P2TR_LEN && bytes[0] == OP_1 && /* Segwit v1 */ bytes[1] == 32; /* X-ONLY-PUBKEY */ } diff --git a/src/script.h b/src/script.h index 05df1d6d8..cb39e7dc2 100644 --- a/src/script.h +++ b/src/script.h @@ -18,6 +18,8 @@ int script_get_push_opcode_size_from_bytes( /* Get OP_N */ bool script_is_op_n(unsigned char op, bool allow_zero, size_t *n); +bool scriptpubkey_is_p2tr(const unsigned char *bytes, size_t bytes_len); + /* Convert 0-16 to OP_ */ size_t value_to_op_n(uint64_t v);