WIP add AES to local cache
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
# import notifier
|
||||
from clicada.cli.notify import NotifyWriter
|
||||
notifier = NotifyWriter()
|
||||
notifier.notify('loading script')
|
||||
|
||||
# standard imports
|
||||
import os
|
||||
#import argparse
|
||||
import logging
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
# external imports
|
||||
import confini
|
||||
@@ -25,6 +30,20 @@ data_dir = os.path.join(script_dir, '..', 'data')
|
||||
base_config_dir = os.path.join(data_dir, 'config')
|
||||
|
||||
|
||||
class NullWriter:
|
||||
|
||||
def notify(self, v):
|
||||
pass
|
||||
|
||||
|
||||
def ouch(self, v):
|
||||
pass
|
||||
|
||||
|
||||
def write(self, v):
|
||||
sys.stdout.write(str(v))
|
||||
|
||||
|
||||
class CmdCtrl:
|
||||
|
||||
__cmd_alias = {
|
||||
@@ -45,10 +64,12 @@ class CmdCtrl:
|
||||
|
||||
self.config()
|
||||
|
||||
self.notifier()
|
||||
|
||||
self.auth()
|
||||
|
||||
self.blockchain()
|
||||
|
||||
|
||||
self.remote_openers = {}
|
||||
if self.get('META_URL') != None:
|
||||
auth_client_session = PGPClientSession(self.__auth)
|
||||
@@ -156,3 +177,27 @@ class CmdCtrl:
|
||||
|
||||
def opener(self, k):
|
||||
return self.remote_openers[k]
|
||||
|
||||
|
||||
def notifier(self):
|
||||
if logg.root.level >= logging.WARNING:
|
||||
logging.disable()
|
||||
self.writer = notifier
|
||||
else:
|
||||
self.writer = NullWriter()
|
||||
|
||||
|
||||
def notify(self, v):
|
||||
self.writer.notify(v)
|
||||
|
||||
|
||||
def ouch(self, v):
|
||||
self.writer.croak(v)
|
||||
print()
|
||||
|
||||
|
||||
def write(self, v):
|
||||
self.writer.write("")
|
||||
self.writer.write(v)
|
||||
print()
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from clicada.token import (
|
||||
token_balance,
|
||||
)
|
||||
from clicada.tx import ResolvedTokenTx
|
||||
from clicada.error import MetadataNotFoundError
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
@@ -51,24 +52,27 @@ def validate(config, args):
|
||||
|
||||
|
||||
def execute(ctrl):
|
||||
tx_getter = TxGetter(ctrl.get('TX_CACHE_URL'))
|
||||
tx_getter = TxGetter(ctrl.get('TX_CACHE_URL'), 10)
|
||||
|
||||
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')))
|
||||
|
||||
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'))
|
||||
if user_address == None:
|
||||
sys.stderr.write('unknown identifier: {}\n'.format(ctrl.get('_IDENTIFIER')))
|
||||
ctrl.ouch('unknown identifier: {}\n'.format(ctrl.get('_IDENTIFIER')))
|
||||
sys.exit(1)
|
||||
try:
|
||||
user_address = to_checksum_address(user_address)
|
||||
except ValueError:
|
||||
sys.stderr.write('invalid response "{}" for {}\n'.format(user_address, ctrl.get('_IDENTIFIER')))
|
||||
ctrl.ouch('invalid response "{}" for {}\n'.format(user_address, ctrl.get('_IDENTIFIER')))
|
||||
sys.exit(1)
|
||||
|
||||
logg.debug('loaded user address {} for {}'.format(user_address, ctrl.get('_IDENTIFIER')))
|
||||
|
||||
user_address_normal = tx_normalizer.wallet_address(user_address)
|
||||
ctrl.notify('retrieving txs for address {}'.format(user_address_normal))
|
||||
txs = tx_getter.get(user_address)
|
||||
|
||||
token_store = FileTokenStore(ctrl.chain(), ctrl.conn(), 'token', store_path)
|
||||
@@ -76,12 +80,14 @@ def execute(ctrl):
|
||||
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')))
|
||||
|
||||
user_address_normal = tx_normalizer.wallet_address(user_address)
|
||||
ctrl.notify('resolving metadata for address {}'.format(user_address_normal))
|
||||
try:
|
||||
r = user_address_store.by_address(user_address_normal, update=ctrl.get('_FORCE'))
|
||||
except MetadataNotFoundError as e:
|
||||
ctrl.ouch('could not resolve metadata for user: {}'.format(e))
|
||||
sys.exit(1)
|
||||
|
||||
r = user_address_store.by_address(user_address_normal, update=ctrl.get('_FORCE'))
|
||||
print('r {}'.format(r))
|
||||
|
||||
print("""Phone: {}
|
||||
ctrl.write("""Phone: {}
|
||||
Network address: {}
|
||||
Chain: {}
|
||||
Name: {}
|
||||
@@ -89,8 +95,7 @@ Registered: {}
|
||||
Gender: {}
|
||||
Location: {}
|
||||
Products: {}
|
||||
Tags: {}
|
||||
Balances:""".format(
|
||||
Tags: {}""".format(
|
||||
ctrl.get('_IDENTIFIER'),
|
||||
add_0x(user_address),
|
||||
ctrl.chain().common_name(),
|
||||
@@ -106,6 +111,7 @@ Balances:""".format(
|
||||
tx_lines = []
|
||||
seen_tokens = {}
|
||||
for tx_src in txs['data']:
|
||||
ctrl.notify('resolve details for tx {}'.format(tx_src['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)
|
||||
@@ -113,12 +119,14 @@ Balances:""".format(
|
||||
seen_tokens[tx.destination_token_label] = tx.destination_token
|
||||
|
||||
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])
|
||||
ctrl.notify('get token balance for {} => {}'.format(token_symbol, seen_tokens[k]))
|
||||
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))
|
||||
print("\t{} {}".format(token_symbol, decimal_balance))
|
||||
ctrl.write("Balances:\n {} {}".format(token_symbol, decimal_balance))
|
||||
|
||||
print()
|
||||
for l in tx_lines:
|
||||
print(l)
|
||||
ctrl.write(l)
|
||||
|
||||
Reference in New Issue
Block a user