Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/generate-bestchainparams.sh
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
#!/bin/bash | |||||
# set -e Script exits immediately when a command fails. | |||||
# set -u Treats unset variables as a failure. | |||||
set -eu | |||||
help_message() { | |||||
echo "Generate a chainparams chain source file." | |||||
echo "Usage: $0 <options> > chainparamsbestchainmainnet.h" | |||||
Fabien: The script help message doesn't match the code, it states that every argument is an option… | |||||
echo "-b, --blockhash <hash> The block hash to update defaultAssumeValid to." | |||||
echo "-c, --chainwork <hex> The chainwork to update nMinimumChainWork to." | |||||
echo "-t, --testnet If set, testnet chainparams will be updated instead of mainnet chainparams." | |||||
} | |||||
BLOCK_HASH="" | |||||
CHAIN_WORK="" | |||||
CHAIN="MainNet" | |||||
# Parse command line arguments | |||||
while [[ $# -gt 0 ]]; do | |||||
case "$1" in | |||||
-b|--blockhash) | |||||
BLOCK_HASH="$2" | |||||
shift # shift past argument | |||||
shift # shift past value | |||||
;; | |||||
-c|--chainwork) | |||||
CHAIN_WORK="$2" | |||||
shift # shift past argument | |||||
shift # shift past value | |||||
;; | |||||
-h|--help) | |||||
help_message | |||||
exit 0 | |||||
;; | |||||
-t|--testnet) | |||||
CHAIN="TestNet" | |||||
shift # shift past argument | |||||
;; | |||||
*) | |||||
echo "Unknown argument: $1" | |||||
help_message | |||||
exit 1 | |||||
;; | |||||
esac | |||||
done | |||||
if [ -z "$BLOCK_HASH" ]; then | |||||
echo "Block hash is not set." | |||||
echo "" | |||||
help_message | |||||
exit 1 | |||||
fi | |||||
if [[ ! "$BLOCK_HASH" =~ ^[0-9a-z]{64}$ ]]; then | |||||
FabienUnsubmitted Not Done Inline Actions[0-9a-f] is enough Fabien: `[0-9a-f]` is enough | |||||
echo "Block hash is not a valid block hash." | |||||
exit 1 | |||||
fi | |||||
if [ -z "$CHAIN_WORK" ]; then | |||||
echo "Chain work is not set." | |||||
echo "" | |||||
help_message | |||||
exit 1 | |||||
fi | |||||
if [[ ! "$CHAIN_WORK" =~ ^[0-9a-z]{64}$ ]]; then | |||||
FabienUnsubmitted Not Done Inline ActionsDito Fabien: Dito | |||||
echo "Chain work is not a valid uint256 hex value." | |||||
exit 1 | |||||
fi | |||||
echo "// Copyright (c) 2019 The Bitcoin developers" | |||||
echo "// Distributed under the MIT software license, see the accompanying" | |||||
echo "// file COPYING or http://www.opensource.org/licenses/mit-license.php." | |||||
echo "" | |||||
echo "// This file is autogenerated. See /contrib/devtools/generate-chainparams.sh" | |||||
echo "" | |||||
echo "#ifndef BITCOIN_CHAINPARAMSBESTCHAIN${CHAIN^^}_H" | |||||
echo "#define BITCOIN_CHAINPARAMSBESTCHAIN${CHAIN^^}_H" | |||||
echo "" | |||||
echo "#include <uint256.h>" | |||||
echo "" | |||||
echo "static inline uint256 Get${CHAIN}MinimumChainWork() {" | |||||
echo " return uint256S(" | |||||
echo " \"${CHAIN_WORK}\");" | |||||
echo "};" | |||||
echo "" | |||||
echo "static inline uint256 Get${CHAIN}DefaultAssumeValid() {" | |||||
echo " return uint256S(" | |||||
echo " \"${BLOCK_HASH}\");" | |||||
echo "};" | |||||
echo "#endif // BITCOIN_CHAINPARAMSBESTCHAIN${CHAIN^^}_H" | |||||
deadalnixUnsubmitted Not Done Inline ActionsSo this is just formatting a string? You realize that the caller will have to format a string, with the parameters, to create a command line? This part of the patch is absolutely not useful. deadalnix: So this is just formatting a string?
You realize that the caller will have to format a string… |
The script help message doesn't match the code, it states that every argument is an option while 2 over 3 are mandatory.