2018-08-22 11:48:32 +00:00
|
|
|
# generated from coininfo.py.mako
|
|
|
|
# do not edit manually!
|
2019-08-22 18:15:16 +00:00
|
|
|
from trezor import utils
|
2018-10-14 14:08:37 +00:00
|
|
|
from trezor.crypto.base58 import blake256d_32, groestl512d_32, keccak_32, sha256d_32
|
2018-10-10 12:45:59 +00:00
|
|
|
from trezor.crypto.scripts import blake256_ripemd160_digest, sha256_ripemd160_digest
|
2018-08-22 11:48:32 +00:00
|
|
|
|
2019-05-22 12:55:32 +00:00
|
|
|
# flake8: noqa
|
|
|
|
|
2018-08-22 11:48:32 +00:00
|
|
|
|
|
|
|
class CoinInfo:
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
coin_name: str,
|
|
|
|
coin_shortcut: str,
|
2019-12-09 16:43:30 +00:00
|
|
|
decimals: int,
|
2018-08-22 11:48:32 +00:00
|
|
|
address_type: int,
|
|
|
|
address_type_p2sh: int,
|
|
|
|
maxfee_kb: int,
|
|
|
|
signed_message_header: str,
|
|
|
|
xpub_magic: int,
|
2018-09-05 13:42:31 +00:00
|
|
|
xpub_magic_segwit_p2sh: int,
|
|
|
|
xpub_magic_segwit_native: int,
|
2018-08-22 11:48:32 +00:00
|
|
|
bech32_prefix: str,
|
|
|
|
cashaddr_prefix: str,
|
|
|
|
slip44: int,
|
|
|
|
segwit: bool,
|
|
|
|
fork_id: int,
|
|
|
|
force_bip143: bool,
|
2018-09-21 10:52:32 +00:00
|
|
|
decred: bool,
|
2019-08-09 14:01:28 +00:00
|
|
|
negative_fee: bool,
|
2018-08-22 11:48:32 +00:00
|
|
|
curve_name: str,
|
2020-03-09 21:23:27 +00:00
|
|
|
extra_data: bool,
|
|
|
|
timestamp: bool,
|
2020-03-12 14:13:08 +00:00
|
|
|
overwintered: bool,
|
2019-08-12 10:52:20 +00:00
|
|
|
confidential_assets: dict,
|
2018-08-22 11:48:32 +00:00
|
|
|
):
|
|
|
|
self.coin_name = coin_name
|
|
|
|
self.coin_shortcut = coin_shortcut
|
2019-12-09 16:43:30 +00:00
|
|
|
self.decimals = decimals
|
2018-08-22 11:48:32 +00:00
|
|
|
self.address_type = address_type
|
|
|
|
self.address_type_p2sh = address_type_p2sh
|
|
|
|
self.maxfee_kb = maxfee_kb
|
|
|
|
self.signed_message_header = signed_message_header
|
|
|
|
self.xpub_magic = xpub_magic
|
2018-09-05 13:42:31 +00:00
|
|
|
self.xpub_magic_segwit_p2sh = xpub_magic_segwit_p2sh
|
|
|
|
self.xpub_magic_segwit_native = xpub_magic_segwit_native
|
2018-08-22 11:48:32 +00:00
|
|
|
self.bech32_prefix = bech32_prefix
|
|
|
|
self.cashaddr_prefix = cashaddr_prefix
|
|
|
|
self.slip44 = slip44
|
|
|
|
self.segwit = segwit
|
|
|
|
self.fork_id = fork_id
|
|
|
|
self.force_bip143 = force_bip143
|
2018-09-21 10:52:32 +00:00
|
|
|
self.decred = decred
|
2019-08-09 14:01:28 +00:00
|
|
|
self.negative_fee = negative_fee
|
2018-08-22 11:48:32 +00:00
|
|
|
self.curve_name = curve_name
|
2020-03-09 21:23:27 +00:00
|
|
|
self.extra_data = extra_data
|
|
|
|
self.timestamp = timestamp
|
2020-03-12 14:13:08 +00:00
|
|
|
self.overwintered = overwintered
|
2019-08-12 10:52:20 +00:00
|
|
|
self.confidential_assets = confidential_assets
|
2018-08-22 11:48:32 +00:00
|
|
|
if curve_name == "secp256k1-groestl":
|
|
|
|
self.b58_hash = groestl512d_32
|
|
|
|
self.sign_hash_double = False
|
2018-10-10 12:45:59 +00:00
|
|
|
self.script_hash = sha256_ripemd160_digest
|
2018-10-08 12:34:51 +00:00
|
|
|
elif curve_name == "secp256k1-decred":
|
2018-10-14 14:08:37 +00:00
|
|
|
self.b58_hash = blake256d_32
|
2018-10-08 12:34:51 +00:00
|
|
|
self.sign_hash_double = False
|
2018-10-10 12:45:59 +00:00
|
|
|
self.script_hash = blake256_ripemd160_digest
|
2018-10-13 02:13:18 +00:00
|
|
|
elif curve_name == "secp256k1-smart":
|
2018-10-14 14:08:37 +00:00
|
|
|
self.b58_hash = keccak_32
|
2018-10-13 02:13:18 +00:00
|
|
|
self.sign_hash_double = False
|
|
|
|
self.script_hash = sha256_ripemd160_digest
|
2018-08-22 11:48:32 +00:00
|
|
|
else:
|
|
|
|
self.b58_hash = sha256d_32
|
|
|
|
self.sign_hash_double = True
|
2018-10-10 12:45:59 +00:00
|
|
|
self.script_hash = sha256_ripemd160_digest
|
2018-08-22 11:48:32 +00:00
|
|
|
|
2019-05-22 20:46:22 +00:00
|
|
|
def __eq__(self, other):
|
|
|
|
if not isinstance(other, CoinInfo):
|
|
|
|
return NotImplemented
|
|
|
|
return self.coin_name == other.coin_name
|
|
|
|
|
2018-08-22 11:48:32 +00:00
|
|
|
|
|
|
|
# fmt: off
|
|
|
|
<%
|
|
|
|
def hexfmt(x):
|
|
|
|
if x is None:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return "0x{:08x}".format(x)
|
|
|
|
|
2019-08-12 10:52:20 +00:00
|
|
|
def optional_dict(x):
|
|
|
|
if x is None:
|
|
|
|
return None
|
|
|
|
return dict(x)
|
|
|
|
|
2018-08-22 11:48:32 +00:00
|
|
|
ATTRIBUTES = (
|
2019-05-22 12:55:32 +00:00
|
|
|
("coin_name", lambda _: "name"),
|
2018-08-22 11:48:32 +00:00
|
|
|
("coin_shortcut", black_repr),
|
2019-12-09 16:43:30 +00:00
|
|
|
("decimals", int),
|
2018-08-22 11:48:32 +00:00
|
|
|
("address_type", int),
|
|
|
|
("address_type_p2sh", int),
|
|
|
|
("maxfee_kb", int),
|
|
|
|
("signed_message_header", black_repr),
|
|
|
|
("xpub_magic", hexfmt),
|
2018-09-05 13:42:31 +00:00
|
|
|
("xpub_magic_segwit_p2sh", hexfmt),
|
|
|
|
("xpub_magic_segwit_native", hexfmt),
|
2018-08-22 11:48:32 +00:00
|
|
|
("bech32_prefix", black_repr),
|
|
|
|
("cashaddr_prefix", black_repr),
|
|
|
|
("slip44", int),
|
|
|
|
("segwit", bool),
|
|
|
|
("fork_id", black_repr),
|
|
|
|
("force_bip143", bool),
|
2018-09-21 10:52:32 +00:00
|
|
|
("decred", bool),
|
2019-08-09 14:01:28 +00:00
|
|
|
("negative_fee", bool),
|
2018-08-22 11:48:32 +00:00
|
|
|
("curve_name", lambda r: repr(r.replace("_", "-"))),
|
2020-03-09 21:23:27 +00:00
|
|
|
("extra_data", bool),
|
|
|
|
("timestamp", bool),
|
2020-03-12 14:13:08 +00:00
|
|
|
("overwintered", bool),
|
2019-08-12 10:52:20 +00:00
|
|
|
("confidential_assets", optional_dict),
|
2018-08-22 11:48:32 +00:00
|
|
|
)
|
2019-08-22 18:15:16 +00:00
|
|
|
|
|
|
|
btc_names = ["Bitcoin", "Testnet", "Regtest"]
|
|
|
|
|
|
|
|
coins_btc = [c for c in supported_on("trezor2", bitcoin) if c.name in btc_names]
|
|
|
|
coins_alt = [c for c in supported_on("trezor2", bitcoin) if c.name not in btc_names]
|
|
|
|
|
2020-03-12 14:13:08 +00:00
|
|
|
for c in coins_btc + coins_alt:
|
|
|
|
c.overwintered = bool(c.consensus_branch_id)
|
|
|
|
|
2018-08-22 11:48:32 +00:00
|
|
|
%>\
|
2019-05-22 12:55:32 +00:00
|
|
|
def by_name(name: str) -> CoinInfo:
|
|
|
|
if False:
|
|
|
|
pass
|
2019-08-22 18:15:16 +00:00
|
|
|
% for coin in coins_btc:
|
2019-05-22 12:55:32 +00:00
|
|
|
elif name == ${black_repr(coin["coin_name"])}:
|
|
|
|
return CoinInfo(
|
|
|
|
% for attr, func in ATTRIBUTES:
|
|
|
|
${attr}=${func(coin[attr])},
|
|
|
|
% endfor
|
|
|
|
)
|
2019-08-22 18:15:16 +00:00
|
|
|
% endfor
|
|
|
|
if not utils.BITCOIN_ONLY:
|
|
|
|
if False:
|
|
|
|
pass
|
|
|
|
% for coin in coins_alt:
|
|
|
|
elif name == ${black_repr(coin["coin_name"])}:
|
|
|
|
return CoinInfo(
|
|
|
|
% for attr, func in ATTRIBUTES:
|
|
|
|
${attr}=${func(coin[attr])},
|
|
|
|
% endfor
|
|
|
|
)
|
2018-08-22 11:48:32 +00:00
|
|
|
% endfor
|
2019-05-22 12:55:32 +00:00
|
|
|
raise ValueError('Unknown coin name "%s"' % name)
|