2018-08-30 13:34:14 +00:00
# Common Tools
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
This directory contains mostly tools that can manipulate definitions in [defs/ ](../defs ).
Tools are written with [Click ](http://click.pocoo.org/6/ ), so you always get a help text
if you use the `--help` option.
2024-06-12 10:08:07 +00:00
All tools require Python 3.8 or higher and a bunch of dependencies, listed in `requirements.txt` .
2018-08-30 13:34:14 +00:00
You can install them all with `pip3 install -r requirements.txt` .
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
## Tools overview
2018-07-30 13:59:14 +00:00
2018-08-15 16:46:00 +00:00
### `cointool.py`
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
This is a general-purpose tool to examine coin definitions. Currently it implements
the following commands:
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
* **`render`**: generate code based on a [Mako ](http://docs.makotemplates.org/en/latest/index.html )
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.
2018-09-14 13:57:11 +00:00
* **`dump`**: dump coin information, including support status, in JSON format. Various
filtering options are available, check help for details.
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
Use `cointool.py command --help` to get more information on each command.
### `support.py`
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
Used to query and manage info in `support.json` . This mainly supports the release flow.
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
The following commands are available:
* **`check`**: check validity of json data. Used in CI.
2023-02-08 11:58:42 +00:00
* **`fix`**: prune keys without associated coins.
2018-08-30 13:34:14 +00:00
* **`show`**: keyword-search for a coin and show its support status for each device.
* **`set`**: set support data.
* **`release`**: perform the [release workflow ](#release-workflow ).
Use `support.py command --help` to get more information on each command.
2018-07-30 13:59:14 +00:00
2018-08-30 13:34:14 +00:00
### `coin_info.py`
In case where code generation with `cointool.py render` is impractical or not sufficient,
you can query the data directly through Python. Short usage example:
```python
import coin_info
defs = coin_info.coin_info()
list_of_all_coins = defs.as_list()
dict_by_coin_key = defs.as_dict()
for token in defs.erc20:
print(token["key"], token["name"], token["shortcut"])
support_info = coin_info.support_info(defs.misc)
for key, support in support_info.values():
2023-08-28 14:46:57 +00:00
t2_support = support["T2T1"]
2018-08-30 13:34:14 +00:00
coin_name = dict_by_coin_key[key]
2021-09-20 10:37:56 +00:00
if t2_support:
2018-08-30 13:34:14 +00:00
print(coin_name, "is supported since version", t2_support)
else:
print(coin_name, "is not supported")
```
See docstrings for the most important functions: `coin_info()` and `support_info()` .
The file `coindef.py` is a protobuf definition for passing coin data to Trezor
from the outside.
2020-08-24 22:21:24 +00:00
### `marketcap.py`
2022-06-15 10:27:48 +00:00
Module for obtaining market cap and price data used by `maxfee.py` .
2020-08-24 22:21:24 +00:00
### `maxfee.py`
Updates the `maxfee_kb` coin property based on a specified maximum per-transaction fee. The command
fetches current price data from https://coinmarketcap.com/ to convert from fiat-denominated maximum
fee.
2018-08-30 13:34:14 +00:00
# Release Workflow
2021-09-20 10:37:56 +00:00
This entails collecting information on coins whose support status is unknown and
2023-02-08 11:58:42 +00:00
bumping timestamp of external definitions < ??? TODO>.
2018-08-30 13:34:14 +00:00
## Maintaining Support Status
When a new coin definition is added, its support status is _unknown_ . It is excluded
from code generation by default. If you want to include a coin in a firmware build,
2021-09-20 10:37:56 +00:00
you need to switch it to supported in a particular version first. You can set multiple
support statuses at the same time:
2018-08-30 13:34:14 +00:00
```
$ ./support.py show Ontology
misc:ONT - Ontology (ONT)
* connect : NO
2023-08-28 14:46:57 +00:00
* T1B1 : support info missing
* T2T1 : support info missing
2021-03-17 14:31:14 +00:00
* suite : NO
2018-08-30 13:34:14 +00:00
2023-08-28 14:46:57 +00:00
$ ./support.py set misc:ONT T1B1=no -r "not planned on T1" T2T1=2.4.7
2018-08-30 13:34:14 +00:00
misc:ONT - Ontology (ONT)
* connect : NO
2023-08-28 14:46:57 +00:00
* T1B1 : NO (reason: not planned on T1)
* T2T1 : 2.4.7
2021-03-17 14:31:14 +00:00
* suite : NO
2018-08-30 13:34:14 +00:00
```
Afterwards, review and commit changes to `defs/support.json` , and update the `trezor-common`
submodule in your target firmware.
## Releasing a new firmware
2022-06-15 10:27:48 +00:00
#### **Step 1:** run the release script
2018-08-30 13:34:14 +00:00
```sh
2022-06-15 10:27:48 +00:00
./tools/release.sh
2018-08-30 13:34:14 +00:00
```
Coins in state _unknown_ , i.e., coins that are known in the definitions but not listed
2023-02-08 11:58:42 +00:00
in support files, will be interactively added one by one. To avoid that, run `support.py
release -y` separately.
2018-07-30 13:59:14 +00:00
2022-06-15 10:27:48 +00:00
#### **Step 2:** review and commit your changes
2018-07-30 13:59:14 +00:00
2023-02-08 11:58:42 +00:00
Use `git diff` to review changes made, commit and push.