Update findcheckpoint utility to use btcnet.
This commit is contained in:
parent
dd8265c22c
commit
009c4bcd76
2 changed files with 20 additions and 10 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
_ "github.com/conformal/btcdb/ldb"
|
_ "github.com/conformal/btcdb/ldb"
|
||||||
|
"github.com/conformal/btcnet"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/go-flags"
|
"github.com/conformal/go-flags"
|
||||||
|
@ -26,7 +27,7 @@ var (
|
||||||
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
btcdHomeDir = btcutil.AppDataDir("btcd", false)
|
||||||
defaultDataDir = filepath.Join(btcdHomeDir, "data")
|
defaultDataDir = filepath.Join(btcdHomeDir, "data")
|
||||||
knownDbTypes = btcdb.SupportedDBs()
|
knownDbTypes = btcdb.SupportedDBs()
|
||||||
activeNetwork = btcwire.MainNet
|
activeNetwork = &btcnet.MainNetParams
|
||||||
)
|
)
|
||||||
|
|
||||||
// config defines the configuration options for findcheckpoint.
|
// config defines the configuration options for findcheckpoint.
|
||||||
|
@ -51,13 +52,22 @@ func validDbType(dbType string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// netName returns a human-readable name for the passed bitcoin network.
|
// netName returns the name used when referring to a bitcoin network. At the
|
||||||
func netName(btcnet btcwire.BitcoinNet) string {
|
// time of writing, btcd currently places blocks for testnet version 3 in the
|
||||||
net := "mainnet"
|
// data and log directory "testnet", which does not match the Name field of the
|
||||||
if btcnet == btcwire.TestNet3 {
|
// btcnet parameters. This function can be used to override this directory name
|
||||||
net = "testnet"
|
// 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.
|
// loadConfig initializes and parses the config using command line options.
|
||||||
|
@ -81,7 +91,7 @@ func loadConfig() (*config, []string, error) {
|
||||||
|
|
||||||
// Choose the active network based on the flags.
|
// Choose the active network based on the flags.
|
||||||
if cfg.TestNet3 {
|
if cfg.TestNet3 {
|
||||||
activeNetwork = btcwire.TestNet3
|
activeNetwork = &btcnet.TestNet3Params
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate database type.
|
// Validate database type.
|
||||||
|
|
|
@ -51,7 +51,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check
|
||||||
|
|
||||||
// Setup chain and get the latest checkpoint. Ignore notifications
|
// Setup chain and get the latest checkpoint. Ignore notifications
|
||||||
// since they aren't needed for this util.
|
// since they aren't needed for this util.
|
||||||
chain := btcchain.New(db, activeNetwork, nil)
|
chain := btcchain.New(db, activeNetwork.Net, nil)
|
||||||
latestCheckpoint := chain.LatestCheckpoint()
|
latestCheckpoint := chain.LatestCheckpoint()
|
||||||
if latestCheckpoint == nil {
|
if latestCheckpoint == nil {
|
||||||
return nil, fmt.Errorf("unable to retrieve latest checkpoint")
|
return nil, fmt.Errorf("unable to retrieve latest checkpoint")
|
||||||
|
@ -76,7 +76,7 @@ func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcchain.Check
|
||||||
defer fmt.Println()
|
defer fmt.Println()
|
||||||
|
|
||||||
// Loop backwards through the chain to find checkpoint candidates.
|
// Loop backwards through the chain to find checkpoint candidates.
|
||||||
var candidates []*btcchain.Checkpoint
|
candidates := make([]*btcchain.Checkpoint, 0, cfg.NumCandidates)
|
||||||
numTested := int64(0)
|
numTested := int64(0)
|
||||||
for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight {
|
for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight {
|
||||||
// Display progress.
|
// Display progress.
|
||||||
|
|
Loading…
Reference in a new issue