Skip to content

Commit

Permalink
Enable signet chain configs
Browse files Browse the repository at this point in the history
This enables adding of signet chain configs in bitcoin.conf.
This enables running of multiple signets with diffrent configurations

i.e
chain=signet_xxxx

[signet_xxxx]
seednodes=x.x.x.x
signetchallenge=xxxxxxxxx
  • Loading branch information
BrandonOdiwuor committed May 30, 2024
1 parent 213c6e2 commit 1f87975
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& option
}
}

void ReadSigNetChainArgs(const ArgsManager& args, CChainParams::SigNetOptions& options) {
const auto chain = args.GetArg("-chain", "");
if (chain.starts_with("signet_")){
auto seed_node = args.GetSectionArg(chain, "signetseednode");
if (!seed_node.empty()) {
options.seeds.emplace(seed_node);
}
auto signet_challenge = args.GetSectionArg(chain, "signetchallenge");
if (!signet_challenge.empty()) {
options.challenge.emplace(validateSignetChallenge(signet_challenge));
}
}
}

void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& options)
{
if (auto value = args.GetBoolArg("-fastprune")) options.fastprune = *value;
Expand Down Expand Up @@ -120,6 +134,7 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
case ChainType::SIGNET: {
auto opts = CChainParams::SigNetOptions{};
ReadSigNetArgs(args, opts);
ReadSigNetChainArgs(gArgs, opts);
return CChainParams::SigNet(opts);
}
case ChainType::REGTEST: {
Expand Down
15 changes: 15 additions & 0 deletions src/common/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,21 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
return result;
}

std::vector<std::string> ArgsManager::GetSectionArg(const std::string& section, const std::string& strArg) const
{
std::vector<std::string> result;
LOCK(cs_args);
if (auto* _section = common::FindKey(m_settings.ro_config, section)) {
if (auto* values = common::FindKey(*_section, strArg)) {
for (int i = 0; i < values->size(); i++) {
result.push_back((*values)[i].get_str());
}

}
}
return result;
}

bool ArgsManager::IsArgSet(const std::string& strArg) const
{
return !GetSetting(strArg).isNull();
Expand Down
9 changes: 9 additions & 0 deletions src/common/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ class ArgsManager
*/
std::vector<std::string> GetArgs(const std::string& strArg) const;

/**
* Retrieves values associated with a specified argument in a given configuration section.
*
* @param section section in m_settings.ro_config to seach
* @param strArg Argument to get (e.g. "-foo")
* @return Vector of string values for the argument in the configuration file.
*/
std::vector<std::string> GetSectionArg(const std::string& section, const std::string& strArg) const;

/**
* Return true if the given argument has been manually set
*
Expand Down
2 changes: 1 addition & 1 deletion src/util/chaintype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::optional<ChainType> ChainTypeFromString(std::string_view chain)
return ChainType::MAIN;
} else if (chain == "test") {
return ChainType::TESTNET;
} else if (chain == "signet") {
} else if (chain == "signet" || chain.starts_with("signet_") ) {
return ChainType::SIGNET;
} else if (chain == "regtest") {
return ChainType::REGTEST;
Expand Down

0 comments on commit 1f87975

Please sign in to comment.