Begin update to use btcnet.Params.

This is an intial pass at converting the btcwallet and deps codebases
to pass a network by their parameters, rather than by a magic number
to identify the network.  The parameters in params.go have been
updated to embed a *btcnet.Params, and all previous uses of cfg.Net()
have been replaced with activeNet.{Params,Net} (where activeNet is
the global var for the active network).

Although dependancy packages have not yet been updated from using
btcwire.BitcoinNet to btcnet.Params, the parameters are now accessible
at all callsites, and individual packages can be updated to use btcnet
without requiring updates in each external btc* package at once.

While here, the exported API for btcwallet internal library packages
(txstore and wallet) have been updated to pass full network parameters
rather than the btcwire definition of a network.
This commit is contained in:
Josh Rickmar 2014-05-22 21:16:50 -05:00
commit c3224f4fbc
12 changed files with 96 additions and 118 deletions

View file

@ -18,27 +18,34 @@ package main
import (
"fmt"
"github.com/conformal/btcwire"
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/conformal/btcnet"
"github.com/conformal/btcwire"
)
// networkDir returns the directory name of a network directory to hold account
// files.
func networkDir(net btcwire.BitcoinNet) string {
var netname string
if net == btcwire.MainNet {
netname = "mainnet"
} else {
func networkDir(net *btcnet.Params) string {
netname := net.Name
// For now, we must always name the testnet data directory as "testnet"
// and not "testnet3" or any other version, as the btcnet testnet3
// paramaters will likely be switched to being named "testnet3" in the
// future. This is done to future proof that change, and an upgrade
// plan to move the testnet3 data directory can be worked out later.
if net.Net == btcwire.TestNet3 {
netname = "testnet"
}
return filepath.Join(cfg.DataDir, netname)
}
// tmpNetworkDir returns the temporary directory name for a given network.
func tmpNetworkDir(net btcwire.BitcoinNet) string {
func tmpNetworkDir(net *btcnet.Params) string {
return networkDir(net) + "_tmp"
}
@ -218,11 +225,11 @@ func (ds *DiskSyncer) Start() {
//
// This never returns and is should be called from a new goroutine.
func (ds *DiskSyncer) handler() {
netdir := networkDir(cfg.Net())
netdir := networkDir(activeNet.Params)
if err := checkCreateDir(netdir); err != nil {
log.Errorf("Unable to create or write to account directory: %v", err)
}
tmpnetdir := tmpNetworkDir(cfg.Net())
tmpnetdir := tmpNetworkDir(activeNet.Params)
const wait = 10 * time.Second
var timer <-chan time.Time