feat: add ability to query user using address
This commit is contained in:
parent
618aa7716e
commit
1dba2d09d1
@ -1,27 +1,22 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import sys
|
|
||||||
import logging
|
|
||||||
import datetime
|
import datetime
|
||||||
from pathlib import Path
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from chainlib.encode import TxHexNormalizer
|
||||||
|
from chainlib.eth.address import is_address, to_checksum_address
|
||||||
# external imports
|
# external imports
|
||||||
from cic_eth_registry import CICRegistry
|
from cic_eth_registry import CICRegistry
|
||||||
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
|
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
|
||||||
from cic_types.models.person import Person
|
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
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from clicada.tx import TxGetter
|
|
||||||
from clicada.user import FileUserStore
|
|
||||||
from clicada.token import (
|
|
||||||
FileTokenStore,
|
|
||||||
token_balance,
|
|
||||||
)
|
|
||||||
from clicada.tx import ResolvedTokenTx
|
|
||||||
from clicada.error import MetadataNotFoundError
|
from clicada.error import MetadataNotFoundError
|
||||||
|
from clicada.token import FileTokenStore, token_balance
|
||||||
|
# local imports
|
||||||
|
from clicada.tx import ResolvedTokenTx, TxGetter
|
||||||
|
from clicada.user import FileUserStore
|
||||||
|
from hexathon import add_0x
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -32,7 +27,7 @@ def process_args(argparser):
|
|||||||
argparser.add_argument('-m', '--method', type=str, help='lookup method')
|
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('--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('-f', '--force-update', dest='force_update', action='store_true', help='Update records of mutable entries')
|
||||||
argparser.add_argument('identifier', type=str, help='user identifier')
|
argparser.add_argument('identifier', type=str, help='user identifier (phone_number or address)')
|
||||||
|
|
||||||
|
|
||||||
def extra_args():
|
def extra_args():
|
||||||
@ -60,18 +55,22 @@ def execute(ctrl):
|
|||||||
user_phone_file_label = 'phone'
|
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)
|
||||||
|
|
||||||
ctrl.notify('resolving identifier {} to wallet address'.format(ctrl.get('_IDENTIFIER')))
|
identifier = ctrl.get('_IDENTIFIER')
|
||||||
user_address = user_phone_store.by_phone(ctrl.get('_IDENTIFIER'), update=ctrl.get('_FORCE'))
|
ctrl.notify('resolving identifier {} to wallet address'.format(identifier))
|
||||||
|
if is_address(identifier):
|
||||||
|
user_address = identifier
|
||||||
|
else:
|
||||||
|
user_address = user_phone_store.by_phone(identifier, update=ctrl.get('_FORCE'))
|
||||||
if user_address == None:
|
if user_address == None:
|
||||||
ctrl.ouch('unknown identifier: {}\n'.format(ctrl.get('_IDENTIFIER')))
|
ctrl.ouch('unknown identifier: {}\n'.format(identifier))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
user_address = to_checksum_address(user_address)
|
user_address = to_checksum_address(user_address)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
ctrl.ouch('invalid response "{}" for {}\n'.format(user_address, ctrl.get('_IDENTIFIER')))
|
ctrl.ouch('invalid response "{}" for {}\n'.format(user_address, identifier))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logg.debug('loaded user address {} for {}'.format(user_address, ctrl.get('_IDENTIFIER')))
|
logg.debug('loaded user address {} for {}'.format(user_address, identifier))
|
||||||
|
|
||||||
user_address_normal = tx_normalizer.wallet_address(user_address)
|
user_address_normal = tx_normalizer.wallet_address(user_address)
|
||||||
ctrl.notify('retrieving txs for address {}'.format(user_address_normal))
|
ctrl.notify('retrieving txs for address {}'.format(user_address_normal))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = clicada
|
name = clicada
|
||||||
version = 0.0.9
|
version = 0.1.0
|
||||||
description = CLI CRM tool for the cic-stack custodial wallet system
|
description = CLI CRM tool for the cic-stack custodial wallet system
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
Loading…
Reference in New Issue
Block a user