This adds a netmagic command to bitcoin-util. It will return the network magic bytes of the selected chain:
$ bitcoin-util netmagic
f9beb4d9
$ bitcoin-util -regtest netmagic
fabfb5da
$ bitcoin-util -testnet4 netmagic
1c163f28
$ bitcoin-util -signet netmagic
0a03cf40
# default challenge
$ bitcoin-util -signet -signetchallenge=512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae netmagic
0a03cf40
$ bitcoin-util -signet -signetchallenge=51 netmagic
54d26fbd
This will be particularly useful for #34566 to determine the datadir path of a custom signet, before starting bitcoind, since #34566 will add the network magic as a suffix. This was mentioned in #34566 (comment). It uses the same code from init.cpp to print the signet derived magic:
Since it does not depend on #34566, and the changes are quite simple, I created a separate PR for this for easier review and discussion.
I have tested this by invoking the command with the options above.