eth-cache

Ethereum chain data caching tools
Log | Files | Refs | LICENSE

commit 67b8d04872a7b2ce4acc29cf2199674facd02548
parent 7ffd3e25c717cfc8d822cfd4d40bdca713b602be
Author: nolash <dev@holbrook.no>
Date:   Mon, 14 Jun 2021 09:54:57 +0200

Use store frontend for tx get tool

Diffstat:
Meth_cache/runnable/get.py | 20+++++++++++++++++---
Meth_cache/store.py | 11++++++++---
2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/eth_cache/runnable/get.py b/eth_cache/runnable/get.py @@ -16,10 +16,17 @@ from chainlib.eth.tx import ( transaction, Tx, ) +from chainlib.eth.block import ( + Block, + block_by_hash, + ) from hexathon import strip_0x # local imports -from eth_cache.store import PointerHexDir +from eth_cache.store import ( + PointerHexDir, + TxFileStore, + ) logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() @@ -73,7 +80,14 @@ if __name__ == '__main__': r = rpc.do(o) tx.apply_receipt(r) + rcpt = Tx.src_normalize(r) + o = block_by_hash(rcpt['block_hash']) + r = rpc.do(o) + block = Block(r) + tx.apply_block(block) + store_backend = PointerHexDir(data_dir, 32) store_backend.register_pointer('address') - #store = TxFileStore(chain_spec, backend) - store_backend.add(bytes.fromhex(strip_0x(tx_hash)), tx_raw) + store = TxFileStore(chain_spec, store_backend) + #store_backend.add(bytes.fromhex(strip_0x(tx_hash)), tx_raw) + store.put(block, tx, []) diff --git a/eth_cache/store.py b/eth_cache/store.py @@ -57,9 +57,14 @@ class TxFileStore: self.chain_spec = chain_spec - def put(self, block, tx, addresses, attrs={}): + def put(self, block, tx, addresses=[], attrs={}): + tx_src = tx.as_dict() + tx_raw = pack(tx_src, self.chain_spec) + + if len(addresses) == 0: + self.backend.add(bytes.fromhex(tx.hash), tx_raw, pointers={}) + return + for address in addresses: - tx_src = tx.as_dict() - tx_raw = pack(tx_src, self.chain_spec) filename = '{}_{}_{}'.format(block.number, tx.index, strip_0x(tx.hash)) self.backend.add(bytes.fromhex(tx.hash), tx_raw, pointers={'address': [strip_0x(address),filename]})