Add balances

This commit is contained in:
nolash 2021-11-06 10:59:49 +01:00
parent bdfdd0fdd7
commit f0ba197b08
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 29 additions and 4 deletions

View File

@ -13,7 +13,10 @@ 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.token import (
FileTokenStore,
token_balance,
)
from clicada.tx import ResolvedTokenTx
logg = logging.getLogger(__name__)
@ -81,7 +84,7 @@ Registered: {}
Gender: {}
Location: {}
Products: {}
""".format(
Balances:""".format(
ctrl.get('_IDENTIFIER'),
user_address,
str(r),
@ -92,8 +95,19 @@ Products: {}
)
)
tx_lines = []
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'))
print(tx)
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():
balance = token_balance(ctrl.chain(), ctrl.conn(), seen_tokens[k], user_address)
print("\t{} {}".format(k, balance))
print()
for l in tx_lines:
print(l)

View File

@ -1 +1,2 @@
from .token import *
from .util import token_balance

10
clicada/token/util.py Normal file
View File

@ -0,0 +1,10 @@
# external imports
from eth_erc20 import ERC20
from chainlib.eth.constant import ZERO_ADDRESS
def token_balance(chain_spec, conn, token_address, wallet_address, caller_address=ZERO_ADDRESS):
c = ERC20(chain_spec)
o = c.balance(token_address, wallet_address, sender_address=caller_address)
r = conn.do(o)
return c.parse_balance(r)