Convert addblock utility to use btcnet.
This commit is contained in:
parent
7b0116dfd0
commit
dd8265c22c
2 changed files with 21 additions and 11 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/conformal/btcdb"
|
||||
_ "github.com/conformal/btcdb/ldb"
|
||||
"github.com/conformal/btcnet"
|
||||
"github.com/conformal/btcutil"
|
||||
"github.com/conformal/btcwire"
|
||||
"github.com/conformal/go-flags"
|
||||
|
@ -25,7 +26,7 @@ var (
|
|||
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
||||
defaultDataDir = filepath.Join(btcdHomeDir, "data")
|
||||
knownDbTypes = btcdb.SupportedDBs()
|
||||
activeNetwork = btcwire.MainNet
|
||||
activeNetwork = &btcnet.MainNetParams
|
||||
)
|
||||
|
||||
// config defines the configuration options for findcheckpoint.
|
||||
|
@ -60,13 +61,22 @@ func validDbType(dbType string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// netName returns a human-readable name for the passed bitcoin network.
|
||||
func netName(btcnet btcwire.BitcoinNet) string {
|
||||
net := "mainnet"
|
||||
if btcnet == btcwire.TestNet3 {
|
||||
net = "testnet"
|
||||
// netName returns the name used when referring to a bitcoin network. At the
|
||||
// time of writing, btcd currently places blocks for testnet version 3 in the
|
||||
// data and log directory "testnet", which does not match the Name field of the
|
||||
// btcnet parameters. This function can be used to override this directory name
|
||||
// as "testnet" when the passed active network matches btcwire.TestNet3.
|
||||
//
|
||||
// A proper upgrade to move the data and log directories for this network to
|
||||
// "testnet3" is planned for the future, at which point this function can be
|
||||
// removed and the network parameter's name used instead.
|
||||
func netName(netParams *btcnet.Params) string {
|
||||
switch netParams.Net {
|
||||
case btcwire.TestNet3:
|
||||
return "testnet"
|
||||
default:
|
||||
return netParams.Name
|
||||
}
|
||||
return net
|
||||
}
|
||||
|
||||
// loadConfig initializes and parses the config using command line options.
|
||||
|
@ -91,7 +101,7 @@ func loadConfig() (*config, []string, error) {
|
|||
|
||||
// Choose the active network based on the flags.
|
||||
if cfg.TestNet3 {
|
||||
activeNetwork = btcwire.TestNet3
|
||||
activeNetwork = &btcnet.TestNet3Params
|
||||
}
|
||||
|
||||
// Validate database type.
|
||||
|
|
|
@ -60,9 +60,9 @@ func (bi *blockImporter) readBlock() ([]byte, error) {
|
|||
// No block and no error means there are no more blocks to read.
|
||||
return nil, nil
|
||||
}
|
||||
if net != uint32(activeNetwork) {
|
||||
if net != uint32(activeNetwork.Net) {
|
||||
return nil, fmt.Errorf("network mismatch -- got %x, want %x",
|
||||
net, uint32(activeNetwork))
|
||||
net, uint32(activeNetwork.Net))
|
||||
}
|
||||
|
||||
// Read the block length and ensure it is sane.
|
||||
|
@ -288,7 +288,7 @@ func newBlockImporter(db btcdb.Db, r io.ReadSeeker) *blockImporter {
|
|||
doneChan: make(chan bool),
|
||||
errChan: make(chan error),
|
||||
quit: make(chan bool),
|
||||
chain: btcchain.New(db, activeNetwork, nil),
|
||||
chain: btcchain.New(db, activeNetwork.Net, nil),
|
||||
lastLogTime: time.Now(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue