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 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). 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. * **`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. * **`dump`**: dump all coin information, including support status, in JSON format.
This file contains data on Bitcoin-like coins and their support status.
* **`coindefs`**: generate signed protobuf descriptions of coins. This is for future use * **`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. 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() @cli.command()
@click.option("-o", "--outfile", type=click.File(mode="w"), default="./coins.json") @click.option("-o", "--outfile", type=click.File(mode="w"), default="./coins.json")
def coins_json(outfile): def dump(outfile):
"""Generate coins.json for consumption in python-trezor and Connect/Wallet""" """Dump all coin data in a single JSON file.
coins = coin_info.coin_info().bitcoin
support_info = coin_info.support_info(coins) This file is structured the same as the internal data. That is, top-level object
by_name = {} is a dict with keys: 'bitcoin', 'eth', 'erc20', 'nem' and 'misc'. Value for each
for coin in coins: key is a list of dicts, each describing a known coin.
coin["support"] = support_info[coin["key"]]
by_name[coin["name"]] = 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: with outfile:
json.dump(by_name, outfile, indent=4, sort_keys=True) json.dump(coins, outfile, indent=4, sort_keys=True)
outfile.write("\n") outfile.write("\n")