Add tx filestore, add tx dict src to hexdir in store

This commit is contained in:
lash 2022-01-22 08:44:36 +00:00
parent 0bfe054b90
commit 265a53f9ca
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 31 additions and 3 deletions

View File

@ -9,7 +9,10 @@ from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
from cic_types.models.person import Person
from chainlib.eth.address import to_checksum_address
from chainlib.encode import TxHexNormalizer
from hexathon import add_0x
from hexathon import (
add_0x,
strip_0x,
)
# local imports
from clicada.tx import TxGetter
@ -19,6 +22,7 @@ from clicada.token import (
token_balance,
)
from clicada.tx import ResolvedTokenTx
from clicada.tx.file import FileTxStore
from clicada.error import MetadataNotFoundError
logg = logging.getLogger(__name__)
@ -108,15 +112,19 @@ Tags: {}""".format(
)
)
tx_store = FileTxStore(store_path)
tx_lines = []
seen_tokens = {}
for tx_src in txs['data']:
ctrl.notify('resolve details for tx {}'.format(tx_src['tx_hash']))
tx_hash = strip_0x(tx_src['tx_hash'])
ctrl.notify('resolve details for tx {}'.format(tx_hash))
tx = ResolvedTokenTx.from_dict(tx_src)
tx.resolve(token_store, user_address_store, show_decimals=True, update=ctrl.get('_FORCE'))
tx_lines.append(tx)
seen_tokens[tx.source_token_label] = tx.source_token
seen_tokens[tx.destination_token_label] = tx.destination_token
tx_store.put(tx_hash, str(tx_src))
for k in seen_tokens.keys():
ctrl.notify('resolve token {}'.format(seen_tokens[k]))

20
clicada/tx/file.py Normal file
View File

@ -0,0 +1,20 @@
import os
from leveldir.numeric import NumDir
from leveldir.hex import HexDir
class FileTxStore:
subdivision = 100000
def __init__(self, store_base_path):
tx_base_path = os.path.join(store_base_path, 'tx')
num_base_path = os.path.join(tx_base_path, 'blocks')
hash_base_path = os.path.join(tx_base_path, 'hash')
self.block_index_dir = NumDir(num_base_path)
self.hash_index_dir = HexDir(hash_base_path, 32)
def put(self, k, v):
hsh = bytes.fromhex(k)
self.hash_index_dir.add(hsh, v.encode('utf-8'))

View File

@ -191,7 +191,6 @@ class FileUserStore:
if self.encrypter != None:
v = self.encrypter.decrypt(k, v)
logg.debug('>>>>>>>>>>>>< v decoded {}'.format(v))
v = v.decode('utf-8')
logg.debug('retrieved {} from {}'.format(k, p))

View File

@ -8,3 +8,4 @@ hexathon~=0.1.0
pycryptodome~=3.10.1
chainlib-eth~=0.0.21
chainlib~=0.0.17
leveldir~=0.1.0