Add tagger
This commit is contained in:
@@ -11,6 +11,7 @@ from chainlib.chain import ChainSpec
|
||||
|
||||
# local imports
|
||||
import clicada.cli.user as cmd_user
|
||||
import clicada.cli.tag as cmd_tag
|
||||
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
data_dir = os.path.join(script_dir, '..', 'data')
|
||||
@@ -21,6 +22,7 @@ class CmdCtrl:
|
||||
|
||||
__cmd_alias = {
|
||||
'u': 'user',
|
||||
't': 'tag',
|
||||
}
|
||||
|
||||
def __init__(self, argv=None, description=None, logger=None, *args, **kwargs):
|
||||
@@ -35,6 +37,8 @@ class CmdCtrl:
|
||||
sub.dest = 'command'
|
||||
sub_user = sub.add_parser('user', aliases=['u'], help='retrieve transactions for a user')
|
||||
cmd_user.process_args(sub_user)
|
||||
sub_tag = sub.add_parser('tag', aliases=['t'], help='locally assign a display value to an identifier')
|
||||
cmd_tag.process_args(sub_tag)
|
||||
|
||||
self.cmd_args = self.argparser.parse_args(argv)
|
||||
|
||||
@@ -57,10 +61,6 @@ class CmdCtrl:
|
||||
logger.debug('using module {}'.format(modname))
|
||||
self.cmd_mod = importlib.import_module(modname)
|
||||
|
||||
# if self.cmd_args.c:
|
||||
# self.config = confini.Config(base_config_dir, override_dirs=self.cmd_args.c)
|
||||
# else:
|
||||
# self.config = confini.Config(base_config_dir)
|
||||
extra_args = self.cmd_mod.extra_args()
|
||||
logger.debug('using extra args {}'.format(extra_args))
|
||||
if self.cmd_args.config:
|
||||
@@ -87,9 +87,14 @@ class CmdCtrl:
|
||||
return self.config.true(k)
|
||||
return r
|
||||
|
||||
|
||||
def chain(self):
|
||||
return self.chain_spec
|
||||
|
||||
|
||||
def conn(self):
|
||||
return self.__conn
|
||||
|
||||
|
||||
def execute(self):
|
||||
self.cmd_mod.execute(self)
|
||||
|
||||
41
clicada/cli/tag.py
Normal file
41
clicada/cli/tag.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# standard imports
|
||||
import json
|
||||
|
||||
# external imports
|
||||
from clicada.user import FileUserStore
|
||||
|
||||
|
||||
categories = [
|
||||
'phone',
|
||||
'address',
|
||||
]
|
||||
|
||||
|
||||
def process_args(argparser):
|
||||
argparser.add_argument('--category', required=True, type=str, help='Identifier category')
|
||||
argparser.add_argument('identifier', type=str, help='Identifier to store a display tag for')
|
||||
argparser.add_argument('tag', type=str, help='Display tag to store for the identifier')
|
||||
|
||||
|
||||
def extra_args():
|
||||
return {
|
||||
'category': None,
|
||||
'identifier': None,
|
||||
'tag': None,
|
||||
}
|
||||
|
||||
|
||||
def apply_args(config, args):
|
||||
pass
|
||||
|
||||
|
||||
def validate(config, args):
|
||||
if category not in categories:
|
||||
raise ValueError('Invalid category. Valid categories are: {}'.format(','.join(categories)))
|
||||
|
||||
|
||||
def execute(ctrl):
|
||||
store_path = '.clicada'
|
||||
user_store = FileUserStore(ctrl.chain(), ctrl.get('_CATEGORY'), store_path, int(ctrl.get('FILESTORE_TTL')))
|
||||
user_store.put(ctrl.get('_IDENTIFIER'), json.dumps(ctrl.get('_TAG')), force=True)
|
||||
user_store.stick(ctrl.get('_IDENTIFIER'))
|
||||
@@ -1,3 +1,22 @@
|
||||
# standard imports
|
||||
import sys
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from cic_eth_registry import CICRegistry
|
||||
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
|
||||
from cic_types.ext.metadata import MetadataRequestsHandler
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
|
||||
# local imports
|
||||
from clicada.tx import TxGetter
|
||||
from clicada.user import FileUserStore
|
||||
from clicada.token import FileTokenStore
|
||||
from clicada.tx import ResolvedTokenTx
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
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')
|
||||
@@ -14,13 +33,45 @@ def extra_args():
|
||||
}
|
||||
|
||||
|
||||
def validate_args(args):
|
||||
pass
|
||||
|
||||
|
||||
def apply_args(config, args):
|
||||
if config.get('META_LOOKUP_METHOD'):
|
||||
raise NotImplementedError('Sorry, currently only "phone" lookup method is implemented')
|
||||
|
||||
|
||||
def validate(config, args):
|
||||
pass
|
||||
|
||||
|
||||
def execute(config, args):
|
||||
pass
|
||||
def execute(ctrl):
|
||||
tx_getter = TxGetter(ctrl.get('TX_CACHE_URL'))
|
||||
|
||||
MetadataRequestsHandler.base_url = ctrl.get('META_URL')
|
||||
|
||||
store_path = '.clicada'
|
||||
user_phone_file_label = 'phone'
|
||||
user_phone_store = FileUserStore(ctrl.chain(), user_phone_file_label, store_path, int(ctrl.get('FILESTORE_TTL')))
|
||||
|
||||
user_address = user_phone_store.by_phone(ctrl.get('_ARG_USER_IDENTIFIER'), update=ctrl.get('_FORCE'))
|
||||
if user_address == None:
|
||||
sys.stderr.write('unknown identifier: {}\n'.format(ctrl.get('_ARG_USER_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('_ARG_USER_IDENTIFIER')))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
logg.debug('loaded user address {} for {}'.format(user_address, ctrl.get('_ARG_USER_IDENTIFIER')))
|
||||
|
||||
txs = tx_getter.get(user_address)
|
||||
|
||||
token_store = FileTokenStore(ctrl.chain(), ctrl.conn(), 'token', store_path)
|
||||
|
||||
user_address_file_label = 'address'
|
||||
user_address_store = FileUserStore(ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')))
|
||||
|
||||
for tx_src in txs['data']:
|
||||
tx = ResolvedTokenTx.from_dict(tx_src)
|
||||
tx.resolve(token_store, user_address_store, update=ctrl.get('_FORCE'))
|
||||
print(tx)
|
||||
|
||||
Reference in New Issue
Block a user