Rename is_coinbase to is_generation and make it efficient (#569)
This commit is contained in:
parent
05c9e6b38f
commit
00815442a9
@ -42,8 +42,8 @@ class Tx(namedtuple("Tx", "version inputs outputs locktime")):
|
|||||||
'''Class representing a transaction.'''
|
'''Class representing a transaction.'''
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_generation(self):
|
||||||
return self.inputs[0].is_coinbase
|
return self.inputs[0].is_generation
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
return b''.join((
|
return b''.join((
|
||||||
@ -63,9 +63,9 @@ class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")):
|
|||||||
MINUS_1 = 4294967295
|
MINUS_1 = 4294967295
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_generation(self):
|
||||||
return (self.prev_hash == TxInput.ZERO and
|
return (self.prev_idx == TxInput.MINUS_1 and
|
||||||
self.prev_idx == TxInput.MINUS_1)
|
self.prev_hash == TxInput.ZERO)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
script = self.script.hex()
|
script = self.script.hex()
|
||||||
@ -215,8 +215,8 @@ class TxSegWit(namedtuple("Tx", "version marker flag inputs outputs "
|
|||||||
'''Class representing a SegWit transaction.'''
|
'''Class representing a SegWit transaction.'''
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_generation(self):
|
||||||
return self.inputs[0].is_coinbase
|
return self.inputs[0].is_generation
|
||||||
|
|
||||||
|
|
||||||
class DeserializerSegWit(Deserializer):
|
class DeserializerSegWit(Deserializer):
|
||||||
@ -327,8 +327,8 @@ class TxJoinSplit(namedtuple("Tx", "version inputs outputs locktime")):
|
|||||||
'''Class representing a JoinSplit transaction.'''
|
'''Class representing a JoinSplit transaction.'''
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_generation(self):
|
||||||
return self.inputs[0].is_coinbase if len(self.inputs) > 0 else False
|
return self.inputs[0].is_generation if len(self.inputs) > 0 else False
|
||||||
|
|
||||||
|
|
||||||
class DeserializerZcash(DeserializerEquihash):
|
class DeserializerZcash(DeserializerEquihash):
|
||||||
@ -361,8 +361,8 @@ class TxTime(namedtuple("Tx", "version time inputs outputs locktime")):
|
|||||||
'''Class representing transaction that has a time field.'''
|
'''Class representing transaction that has a time field.'''
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_generation(self):
|
||||||
return self.inputs[0].is_coinbase
|
return self.inputs[0].is_generation
|
||||||
|
|
||||||
|
|
||||||
class DeserializerTxTime(Deserializer):
|
class DeserializerTxTime(Deserializer):
|
||||||
@ -445,13 +445,10 @@ class DeserializerGroestlcoin(DeserializerSegWit):
|
|||||||
class TxInputDcr(namedtuple("TxInput", "prev_hash prev_idx tree sequence")):
|
class TxInputDcr(namedtuple("TxInput", "prev_hash prev_idx tree sequence")):
|
||||||
'''Class representing a Decred transaction input.'''
|
'''Class representing a Decred transaction input.'''
|
||||||
|
|
||||||
ZERO = bytes(32)
|
|
||||||
MINUS_1 = 4294967295
|
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_generation(self):
|
||||||
return (self.prev_hash == TxInputDcr.ZERO and
|
return (self.prev_idx == TxInput.MINUS_1 and
|
||||||
self.prev_idx == TxInputDcr.MINUS_1)
|
self.prev_hash == TxInput.ZERO)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
prev_hash = hash_to_hex_str(self.prev_hash)
|
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.'''
|
'''Class representing a Decred transaction.'''
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_generation(self):
|
||||||
return self.inputs[0].is_coinbase
|
return self.inputs[0].is_generation
|
||||||
|
|
||||||
|
|
||||||
class DeserializerDecred(Deserializer):
|
class DeserializerDecred(Deserializer):
|
||||||
@ -546,7 +543,7 @@ class DeserializerDecred(Deserializer):
|
|||||||
|
|
||||||
# Drop the coinbase-like input from a vote tx as it creates problems
|
# Drop the coinbase-like input from a vote tx as it creates problems
|
||||||
# with UTXOs lookups and mempool management
|
# 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:]
|
inputs = inputs[1:]
|
||||||
|
|
||||||
if produce_hash:
|
if produce_hash:
|
||||||
|
|||||||
@ -411,7 +411,7 @@ class BlockProcessor(object):
|
|||||||
tx_numb = s_pack('<I', tx_num)
|
tx_numb = s_pack('<I', tx_num)
|
||||||
|
|
||||||
# Spend the inputs
|
# Spend the inputs
|
||||||
if not tx.is_coinbase:
|
if not tx.is_generation:
|
||||||
for txin in tx.inputs:
|
for txin in tx.inputs:
|
||||||
cache_value = spend_utxo(txin.prev_hash, txin.prev_idx)
|
cache_value = spend_utxo(txin.prev_hash, txin.prev_idx)
|
||||||
undo_info_append(cache_value)
|
undo_info_append(cache_value)
|
||||||
@ -490,7 +490,7 @@ class BlockProcessor(object):
|
|||||||
touched.add(cache_value[:-12])
|
touched.add(cache_value[:-12])
|
||||||
|
|
||||||
# Restore the inputs
|
# Restore the inputs
|
||||||
if not tx.is_coinbase:
|
if not tx.is_generation:
|
||||||
for txin in reversed(tx.inputs):
|
for txin in reversed(tx.inputs):
|
||||||
n -= undo_entry_len
|
n -= undo_entry_len
|
||||||
undo_item = undo_info[n:n + undo_entry_len]
|
undo_item = undo_info[n:n + undo_entry_len]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user