From 00815442a9dc3fd15b136a4f5c44d94088c222b4 Mon Sep 17 00:00:00 2001 From: "John L. Jegutanis" Date: Sun, 12 Aug 2018 13:43:08 +0200 Subject: [PATCH] Rename is_coinbase to is_generation and make it efficient (#569) --- electrumx/lib/tx.py | 37 +++++++++++++---------------- electrumx/server/block_processor.py | 4 ++-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/electrumx/lib/tx.py b/electrumx/lib/tx.py index 6239805..35fa419 100644 --- a/electrumx/lib/tx.py +++ b/electrumx/lib/tx.py @@ -42,8 +42,8 @@ class Tx(namedtuple("Tx", "version inputs outputs locktime")): '''Class representing a transaction.''' @cachedproperty - def is_coinbase(self): - return self.inputs[0].is_coinbase + def is_generation(self): + return self.inputs[0].is_generation def serialize(self): return b''.join(( @@ -63,9 +63,9 @@ class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")): MINUS_1 = 4294967295 @cachedproperty - def is_coinbase(self): - return (self.prev_hash == TxInput.ZERO and - self.prev_idx == TxInput.MINUS_1) + def is_generation(self): + return (self.prev_idx == TxInput.MINUS_1 and + self.prev_hash == TxInput.ZERO) def __str__(self): script = self.script.hex() @@ -215,8 +215,8 @@ class TxSegWit(namedtuple("Tx", "version marker flag inputs outputs " '''Class representing a SegWit transaction.''' @cachedproperty - def is_coinbase(self): - return self.inputs[0].is_coinbase + def is_generation(self): + return self.inputs[0].is_generation class DeserializerSegWit(Deserializer): @@ -327,8 +327,8 @@ class TxJoinSplit(namedtuple("Tx", "version inputs outputs locktime")): '''Class representing a JoinSplit transaction.''' @cachedproperty - def is_coinbase(self): - return self.inputs[0].is_coinbase if len(self.inputs) > 0 else False + def is_generation(self): + return self.inputs[0].is_generation if len(self.inputs) > 0 else False class DeserializerZcash(DeserializerEquihash): @@ -361,8 +361,8 @@ class TxTime(namedtuple("Tx", "version time inputs outputs locktime")): '''Class representing transaction that has a time field.''' @cachedproperty - def is_coinbase(self): - return self.inputs[0].is_coinbase + def is_generation(self): + return self.inputs[0].is_generation class DeserializerTxTime(Deserializer): @@ -445,13 +445,10 @@ class DeserializerGroestlcoin(DeserializerSegWit): class TxInputDcr(namedtuple("TxInput", "prev_hash prev_idx tree sequence")): '''Class representing a Decred transaction input.''' - ZERO = bytes(32) - MINUS_1 = 4294967295 - @cachedproperty - def is_coinbase(self): - return (self.prev_hash == TxInputDcr.ZERO and - self.prev_idx == TxInputDcr.MINUS_1) + def is_generation(self): + return (self.prev_idx == TxInput.MINUS_1 and + self.prev_hash == TxInput.ZERO) def __str__(self): prev_hash = hash_to_hex_str(self.prev_hash) @@ -469,8 +466,8 @@ class TxDcr(namedtuple("Tx", "version inputs outputs locktime expiry " '''Class representing a Decred transaction.''' @cachedproperty - def is_coinbase(self): - return self.inputs[0].is_coinbase + def is_generation(self): + return self.inputs[0].is_generation class DeserializerDecred(Deserializer): @@ -546,7 +543,7 @@ class DeserializerDecred(Deserializer): # Drop the coinbase-like input from a vote tx as it creates problems # with UTXOs lookups and mempool management - if inputs[0].is_coinbase and len(inputs) > 1: + if inputs[0].is_generation and len(inputs) > 1: inputs = inputs[1:] if produce_hash: diff --git a/electrumx/server/block_processor.py b/electrumx/server/block_processor.py index c9bde57..bea879e 100644 --- a/electrumx/server/block_processor.py +++ b/electrumx/server/block_processor.py @@ -411,7 +411,7 @@ class BlockProcessor(object): tx_numb = s_pack('