From aa64119b9668fad8d9da027caf2a0cd40db02be6 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 12 Feb 2019 10:56:34 +0100 Subject: [PATCH] tools/cointool: add check for segwit fields --- defs/bitcoin/capricoin.json | 4 ++-- tools/cointool.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/defs/bitcoin/capricoin.json b/defs/bitcoin/capricoin.json index f0b82f694b..3b26592774 100644 --- a/defs/bitcoin/capricoin.json +++ b/defs/bitcoin/capricoin.json @@ -14,8 +14,8 @@ "hash_genesis_block": "00000d23fa0fc52c90893adb1181c9ddffb6c797a3e41864b9a23aa2f2981fe3", "xprv_magic": 76066276, "xpub_magic": 76067358, - "xpub_magic_segwit_p2sh": 77429938, - "xpub_magic_segwit_native": 78792518, + "xpub_magic_segwit_p2sh": null, + "xpub_magic_segwit_native": null, "bech32_prefix": null, "cashaddr_prefix": null, "slip44": 289, diff --git a/tools/cointool.py b/tools/cointool.py index 92820cf4f7..10adbf587a 100755 --- a/tools/cointool.py +++ b/tools/cointool.py @@ -411,6 +411,42 @@ def check_key_uniformity(coins): return False +def check_segwit(coins): + for coin in coins: + segwit = coin["segwit"] + if segwit: + if coin["xpub_magic_segwit_native"] is None: + print_log( + logging.WARNING, + coin["name"], + "segwit is True => xpub_magic_segwit_native should be set", + ) + # return False + if coin["xpub_magic_segwit_p2sh"] is None: + print_log( + logging.WARNING, + coin["name"], + "segwit is True => xpub_magic_segwit_p2sh should be set", + ) + # return False + else: + if coin["xpub_magic_segwit_native"] is not None: + print_log( + logging.ERROR, + coin["name"], + "segwit is False => xpub_magic_segwit_native should NOT be set", + ) + return False + if coin["xpub_magic_segwit_p2sh"] is not None: + print_log( + logging.ERROR, + coin["name"], + "segwit is False => xpub_magic_segwit_p2sh should NOT be set", + ) + return False + return True + + # ====== coindefs generators ====== @@ -564,6 +600,10 @@ def check(backend, icons, show_duplicates): if not check_backends(defs.bitcoin): all_checks_passed = False + print("Checking segwit fields...") + if not check_segwit(defs.bitcoin): + all_checks_passed = False + print("Checking key uniformity...") for cointype, coinlist in defs.items(): if cointype in ("erc20", "nem"):