Browse Source

Recognise OP_FALSE, OP_RETURN scripts as unspendable

patch-2
Neil Booth 6 years ago
parent
commit
1247744382
  1. 5
      electrumx/lib/coins.py
  2. 29
      tests/lib/test_coins.py

5
electrumx/lib/coins.py

@ -52,7 +52,6 @@ from electrumx.server.session import (ElectrumX, DashElectrumX,
Block = namedtuple("Block", "raw header transactions")
OP_RETURN = OpCodes.OP_RETURN
class CoinError(Exception):
@ -144,7 +143,9 @@ class Coin(object):
'''Returns a hashX from a script, or None if the script is provably
unspendable so the output can be dropped.
'''
if script and script[0] == OP_RETURN:
prefix = script[:2]
# Match a prefix of OP_RETURN or (OP_FALSE, OP_RETURN)
if prefix == b'\x00\x6a' or (prefix and prefix[0] == 0x6a):
return None
return sha256(script).digest()[:HASHX_LEN]

29
tests/lib/test_coins.py

@ -0,0 +1,29 @@
# Tests of lib/coins.py
import pytest
from electrumx.lib.coins import BitcoinSV
from electrumx.lib.script import OpCodes
coin = BitcoinSV
@pytest.mark.parametrize("script", (
bytes([OpCodes.OP_RETURN]),
bytes([OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
bytes([OpCodes.OP_0, OpCodes.OP_RETURN]),
bytes([OpCodes.OP_0, OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
))
def test_op_return(script):
assert coin.hashX_from_script(script) is None
@pytest.mark.parametrize("script", (
bytes([]),
bytes([OpCodes.OP_1, OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
bytes([OpCodes.OP_0]),
bytes([OpCodes.OP_0, OpCodes.OP_1]),
bytes([OpCodes.OP_HASH160]),
))
def test_not_op_return(script):
assert coin.hashX_from_script(script) is not None
Loading…
Cancel
Save