mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
Decouple SigNetChainParams from ArgsManager
SigNet chain params can now be initialized by configuring a SigNetOptions struct, or with ArgsManager. This offers an interface for creating SigNetChainParams without a gArgs object.
This commit is contained in:
parent
b175bdb9b2
commit
76cd4e7c96
2 changed files with 35 additions and 13 deletions
|
@ -277,11 +277,12 @@ public:
|
|||
*/
|
||||
class SigNetParams : public CChainParams {
|
||||
public:
|
||||
explicit SigNetParams(const ArgsManager& args) {
|
||||
explicit SigNetParams(const SigNetOptions& options)
|
||||
{
|
||||
std::vector<uint8_t> bin;
|
||||
vSeeds.clear();
|
||||
|
||||
if (!args.IsArgSet("-signetchallenge")) {
|
||||
if (!options.challenge) {
|
||||
bin = ParseHex("512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae");
|
||||
vSeeds.emplace_back("seed.signet.bitcoin.sprovoost.nl.");
|
||||
|
||||
|
@ -300,12 +301,7 @@ public:
|
|||
.dTxRate = 0.02336701143027275,
|
||||
};
|
||||
} else {
|
||||
const auto signet_challenge = args.GetArgs("-signetchallenge");
|
||||
if (signet_challenge.size() != 1) {
|
||||
throw std::runtime_error(strprintf("%s: -signetchallenge cannot be multiple values.", __func__));
|
||||
}
|
||||
bin = ParseHex(signet_challenge[0]);
|
||||
|
||||
bin = *options.challenge;
|
||||
consensus.nMinimumChainWork = uint256{};
|
||||
consensus.defaultAssumeValid = uint256{};
|
||||
m_assumed_blockchain_size = 0;
|
||||
|
@ -315,11 +311,11 @@ public:
|
|||
0,
|
||||
0,
|
||||
};
|
||||
LogPrintf("Signet with challenge %s\n", signet_challenge[0]);
|
||||
LogPrintf("Signet with challenge %s\n", HexStr(bin));
|
||||
}
|
||||
|
||||
if (args.IsArgSet("-signetseednode")) {
|
||||
vSeeds = args.GetArgs("-signetseednode");
|
||||
if (options.seeds) {
|
||||
vSeeds = *options.seeds;
|
||||
}
|
||||
|
||||
strNetworkID = CBaseChainParams::SIGNET;
|
||||
|
@ -382,11 +378,26 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
|
||||
{
|
||||
if (args.IsArgSet("-signetseednode")) {
|
||||
options.seeds.emplace(args.GetArgs("-signetseednode"));
|
||||
}
|
||||
if (args.IsArgSet("-signetchallenge")) {
|
||||
const auto signet_challenge = args.GetArgs("-signetchallenge");
|
||||
if (signet_challenge.size() != 1) {
|
||||
throw std::runtime_error(strprintf("%s: -signetchallenge cannot be multiple values.", __func__));
|
||||
}
|
||||
options.challenge.emplace(ParseHex(signet_challenge[0]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test: intended for private networks only. Has minimal difficulty to ensure that
|
||||
* blocks can be found instantly.
|
||||
*/
|
||||
class CRegTestParams : public CChainParams {
|
||||
class CRegTestParams : public CChainParams
|
||||
{
|
||||
public:
|
||||
explicit CRegTestParams(const ArgsManager& args) {
|
||||
strNetworkID = CBaseChainParams::REGTEST;
|
||||
|
@ -570,7 +581,9 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
|
|||
} else if (chain == CBaseChainParams::TESTNET) {
|
||||
return std::unique_ptr<CChainParams>(new CTestNetParams());
|
||||
} else if (chain == CBaseChainParams::SIGNET) {
|
||||
return std::unique_ptr<CChainParams>(new SigNetParams(args));
|
||||
auto opts = CChainParams::SigNetOptions{};
|
||||
ReadSigNetArgs(args, opts);
|
||||
return std::make_unique<const SigNetParams>(opts);
|
||||
} else if (chain == CBaseChainParams::REGTEST) {
|
||||
return std::unique_ptr<CChainParams>(new CRegTestParams(args));
|
||||
}
|
||||
|
|
|
@ -122,6 +122,15 @@ public:
|
|||
const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }
|
||||
|
||||
const ChainTxData& TxData() const { return chainTxData; }
|
||||
|
||||
/**
|
||||
* SigNetOptions holds configurations for creating a signet CChainParams.
|
||||
*/
|
||||
struct SigNetOptions {
|
||||
std::optional<std::vector<uint8_t>> challenge{};
|
||||
std::optional<std::vector<std::string>> seeds{};
|
||||
};
|
||||
|
||||
protected:
|
||||
CChainParams() {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue