Details
- Reviewers
deadalnix Fabien - Group Reviewers
Restricted Project - Commits
- rSTAGINGe03ddb98ec2c: Added a script to generate chainparams constants from intermediate files
rABCe03ddb98ec2c: Added a script to generate chainparams constants from intermediate files
For actually testing the process flow, generate the chainparams_*.txt files:
bitcoind make_chainparams.py > chainparams_main.txt bitcoind --testnet make_chainparams.py -a 127.0.0.1:18332 > chainparams_main.txt
For this diff, I did not do the above, I copied the existing chainparams manually into the chainparams_*.txt files so that we don't add updating those to the review process of this diff.
After the chainparams_*.txt files are ready, do the following:
generate_chainparams_constants.py . make check ninja check
TeamCity IBD
Diff Detail
- Repository
- rABC Bitcoin ABC
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
contrib/devtools/chainparams/generate_chainparams_constants.py | ||
---|---|---|
38 ↗ | (On Diff #13094) | This is what print does by default, you can replace output.write with print and this line becomes unecessary. |
59 ↗ | (On Diff #13094) | You can use a single text block (heredoc style) and format it to improve the readability. |
59 ↗ | (On Diff #13094) | I came to an example: def process_constants(indir, file_name): with open(os.path.join(indir, file_name), 'r', encoding="utf8") as f: constants = f.readlines() return [line.strip() for line in constants] def main(): if len(sys.argv) != 2: print('Usage: {} <path_to_chainparams_txt>'.format(sys.argv[0]), file=sys.stderr) sys.exit(1) indir = sys.argv[1] print(''' #ifndef BITCOIN_CHAINPARAMSCONSTANTS_H #define BITCOIN_CHAINPARAMSCONSTANTS_H /** * @{} by contrib/devtools/chainparams/generate_chainparams_constants.py */ #include <uint256.h> namespace ChainParamsConstants {{ const uint256 MAINNET_DEFAULT_ASSUME_VALID = uint256S("{}"); const uint256 MAINNET_MINIMUM_CHAIN_WORK = uint256S("{}"); const uint256 TESTNET_DEFAULT_ASSUME_VALID = uint256S("{}"); const uint256 TESTNET_MINIMUM_CHAIN_WORK = uint256S("{}"); }} // namespace ChainParamsConstants #endif // BITCOIN_CHAINPARAMSCONSTANTS_H '''.format( "generated", *process_constants(indir, 'chainparams_main.txt'), *process_constants(indir, 'chainparams_test.txt'))[1:-1] ) |
Incorporated feedback with a minor adjustment to simplify the formatting of newlines at the beginning and end of the generated output.
contrib/devtools/chainparams/generate_chainparams_constants.py | ||
---|---|---|
30 ↗ | (On Diff #13121) | Assert that there are exactly 2 lines before returning, otherwise the output can silently corrupt. |
contrib/devtools/chainparams/generate_chainparams_constants.py | ||
---|---|---|
41 ↗ | (On Diff #13121) | Should we add a copyright header to generated files ? |
contrib/devtools/chainparams/generate_chainparams_constants.py | ||
---|---|---|
41 ↗ | (On Diff #13121) | Considering that chainparamsseeds.h doesn't have one, it probably doesn't matter much. |