mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00

* [NOD-386] Extract net parsing functionality to a shared place. * [NOD-386] Add extract ActiveNetParams to cmdconfig * [NOD-386] Adding comments so go-vet won't shout at me * [NOD-386] Rename package name to config * [NOD-386] Rename commandConfig to configFlags * [NOD-386] Rename function to ResolveNetwork * [NOD-386] Fix renaming errors * [NOD-386] Refactor network config to btcd level so APIserver and btcd could use it * [NOD-386] Refactor network config to config package * [NOD-386] Move ActiveNetParams to network section * [NOD-386] Explictly return nil * [NOD-386] Reuse activeNetParams from netwrok config * [NOD-386] Set ActiveNetworkFlags instance to be global * [NOD-386] Remove redundant newline * [NOD-386] Init ActiveNetParams in address manager test * [NOD-386] Add dnsseeder network config * [NOD-386] Use ActiveConfig() method to access configuration
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/daglabs/btcd/dagconfig"
|
|
"github.com/jessevdk/go-flags"
|
|
"github.com/pkg/errors"
|
|
"os"
|
|
)
|
|
|
|
// NetworkFlags holds the network configuration, that is which network is selected.
|
|
type NetworkFlags struct {
|
|
TestNet bool `long:"testnet" description:"Use the test network"`
|
|
RegressionTest bool `long:"regtest" description:"Use the regression test network"`
|
|
SimNet bool `long:"simnet" description:"Use the simulation test network"`
|
|
DevNet bool `long:"devnet" description:"Use the development test network"`
|
|
ActiveNetParams *dagconfig.Params
|
|
}
|
|
|
|
// ResolveNetwork parses the network command line argument and sets NetParams accordingly.
|
|
// It returns error if more than one network was selected, nil otherwise.
|
|
func (networkFlags *NetworkFlags) ResolveNetwork(parser *flags.Parser) error {
|
|
//NetParams holds the selected network parameters. Default value is main-net.
|
|
networkFlags.ActiveNetParams = &dagconfig.MainNetParams
|
|
// Multiple networks can't be selected simultaneously.
|
|
numNets := 0
|
|
// default net is main net
|
|
// Count number of network flags passed; assign active network params
|
|
// while we're at it
|
|
if networkFlags.TestNet {
|
|
numNets++
|
|
networkFlags.ActiveNetParams = &dagconfig.TestNetParams
|
|
}
|
|
if networkFlags.RegressionTest {
|
|
numNets++
|
|
networkFlags.ActiveNetParams = &dagconfig.RegressionNetParams
|
|
}
|
|
if networkFlags.SimNet {
|
|
numNets++
|
|
networkFlags.ActiveNetParams = &dagconfig.SimNetParams
|
|
}
|
|
if networkFlags.DevNet {
|
|
numNets++
|
|
networkFlags.ActiveNetParams = &dagconfig.DevNetParams
|
|
}
|
|
if numNets > 1 {
|
|
message := "Multiple networks parameters (testnet, simnet, devnet, etc.) cannot be used" +
|
|
"together. Please choose only one network"
|
|
err := errors.Errorf(message)
|
|
fmt.Fprintln(os.Stderr, err)
|
|
parser.WriteHelp(os.Stderr)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// NetParams returns the ActiveNetParams
|
|
func (networkFlags *NetworkFlags) NetParams() *dagconfig.Params {
|
|
return networkFlags.ActiveNetParams
|
|
}
|