1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

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.
This commit is contained in:
matejcik 2018-09-04 15:28:06 +02:00
parent 50a619e12d
commit 9342b52c6b
2 changed files with 26 additions and 11 deletions

View File

@ -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.

View File

@ -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:
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"]]
by_name[coin["name"]] = coin
# 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")