Use store frontend for tx get tool
This commit is contained in:
parent
7ffd3e25c7
commit
67b8d04872
@ -16,10 +16,17 @@ from chainlib.eth.tx import (
|
|||||||
transaction,
|
transaction,
|
||||||
Tx,
|
Tx,
|
||||||
)
|
)
|
||||||
|
from chainlib.eth.block import (
|
||||||
|
Block,
|
||||||
|
block_by_hash,
|
||||||
|
)
|
||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from eth_cache.store import PointerHexDir
|
from eth_cache.store import (
|
||||||
|
PointerHexDir,
|
||||||
|
TxFileStore,
|
||||||
|
)
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@ -73,7 +80,14 @@ if __name__ == '__main__':
|
|||||||
r = rpc.do(o)
|
r = rpc.do(o)
|
||||||
tx.apply_receipt(r)
|
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 = PointerHexDir(data_dir, 32)
|
||||||
store_backend.register_pointer('address')
|
store_backend.register_pointer('address')
|
||||||
#store = TxFileStore(chain_spec, backend)
|
store = TxFileStore(chain_spec, store_backend)
|
||||||
store_backend.add(bytes.fromhex(strip_0x(tx_hash)), tx_raw)
|
#store_backend.add(bytes.fromhex(strip_0x(tx_hash)), tx_raw)
|
||||||
|
store.put(block, tx, [])
|
||||||
|
@ -57,9 +57,14 @@ class TxFileStore:
|
|||||||
self.chain_spec = chain_spec
|
self.chain_spec = chain_spec
|
||||||
|
|
||||||
|
|
||||||
def put(self, block, tx, addresses, attrs={}):
|
def put(self, block, tx, addresses=[], attrs={}):
|
||||||
for address in addresses:
|
|
||||||
tx_src = tx.as_dict()
|
tx_src = tx.as_dict()
|
||||||
tx_raw = pack(tx_src, self.chain_spec)
|
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:
|
||||||
filename = '{}_{}_{}'.format(block.number, tx.index, strip_0x(tx.hash))
|
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]})
|
self.backend.add(bytes.fromhex(tx.hash), tx_raw, pointers={'address': [strip_0x(address),filename]})
|
||||||
|
Loading…
Reference in New Issue
Block a user