Add raw tx filestore, optional retrieve and cache of raw tx
This commit is contained in:
@@ -158,6 +158,8 @@ class CmdCtrl:
|
||||
r = self.config.get(k, default)
|
||||
if k in [
|
||||
'_FORCE',
|
||||
'_FORCE_ALL',
|
||||
'_RAW_TX',
|
||||
]:
|
||||
if r == None:
|
||||
return False
|
||||
|
||||
@@ -34,12 +34,16 @@ def process_args(argparser):
|
||||
argparser.add_argument('-m', '--method', type=str, help='lookup method')
|
||||
argparser.add_argument('--meta-url', dest='meta_url', type=str, help='Url to retrieve metadata from')
|
||||
argparser.add_argument('-f', '--force-update', dest='force_update', action='store_true', help='Update records of mutable entries')
|
||||
argparser.add_argument('-ff', '--force-update-all', dest='force_update_all', action='store_true', help='Update records of mutable entries and immutable entries')
|
||||
argparser.add_argument('--raw-tx', dest='raw_tx', action='store_true', help='Also cache raw transaction data')
|
||||
argparser.add_argument('identifier', type=str, help='user identifier')
|
||||
|
||||
|
||||
def extra_args():
|
||||
return {
|
||||
'raw_tx': '_RAW_TX',
|
||||
'force_update': '_FORCE',
|
||||
'force_update_all': '_FORCE_ALL',
|
||||
'method': 'META_LOOKUP_METHOD',
|
||||
'meta_url': 'META_URL',
|
||||
'identifier': '_IDENTIFIER',
|
||||
@@ -60,7 +64,7 @@ def execute(ctrl):
|
||||
|
||||
store_path = '.clicada'
|
||||
user_phone_file_label = 'phone'
|
||||
user_phone_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_phone_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
|
||||
user_phone_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_phone_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter, notifier=ctrl)
|
||||
|
||||
ctrl.notify('resolving identifier {} to wallet address'.format(ctrl.get('_IDENTIFIER')))
|
||||
user_address = user_phone_store.by_phone(ctrl.get('_IDENTIFIER'), update=ctrl.get('_FORCE'))
|
||||
@@ -82,7 +86,7 @@ def execute(ctrl):
|
||||
token_store = FileTokenStore(ctrl.chain(), ctrl.conn(), 'token', store_path)
|
||||
|
||||
user_address_file_label = 'address'
|
||||
user_address_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
|
||||
user_address_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter, notifier=ctrl)
|
||||
|
||||
ctrl.notify('resolving metadata for address {}'.format(user_address_normal))
|
||||
try:
|
||||
@@ -112,7 +116,11 @@ Tags: {}""".format(
|
||||
)
|
||||
)
|
||||
|
||||
tx_store = FileTxStore(store_path)
|
||||
raw_rpc = None
|
||||
if ctrl.get('_RAW_TX'):
|
||||
raw_rpc = ctrl.rpc
|
||||
|
||||
tx_store = FileTxStore(store_path, rpc=raw_rpc, notifier=ctrl)
|
||||
tx_lines = []
|
||||
seen_tokens = {}
|
||||
for tx_src in txs['data']:
|
||||
@@ -123,9 +131,9 @@ Tags: {}""".format(
|
||||
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))
|
||||
|
||||
tx_store.put(tx_hash, str(tx_src), overwrite=ctrl.get('_FORCE_ALL'))
|
||||
|
||||
ctrl.write("Balances:")
|
||||
for k in seen_tokens.keys():
|
||||
ctrl.notify('resolve token {}'.format(seen_tokens[k]))
|
||||
(token_symbol, token_decimals) = token_store.by_address(seen_tokens[k])
|
||||
@@ -133,7 +141,7 @@ Tags: {}""".format(
|
||||
balance = token_balance(ctrl.chain(), ctrl.conn(), seen_tokens[k], user_address)
|
||||
fmt = '{:.' + str(token_decimals) + 'f}'
|
||||
decimal_balance = fmt.format(balance / (10 ** token_decimals))
|
||||
ctrl.write("Balances:\n {} {}".format(token_symbol, decimal_balance))
|
||||
ctrl.write(" {} {}".format(token_symbol, decimal_balance))
|
||||
|
||||
print()
|
||||
for l in tx_lines:
|
||||
|
||||
Reference in New Issue
Block a user