mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-06 06:42:33 +00:00
core: store bitcoin-like coins as a decision tree
This commit is contained in:
parent
9676eec4df
commit
1f3adc7069
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,8 @@
|
|||||||
from trezor.crypto.base58 import blake256d_32, groestl512d_32, keccak_32, sha256d_32
|
from trezor.crypto.base58 import blake256d_32, groestl512d_32, keccak_32, sha256d_32
|
||||||
from trezor.crypto.scripts import blake256_ripemd160_digest, sha256_ripemd160_digest
|
from trezor.crypto.scripts import blake256_ripemd160_digest, sha256_ripemd160_digest
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
|
||||||
class CoinInfo:
|
class CoinInfo:
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -71,7 +73,7 @@ def hexfmt(x):
|
|||||||
return "0x{:08x}".format(x)
|
return "0x{:08x}".format(x)
|
||||||
|
|
||||||
ATTRIBUTES = (
|
ATTRIBUTES = (
|
||||||
("coin_name", black_repr),
|
("coin_name", lambda _: "name"),
|
||||||
("coin_shortcut", black_repr),
|
("coin_shortcut", black_repr),
|
||||||
("address_type", int),
|
("address_type", int),
|
||||||
("address_type_p2sh", int),
|
("address_type_p2sh", int),
|
||||||
@ -91,12 +93,15 @@ ATTRIBUTES = (
|
|||||||
("curve_name", lambda r: repr(r.replace("_", "-"))),
|
("curve_name", lambda r: repr(r.replace("_", "-"))),
|
||||||
)
|
)
|
||||||
%>\
|
%>\
|
||||||
COINS = [
|
def by_name(name: str) -> CoinInfo:
|
||||||
|
if False:
|
||||||
|
pass
|
||||||
% for coin in supported_on("trezor2", bitcoin):
|
% for coin in supported_on("trezor2", bitcoin):
|
||||||
CoinInfo(
|
elif name == ${black_repr(coin["coin_name"])}:
|
||||||
% for attr, func in ATTRIBUTES:
|
return CoinInfo(
|
||||||
${attr}=${func(coin[attr])},
|
% for attr, func in ATTRIBUTES:
|
||||||
% endfor
|
${attr}=${func(coin[attr])},
|
||||||
),
|
% endfor
|
||||||
|
)
|
||||||
% endfor
|
% endfor
|
||||||
]
|
raise ValueError('Unknown coin name "%s"' % name)
|
||||||
|
@ -1,22 +1 @@
|
|||||||
from apps.common.coininfo import COINS
|
from apps.common.coininfo import by_name
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user