From 9342b52c6b4227774fada0425443407fedf76997 Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 4 Sep 2018 15:28:06 +0200 Subject: [PATCH] cointool: replace 'coins_json' with 'dump' `cointool.py coins_json` generated an old-style `coins.json` file with entries on bitcoin-like coins. This is no longe really doing what we need. Instead, the new command `dump` will output _all available data_ in the same format as Python sees it. Much more useful for other kinds of consumers. --- tools/README.md | 3 +-- tools/cointool.py | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tools/README.md b/tools/README.md index 680553f631..cb65b5aff2 100644 --- a/tools/README.md +++ b/tools/README.md @@ -19,8 +19,7 @@ the following commands: template. By default, `cointool.py render foo.bar.mako` will put its result into file `foo.bar` in the same directory. See [usage in `trezor-core`](https://github.com/trezor/trezor-core/commit/348b99b8dc5bcfc4ab85e1e7faad3fb4ef3e8763). * **`check`**: check validity of json definitions and associated data. Used in CI. -* **`coins_json`**: generate `coins.json` file for use in Connect, webwallet and python-trezor. - This file contains data on Bitcoin-like coins and their support status. +* **`dump`**: dump all coin information, including support status, in JSON format. * **`coindefs`**: generate signed protobuf descriptions of coins. This is for future use and could allow us to not need to store coin data in Trezor itself. diff --git a/tools/cointool.py b/tools/cointool.py index 1d3fbd070d..ca6a3708a1 100755 --- a/tools/cointool.py +++ b/tools/cointool.py @@ -542,17 +542,33 @@ def check(backend, icons, show_duplicates): @cli.command() @click.option("-o", "--outfile", type=click.File(mode="w"), default="./coins.json") -def coins_json(outfile): - """Generate coins.json for consumption in python-trezor and Connect/Wallet""" - coins = coin_info.coin_info().bitcoin - support_info = coin_info.support_info(coins) - by_name = {} - for coin in coins: - coin["support"] = support_info[coin["key"]] - by_name[coin["name"]] = coin +def dump(outfile): + """Dump all coin data in a single JSON file. + + This file is structured the same as the internal data. That is, top-level object + is a dict with keys: 'bitcoin', 'eth', 'erc20', 'nem' and 'misc'. Value for each + key is a list of dicts, each describing a known coin. + + \b + Fields are category-specific, except for four common ones: + - 'name' - human-readable name + - 'shortcut' - currency symbol + - 'key' - unique identifier, e.g., 'bitcoin:BTC' + - 'support' - a dict with entries per known device + """ + coins = coin_info.coin_info() + support_info = coin_info.support_info(coins.as_list()) + + for category in coins.values(): + for coin in category: + coin["support"] = support_info[coin["key"]] + + # get rid of address_bytes which are bytes which can't be JSON encoded + for coin in coins.erc20: + coin.pop("address_bytes", None) with outfile: - json.dump(by_name, outfile, indent=4, sort_keys=True) + json.dump(coins, outfile, indent=4, sort_keys=True) outfile.write("\n")