From d235875e5eb2c2503ae6e1996970aff5ab3ef56b Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 4 Sep 2018 15:36:56 +0200 Subject: [PATCH] build: support new tooling in trezor-common --- setup.py | 30 ++++++++++++++++++++---------- trezorlib/coins.py | 3 ++- vendor/trezor-common | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 6840c817c9..7322ef2e10 100755 --- a/setup.py +++ b/setup.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 import glob +import json import os.path import re -import shutil import subprocess import sys -import tempfile from distutils.errors import DistutilsError from setuptools import Command, find_packages, setup @@ -42,6 +41,22 @@ def find_version(): raise RuntimeError("Version string not found") +def build_coins_json(dst): + TOOLS_PATH = os.path.join(TREZOR_COMMON, "tools") + sys.path.insert(0, TOOLS_PATH) + import coin_info + + coins = coin_info.coin_info().bitcoin + support = coin_info.support_info(coins) + for coin in coins: + coin["support"] = support[coin["key"]] + + with open(dst, "w") as f: + json.dump(coins, f, indent=2, sort_keys=True) + + del sys.path[0] + + class PrebuildCommand(Command): description = "update vendored files (coins.json, protobuf messages)" user_options = [] @@ -58,17 +73,12 @@ class PrebuildCommand(Command): if not os.path.exists(common_defs): raise DistutilsError( "trezor-common submodule seems to be missing.\n" - + 'Use "git submodule update --init" to retrieve it.' + + "Use 'git submodule update --init' to retrieve it." ) # generate and copy coins.json to the tree - with tempfile.TemporaryDirectory() as tmpdir: - build_coins = os.path.join(TREZOR_COMMON, "tools", "cointool.py") - subprocess.check_call([sys.executable, build_coins], cwd=tmpdir) - shutil.copy( - os.path.join(tmpdir, "coins.json"), - os.path.join(CWD, "trezorlib", "coins.json"), - ) + coins_json = os.path.join(CWD, "trezorlib", "coins.json") + build_coins_json(coins_json) # regenerate messages try: diff --git a/trezorlib/coins.py b/trezorlib/coins.py index d81c7e98ba..2c651e0fb9 100644 --- a/trezorlib/coins.py +++ b/trezorlib/coins.py @@ -48,7 +48,8 @@ def _insight_for_coin(coin): __all__ = ["by_name", "slip44", "tx_api"] try: - by_name = _load_coins_json() + coins_list = _load_coins_json() + by_name = {coin["name"]: coin for coin in coins_list} except Exception as e: raise ImportError("Failed to load coins.json. Check your installation.") from e diff --git a/vendor/trezor-common b/vendor/trezor-common index d8f8c882d5..d597243891 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit d8f8c882d5dcad7b90cecb593b424556835c8961 +Subproject commit d5972438919239debf4975329476c181a4fed6ea