1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

core: store bitcoin-like coins as a decision tree

This commit is contained in:
Jan Pochyla 2019-05-22 14:55:32 +02:00 committed by Pavol Rusnak
parent 9676eec4df
commit 1f3adc7069
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 1385 additions and 1332 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,8 @@
from trezor.crypto.base58 import blake256d_32, groestl512d_32, keccak_32, sha256d_32
from trezor.crypto.scripts import blake256_ripemd160_digest, sha256_ripemd160_digest
# flake8: noqa
class CoinInfo:
def __init__(
@ -71,7 +73,7 @@ def hexfmt(x):
return "0x{:08x}".format(x)
ATTRIBUTES = (
("coin_name", black_repr),
("coin_name", lambda _: "name"),
("coin_shortcut", black_repr),
("address_type", int),
("address_type_p2sh", int),
@ -91,12 +93,15 @@ ATTRIBUTES = (
("curve_name", lambda r: repr(r.replace("_", "-"))),
)
%>\
COINS = [
def by_name(name: str) -> CoinInfo:
if False:
pass
% for coin in supported_on("trezor2", bitcoin):
CoinInfo(
% for attr, func in ATTRIBUTES:
${attr}=${func(coin[attr])},
% endfor
),
elif name == ${black_repr(coin["coin_name"])}:
return CoinInfo(
% for attr, func in ATTRIBUTES:
${attr}=${func(coin[attr])},
% endfor
)
% endfor
]
raise ValueError('Unknown coin name "%s"' % name)

View File

@ -1,22 +1 @@
from apps.common.coininfo import COINS
def by_shortcut(shortcut):
for c in COINS:
if c.coin_shortcut == shortcut:
return c
raise ValueError('Unknown coin shortcut "%s"' % shortcut)
def by_name(name):
for c in COINS:
if c.coin_name == name:
return c
raise ValueError('Unknown coin name "%s"' % name)
def by_slip44(slip44):
for c in COINS:
if c.slip44 == slip44:
return c
raise ValueError("Unknown coin slip44 index %d" % slip44)
from apps.common.coininfo import by_name