Add --simnet option to btcctl.

This flag works similar to the existing --testnet flag does.  That is to
say it selects the default simulation test network RPC port for either
btcd or btcwallet depending on whether or not the --wallet flag is also
present.
This commit is contained in:
Dave Collins 2014-05-30 16:35:44 -05:00
parent 605eb7f4b4
commit 0d2c5a8ffb

View file

@ -32,23 +32,31 @@ type config struct {
RPCCert string `short:"c" long:"rpccert" description:"RPC server certificate chain for validation"`
NoTls bool `long:"notls" description:"Disable TLS"`
TestNet3 bool `long:"testnet" description:"Connect to testnet"`
SimNet bool `long:"simnet" description:"Connect to the simulation test network"`
TlsSkipVerify bool `long:"skipverify" description:"Do not verify tls certificates (not recommended!)"`
Wallet bool `long:"wallet" description:"Connect to wallet"`
}
// normalizeAddress returns addr with the passed default port appended if
// there is not already a port specified.
func normalizeAddress(addr string, useTestNet3, useWallet bool) string {
func normalizeAddress(addr string, useTestNet3, useSimNet, useWallet bool) string {
_, _, err := net.SplitHostPort(addr)
if err != nil {
var defaultPort string
if useTestNet3 {
switch {
case useTestNet3:
if useWallet {
defaultPort = "18332"
} else {
defaultPort = "18334"
}
} else {
case useSimNet:
if useWallet {
defaultPort = "18554"
} else {
defaultPort = "18556"
}
default:
if useWallet {
defaultPort = "8332"
} else {
@ -133,6 +141,22 @@ func loadConfig() (*flags.Parser, *config, []string, error) {
return parser, nil, nil, err
}
// Multiple networks can't be selected simultaneously.
numNets := 0
if cfg.TestNet3 {
numNets++
}
if cfg.SimNet {
numNets++
}
if numNets > 1 {
str := "%s: The testnet and simnet params can't be used " +
"together -- choose one of the two"
err := fmt.Errorf(str, "loadConfig")
fmt.Fprintln(os.Stderr, err)
return parser, nil, nil, err
}
// Override the RPC certificate if the --wallet flag was specified and
// the user did not specify one.
if cfg.Wallet && cfg.RPCCert == defaultRPCCertFile {
@ -144,7 +168,8 @@ func loadConfig() (*flags.Parser, *config, []string, error) {
// Add default port to RPC server based on --testnet and --wallet flags
// if needed.
cfg.RPCServer = normalizeAddress(cfg.RPCServer, cfg.TestNet3, cfg.Wallet)
cfg.RPCServer = normalizeAddress(cfg.RPCServer, cfg.TestNet3,
cfg.SimNet, cfg.Wallet)
return parser, &cfg, remainingArgs, nil
}