diff --git a/contrib/devtools/chainparams/generate_chainparams_constants.py b/contrib/devtools/chainparams/generate_chainparams_constants.py new file mode 100755 --- /dev/null +++ b/contrib/devtools/chainparams/generate_chainparams_constants.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# Copyright (c) 2019 The Bitcoin developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +''' +Script to generate list of chainparams constants (ie. assumevalid and +minimum chainwork). + +This script expects a text file for each chain in the directory that is passed +as an argument: + + chainparams_main.txt + chainparams_test.txt + +These files must consist of lines in the format + + + + +The outputted constants should be pasted into `src/chainparamsconstants.h`. +''' + +import sys +import os + + +def process_constants(output, f, chainName): + output.write(' static const uint256 {}_DEFAULT_ASSUME_VALID = uint256S("{}");\n'.format(chainName, f.readline())) + output.write(' static const uint256 {}_MINIMUM_CHAIN_WORK = uint256S("{}");\n'.format(chainName, f.readline)) + + +def main(): + if len(sys.argv) != 2: + print('Usage: {} '.format(sys.argv[0]), file=sys.stderr) + sys.exit(1) + output = sys.stdout + indir = sys.argv[1] + output.write('#ifndef BITCOIN_CHAINPARAMSCONSTANTS_H\n') + output.write('#define BITCOIN_CHAINPARAMSCONSTANTS_H\n') + output.write('/**\n') + output.write(' * Chain params constants for each tracked chain.\n') + output.write(' * @generated by contrib/devtools/chainparams/generate_chainparams_constants.py\n') + output.write(' */\n') + output.write('\n') + output.write('#include \n') + output.write('\n') + output.write('namespace ChainParamsConstants {\n') + with open(os.path.join(indir, 'chainparams_main.txt'), 'r', encoding="utf8") as f: + process_constants(output, f, 'MAINNET') + output.write('\n') + with open(os.path.join(indir, 'chainparams_test.txt'), 'r', encoding="utf8") as f: + process_constants(output, f, 'TESTNET') + output.write('}\n') + output.write('\n') + output.write('#endif // BITCOIN_CHAINPARAMSCONSTANTS_H\n') + + +if __name__ == '__main__': + main()