2018-08-22 11:48:32 +00:00
|
|
|
# generated from tokens.py.mako
|
|
|
|
# do not edit manually!
|
2019-05-22 13:06:23 +00:00
|
|
|
# flake8: noqa
|
|
|
|
# fmt: off
|
2019-05-20 13:51:30 +00:00
|
|
|
<%
|
|
|
|
from collections import defaultdict
|
2018-08-22 11:48:32 +00:00
|
|
|
|
2019-05-20 13:51:30 +00:00
|
|
|
def group_tokens(tokens):
|
|
|
|
r = defaultdict(list)
|
2019-05-20 16:04:12 +00:00
|
|
|
for t in sorted(tokens, key=lambda t: t.chain_id):
|
2019-05-20 13:51:30 +00:00
|
|
|
r[t.chain_id].append(t)
|
|
|
|
return r
|
2019-05-22 13:06:23 +00:00
|
|
|
%>\
|
2018-08-22 11:48:32 +00:00
|
|
|
|
|
|
|
|
2021-08-31 09:45:21 +00:00
|
|
|
class TokenInfo:
|
|
|
|
def __init__(self, symbol: str, decimals: int) -> None:
|
|
|
|
self.symbol = symbol
|
|
|
|
self.decimals = decimals
|
2018-08-22 11:48:32 +00:00
|
|
|
|
2021-08-31 09:45:21 +00:00
|
|
|
UNKNOWN_TOKEN = TokenInfo("Wei UNKN", 0)
|
|
|
|
|
|
|
|
|
|
|
|
def token_by_chain_address(chain_id: int, address: bytes) -> TokenInfo:
|
2019-05-20 13:51:30 +00:00
|
|
|
if False:
|
|
|
|
pass
|
|
|
|
% for token_chain_id, tokens in group_tokens(supported_on("trezor2", erc20)).items():
|
|
|
|
elif chain_id == ${token_chain_id}:
|
|
|
|
if False:
|
|
|
|
pass
|
|
|
|
% for t in tokens:
|
|
|
|
elif address == ${black_repr(t.address_bytes)}:
|
2021-08-31 09:45:21 +00:00
|
|
|
return TokenInfo(${black_repr(t.symbol)}, ${t.decimals}) # ${t.chain} / ${t.name.strip()}
|
2019-05-20 13:51:30 +00:00
|
|
|
% endfor
|
2018-08-22 11:48:32 +00:00
|
|
|
% endfor
|
2019-05-20 13:51:30 +00:00
|
|
|
return UNKNOWN_TOKEN
|