Add custom user info, decimals to values
This commit is contained in:
		
							parent
							
								
									f0ba197b08
								
							
						
					
					
						commit
						e3c002082b
					
				@ -9,6 +9,7 @@ from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
 | 
			
		||||
from cic_types.ext.metadata import MetadataRequestsHandler
 | 
			
		||||
from cic_types.models.person import Person
 | 
			
		||||
from chainlib.eth.address import to_checksum_address
 | 
			
		||||
from hexathon import add_0x
 | 
			
		||||
 | 
			
		||||
# local imports
 | 
			
		||||
from clicada.tx import TxGetter
 | 
			
		||||
@ -78,20 +79,24 @@ def execute(ctrl):
 | 
			
		||||
    r = user_address_store.by_address(user_address)
 | 
			
		||||
 | 
			
		||||
    print("""Phone: {}
 | 
			
		||||
EVM address: {}
 | 
			
		||||
Network address: {}
 | 
			
		||||
Chain: {}
 | 
			
		||||
Name: {}
 | 
			
		||||
Registered: {}
 | 
			
		||||
Gender: {}
 | 
			
		||||
Location: {}
 | 
			
		||||
Products: {}
 | 
			
		||||
Tags: {}
 | 
			
		||||
Balances:""".format(
 | 
			
		||||
    ctrl.get('_IDENTIFIER'),
 | 
			
		||||
    user_address,
 | 
			
		||||
    add_0x(user_address),
 | 
			
		||||
    ctrl.chain().common_name(),
 | 
			
		||||
    str(r),
 | 
			
		||||
    datetime.datetime.fromtimestamp(r.date_registered).ctime(),
 | 
			
		||||
    r.gender,
 | 
			
		||||
    r.location['area_name'],
 | 
			
		||||
    ','.join(r.products),
 | 
			
		||||
    ','.join(r.tags),
 | 
			
		||||
    )
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -99,14 +104,17 @@ Balances:""".format(
 | 
			
		||||
    seen_tokens = {}
 | 
			
		||||
    for tx_src in txs['data']:
 | 
			
		||||
        tx = ResolvedTokenTx.from_dict(tx_src)
 | 
			
		||||
        tx.resolve(token_store, user_address_store, update=ctrl.get('_FORCE'))
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
    for k in seen_tokens.keys():
 | 
			
		||||
        (token_symbol, token_decimals) = token_store.by_address(seen_tokens[k])
 | 
			
		||||
        balance = token_balance(ctrl.chain(), ctrl.conn(), seen_tokens[k], user_address)
 | 
			
		||||
        print("\t{} {}".format(k, balance))
 | 
			
		||||
        fmt =  '{:.' + str(token_decimals) + 'f}'
 | 
			
		||||
        decimal_balance = fmt.format(balance / (10 ** token_decimals))
 | 
			
		||||
        print("\t{} {}".format(token_symbol, decimal_balance))
 | 
			
		||||
 | 
			
		||||
    print()
 | 
			
		||||
    for l in tx_lines:
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,8 @@ class ResolvedTokenTx(TokenTx):
 | 
			
		||||
        super(ResolvedTokenTx, self).__init__()
 | 
			
		||||
        self.source_token_name = None
 | 
			
		||||
        self.destination_token_name = None
 | 
			
		||||
        self.source_token_decimals = None
 | 
			
		||||
        self.destination_token_decimals = None
 | 
			
		||||
        self.symmetric = True
 | 
			
		||||
        self.sender_entity = None
 | 
			
		||||
        self.recipient_entity = None
 | 
			
		||||
@ -30,22 +32,26 @@ class ResolvedTokenTx(TokenTx):
 | 
			
		||||
 | 
			
		||||
    def resolve_tokens(self, token_store, show_decimals=False, update=False):
 | 
			
		||||
        (token_symbol, token_decimals) = token_store.by_address(self.source_token)
 | 
			
		||||
        self.source_token_decimals = token_decimals
 | 
			
		||||
        self.source_token_label = token_symbol
 | 
			
		||||
        token_value = self.to_value / (10 ** token_decimals)
 | 
			
		||||
        show_token_decimals = token_decimals
 | 
			
		||||
        if not show_decimals:
 | 
			
		||||
            token_decimals = 0
 | 
			
		||||
        fmt = '{:.' + str(token_decimals) + 'f}'
 | 
			
		||||
            show_token_decimals = 0
 | 
			
		||||
        fmt = '{:.' + str(show_token_decimals) + 'f}'
 | 
			
		||||
        self.from_value_label = fmt.format(token_value)
 | 
			
		||||
 | 
			
		||||
        if self.destination_token != self.source_token:
 | 
			
		||||
            self.symmetric = False
 | 
			
		||||
            (token_symbol, token_decimals) = token_store.by_address(self.destination_token)
 | 
			
		||||
            show_token_decimals = token_decimals
 | 
			
		||||
 | 
			
		||||
        self.destination_token_label = token_symbol
 | 
			
		||||
        self.destination_token_decimals = token_decimals
 | 
			
		||||
        token_value = self.to_value / (10 ** token_decimals)
 | 
			
		||||
        if not show_decimals:
 | 
			
		||||
            token_decimals = 0
 | 
			
		||||
        fmt = '{:.' + str(token_decimals) + 'f}'
 | 
			
		||||
            show_token_decimals = 0
 | 
			
		||||
        fmt = '{:.' + str(show_token_decimals) + 'f}'
 | 
			
		||||
 | 
			
		||||
        self.to_value_label = fmt.format(token_value)
 | 
			
		||||
 | 
			
		||||
@ -93,7 +99,7 @@ class ResolvedTokenTx(TokenTx):
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        if self.symmetric:
 | 
			
		||||
            return '{}: {} => {}\t{} {}'.format(
 | 
			
		||||
            return '{}\t{} => {}\t{} {}'.format(
 | 
			
		||||
                    self.date_block_label,
 | 
			
		||||
                    self.sender_label,
 | 
			
		||||
                    self.recipient_label,
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,18 @@ from clicada.error import ExpiredRecordError
 | 
			
		||||
logg = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Account(Person):
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        super(Account, self).__init__()
 | 
			
		||||
        self.tags = []
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def apply_custom(self, custom_data):
 | 
			
		||||
        self.tags = custom_data['tags']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FileUserStore:
 | 
			
		||||
 | 
			
		||||
    def __init__(self, chain_spec, label, store_base_path, ttl):
 | 
			
		||||
@ -199,7 +211,16 @@ class FileUserStore:
 | 
			
		||||
            return address
 | 
			
		||||
 | 
			
		||||
        data = r.json()
 | 
			
		||||
        person = Person()
 | 
			
		||||
        person = Account()
 | 
			
		||||
        person_data = person.deserialize(person_data=data)
 | 
			
		||||
        self.put(address, json.dumps(person_data.serialize()))
 | 
			
		||||
 | 
			
		||||
        getter = MetadataRequestsHandler(MetadataPointer.CUSTOM, bytes.fromhex(address))
 | 
			
		||||
        r = None
 | 
			
		||||
        try:
 | 
			
		||||
            r = getter.query()
 | 
			
		||||
            person_data.apply_custom(r.json())
 | 
			
		||||
        except requests.exceptions.HTTPError as e:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
        return person_data
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,7 @@
 | 
			
		||||
usumbufu~=0.3.2
 | 
			
		||||
confini~=0.5.1
 | 
			
		||||
cic-eth-registry~=0.6.1
 | 
			
		||||
cic-types~=0.2.1a3
 | 
			
		||||
cic-types~=0.2.1a4
 | 
			
		||||
phonenumbers==8.12.12
 | 
			
		||||
eth-erc20~=0.1.2
 | 
			
		||||
hexathon~=0.1.0
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user