From 6398dc098e348c61c042a665aae58c85414c6041 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 29 May 2014 16:15:32 -0500 Subject: [PATCH] Add support for the simulation test network. --- config.go | 27 ++++++++++++++++++++++++--- params.go | 9 +++++++++ sample-btcwallet.conf | 5 ++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/config.go b/config.go index 9d6bb83..ec53d5e 100644 --- a/config.go +++ b/config.go @@ -49,10 +49,10 @@ var ( type config struct { ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"` CAFile string `long:"cafile" description:"File containing root certificates to authenticate a TLS connections with btcd"` - RPCConnect string `short:"c" long:"rpcconnect" description:"Hostname/IP and port of btcd RPC server to connect to (default localhost:18334, mainnet: localhost:8334)"` + RPCConnect string `short:"c" long:"rpcconnect" description:"Hostname/IP and port of btcd RPC server to connect to (default localhost:18334, mainnet: localhost:8334, simnet: localhost:18556)"` DebugLevel string `short:"d" long:"debuglevel" description:"Logging level {trace, debug, info, warn, error, critical}"` ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"` - SvrListeners []string `long:"rpclisten" description:"Listen for RPC/websocket connections on this interface/port (default port: 18332, mainnet: 8332)"` + SvrListeners []string `long:"rpclisten" description:"Listen for RPC/websocket connections on this interface/port (default port: 18332, mainnet: 8332, simnet: 18555)"` DataDir string `short:"D" long:"datadir" description:"Directory to store wallets and transactions"` Username string `short:"u" long:"username" description:"Username for client and btcd authorization"` Password string `short:"P" long:"password" default-mask:"-" description:"Password for client and btcd authorization"` @@ -61,6 +61,7 @@ type config struct { RPCCert string `long:"rpccert" description:"File containing the certificate file"` RPCKey string `long:"rpckey" description:"File containing the certificate key"` MainNet bool `long:"mainnet" description:"Use the main Bitcoin network (default testnet3)"` + SimNet bool `long:"simnet" description:"Use the simulation test network (default testnet3)"` KeypoolSize uint `short:"k" long:"keypoolsize" description:"Maximum number of addresses in keypool"` DisallowFree bool `long:"disallowfree" description:"Force transactions to always include a fee"` Proxy string `long:"proxy" description:"Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)"` @@ -217,9 +218,29 @@ func loadConfig() (*config, []string, error) { } } - // Choose the active network params based on the mainnet net flag. + // Multiple networks can't be selected simultaneously. + numNets := 0 if cfg.MainNet { + numNets++ + } + if cfg.SimNet { + numNets++ + } + if numNets > 1 { + str := "%s: The mainnet and simnet params can't be used " + + "togther -- choose one" + err := fmt.Errorf(str, "loadConfig") + fmt.Fprintln(os.Stderr, err) + parser.WriteHelp(os.Stderr) + return nil, nil, err + } + + // Choose the active network params based on the selected network. + switch { + case cfg.MainNet: activeNet = &mainNetParams + case cfg.SimNet: + activeNet = &simNetParams } // Validate debug log level diff --git a/params.go b/params.go index 677edde..e1c630f 100644 --- a/params.go +++ b/params.go @@ -48,3 +48,12 @@ var testNet3Params = params{ btcdPort: "18334", svrPort: "18332", } + +// simNetParams contains parameters specific to the simulation test network +// (btcwire.SimNet). +var simNetParams = params{ + Params: &btcnet.SimNetParams, + connect: "localhost:18556", + btcdPort: "18556", + svrPort: "18555", +} diff --git a/sample-btcwallet.conf b/sample-btcwallet.conf index d833da9..e4b0de5 100644 --- a/sample-btcwallet.conf +++ b/sample-btcwallet.conf @@ -4,9 +4,12 @@ ; Bitcoin wallet settings ; ------------------------------------------------------------------------------ -; Use mainnet. +; Use mainnet (cannot be used with simnet=1). ; mainnet=0 +; Use simnet (cannot be used with mainnet=1). +; simnet=0 + ; The directory to open and save wallet, transaction, and unspent transaction ; output files. Two directories, `mainnet` and `testnet` are used in this ; directory for mainnet and testnet wallets, respectively.