Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/chainparams/generate_chainparams_constants.py
Show All 10 Lines | as an argument: | ||||
chainparams_main.txt | chainparams_main.txt | ||||
chainparams_test.txt | chainparams_test.txt | ||||
These files must consist of lines in the format | These files must consist of lines in the format | ||||
<assumevalid hash> | <assumevalid hash> | ||||
<minimum chainwork> | <minimum chainwork> | ||||
<assumed blockchain size on disk (in GB)> | |||||
<assumed chainstate size on disk (in GB)> | |||||
The outputted constants should be pasted into `src/chainparamsconstants.h`. | The outputted constants should be pasted into `src/chainparamsconstants.h`. | ||||
''' | ''' | ||||
import sys | import sys | ||||
import os | import os | ||||
def process_constants(indir, file_name): | def process_constants(indir, file_name): | ||||
with open(os.path.join(indir, file_name), 'r', encoding="utf8") as f: | with open(os.path.join(indir, file_name), 'r', encoding="utf8") as f: | ||||
constants = f.readlines() | constants = f.readlines() | ||||
# Ensure only two lines are read from the file. | # Ensure only the expected number of lines are read from the file | ||||
assert(len(constants) == 2) | assert(len(constants) == 4) | ||||
return [line.rstrip() for line in constants] | return [line.rstrip() for line in constants] | ||||
def main(): | def main(): | ||||
if len(sys.argv) != 2: | if len(sys.argv) != 2: | ||||
print('Usage: {} <dir_with_chainparams_txt>'.format( | print('Usage: {} <dir_with_chainparams_txt>'.format( | ||||
sys.argv[0]), file=sys.stderr) | sys.argv[0]), file=sys.stderr) | ||||
Show All 10 Lines | |||||
*/ | */ | ||||
#include <primitives/blockhash.h> | #include <primitives/blockhash.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
namespace ChainParamsConstants {{ | namespace ChainParamsConstants {{ | ||||
const BlockHash MAINNET_DEFAULT_ASSUME_VALID = BlockHash::fromHex("{}"); | const BlockHash MAINNET_DEFAULT_ASSUME_VALID = BlockHash::fromHex("{}"); | ||||
const uint256 MAINNET_MINIMUM_CHAIN_WORK = uint256S("{}"); | const uint256 MAINNET_MINIMUM_CHAIN_WORK = uint256S("{}"); | ||||
const uint64_t MAINNET_ASSUMED_BLOCKCHAIN_SIZE = {}; | |||||
const uint64_t MAINNET_ASSUMED_CHAINSTATE_SIZE = {}; | |||||
const BlockHash TESTNET_DEFAULT_ASSUME_VALID = BlockHash::fromHex("{}"); | const BlockHash TESTNET_DEFAULT_ASSUME_VALID = BlockHash::fromHex("{}"); | ||||
const uint256 TESTNET_MINIMUM_CHAIN_WORK = uint256S("{}"); | const uint256 TESTNET_MINIMUM_CHAIN_WORK = uint256S("{}"); | ||||
const uint64_t TESTNET_ASSUMED_BLOCKCHAIN_SIZE = {}; | |||||
const uint64_t TESTNET_ASSUMED_CHAINSTATE_SIZE = {}; | |||||
}} // namespace ChainParamsConstants | }} // namespace ChainParamsConstants | ||||
#endif // BITCOIN_CHAINPARAMSCONSTANTS_H\ | #endif // BITCOIN_CHAINPARAMSCONSTANTS_H\ | ||||
'''.format( | '''.format( | ||||
# 'generated' is split out so this file is not identified as generated. | # 'generated' is split out so this file is not identified as generated. | ||||
"generated", | "generated", | ||||
*process_constants(indir, 'chainparams_main.txt'), | *process_constants(indir, 'chainparams_main.txt'), | ||||
*process_constants(indir, 'chainparams_test.txt')) | *process_constants(indir, 'chainparams_test.txt')) | ||||
) | ) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |