Add comparison handling to Block, fix reward type

This commit is contained in:
Michał Sałaban 2020-01-24 12:38:33 +01:00
parent 1b503fd0ab
commit c6256fe4e1
5 changed files with 83 additions and 6 deletions

View file

@ -115,7 +115,7 @@ class JSONRPCDaemon(object):
'nonce': bhdr['nonce'],
'orphan': bhdr['orphan_status'],
'prev_hash': bhdr['prev_hash'],
'reward': bhdr['reward'],
'reward': from_atomic(bhdr['reward']),
'transactions': self.transactions(
[bhdr['miner_tx_hash']] + sub_json['tx_hashes']),
}

View file

@ -25,10 +25,17 @@ class Block(object):
def __init__(self, **kwargs):
for k in ('hash', 'height', 'timestamp', 'version', 'difficulty', 'nonce', 'prev_hash', 'reward'):
setattr(self, k, kwargs[k])
self.orphan = kwargs['orphan']
self.transactions = kwargs['transactions']
self.blob = kwargs.get('blob', None)
setattr(self, k, kwargs.get(k, getattr(self, k)))
self.orphan = kwargs.get('orphan', self.orphan)
self.transactions = kwargs.get('transactions', self.transactions or [])
self.blob = kwargs.get('blob', self.blob)
def __eq__(self, other):
if isinstance(other, Block):
return self.hash == other.hash
elif isinstance(other, six.string_types):
return six.ensure_text(self.hash) == six.ensure_text(other)
return super(Block, self).__eq__(other)
def __contains__(self, tx):
if isinstance(tx, six.string_types):