|
|
@ -79,38 +79,38 @@ class LevelDBReader(object): |
|
|
|
gets head block header |
|
|
|
gets head block header |
|
|
|
''' |
|
|
|
''' |
|
|
|
if not self.head_block_header: |
|
|
|
if not self.head_block_header: |
|
|
|
hash = self.db.get(head_header_key) |
|
|
|
block_hash = self.db.get(head_header_key) |
|
|
|
num = self._get_block_number(hash) |
|
|
|
num = self._get_block_number(block_hash) |
|
|
|
self.head_block_header = self._get_block_header(hash, num) |
|
|
|
self.head_block_header = self._get_block_header(block_hash, num) |
|
|
|
# find header with valid state |
|
|
|
# find header with valid state |
|
|
|
while not self.db.get(self.head_block_header.state_root) and self.head_block_header.prevhash is not None: |
|
|
|
while not self.db.get(self.head_block_header.state_root) and self.head_block_header.prevhash is not None: |
|
|
|
hash = self.head_block_header.prevhash |
|
|
|
block_hash = self.head_block_header.prevhash |
|
|
|
num = self._get_block_number(hash) |
|
|
|
num = self._get_block_number(block_hash) |
|
|
|
self.head_block_header = self._get_block_header(hash, num) |
|
|
|
self.head_block_header = self._get_block_header(block_hash, num) |
|
|
|
|
|
|
|
|
|
|
|
return self.head_block_header |
|
|
|
return self.head_block_header |
|
|
|
|
|
|
|
|
|
|
|
def _get_block_number(self, hash): |
|
|
|
def _get_block_number(self, block_hash): |
|
|
|
''' |
|
|
|
''' |
|
|
|
gets block number by hash |
|
|
|
gets block number by its hash |
|
|
|
''' |
|
|
|
''' |
|
|
|
number_key = block_hash_prefix + hash |
|
|
|
number_key = block_hash_prefix + block_hash |
|
|
|
return self.db.get(number_key) |
|
|
|
return self.db.get(number_key) |
|
|
|
|
|
|
|
|
|
|
|
def _get_block_header(self, hash, num): |
|
|
|
def _get_block_header(self, block_hash, num): |
|
|
|
''' |
|
|
|
''' |
|
|
|
get block header by block header hash & number |
|
|
|
get block header by block header hash & number |
|
|
|
''' |
|
|
|
''' |
|
|
|
header_key = header_prefix + num + hash |
|
|
|
header_key = header_prefix + num + block_hash |
|
|
|
block_header_data = self.db.get(header_key) |
|
|
|
block_header_data = self.db.get(header_key) |
|
|
|
header = rlp.decode(block_header_data, sedes=BlockHeader) |
|
|
|
header = rlp.decode(block_header_data, sedes=BlockHeader) |
|
|
|
return header |
|
|
|
return header |
|
|
|
|
|
|
|
|
|
|
|
def _get_address_by_hash(self, hash): |
|
|
|
def _get_address_by_hash(self, block_hash): |
|
|
|
''' |
|
|
|
''' |
|
|
|
get mapped address by its hash |
|
|
|
get mapped address by its hash |
|
|
|
''' |
|
|
|
''' |
|
|
|
address_key = address_prefix + hash |
|
|
|
address_key = address_prefix + block_hash |
|
|
|
return self.db.get(address_key) |
|
|
|
return self.db.get(address_key) |
|
|
|
|
|
|
|
|
|
|
|
def _get_last_indexed_number(self): |
|
|
|
def _get_last_indexed_number(self): |
|
|
@ -119,12 +119,12 @@ class LevelDBReader(object): |
|
|
|
''' |
|
|
|
''' |
|
|
|
return self.db.get(address_mapping_head_key) |
|
|
|
return self.db.get(address_mapping_head_key) |
|
|
|
|
|
|
|
|
|
|
|
def _get_block_receipts(self, hash, num): |
|
|
|
def _get_block_receipts(self, block_hash, num): |
|
|
|
''' |
|
|
|
''' |
|
|
|
get block transaction receipts by block header hash & number |
|
|
|
get block transaction receipts by block header hash & number |
|
|
|
''' |
|
|
|
''' |
|
|
|
number = _format_block_number(num) |
|
|
|
number = _format_block_number(num) |
|
|
|
receipts_key = block_receipts_prefix + number + hash |
|
|
|
receipts_key = block_receipts_prefix + number + block_hash |
|
|
|
receipts_data = self.db.get(receipts_key) |
|
|
|
receipts_data = self.db.get(receipts_key) |
|
|
|
receipts = rlp.decode(receipts_data, sedes=CountableList(ReceiptForStorage)) |
|
|
|
receipts = rlp.decode(receipts_data, sedes=CountableList(ReceiptForStorage)) |
|
|
|
return receipts |
|
|
|
return receipts |
|
|
@ -216,12 +216,12 @@ class EthLevelDB(object): |
|
|
|
if not cnt % 1000: |
|
|
|
if not cnt % 1000: |
|
|
|
logging.info("Searched %d contracts" % cnt) |
|
|
|
logging.info("Searched %d contracts" % cnt) |
|
|
|
|
|
|
|
|
|
|
|
def contract_hash_to_address(self, hash): |
|
|
|
def contract_hash_to_address(self, contract_hash): |
|
|
|
''' |
|
|
|
''' |
|
|
|
tries to find corresponding account address |
|
|
|
tries to find corresponding account address |
|
|
|
''' |
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
address_hash = binascii.a2b_hex(utils.remove_0x_head(hash)) |
|
|
|
address_hash = binascii.a2b_hex(utils.remove_0x_head(contract_hash)) |
|
|
|
indexer = AccountIndexer(self) |
|
|
|
indexer = AccountIndexer(self) |
|
|
|
|
|
|
|
|
|
|
|
return _encode_hex(indexer.get_contract_by_hash(address_hash)) |
|
|
|
return _encode_hex(indexer.get_contract_by_hash(address_hash)) |
|
|
@ -230,9 +230,9 @@ class EthLevelDB(object): |
|
|
|
''' |
|
|
|
''' |
|
|
|
gets block header by block number |
|
|
|
gets block header by block number |
|
|
|
''' |
|
|
|
''' |
|
|
|
hash = self.reader._get_block_hash(number) |
|
|
|
block_hash = self.reader._get_block_hash(number) |
|
|
|
block_number = _format_block_number(number) |
|
|
|
block_number = _format_block_number(number) |
|
|
|
return self.reader._get_block_header(hash, block_number) |
|
|
|
return self.reader._get_block_header(block_hash, block_number) |
|
|
|
|
|
|
|
|
|
|
|
def eth_getBlockByNumber(self, number): |
|
|
|
def eth_getBlockByNumber(self, number): |
|
|
|
''' |
|
|
|
''' |
|
|
|