From 10b248b18fe807cefd93ac373743448a4b235f5a Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Thu, 14 Sep 2023 19:10:25 +0200 Subject: [PATCH] feat(common): cointool: add new-definitions command [no changelog] --- common/tools/cointool.py | 22 ++++++++++++++++++++++ common/tools/release.sh | 1 + 2 files changed, 23 insertions(+) diff --git a/common/tools/cointool.py b/common/tools/cointool.py index e38aad759..67e9f9449 100755 --- a/common/tools/cointool.py +++ b/common/tools/cointool.py @@ -21,6 +21,9 @@ from coin_info import Coin, CoinBuckets, Coins, CoinsInfo, FidoApps, SupportInfo DEFINITIONS_TIMESTAMP_PATH = ( coin_info.DEFS_DIR / "ethereum" / "released-definitions-timestamp.txt" ) +DEFINITIONS_LATEST_URL = ( + "https://raw.githubusercontent.com/trezor/definitions/main/definitions-latest.json" +) try: import termcolor @@ -912,5 +915,24 @@ def render( do_render(file, dst) +@cli.command() +# fmt: off +@click.option("-v", "--verbose", is_flag=True, help="Print timestamp and merkle root") +# fmt: on +def new_definitions(verbose: bool) -> None: + """Update timestamp of external coin definitions.""" + assert requests is not None + eth_defs = requests.get(DEFINITIONS_LATEST_URL).json() + eth_defs_date = eth_defs["metadata"]["datetime"] + if verbose: + click.echo( + f"Latest definitions from {eth_defs_date}: {eth_defs['metadata']['merkle_root']}" + ) + eth_defs_date = datetime.datetime.fromisoformat(eth_defs_date) + DEFINITIONS_TIMESTAMP_PATH.write_text( + eth_defs_date.isoformat(timespec="seconds") + "\n" + ) + + if __name__ == "__main__": cli() diff --git a/common/tools/release.sh b/common/tools/release.sh index 3e6a34bd2..9c7ba8482 100755 --- a/common/tools/release.sh +++ b/common/tools/release.sh @@ -7,6 +7,7 @@ trap "rm -r $CHECK_OUTPUT" EXIT $HERE/cointool.py check > $CHECK_OUTPUT/pre.txt +$HERE/cointool.py new-definitions -v $HERE/support.py release $HERE/cointool.py check > $CHECK_OUTPUT/post.txt