From 56d03625f669fda0744ab49fa5e404be67d9b7a0 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Wed, 11 Oct 2017 14:03:18 +0900 Subject: [PATCH] Keep P2PK scripts separate from P2PKH scripts This makes the DB incompatible with prior versions, so the DB version is bumped. --- lib/coins.py | 10 ++++++---- lib/script.py | 21 --------------------- server/db.py | 2 +- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/lib/coins.py b/lib/coins.py index c8b40e3..b8c8a93 100644 --- a/lib/coins.py +++ b/lib/coins.py @@ -38,7 +38,7 @@ from hashlib import sha256 import lib.util as util from lib.hash import Base58, hash160, double_sha256, hash_to_str -from lib.script import ScriptPubKey +from lib.script import ScriptPubKey, OpCodes from lib.tx import Deserializer, DeserializerSegWit, DeserializerAuxPow, \ DeserializerZcash, DeserializerTxTime, DeserializerReddcoin from server.block_processor import BlockProcessor @@ -47,6 +47,7 @@ from server.session import ElectrumX, DashElectrumX Block = namedtuple("Block", "raw header transactions") +OP_RETURN = OpCodes.OP_RETURN class CoinError(Exception): @@ -131,9 +132,10 @@ class Coin(object): @classmethod def hashX_from_script(cls, script): - '''Returns a hashX from a script.''' - script = ScriptPubKey.hashX_script(script) - if script is None: + '''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: return None return sha256(script).digest()[:cls.HASHX_LEN] diff --git a/lib/script.py b/lib/script.py index 2c35184..2741924 100644 --- a/lib/script.py +++ b/lib/script.py @@ -102,27 +102,6 @@ class ScriptPubKey(object): PayToHandlers = namedtuple('PayToHandlers', 'address script_hash pubkey ' 'unspendable strange') - @classmethod - def hashX_script(cls, script): - '''Return None if the script is provably unspendable. Return a - pay-to-pubkey-hash script if it is pay-to-pubkey, otherwise - return script. - ''' - if script: - op = script[0] - if op == OpCodes.OP_RETURN: - return None - if op <= OpCodes.OP_PUSHDATA4: - try: - ops = Script.get_ops(script) - except ScriptError: - pass - else: - if _match_ops(ops, cls.TO_PUBKEY_OPS): - pubkey = ops[0][1] - script = ScriptPubKey.P2PKH_script(hash160(pubkey)) - return script - @classmethod def pay_to(cls, handlers, script): '''Parse a script, invoke the appropriate handler and diff --git a/server/db.py b/server/db.py index 6e1b829..46aef3f 100644 --- a/server/db.py +++ b/server/db.py @@ -32,7 +32,7 @@ class DB(util.LoggedClass): it was shutdown uncleanly. ''' - DB_VERSIONS = [5] + DB_VERSIONS = [6] class MissingUTXOError(Exception): '''Raised if a mempool tx input UTXO couldn't be found.'''