diff --git a/blockchain/accept.go b/blockchain/accept.go index 64cb6d26..cb840395 100644 --- a/blockchain/accept.go +++ b/blockchain/accept.go @@ -111,8 +111,8 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags) // upgraded. This is part of BIP0034. if blockHeader.Version < 2 { if b.isMajorityVersion(2, prevNode, - b.netParams.BlockV1RejectNumRequired, - b.netParams.BlockV1RejectNumToCheck) { + b.chainParams.BlockV1RejectNumRequired, + b.chainParams.BlockV1RejectNumToCheck) { str := "new blocks with version %d are no " + "longer valid" @@ -128,8 +128,8 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags) if blockHeader.Version >= serializedHeightVersion { if b.isMajorityVersion(serializedHeightVersion, prevNode, - b.netParams.CoinbaseBlockHeightNumRequired, - b.netParams.CoinbaseBlockHeightNumToCheck) { + b.chainParams.CoinbaseBlockHeightNumRequired, + b.chainParams.CoinbaseBlockHeightNumToCheck) { expectedHeight := int64(0) if prevNode != nil { diff --git a/blockchain/blocklocator.go b/blockchain/blocklocator.go index d957536e..48de4e31 100644 --- a/blockchain/blocklocator.go +++ b/blockchain/blocklocator.go @@ -41,7 +41,7 @@ func (b *BlockChain) BlockLocatorFromHash(hash *wire.ShaHash) BlockLocator { locator = append(locator, hash) // Nothing more to do if a locator for the genesis hash was requested. - if hash.IsEqual(b.netParams.GenesisHash) { + if hash.IsEqual(b.chainParams.GenesisHash) { return locator } @@ -124,7 +124,7 @@ func (b *BlockChain) BlockLocatorFromHash(hash *wire.ShaHash) BlockLocator { } // Append the appropriate genesis block. - locator = append(locator, b.netParams.GenesisHash) + locator = append(locator, b.chainParams.GenesisHash) return locator } diff --git a/blockchain/chain.go b/blockchain/chain.go index 8e71a841..b467a8bc 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -13,9 +13,9 @@ import ( "sync" "time" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -143,8 +143,8 @@ func removeChildNode(children []*blockNode, node *blockNode) []*blockNode { // selection with reorganization. type BlockChain struct { db database.Db - netParams *btcnet.Params - checkpointsByHeight map[int64]*btcnet.Checkpoint + chainParams *chaincfg.Params + checkpointsByHeight map[int64]*chaincfg.Checkpoint notifications NotificationCallback root *blockNode bestChain *blockNode @@ -157,7 +157,7 @@ type BlockChain struct { blockCache map[wire.ShaHash]*btcutil.Block noVerify bool noCheckpoints bool - nextCheckpoint *btcnet.Checkpoint + nextCheckpoint *chaincfg.Checkpoint checkpointBlock *btcutil.Block } @@ -507,7 +507,7 @@ func (b *BlockChain) getPrevNodeFromNode(node *blockNode) (*blockNode, error) { } // Genesis block. - if node.hash.IsEqual(b.netParams.GenesisHash) { + if node.hash.IsEqual(b.chainParams.GenesisHash) { return nil, nil } @@ -640,7 +640,7 @@ func (b *BlockChain) isMajorityVersion(minVer int32, startNode *blockNode, numRe func (b *BlockChain) calcPastMedianTime(startNode *blockNode) (time.Time, error) { // Genesis block. if startNode == nil { - return b.netParams.GenesisBlock.Header.Timestamp, nil + return b.chainParams.GenesisBlock.Header.Timestamp, nil } // Create a slice of the previous few block timestamps used to calculate @@ -1069,11 +1069,11 @@ func (b *BlockChain) IsCurrent(timeSource MedianTimeSource) bool { // Notification and NotificationType for details on the types and contents of // notifications. The provided callback can be nil if the caller is not // interested in receiving notifications. -func New(db database.Db, params *btcnet.Params, c NotificationCallback) *BlockChain { +func New(db database.Db, params *chaincfg.Params, c NotificationCallback) *BlockChain { // Generate a checkpoint by height map from the provided checkpoints. - var checkpointsByHeight map[int64]*btcnet.Checkpoint + var checkpointsByHeight map[int64]*chaincfg.Checkpoint if len(params.Checkpoints) > 0 { - checkpointsByHeight = make(map[int64]*btcnet.Checkpoint) + checkpointsByHeight = make(map[int64]*chaincfg.Checkpoint) for i := range params.Checkpoints { checkpoint := ¶ms.Checkpoints[i] checkpointsByHeight[checkpoint.Height] = checkpoint @@ -1082,7 +1082,7 @@ func New(db database.Db, params *btcnet.Params, c NotificationCallback) *BlockCh b := BlockChain{ db: db, - netParams: params, + chainParams: params, checkpointsByHeight: checkpointsByHeight, notifications: c, root: nil, diff --git a/blockchain/chain_test.go b/blockchain/chain_test.go index da8fb092..6a48c36d 100644 --- a/blockchain/chain_test.go +++ b/blockchain/chain_test.go @@ -8,8 +8,8 @@ import ( "testing" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -81,7 +81,7 @@ func TestHaveBlock(t *testing.T) { want bool }{ // Genesis block should be present (in the main chain). - {hash: btcnet.MainNetParams.GenesisHash.String(), want: true}, + {hash: chaincfg.MainNetParams.GenesisHash.String(), want: true}, // Block 3a should be present (on a side chain). {hash: "00000000474284d20067a4d33f6a02284e6ef70764a3a26d6a5b9df52ef663dd", want: true}, diff --git a/blockchain/checkpoints.go b/blockchain/checkpoints.go index ff859125..2794dc75 100644 --- a/blockchain/checkpoints.go +++ b/blockchain/checkpoints.go @@ -7,9 +7,9 @@ package blockchain import ( "fmt" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -36,23 +36,23 @@ func (b *BlockChain) DisableCheckpoints(disable bool) { // Checkpoints returns a slice of checkpoints (regardless of whether they are // already known). When checkpoints are disabled or there are no checkpoints // for the active network, it will return nil. -func (b *BlockChain) Checkpoints() []btcnet.Checkpoint { - if b.noCheckpoints || len(b.netParams.Checkpoints) == 0 { +func (b *BlockChain) Checkpoints() []chaincfg.Checkpoint { + if b.noCheckpoints || len(b.chainParams.Checkpoints) == 0 { return nil } - return b.netParams.Checkpoints + return b.chainParams.Checkpoints } // LatestCheckpoint returns the most recent checkpoint (regardless of whether it // is already known). When checkpoints are disabled or there are no checkpoints // for the active network, it will return nil. -func (b *BlockChain) LatestCheckpoint() *btcnet.Checkpoint { - if b.noCheckpoints || len(b.netParams.Checkpoints) == 0 { +func (b *BlockChain) LatestCheckpoint() *chaincfg.Checkpoint { + if b.noCheckpoints || len(b.chainParams.Checkpoints) == 0 { return nil } - checkpoints := b.netParams.Checkpoints + checkpoints := b.chainParams.Checkpoints return &checkpoints[len(checkpoints)-1] } @@ -60,7 +60,7 @@ func (b *BlockChain) LatestCheckpoint() *btcnet.Checkpoint { // match the hard-coded checkpoint data. It also returns true if there is no // checkpoint data for the passed block height. func (b *BlockChain) verifyCheckpoint(height int64, hash *wire.ShaHash) bool { - if b.noCheckpoints || len(b.netParams.Checkpoints) == 0 { + if b.noCheckpoints || len(b.chainParams.Checkpoints) == 0 { return true } @@ -84,12 +84,12 @@ func (b *BlockChain) verifyCheckpoint(height int64, hash *wire.ShaHash) bool { // associated block. It returns nil if a checkpoint can't be found (this should // really only happen for blocks before the first checkpoint). func (b *BlockChain) findPreviousCheckpoint() (*btcutil.Block, error) { - if b.noCheckpoints || len(b.netParams.Checkpoints) == 0 { + if b.noCheckpoints || len(b.chainParams.Checkpoints) == 0 { return nil, nil } // No checkpoints. - checkpoints := b.netParams.Checkpoints + checkpoints := b.chainParams.Checkpoints numCheckpoints := len(checkpoints) if numCheckpoints == 0 { return nil, nil diff --git a/blockchain/common_test.go b/blockchain/common_test.go index a959a814..6494995b 100644 --- a/blockchain/common_test.go +++ b/blockchain/common_test.go @@ -14,11 +14,11 @@ import ( "strings" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/ldb" _ "github.com/btcsuite/btcd/database/memdb" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -108,7 +108,7 @@ func chainSetup(dbName string) (*blockchain.BlockChain, func(), error) { // Insert the main network genesis block. This is part of the initial // database setup. - genesisBlock := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) + genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) _, err := db.InsertBlock(genesisBlock) if err != nil { teardown() @@ -116,7 +116,7 @@ func chainSetup(dbName string) (*blockchain.BlockChain, func(), error) { return nil, nil, err } - chain := blockchain.New(db, &btcnet.MainNetParams, nil) + chain := blockchain.New(db, &chaincfg.MainNetParams, nil) return chain, teardown, nil } diff --git a/blockchain/difficulty.go b/blockchain/difficulty.go index b80f7cd5..b9662195 100644 --- a/blockchain/difficulty.go +++ b/blockchain/difficulty.go @@ -197,9 +197,9 @@ func (b *BlockChain) calcEasiestDifficulty(bits uint32, duration time.Duration) // The test network rules allow minimum difficulty blocks after more // than twice the desired amount of time needed to generate a block has // elapsed. - if b.netParams.ResetMinDifficulty { + if b.chainParams.ResetMinDifficulty { if durationVal > int64(targetSpacing)*2 { - return b.netParams.PowLimitBits + return b.chainParams.PowLimitBits } } @@ -208,14 +208,14 @@ func (b *BlockChain) calcEasiestDifficulty(bits uint32, duration time.Duration) // the number of retargets for the duration and starting difficulty // multiplied by the max adjustment factor. newTarget := CompactToBig(bits) - for durationVal > 0 && newTarget.Cmp(b.netParams.PowLimit) < 0 { + for durationVal > 0 && newTarget.Cmp(b.chainParams.PowLimit) < 0 { newTarget.Mul(newTarget, adjustmentFactor) durationVal -= maxRetargetTimespan } // Limit new value to the proof of work limit. - if newTarget.Cmp(b.netParams.PowLimit) > 0 { - newTarget.Set(b.netParams.PowLimit) + if newTarget.Cmp(b.chainParams.PowLimit) > 0 { + newTarget.Set(b.chainParams.PowLimit) } return BigToCompact(newTarget) @@ -228,7 +228,7 @@ func (b *BlockChain) findPrevTestNetDifficulty(startNode *blockNode) (uint32, er // the special rule applied. iterNode := startNode for iterNode != nil && iterNode.height%BlocksPerRetarget != 0 && - iterNode.bits == b.netParams.PowLimitBits { + iterNode.bits == b.chainParams.PowLimitBits { // Get the previous block node. This function is used over // simply accessing iterNode.parent directly as it will @@ -245,7 +245,7 @@ func (b *BlockChain) findPrevTestNetDifficulty(startNode *blockNode) (uint32, er // Return the found difficulty or the minimum difficulty if no // appropriate block was found. - lastBits := b.netParams.PowLimitBits + lastBits := b.chainParams.PowLimitBits if iterNode != nil { lastBits = iterNode.bits } @@ -260,7 +260,7 @@ func (b *BlockChain) findPrevTestNetDifficulty(startNode *blockNode) (uint32, er func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTime time.Time) (uint32, error) { // Genesis block. if lastNode == nil { - return b.netParams.PowLimitBits, nil + return b.chainParams.PowLimitBits, nil } // Return the previous block's difficulty requirements if this block @@ -269,13 +269,13 @@ func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim // The test network rules allow minimum difficulty blocks after // more than twice the desired amount of time needed to generate // a block has elapsed. - if b.netParams.ResetMinDifficulty { + if b.chainParams.ResetMinDifficulty { // Return minimum difficulty when more than twice the // desired amount of time needed to generate a block has // elapsed. allowMinTime := lastNode.timestamp.Add(targetSpacing * 2) if newBlockTime.After(allowMinTime) { - return b.netParams.PowLimitBits, nil + return b.chainParams.PowLimitBits, nil } // The block was mined within the desired timeframe, so @@ -333,8 +333,8 @@ func (b *BlockChain) calcNextRequiredDifficulty(lastNode *blockNode, newBlockTim newTarget.Div(newTarget, big.NewInt(int64(targetTimespan))) // Limit new value to the proof of work limit. - if newTarget.Cmp(b.netParams.PowLimit) > 0 { - newTarget.Set(b.netParams.PowLimit) + if newTarget.Cmp(b.chainParams.PowLimit) > 0 { + newTarget.Set(b.chainParams.PowLimit) } // Log new target difficulty and return it. The new target logging is diff --git a/blockchain/example_test.go b/blockchain/example_test.go index 229b55f1..e667bb35 100644 --- a/blockchain/example_test.go +++ b/blockchain/example_test.go @@ -9,9 +9,9 @@ import ( "math/big" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/memdb" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -35,7 +35,7 @@ func ExampleBlockChain_ProcessBlock() { // Insert the main network genesis block. This is part of the initial // database setup. Like above, this typically would not be needed when // opening an existing database. - genesisBlock := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) + genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) _, err = db.InsertBlock(genesisBlock) if err != nil { fmt.Printf("Failed to insert genesis block: %v\n", err) @@ -44,7 +44,7 @@ func ExampleBlockChain_ProcessBlock() { // Create a new BlockChain instance using the underlying database for // the main bitcoin network and ignore notifications. - chain := blockchain.New(db, &btcnet.MainNetParams, nil) + chain := blockchain.New(db, &chaincfg.MainNetParams, nil) // Create a new median time source that is required by the upcoming // call to ProcessBlock. Ordinarily this would also add time values diff --git a/blockchain/process.go b/blockchain/process.go index 950022a8..5b944842 100644 --- a/blockchain/process.go +++ b/blockchain/process.go @@ -141,7 +141,7 @@ func (b *BlockChain) ProcessBlock(block *btcutil.Block, timeSource MedianTimeSou } // Perform preliminary sanity checks on the block and its transactions. - err = checkBlockSanity(block, b.netParams.PowLimit, timeSource, flags) + err = checkBlockSanity(block, b.chainParams.PowLimit, timeSource, flags) if err != nil { return false, err } diff --git a/blockchain/validate.go b/blockchain/validate.go index 9b98c2d7..60a68530 100644 --- a/blockchain/validate.go +++ b/blockchain/validate.go @@ -11,10 +11,10 @@ import ( "math/big" "time" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -172,13 +172,13 @@ func isBIP0030Node(node *blockNode) bool { // // At the target block generation rate for the main network, this is // approximately every 4 years. -func CalcBlockSubsidy(height int64, netParams *btcnet.Params) int64 { - if netParams.SubsidyHalvingInterval == 0 { +func CalcBlockSubsidy(height int64, chainParams *chaincfg.Params) int64 { + if chainParams.SubsidyHalvingInterval == 0 { return baseSubsidy } // Equivalent to: baseSubsidy / 2^(height/subsidyHalvingInterval) - return baseSubsidy >> uint(height/int64(netParams.SubsidyHalvingInterval)) + return baseSubsidy >> uint(height/int64(chainParams.SubsidyHalvingInterval)) } // CheckTransactionSanity performs some preliminary checks on a transaction to @@ -786,7 +786,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block) er // The coinbase for the Genesis block is not spendable, so just return // now. - if node.hash.IsEqual(b.netParams.GenesisHash) && b.bestChain == nil { + if node.hash.IsEqual(b.chainParams.GenesisHash) && b.bestChain == nil { return nil } @@ -894,7 +894,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block) er for _, txOut := range transactions[0].MsgTx().TxOut { totalSatoshiOut += txOut.Value } - expectedSatoshiOut := CalcBlockSubsidy(node.height, b.netParams) + + expectedSatoshiOut := CalcBlockSubsidy(node.height, b.chainParams) + totalFees if totalSatoshiOut > expectedSatoshiOut { str := fmt.Sprintf("coinbase transaction for block pays %v "+ diff --git a/blockchain/validate_test.go b/blockchain/validate_test.go index 566b5468..46a9c330 100644 --- a/blockchain/validate_test.go +++ b/blockchain/validate_test.go @@ -11,8 +11,8 @@ import ( "time" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -34,7 +34,7 @@ func TestCheckConnectBlock(t *testing.T) { // The genesis block should fail to connect since it's already // inserted. - genesisBlock := btcnet.MainNetParams.GenesisBlock + genesisBlock := chaincfg.MainNetParams.GenesisBlock err = chain.CheckConnectBlock(btcutil.NewBlock(genesisBlock)) if err == nil { t.Errorf("CheckConnectBlock: Did not received expected error") @@ -44,7 +44,7 @@ func TestCheckConnectBlock(t *testing.T) { // TestCheckBlockSanity tests the CheckBlockSanity function to ensure it works // as expected. func TestCheckBlockSanity(t *testing.T) { - powLimit := btcnet.MainNetParams.PowLimit + powLimit := chaincfg.MainNetParams.PowLimit block := btcutil.NewBlock(&Block100000) timeSource := blockchain.NewMedianTime() err := blockchain.CheckBlockSanity(block, powLimit, timeSource) diff --git a/blockmanager.go b/blockmanager.go index 2a78c50c..28fb6245 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -14,9 +14,9 @@ import ( "time" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -180,7 +180,7 @@ type blockManager struct { headersFirstMode bool headerList *list.List startHeader *list.Element - nextCheckpoint *btcnet.Checkpoint + nextCheckpoint *chaincfg.Checkpoint } // resetHeaderState sets the headers-first mode state to values appropriate for @@ -221,13 +221,13 @@ func (b *blockManager) updateChainState(newestHash *wire.ShaHash, newestHeight i // It returns nil when there is not one either because the height is already // later than the final checkpoint or some other reason such as disabled // checkpoints. -func (b *blockManager) findNextHeaderCheckpoint(height int64) *btcnet.Checkpoint { +func (b *blockManager) findNextHeaderCheckpoint(height int64) *chaincfg.Checkpoint { // There is no next checkpoint if checkpoints are disabled or there are // none for this current network. if cfg.DisableCheckpoints { return nil } - checkpoints := b.server.netParams.Checkpoints + checkpoints := b.server.chainParams.Checkpoints if len(checkpoints) == 0 { return nil } @@ -1324,7 +1324,7 @@ func newBlockManager(s *server) (*blockManager, error) { quit: make(chan struct{}), } bm.progressLogger = newBlockProgressLogger("Processed", bmgrLog) - bm.blockChain = blockchain.New(s.db, s.netParams, bm.handleNotifyMsg) + bm.blockChain = blockchain.New(s.db, s.chainParams, bm.handleNotifyMsg) bm.blockChain.DisableCheckpoints(cfg.DisableCheckpoints) if !cfg.DisableCheckpoints { // Initialize the next checkpoint based on the current height. diff --git a/cmd/addblock/config.go b/cmd/addblock/config.go index 43d1dc22..87fd071b 100644 --- a/cmd/addblock/config.go +++ b/cmd/addblock/config.go @@ -9,10 +9,10 @@ import ( "os" "path/filepath" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/ldb" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" flags "github.com/btcsuite/go-flags" ) @@ -27,7 +27,7 @@ var ( btcdHomeDir = btcutil.AppDataDir("btcd", false) defaultDataDir = filepath.Join(btcdHomeDir, "data") knownDbTypes = database.SupportedDBs() - activeNetParams = &btcnet.MainNetParams + activeNetParams = &chaincfg.MainNetParams ) // config defines the configuration options for findcheckpoint. @@ -67,18 +67,18 @@ func validDbType(dbType string) bool { // 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 +// chaincfg parameters. This function can be used to override this directory name // as "testnet" when the passed active network matches wire.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 { +func netName(chainParams *chaincfg.Params) string { + switch chainParams.Net { case wire.TestNet3: return "testnet" default: - return netParams.Name + return chainParams.Name } } @@ -109,15 +109,15 @@ func loadConfig() (*config, []string, error) { // while we're at it if cfg.TestNet3 { numNets++ - activeNetParams = &btcnet.TestNet3Params + activeNetParams = &chaincfg.TestNet3Params } if cfg.RegressionTest { numNets++ - activeNetParams = &btcnet.RegressionNetParams + activeNetParams = &chaincfg.RegressionNetParams } if cfg.SimNet { numNets++ - activeNetParams = &btcnet.SimNetParams + activeNetParams = &chaincfg.SimNetParams } if numNets > 1 { str := "%s: The testnet, regtest, and simnet params can't be " + diff --git a/cmd/dropafter/dropafter.go b/cmd/dropafter/dropafter.go index 7707604d..d62b8622 100644 --- a/cmd/dropafter/dropafter.go +++ b/cmd/dropafter/dropafter.go @@ -11,11 +11,11 @@ import ( "path/filepath" "strconv" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/ldb" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btclog" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" flags "github.com/btcsuite/go-flags" ) @@ -33,7 +33,7 @@ var ( btcdHomeDir = btcutil.AppDataDir("btcd", false) defaultDataDir = filepath.Join(btcdHomeDir, "data") log btclog.Logger - activeNetParams = &btcnet.MainNetParams + activeNetParams = &chaincfg.MainNetParams ) const ( @@ -44,18 +44,18 @@ const ( // 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 +// chaincfg parameters. This function can be used to override this directory name // as "testnet" when the passed active network matches wire.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 { +func netName(chainParams *chaincfg.Params) string { + switch chainParams.Net { case wire.TestNet3: return "testnet" default: - return netParams.Name + return chainParams.Name } } @@ -85,15 +85,15 @@ func main() { // while we're at it if cfg.TestNet3 { numNets++ - activeNetParams = &btcnet.TestNet3Params + activeNetParams = &chaincfg.TestNet3Params } if cfg.RegressionTest { numNets++ - activeNetParams = &btcnet.RegressionNetParams + activeNetParams = &chaincfg.RegressionNetParams } if cfg.SimNet { numNets++ - activeNetParams = &btcnet.SimNetParams + activeNetParams = &chaincfg.SimNetParams } if numNets > 1 { str := "%s: The testnet, regtest, and simnet params can't be " + diff --git a/cmd/findcheckpoint/config.go b/cmd/findcheckpoint/config.go index d9ab1ba5..906d2377 100644 --- a/cmd/findcheckpoint/config.go +++ b/cmd/findcheckpoint/config.go @@ -9,10 +9,10 @@ import ( "os" "path/filepath" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/ldb" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" flags "github.com/btcsuite/go-flags" ) @@ -28,7 +28,7 @@ var ( btcdHomeDir = btcutil.AppDataDir("btcd", false) defaultDataDir = filepath.Join(btcdHomeDir, "data") knownDbTypes = database.SupportedDBs() - activeNetParams = &btcnet.MainNetParams + activeNetParams = &chaincfg.MainNetParams ) // config defines the configuration options for findcheckpoint. @@ -58,18 +58,18 @@ func validDbType(dbType string) bool { // 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 +// chaincfg parameters. This function can be used to override this directory name // as "testnet" when the passed active network matches wire.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 { +func netName(chainParams *chaincfg.Params) string { + switch chainParams.Net { case wire.TestNet3: return "testnet" default: - return netParams.Name + return chainParams.Name } } @@ -99,15 +99,15 @@ func loadConfig() (*config, []string, error) { // while we're at it if cfg.TestNet3 { numNets++ - activeNetParams = &btcnet.TestNet3Params + activeNetParams = &chaincfg.TestNet3Params } if cfg.RegressionTest { numNets++ - activeNetParams = &btcnet.RegressionNetParams + activeNetParams = &chaincfg.RegressionNetParams } if cfg.SimNet { numNets++ - activeNetParams = &btcnet.SimNetParams + activeNetParams = &chaincfg.SimNetParams } if numNets > 1 { str := "%s: The testnet, regtest, and simnet params can't be " + diff --git a/cmd/findcheckpoint/findcheckpoint.go b/cmd/findcheckpoint/findcheckpoint.go index 68ce52e6..57d59a74 100644 --- a/cmd/findcheckpoint/findcheckpoint.go +++ b/cmd/findcheckpoint/findcheckpoint.go @@ -10,10 +10,10 @@ import ( "path/filepath" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/ldb" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" ) const blockDbNamePrefix = "blocks" @@ -44,7 +44,7 @@ func loadBlockDB() (database.Db, error) { // candidates at the last checkpoint that is already hard coded into btcchain // since there is no point in finding candidates before already existing // checkpoints. -func findCandidates(db database.Db, latestHash *wire.ShaHash) ([]*btcnet.Checkpoint, error) { +func findCandidates(db database.Db, latestHash *wire.ShaHash) ([]*chaincfg.Checkpoint, error) { // Start with the latest block of the main chain. block, err := db.FetchBlockBySha(latestHash) if err != nil { @@ -78,7 +78,7 @@ func findCandidates(db database.Db, latestHash *wire.ShaHash) ([]*btcnet.Checkpo defer fmt.Println() // Loop backwards through the chain to find checkpoint candidates. - candidates := make([]*btcnet.Checkpoint, 0, cfg.NumCandidates) + candidates := make([]*chaincfg.Checkpoint, 0, cfg.NumCandidates) numTested := int64(0) for len(candidates) < cfg.NumCandidates && block.Height() > requiredHeight { // Display progress. @@ -99,7 +99,7 @@ func findCandidates(db database.Db, latestHash *wire.ShaHash) ([]*btcnet.Checkpo if err != nil { return nil, err } - checkpoint := btcnet.Checkpoint{ + checkpoint := chaincfg.Checkpoint{ Height: block.Height(), Hash: candidateHash, } @@ -119,7 +119,7 @@ func findCandidates(db database.Db, latestHash *wire.ShaHash) ([]*btcnet.Checkpo // showCandidate display a checkpoint candidate using and output format // determined by the configuration parameters. The Go syntax output // uses the format the btcchain code expects for checkpoints added to the list. -func showCandidate(candidateNum int, checkpoint *btcnet.Checkpoint) { +func showCandidate(candidateNum int, checkpoint *chaincfg.Checkpoint) { if cfg.UseGoOutput { fmt.Printf("Candidate %d -- {%d, newShaHashFromStr(\"%v\")},\n", candidateNum, checkpoint.Height, checkpoint.Hash) diff --git a/database/common_test.go b/database/common_test.go index daee6b3d..a149cf38 100644 --- a/database/common_test.go +++ b/database/common_test.go @@ -14,11 +14,11 @@ import ( "strings" "testing" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/ldb" _ "github.com/btcsuite/btcd/database/memdb" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -140,7 +140,7 @@ func setupDB(dbType, dbName string) (database.Db, func(), error) { // Insert the main network genesis block. This is part of the initial // database setup. - genesisBlock := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) + genesisBlock := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) _, err = db.InsertBlock(genesisBlock) if err != nil { teardown() @@ -179,7 +179,7 @@ func loadBlocks(t *testing.T) ([]*btcutil.Block, error) { // Set the first block as the genesis block. blocks := make([]*btcutil.Block, 0, 256) - genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) + genesis := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) blocks = append(blocks, genesis) for height := int64(1); err == nil; height++ { diff --git a/database/example_test.go b/database/example_test.go index 90da19a1..92a66156 100644 --- a/database/example_test.go +++ b/database/example_test.go @@ -7,9 +7,9 @@ package database_test import ( "fmt" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" _ "github.com/btcsuite/btcd/database/memdb" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -37,7 +37,7 @@ func ExampleCreateDB() { defer db.Close() // Insert the main network genesis block. - genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) + genesis := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) newHeight, err := db.InsertBlock(genesis) if err != nil { fmt.Println(err) @@ -58,7 +58,7 @@ func exampleLoadDB() (database.Db, error) { } // Insert the main network genesis block. - genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) + genesis := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) _, err = db.InsertBlock(genesis) if err != nil { return nil, err diff --git a/database/ldb/operational_test.go b/database/ldb/operational_test.go index 8726a127..ff647df1 100644 --- a/database/ldb/operational_test.go +++ b/database/ldb/operational_test.go @@ -14,10 +14,10 @@ import ( "strings" "testing" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" "golang.org/x/crypto/ripemd160" ) @@ -110,7 +110,7 @@ func testAddrIndexOperations(t *testing.T, db database.Db, newestBlock *btcutil. } // Extract the dest addr from the tx. - _, testAddrs, _, err := txscript.ExtractPkScriptAddrs(testTx.MsgTx().TxOut[0].PkScript, &btcnet.MainNetParams) + _, testAddrs, _, err := txscript.ExtractPkScriptAddrs(testTx.MsgTx().TxOut[0].PkScript, &chaincfg.MainNetParams) if err != nil { t.Fatalf("Unable to decode tx output, err %v", err) } @@ -420,7 +420,7 @@ func loadBlocks(t *testing.T, file string) (blocks []*btcutil.Block, err error) }() // Set the first block as the genesis block. - genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) + genesis := btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock) blocks = append(blocks, genesis) var block *btcutil.Block @@ -523,7 +523,7 @@ func TestLimitAndSkipFetchTxsForAddr(t *testing.T) { // Insert a block with some fake test transactions. The block will have // 10 copies of a fake transaction involving same address. addrString := "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa" - targetAddr, err := btcutil.DecodeAddress(addrString, &btcnet.MainNetParams) + targetAddr, err := btcutil.DecodeAddress(addrString, &chaincfg.MainNetParams) if err != nil { t.Fatalf("Unable to decode test address: %v", err) } diff --git a/database/memdb/memdb_test.go b/database/memdb/memdb_test.go index 8d954e0d..02dc026f 100644 --- a/database/memdb/memdb_test.go +++ b/database/memdb/memdb_test.go @@ -8,10 +8,10 @@ import ( "reflect" "testing" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" "github.com/btcsuite/btcd/database/memdb" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -25,7 +25,7 @@ func TestClosed(t *testing.T) { t.Errorf("Failed to open test database %v", err) return } - _, err = db.InsertBlock(btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)) + _, err = db.InsertBlock(btcutil.NewBlock(chaincfg.MainNetParams.GenesisBlock)) if err != nil { t.Errorf("InsertBlock: %v", err) } @@ -33,7 +33,7 @@ func TestClosed(t *testing.T) { t.Errorf("Close: unexpected error %v", err) } - genesisHash := btcnet.MainNetParams.GenesisHash + genesisHash := chaincfg.MainNetParams.GenesisHash if err := db.DropAfterBlockBySha(genesisHash); err != memdb.ErrDbClosed { t.Errorf("DropAfterBlockBySha: unexpected error %v", err) } @@ -54,7 +54,7 @@ func TestClosed(t *testing.T) { t.Errorf("FetchHeightRange: unexpected error %v", err) } - genesisCoinbaseTx := btcnet.MainNetParams.GenesisBlock.Transactions[0] + genesisCoinbaseTx := chaincfg.MainNetParams.GenesisBlock.Transactions[0] coinbaseHash, err := genesisCoinbaseTx.TxSha() if err != nil { t.Errorf("TxSha: unexpected error %v", err) diff --git a/params.go b/params.go index 532ac02d..c9b83e51 100644 --- a/params.go +++ b/params.go @@ -5,8 +5,8 @@ package main import ( + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcnet" ) // activeNetParams is a pointer to the parameters specific to the @@ -16,7 +16,7 @@ var activeNetParams = &mainNetParams // params is used to group parameters for various networks such as the main // network and test networks. type params struct { - *btcnet.Params + *chaincfg.Params rpcPort string dnsSeeds []string } @@ -28,7 +28,7 @@ type params struct { // it does not handle on to btcd. This approach allows the wallet process // to emulate the full reference implementation RPC API. var mainNetParams = params{ - Params: &btcnet.MainNetParams, + Params: &chaincfg.MainNetParams, rpcPort: "8334", dnsSeeds: []string{ "seed.bitcoin.sipa.be", @@ -46,7 +46,7 @@ var mainNetParams = params{ // than the reference implementation - see the mainNetParams comment for // details. var regressionNetParams = params{ - Params: &btcnet.RegressionNetParams, + Params: &chaincfg.RegressionNetParams, rpcPort: "18334", dnsSeeds: []string{}, } @@ -55,7 +55,7 @@ var regressionNetParams = params{ // (wire.TestNet3). NOTE: The RPC port is intentionally different than the // reference implementation - see the mainNetParams comment for details. var testNet3Params = params{ - Params: &btcnet.TestNet3Params, + Params: &chaincfg.TestNet3Params, rpcPort: "18334", dnsSeeds: []string{ "testnet-seed.alexykot.me", @@ -68,7 +68,7 @@ var testNet3Params = params{ // simNetParams contains parameters specific to the simulation test network // (wire.SimNet). var simNetParams = params{ - Params: &btcnet.SimNetParams, + Params: &chaincfg.SimNetParams, rpcPort: "18556", dnsSeeds: []string{}, // NOTE: There must NOT be any seeds. } @@ -76,17 +76,17 @@ var simNetParams = params{ // 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 wire.TestNet3. +// chaincfg parameters. This function can be used to override this directory +// name as "testnet" when the passed active network matches wire.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 *params) string { - switch netParams.Net { +func netName(chainParams *params) string { + switch chainParams.Net { case wire.TestNet3: return "testnet" default: - return netParams.Name + return chainParams.Name } } diff --git a/peer.go b/peer.go index 2630845a..69ff0644 100644 --- a/peer.go +++ b/peer.go @@ -1890,7 +1890,7 @@ func newPeerBase(s *server, inbound bool) *peer { p := peer{ server: s, protocolVersion: maxProtocolVersion, - btcnet: s.netParams.Net, + btcnet: s.chainParams.Net, services: wire.SFNodeNetwork, inbound: inbound, knownAddresses: make(map[string]struct{}), diff --git a/rpcserver.go b/rpcserver.go index 990cc24c..93cfa984 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -27,12 +27,12 @@ import ( "time" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" "github.com/btcsuite/btcjson" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcws" "github.com/btcsuite/fastsha256" @@ -796,7 +796,7 @@ func handleCreateRawTransaction(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan default: return nil, btcjson.ErrInvalidAddressOrKey } - if !addr.IsForNet(s.server.netParams) { + if !addr.IsForNet(s.server.chainParams) { return nil, btcjson.Error{ Code: btcjson.ErrInvalidAddressOrKey.Code, Message: fmt.Sprintf("%s: %q", @@ -875,7 +875,7 @@ func createVinList(mtx *wire.MsgTx) []btcjson.Vin { // createVoutList returns a slice of JSON objects for the outputs of the passed // transaction. -func createVoutList(mtx *wire.MsgTx, net *btcnet.Params) []btcjson.Vout { +func createVoutList(mtx *wire.MsgTx, chainParams *chaincfg.Params) []btcjson.Vout { voutList := make([]btcjson.Vout, len(mtx.TxOut)) for i, v := range mtx.TxOut { voutList[i].N = uint32(i) @@ -890,7 +890,8 @@ func createVoutList(mtx *wire.MsgTx, net *btcnet.Params) []btcjson.Vout { // Ignore the error here since an error means the script // couldn't parse and there is no additional information about // it anyways. - scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(v.PkScript, net) + scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs( + v.PkScript, chainParams) voutList[i].ScriptPubKey.Type = scriptClass.String() voutList[i].ScriptPubKey.ReqSigs = int32(reqSigs) @@ -909,8 +910,8 @@ func createVoutList(mtx *wire.MsgTx, net *btcnet.Params) []btcjson.Vout { // createTxRawResult converts the passed transaction and associated parameters // to a raw transaction JSON object. -func createTxRawResult(net *btcnet.Params, txSha string, mtx *wire.MsgTx, - blk *btcutil.Block, maxidx int64, +func createTxRawResult(chainParams *chaincfg.Params, txSha string, + mtx *wire.MsgTx, blk *btcutil.Block, maxidx int64, blksha *wire.ShaHash) (*btcjson.TxRawResult, error) { mtxHex, err := messageToHex(mtx) @@ -921,7 +922,7 @@ func createTxRawResult(net *btcnet.Params, txSha string, mtx *wire.MsgTx, txReply := &btcjson.TxRawResult{ Hex: mtxHex, Txid: txSha, - Vout: createVoutList(mtx, net), + Vout: createVoutList(mtx, chainParams), Vin: createVinList(mtx), Version: mtx.Version, LockTime: mtx.LockTime, @@ -974,7 +975,7 @@ func handleDecodeRawTransaction(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan Version: mtx.Version, Locktime: mtx.LockTime, Vin: createVinList(&mtx), - Vout: createVoutList(&mtx, s.server.netParams), + Vout: createVoutList(&mtx, s.server.chainParams), } return txReply, nil } @@ -1004,15 +1005,15 @@ func handleDecodeScript(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{} // Get information about the script. // Ignore the error here since an error means the script couldn't parse // and there is no additinal information about it anyways. - net := s.server.netParams - scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script, net) + scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script, + s.server.chainParams) addresses := make([]string, len(addrs)) for i, addr := range addrs { addresses[i] = addr.EncodeAddress() } // Convert the script itself to a pay-to-script-hash address. - p2sh, err := btcutil.NewAddressScriptHash(script, net) + p2sh, err := btcutil.NewAddressScriptHash(script, s.server.chainParams) if err != nil { return nil, btcjson.Error{ Code: btcjson.ErrInternal.Code, @@ -1212,7 +1213,7 @@ func handleGetBlock(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{}) (i txSha := tx.Sha().String() mtx := tx.MsgTx() - rawTxn, err := createTxRawResult(s.server.netParams, + rawTxn, err := createTxRawResult(s.server.chainParams, txSha, mtx, blk, maxidx, sha) if err != nil { rpcsLog.Errorf("Cannot create TxRawResult for "+ @@ -2055,7 +2056,7 @@ func handleGetConnectionCount(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan st // handleGetCurrentNet implements the getcurrentnet command. func handleGetCurrentNet(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{}) (interface{}, error) { - return s.server.netParams.Net, nil + return s.server.chainParams.Net, nil } // handleGetDifficulty implements the getdifficulty command. @@ -2402,7 +2403,7 @@ func handleGetRawTransaction(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan str } } - rawTxn, err := createTxRawResult(s.server.netParams, c.Txid, mtx, + rawTxn, err := createTxRawResult(s.server.chainParams, c.Txid, mtx, blk, maxidx, blksha) if err != nil { rpcsLog.Errorf("Cannot create TxRawResult for txSha=%s: %v", txSha, err) @@ -2525,8 +2526,8 @@ func handleGetTxOut(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{}) (i // Get further info about the script. // Ignore the error here since an error means the script couldn't parse // and there is no additional information about it anyways. - net := s.server.netParams - scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script, net) + scriptClass, addrs, reqSigs, _ := txscript.ExtractPkScriptAddrs(script, + s.server.chainParams) addresses := make([]string, len(addrs)) for i, addr := range addrs { addresses[i] = addr.EncodeAddress() @@ -2967,7 +2968,7 @@ func handleSearchRawTransactions(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan c := cmd.(*btcjson.SearchRawTransactionsCmd) // Attempt to decode the supplied address. - addr, err := btcutil.DecodeAddress(c.Address, s.server.netParams) + addr, err := btcutil.DecodeAddress(c.Address, s.server.chainParams) if err != nil { return nil, btcjson.Error{ Code: btcjson.ErrInvalidAddressOrKey.Code, @@ -3052,7 +3053,7 @@ func handleSearchRawTransactions(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan blkSha, _ = blk.Sha() } - rawTxn, err := createTxRawResult(s.server.netParams, + rawTxn, err := createTxRawResult(s.server.chainParams, txSha, mtx, blk, maxidx, blkSha) if err != nil { rpcsLog.Errorf("Cannot create TxRawResult for "+ diff --git a/rpcwebsocket.go b/rpcwebsocket.go index 7ba1bf35..e41d12bc 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -490,7 +490,7 @@ func (m *wsNotificationManager) notifyForNewTx(clients map[chan struct{}]*wsClie for _, wsc := range clients { if wsc.verboseTxUpdates { if verboseNtfn == nil { - net := m.server.server.netParams + net := m.server.server.chainParams rawTx, err := createTxRawResult(net, txShaStr, mtx, nil, 0, nil) if err != nil { @@ -625,7 +625,7 @@ func (m *wsNotificationManager) notifyForTxOuts(ops map[wire.OutPoint]map[chan s wscNotified := make(map[chan struct{}]struct{}) for i, txOut := range tx.MsgTx().TxOut { _, txAddrs, _, err := txscript.ExtractPkScriptAddrs( - txOut.PkScript, m.server.server.netParams) + txOut.PkScript, m.server.server.chainParams) if err != nil { continue } @@ -1513,7 +1513,7 @@ func rescanBlock(wsc *wsClient, lookups *rescanKeys, blk *btcutil.Block) { for txOutIdx, txout := range tx.MsgTx().TxOut { _, addrs, _, _ := txscript.ExtractPkScriptAddrs( - txout.PkScript, wsc.server.server.netParams) + txout.PkScript, wsc.server.server.chainParams) for _, addr := range addrs { switch a := addr.(type) { diff --git a/server.go b/server.go index 2be6c906..470e66de 100644 --- a/server.go +++ b/server.go @@ -21,10 +21,10 @@ import ( "github.com/btcsuite/btcd/addrmgr" "github.com/btcsuite/btcd/blockchain" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/database" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcjson" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -75,7 +75,7 @@ type relayMsg struct { type server struct { nonce uint64 listeners []net.Listener - netParams *btcnet.Params + chainParams *chaincfg.Params started int32 // atomic shutdown int32 // atomic shutdownSched int32 // atomic @@ -1096,9 +1096,9 @@ out: } // newServer returns a new btcd server configured to listen on addr for the -// bitcoin network type specified by netParams. Use start to begin accepting +// bitcoin network type specified by chainParams. Use start to begin accepting // connections from peers. -func newServer(listenAddrs []string, db database.Db, netParams *btcnet.Params) (*server, error) { +func newServer(listenAddrs []string, db database.Db, chainParams *chaincfg.Params) (*server, error) { nonce, err := wire.RandomUint64() if err != nil { return nil, err @@ -1233,7 +1233,7 @@ func newServer(listenAddrs []string, db database.Db, netParams *btcnet.Params) ( s := server{ nonce: nonce, listeners: listeners, - netParams: netParams, + chainParams: chainParams, addrManager: amgr, newPeers: make(chan *peer, cfg.MaxPeers), donePeers: make(chan *peer, cfg.MaxPeers), diff --git a/txscript/address.go b/txscript/address.go index cfa5dd09..7c06fc9b 100644 --- a/txscript/address.go +++ b/txscript/address.go @@ -5,7 +5,7 @@ package txscript import ( - "github.com/btcsuite/btcnet" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcutil" ) @@ -13,7 +13,7 @@ import ( // signatures associated with the passed PkScript. Note that it only works for // 'standard' transaction script types. Any data such as public keys which are // invalid are omitted from the results. -func ExtractPkScriptAddrs(pkScript []byte, net *btcnet.Params) (ScriptClass, []btcutil.Address, int, error) { +func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (ScriptClass, []btcutil.Address, int, error) { var addrs []btcutil.Address var requiredSigs int @@ -32,7 +32,8 @@ func ExtractPkScriptAddrs(pkScript []byte, net *btcnet.Params) (ScriptClass, []b // Therefore the pubkey hash is the 3rd item on the stack. // Skip the pubkey hash if it's invalid for some reason. requiredSigs = 1 - addr, err := btcutil.NewAddressPubKeyHash(pops[2].data, net) + addr, err := btcutil.NewAddressPubKeyHash(pops[2].data, + chainParams) if err == nil { addrs = append(addrs, addr) } @@ -43,7 +44,7 @@ func ExtractPkScriptAddrs(pkScript []byte, net *btcnet.Params) (ScriptClass, []b // Therefore the pubkey is the first item on the stack. // Skip the pubkey if it's invalid for some reason. requiredSigs = 1 - addr, err := btcutil.NewAddressPubKey(pops[0].data, net) + addr, err := btcutil.NewAddressPubKey(pops[0].data, chainParams) if err == nil { addrs = append(addrs, addr) } @@ -54,7 +55,8 @@ func ExtractPkScriptAddrs(pkScript []byte, net *btcnet.Params) (ScriptClass, []b // Therefore the script hash is the 2nd item on the stack. // Skip the script hash if it's invalid for some reason. requiredSigs = 1 - addr, err := btcutil.NewAddressScriptHashFromHash(pops[1].data, net) + addr, err := btcutil.NewAddressScriptHashFromHash(pops[1].data, + chainParams) if err == nil { addrs = append(addrs, addr) } @@ -71,7 +73,8 @@ func ExtractPkScriptAddrs(pkScript []byte, net *btcnet.Params) (ScriptClass, []b // Extract the public keys while skipping any that are invalid. addrs = make([]btcutil.Address, 0, numPubKeys) for i := 0; i < numPubKeys; i++ { - addr, err := btcutil.NewAddressPubKey(pops[i+1].data, net) + addr, err := btcutil.NewAddressPubKey(pops[i+1].data, + chainParams) if err == nil { addrs = append(addrs, addr) } diff --git a/txscript/address_test.go b/txscript/address_test.go index 9345e7d7..eeeebe83 100644 --- a/txscript/address_test.go +++ b/txscript/address_test.go @@ -8,8 +8,8 @@ import ( "reflect" "testing" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/txscript" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -32,7 +32,7 @@ func decodeHex(hexStr string) []byte { // in the test source code. func newAddressPubKey(serializedPubKey []byte) btcutil.Address { addr, err := btcutil.NewAddressPubKey(serializedPubKey, - &btcnet.MainNetParams) + &chaincfg.MainNetParams) if err != nil { panic("invalid public key in test source") } @@ -45,7 +45,7 @@ func newAddressPubKey(serializedPubKey []byte) btcutil.Address { // as a helper since the only way it can fail is if there is an error in the // test source code. func newAddressPubKeyHash(pkHash []byte) btcutil.Address { - addr, err := btcutil.NewAddressPubKeyHash(pkHash, &btcnet.MainNetParams) + addr, err := btcutil.NewAddressPubKeyHash(pkHash, &chaincfg.MainNetParams) if err != nil { panic("invalid public key hash in test source") } @@ -59,7 +59,7 @@ func newAddressPubKeyHash(pkHash []byte) btcutil.Address { // test source code. func newAddressScriptHash(scriptHash []byte) btcutil.Address { addr, err := btcutil.NewAddressScriptHashFromHash(scriptHash, - &btcnet.MainNetParams) + &chaincfg.MainNetParams) if err != nil { panic("invalid script hash in test source") } @@ -340,7 +340,7 @@ func TestExtractPkScriptAddrs(t *testing.T) { t.Logf("Running %d tests.", len(tests)) for i, test := range tests { class, addrs, reqSigs, err := txscript.ExtractPkScriptAddrs( - test.script, &btcnet.MainNetParams) + test.script, &chaincfg.MainNetParams) if err != nil { } diff --git a/txscript/example_test.go b/txscript/example_test.go index 4317ef5c..21d1cfe4 100644 --- a/txscript/example_test.go +++ b/txscript/example_test.go @@ -8,8 +8,8 @@ import ( "encoding/hex" "fmt" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/txscript" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -22,7 +22,7 @@ func ExamplePayToAddrScript() { // the address type. It is also required for the upcoming call to // PayToAddrScript. addressStr := "12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV" - address, err := btcutil.DecodeAddress(addressStr, &btcnet.MainNetParams) + address, err := btcutil.DecodeAddress(addressStr, &chaincfg.MainNetParams) if err != nil { fmt.Println(err) return @@ -61,7 +61,7 @@ func ExampleExtractPkScriptAddrs() { // Extract and print details from the script. scriptClass, addresses, reqSigs, err := txscript.ExtractPkScriptAddrs( - script, &btcnet.MainNetParams) + script, &chaincfg.MainNetParams) if err != nil { fmt.Println(err) return diff --git a/txscript/script.go b/txscript/script.go index 8132366c..21f089d2 100644 --- a/txscript/script.go +++ b/txscript/script.go @@ -11,9 +11,9 @@ import ( "fmt" "time" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -1193,11 +1193,12 @@ func signMultiSig(tx *wire.MsgTx, idx int, subScript []byte, hashType SigHashTyp return script, signed == nRequired } -func sign(net *btcnet.Params, tx *wire.MsgTx, idx int, subScript []byte, - hashType SigHashType, kdb KeyDB, sdb ScriptDB) ([]byte, ScriptClass, - []btcutil.Address, int, error) { +func sign(chainParams *chaincfg.Params, tx *wire.MsgTx, idx int, + subScript []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB) ([]byte, + ScriptClass, []btcutil.Address, int, error) { - class, addresses, nrequired, err := ExtractPkScriptAddrs(subScript, net) + class, addresses, nrequired, err := ExtractPkScriptAddrs(subScript, + chainParams) if err != nil { return nil, NonStandardTy, nil, 0, err } @@ -1257,7 +1258,7 @@ func sign(net *btcnet.Params, tx *wire.MsgTx, idx int, subScript []byte, // The return value is the best effort merging of the two scripts. Calling this // function with addresses, class and nrequired that do not match pkScript is // an error and results in undefined behaviour. -func mergeScripts(net *btcnet.Params, tx *wire.MsgTx, idx int, +func mergeScripts(chainParams *chaincfg.Params, tx *wire.MsgTx, idx int, pkScript []byte, class ScriptClass, addresses []btcutil.Address, nRequired int, sigScript, prevScript []byte) []byte { @@ -1284,15 +1285,15 @@ func mergeScripts(net *btcnet.Params, tx *wire.MsgTx, idx int, // We already know this information somewhere up the stack. class, addresses, nrequired, err := - ExtractPkScriptAddrs(script, net) + ExtractPkScriptAddrs(script, chainParams) // regenerate scripts. sigScript, _ := unparseScript(sigPops) prevScript, _ := unparseScript(prevPops) // Merge - mergedScript := mergeScripts(net, tx, idx, script, class, - addresses, nrequired, sigScript, prevScript) + mergedScript := mergeScripts(chainParams, tx, idx, script, + class, addresses, nrequired, sigScript, prevScript) // Reappend the script and return the result. builder := NewScriptBuilder() @@ -1469,20 +1470,20 @@ func (sc ScriptClosure) GetScript(address btcutil.Address) ([]byte, error) { // getScript. If previousScript is provided then the results in previousScript // will be merged in a type-dependant manner with the newly generated. // signature script. -func SignTxOutput(net *btcnet.Params, tx *wire.MsgTx, idx int, +func SignTxOutput(chainParams *chaincfg.Params, tx *wire.MsgTx, idx int, pkScript []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB, previousScript []byte) ([]byte, error) { - sigScript, class, addresses, nrequired, err := sign(net, tx, idx, - pkScript, hashType, kdb, sdb) + sigScript, class, addresses, nrequired, err := sign(chainParams, tx, + idx, pkScript, hashType, kdb, sdb) if err != nil { return nil, err } if class == ScriptHashTy { // TODO keep the sub addressed and pass down to merge. - realSigScript, _, _, _, err := sign(net, tx, idx, sigScript, - hashType, kdb, sdb) + realSigScript, _, _, _, err := sign(chainParams, tx, idx, + sigScript, hashType, kdb, sdb) if err != nil { return nil, err } @@ -1498,8 +1499,8 @@ func SignTxOutput(net *btcnet.Params, tx *wire.MsgTx, idx int, } // Merge scripts. with any previous data, if any. - mergedScript := mergeScripts(net, tx, idx, pkScript, class, addresses, - nrequired, sigScript, previousScript) + mergedScript := mergeScripts(chainParams, tx, idx, pkScript, class, + addresses, nrequired, sigScript, previousScript) if err != nil { return nil, err } diff --git a/txscript/script_test.go b/txscript/script_test.go index 3493333d..4d9eaa6b 100644 --- a/txscript/script_test.go +++ b/txscript/script_test.go @@ -10,10 +10,10 @@ import ( "fmt" "testing" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcec" - "github.com/btcsuite/btcnet" "github.com/btcsuite/btcutil" ) @@ -2963,7 +2963,7 @@ func (b *bogusAddress) ScriptAddress() []byte { } // IsForNet lies blatantly to satisfy the btcutil.Address interface. -func (b *bogusAddress) IsForNet(net *btcnet.Params) bool { +func (b *bogusAddress) IsForNet(chainParams *chaincfg.Params) bool { return true // why not? } @@ -2980,7 +2980,7 @@ func TestPayToAddrScript(t *testing.T) { p2pkhMain, err := btcutil.NewAddressPubKeyHash([]byte{ 0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc, 0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84, - }, &btcnet.MainNetParams) + }, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create public key hash address: %v", err) return @@ -2991,7 +2991,7 @@ func TestPayToAddrScript(t *testing.T) { p2shMain, _ := btcutil.NewAddressScriptHashFromHash([]byte{ 0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37, 0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4, - }, &btcnet.MainNetParams) + }, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create script hash address: %v", err) return @@ -3002,7 +3002,7 @@ func TestPayToAddrScript(t *testing.T) { 0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95, 0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03, 0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca, - 0x52, 0xc6, 0xb4}, &btcnet.MainNetParams) + 0x52, 0xc6, 0xb4}, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed): %v", err) @@ -3012,7 +3012,7 @@ func TestPayToAddrScript(t *testing.T) { 0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1, 0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0, 0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e, - 0xb1, 0x6e, 0x65}, &btcnet.MainNetParams) + 0xb1, 0x6e, 0x65}, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed 2): %v", err) @@ -3026,7 +3026,7 @@ func TestPayToAddrScript(t *testing.T) { 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, - 0xf6, 0x56, 0xb4, 0x12, 0xa3}, &btcnet.MainNetParams) + 0xf6, 0x56, 0xb4, 0x12, 0xa3}, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (uncompressed): %v", err) @@ -3137,7 +3137,7 @@ func TestMultiSigScript(t *testing.T) { 0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95, 0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03, 0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca, - 0x52, 0xc6, 0xb4}, &btcnet.MainNetParams) + 0x52, 0xc6, 0xb4}, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed): %v", err) @@ -3147,7 +3147,7 @@ func TestMultiSigScript(t *testing.T) { 0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1, 0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0, 0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e, - 0xb1, 0x6e, 0x65}, &btcnet.MainNetParams) + 0xb1, 0x6e, 0x65}, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed 2): %v", err) @@ -3161,7 +3161,7 @@ func TestMultiSigScript(t *testing.T) { 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, - 0xf6, 0x56, 0xb4, 0x12, 0xa3}, &btcnet.MainNetParams) + 0xf6, 0x56, 0xb4, 0x12, 0xa3}, &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (uncompressed): %v", err) @@ -3284,7 +3284,7 @@ func signAndCheck(msg string, tx *wire.MsgTx, idx int, pkScript []byte, previousScript []byte) error { sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, idx, pkScript, hashType, + &chaincfg.TestNet3Params, tx, idx, pkScript, hashType, kdb, sdb, []byte{}) if err != nil { return fmt.Errorf("failed to sign output %s: %v", msg, err) @@ -3419,7 +3419,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3456,7 +3456,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3470,7 +3470,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), []byte{}) @@ -3483,7 +3483,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), sigScript) @@ -3517,7 +3517,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3555,7 +3555,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3569,7 +3569,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), []byte{}) @@ -3582,7 +3582,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), sigScript) @@ -3616,7 +3616,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3654,7 +3654,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3668,7 +3668,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), []byte{}) @@ -3681,7 +3681,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), sigScript) @@ -3715,7 +3715,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3753,7 +3753,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3767,7 +3767,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), []byte{}) @@ -3780,7 +3780,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, pkScript, + &chaincfg.TestNet3Params, tx, i, pkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), sigScript) @@ -3814,7 +3814,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3829,7 +3829,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -3871,7 +3871,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3886,7 +3886,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -3902,7 +3902,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ @@ -3917,7 +3917,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ @@ -3953,7 +3953,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -3967,7 +3967,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4010,7 +4010,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKeyHash( - btcutil.Hash160(pk), &btcnet.TestNet3Params) + btcutil.Hash160(pk), &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4024,7 +4024,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4040,7 +4040,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ @@ -4055,7 +4055,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ @@ -4091,7 +4091,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4105,7 +4105,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4148,7 +4148,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeUncompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4162,7 +4162,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4178,7 +4178,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ @@ -4193,7 +4193,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ @@ -4229,7 +4229,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4243,7 +4243,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4286,7 +4286,7 @@ func TestSignTxOutput(t *testing.T) { pk := (*btcec.PublicKey)(&key.PublicKey). SerializeCompressed() address, err := btcutil.NewAddressPubKey(pk, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4300,7 +4300,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4316,7 +4316,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ @@ -4331,7 +4331,7 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ @@ -4367,7 +4367,7 @@ func TestSignTxOutput(t *testing.T) { pk1 := (*btcec.PublicKey)(&key1.PublicKey). SerializeCompressed() address1, err := btcutil.NewAddressPubKey(pk1, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4384,7 +4384,7 @@ func TestSignTxOutput(t *testing.T) { pk2 := (*btcec.PublicKey)(&key2.PublicKey). SerializeCompressed() address2, err := btcutil.NewAddressPubKey(pk2, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address 2 for %s: %v", msg, err) @@ -4400,7 +4400,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4444,7 +4444,7 @@ func TestSignTxOutput(t *testing.T) { pk1 := (*btcec.PublicKey)(&key1.PublicKey). SerializeCompressed() address1, err := btcutil.NewAddressPubKey(pk1, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4461,7 +4461,7 @@ func TestSignTxOutput(t *testing.T) { pk2 := (*btcec.PublicKey)(&key2.PublicKey). SerializeCompressed() address2, err := btcutil.NewAddressPubKey(pk2, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address 2 for %s: %v", msg, err) @@ -4477,7 +4477,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4493,7 +4493,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address1.EncodeAddress(): {key1, true}, }), mkGetScript(map[string][]byte{ @@ -4514,7 +4514,7 @@ func TestSignTxOutput(t *testing.T) { // Sign with the other key and merge sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address2.EncodeAddress(): {key2, true}, }), mkGetScript(map[string][]byte{ @@ -4551,7 +4551,7 @@ func TestSignTxOutput(t *testing.T) { pk1 := (*btcec.PublicKey)(&key1.PublicKey). SerializeCompressed() address1, err := btcutil.NewAddressPubKey(pk1, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address for %s: %v", msg, err) @@ -4568,7 +4568,7 @@ func TestSignTxOutput(t *testing.T) { pk2 := (*btcec.PublicKey)(&key2.PublicKey). SerializeCompressed() address2, err := btcutil.NewAddressPubKey(pk2, - &btcnet.TestNet3Params) + &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make address 2 for %s: %v", msg, err) @@ -4584,7 +4584,7 @@ func TestSignTxOutput(t *testing.T) { } scriptAddr, err := btcutil.NewAddressScriptHash( - pkScript, &btcnet.TestNet3Params) + pkScript, &chaincfg.TestNet3Params) if err != nil { t.Errorf("failed to make p2sh addr for %s: %v", msg, err) @@ -4600,7 +4600,7 @@ func TestSignTxOutput(t *testing.T) { } sigScript, err := txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address1.EncodeAddress(): {key1, true}, }), mkGetScript(map[string][]byte{ @@ -4621,7 +4621,7 @@ func TestSignTxOutput(t *testing.T) { // Sign with the other key and merge sigScript, err = txscript.SignTxOutput( - &btcnet.TestNet3Params, tx, i, scriptPkScript, + &chaincfg.TestNet3Params, tx, i, scriptPkScript, hashType, mkGetKey(map[string]addressToKey{ address1.EncodeAddress(): {key1, true}, address2.EncodeAddress(): {key2, true},