@ -10,6 +10,7 @@
# include <sync.h>
# include <tinyformat.h>
# include <univalue.h>
# include <util/chaintype.h>
# include <util/check.h>
# include <util/fs.h>
# include <util/fs_helpers.h>
@ -33,6 +34,7 @@
# include <stdexcept>
# include <string>
# include <utility>
# include <variant>
const char * const BITCOIN_CONF_FILENAME = " bitcoin.conf " ;
const char * const BITCOIN_SETTINGS_FILENAME = " settings.json " ;
@ -717,7 +719,21 @@ fs::path ArgsManager::GetConfigFilePath() const
return GetConfigFile ( * this , GetPathArg ( " -conf " , BITCOIN_CONF_FILENAME ) ) ;
}
ChainType ArgsManager : : GetChainType ( ) const
{
std : : variant < ChainType , std : : string > arg = GetChainArg ( ) ;
if ( auto * parsed = std : : get_if < ChainType > ( & arg ) ) return * parsed ;
throw std : : runtime_error ( strprintf ( " Unknown chain %s. " , std : : get < std : : string > ( arg ) ) ) ;
}
std : : string ArgsManager : : GetChainName ( ) const
{
auto arg = GetChainArg ( ) ;
if ( auto * parsed = std : : get_if < ChainType > ( & arg ) ) return ChainTypeToString ( * parsed ) ;
return std : : get < std : : string > ( arg ) ;
}
std : : variant < ChainType , std : : string > ArgsManager : : GetChainArg ( ) const
{
auto get_net = [ & ] ( const std : : string & arg ) {
LOCK ( cs_args ) ;
@ -731,20 +747,20 @@ std::string ArgsManager::GetChainName() const
const bool fRegTest = get_net ( " -regtest " ) ;
const bool fSigNet = get_net ( " -signet " ) ;
const bool fTestNet = get_net ( " -testnet " ) ;
const bool is_chain_arg_set = IsArgSet ( " -chain " ) ;
const auto chain_arg = GetArg ( " -chain " ) ;
if ( ( int ) is_chain_arg_set + ( int ) fRegTest + ( int ) fSigNet + ( int ) fTestNet > 1 ) {
if ( ( int ) chain_arg. has_value ( ) + ( int ) fRegTest + ( int ) fSigNet + ( int ) fTestNet > 1 ) {
throw std : : runtime_error ( " Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one. " ) ;
}
if ( fRegTest)
return CBaseChainParams : : REGTEST ;
if ( fSigNet ) {
return CBaseChainParams : : SIGNET ;
if ( chain_arg) {
if ( auto parsed = ChainTypeFromString ( * chain_arg ) ) return * parsed ;
// Not a known string, so return original string
return * chain_arg ;
}
if ( f TestNet)
return CBaseChainParams : : TEST NET;
return GetArg ( " -chain " , CBaseChainParams : : MAIN ) ;
if ( f RegTest) return ChainType : : REGTEST ;
if ( fSigNet ) return ChainType : : SIG NET;
if ( fTestNet ) return ChainType : : TESTNET ;
return ChainType : : MAIN ;
}
bool ArgsManager : : UseDefaultSection ( const std : : string & arg ) const