diff --git a/clicada/cli/user.py b/clicada/cli/user.py index 92a0aa0..2e591ac 100644 --- a/clicada/cli/user.py +++ b/clicada/cli/user.py @@ -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])) diff --git a/clicada/tx/file.py b/clicada/tx/file.py new file mode 100644 index 0000000..06be938 --- /dev/null +++ b/clicada/tx/file.py @@ -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')) diff --git a/clicada/user/file.py b/clicada/user/file.py index 02bf037..9ec3c81 100644 --- a/clicada/user/file.py +++ b/clicada/user/file.py @@ -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)) diff --git a/requirements.txt b/requirements.txt index 2003eba..04f2aee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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