Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add regtest to btcwallet #975

Merged
merged 5 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ linters:
# will also catch magic numbers that make sense to extract.
- gomnd

# Disable tagalign
- tagalign

issues:
# Only check issues in the new code.
new-from-rev: 3f48b446215c751ea4ba0c30fb04413ab9f1a7c7
Expand Down
16 changes: 15 additions & 1 deletion cmd/sweepaccount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func errContext(err error, context string) error {
var opts = struct {
TestNet3 bool `long:"testnet" description:"Use the test bitcoin network (version 3)"`
SimNet bool `long:"simnet" description:"Use the simulation bitcoin network"`
RegressionNet bool `long:"regtest" description:"Use the regression bitcoin network"`
RPCConnect string `short:"c" long:"connect" description:"Hostname[:port] of wallet RPC server"`
RPCUsername string `short:"u" long:"rpcuser" description:"Wallet RPC username"`
RPCCertificateFile string `long:"cafile" description:"Wallet RPC TLS certificate"`
Expand All @@ -53,6 +54,7 @@ var opts = struct {
}{
TestNet3: false,
SimNet: false,
RegressionNet: false,
RPCConnect: "localhost",
RPCUsername: "",
RPCCertificateFile: filepath.Join(walletDataDirectory, "rpc.cert"),
Expand All @@ -79,14 +81,26 @@ func init() {
os.Exit(1)
}

if opts.TestNet3 && opts.SimNet {
numNets := 0
if opts.TestNet3 {
numNets++
}
if opts.SimNet {
numNets++
}
if opts.RegressionNet {
numNets++
}
if numNets > 1 {
fatalf("Multiple bitcoin networks may not be used simultaneously")
}
var activeNet = &netparams.MainNetParams
if opts.TestNet3 {
activeNet = &netparams.TestNet3Params
} else if opts.SimNet {
activeNet = &netparams.SimNetParams
} else if opts.RegressionNet {
activeNet = &netparams.RegressionNetParams
}

if opts.RPCConnect == "" {
Expand Down
14 changes: 10 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
defaultLogDir = filepath.Join(defaultAppDataDir, defaultLogDirname)
)

//nolint:lll
type config struct {
// General application behavior
ConfigFile *cfgutil.ExplicitString `short:"C" long:"configfile" description:"Path to configuration file"`
Expand All @@ -57,6 +58,7 @@ type config struct {
SigNet bool `long:"signet" description:"Use the signet test network (default mainnet)"`
SigNetChallenge string `long:"signetchallenge" description:"Connect to a custom signet network defined by this challenge instead of using the global default signet test network -- Can be specified multiple times"`
SigNetSeedNode []string `long:"signetseednode" description:"Specify a seed node for the signet network instead of using the global default signet network seed nodes"`
RegressionNet bool `long:"regtest" description:"Use the regression test network (default mainnet)"`
NoInitialLoad bool `long:"noinitialload" description:"Defer wallet creation/opening on startup and enable loading wallets over RPC"`
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level {trace, debug, info, warn, error, critical}"`
LogDir string `long:"logdir" description:"Directory to log output."`
Expand All @@ -67,7 +69,7 @@ type config struct {
WalletPass string `long:"walletpass" default-mask:"-" description:"The public wallet password -- Only required if the wallet was created with one"`

// RPC client options
RPCConnect string `short:"c" long:"rpcconnect" description:"Hostname/IP and port of btcd RPC server to connect to (default localhost:8334, testnet: localhost:18334, simnet: localhost:18556)"`
RPCConnect string `short:"c" long:"rpcconnect" description:"Hostname/IP and port of btcd RPC server to connect to (default localhost:8334, testnet: localhost:18334, simnet: localhost:18556, regtest: localhost:18334)"`
CAFile *cfgutil.ExplicitString `long:"cafile" description:"File containing root certificates to authenticate a TLS connections with btcd"`
DisableClientTLS bool `long:"noclienttls" description:"Disable TLS for the RPC client -- NOTE: This is only allowed if the RPC client is connecting to localhost"`
BtcdUsername string `long:"btcdusername" description:"Username for btcd authentication"`
Expand Down Expand Up @@ -96,7 +98,7 @@ type config struct {
RPCKey *cfgutil.ExplicitString `long:"rpckey" description:"File containing the certificate key"`
OneTimeTLSKey bool `long:"onetimetlskey" description:"Generate a new TLS certpair at startup, but only write the certificate to disk"`
DisableServerTLS bool `long:"noservertls" description:"Disable TLS for the RPC server -- NOTE: This is only allowed if the RPC server is bound to localhost"`
LegacyRPCListeners []string `long:"rpclisten" description:"Listen for legacy RPC connections on this interface/port (default port: 8332, testnet: 18332, simnet: 18554)"`
LegacyRPCListeners []string `long:"rpclisten" description:"Listen for legacy RPC connections on this interface/port (default port: 8332, testnet: 18332, simnet: 18554, regtest: 18332)"`
LegacyRPCMaxClients int64 `long:"rpcmaxclients" description:"Max number of legacy RPC clients for standard connections"`
LegacyRPCMaxWebsockets int64 `long:"rpcmaxwebsockets" description:"Max number of legacy RPC websocket connections"`
Username string `short:"u" long:"username" description:"Username for legacy RPC and btcd authentication (if btcdusername is unset)"`
Expand Down Expand Up @@ -409,9 +411,13 @@ func loadConfig() (*config, []string, error) {
)
activeNet.Params = &chainParams
}
if cfg.RegressionNet {
activeNet = &netparams.RegressionNetParams
numNets++
}
if numNets > 1 {
str := "%s: The testnet, signet and simnet params can't be " +
"used together -- choose one"
str := "%s: The testnet, signet, simnet, and regtest params " +
"can't be used together -- choose one"
err := fmt.Errorf(str, "loadConfig")
fmt.Fprintln(os.Stderr, err)
parser.WriteHelp(os.Stderr)
Expand Down
2 changes: 2 additions & 0 deletions internal/legacy/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ func (net *netParams) ReadFrom(r io.Reader) (int64, error) {
*net = (netParams)(chaincfg.TestNet3Params)
case wire.SimNet:
*net = (netParams)(chaincfg.SimNetParams)
case wire.TestNet:
*net = (netParams)(chaincfg.RegressionNetParams)

// The legacy key store won't be compatible with custom signets, only
// the main public one.
Expand Down
8 changes: 8 additions & 0 deletions netparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ func SigNetWire(params *chaincfg.Params) wire.BitcoinNet {

return 0
}

// RegressionNetParams contains parameters specific to the regression test
// network (wire.RegressionNet).
var RegressionNetParams = Params{
Params: &chaincfg.RegressionNetParams,
RPCClientPort: "18334",
RPCServerPort: "18332",
}
7 changes: 5 additions & 2 deletions sample-btcwallet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
; Bitcoin wallet settings
; ------------------------------------------------------------------------------

; Use testnet (cannot be used with simnet=1).
; Use testnet (cannot be used with simnet=1 or regtest=1).
; testnet=0

; Use simnet (cannot be used with testnet=1).
; Use simnet (cannot be used with testnet=1 or regtest=1).
; simnet=0

; Use regtest (cannot be used with testnet=1 or simnet=1).
; regtest=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.
Expand Down
Loading