diff --git a/CHANGES.md b/CHANGES.md index 59e71a576..408cedfb6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## Unreleased + +### Fixed +- wally_scriptpubkey_get_type: mark all scripts starting with OP_RETURN as + WALLY_SCRIPT_TYPE_OP_RETURN. + ## Version 1.2.0 ### Added diff --git a/src/script.c b/src/script.c index 999b53b4f..7a3e1f246 100644 --- a/src/script.c +++ b/src/script.c @@ -299,12 +299,7 @@ size_t confidential_value_to_bytes(const unsigned char *bytes, size_t bytes_len, static bool scriptpubkey_is_op_return(const unsigned char *bytes, size_t bytes_len) { - size_t n_op, n_push; - - return bytes_len && bytes[0] == OP_RETURN && - get_push_size(bytes + 1, bytes_len - 1, true, &n_op) == WALLY_OK && - get_push_size(bytes + 1, bytes_len - 1, false, &n_push) == WALLY_OK && - bytes_len == 1 + n_op + n_push; + return bytes_len && bytes[0] == OP_RETURN; } static bool scriptpubkey_is_p2pkh(const unsigned char *bytes, size_t bytes_len) diff --git a/src/test/test_script.py b/src/test/test_script.py index 1b11d7695..3e75add2f 100755 --- a/src/test/test_script.py +++ b/src/test/test_script.py @@ -95,6 +95,16 @@ def test_scriptpubkey_op_return_from_bytes(self): ret = wally_scriptpubkey_get_type(out, ret[1]) self.assertEqual(ret, (WALLY_OK, SCRIPT_TYPE_OP_RETURN)) + # Some scripts are considered op_return but they cannot be created with + # wally_scriptpubkey_op_return_from_bytes and they might not be standard + for script_hex in [ + '6a', + '6a6a', + ]: + script, script_len = make_cbuffer(script_hex) + ret, typ = wally_scriptpubkey_get_type(script, script_len) + self.assertEqual((ret, typ), (WALLY_OK, SCRIPT_TYPE_OP_RETURN)) + def test_scriptpubkey_p2pkh_from_bytes(self): """Tests for creating p2pkh scriptPubKeys""" # Invalid args