Skip to content

Commit

Permalink
Import btcnet repo into chaincfg directory.
Browse files Browse the repository at this point in the history
This commit contains the entire btcnet repository along with several
changes needed to move all of the files into the chaincfg directory in
order to prepare it for merging.  This does NOT update btcd or any of the
other packages to use the new location as that will be done separately.

- All import paths in the old btcnet test files have been changed to the
  new location
- All references to btcnet as the package name have been changed to
  chaincfg
- The coveralls badge has been removed since it unfortunately doesn't
  support coverage of sub-packages

This is ongoing work toward #214.
  • Loading branch information
davecgh committed Feb 6, 2015
1 parent 4dd7c93 commit 40df138
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 86 deletions.
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

13 changes: 0 additions & 13 deletions LICENSE

This file was deleted.

36 changes: 16 additions & 20 deletions README.md → chaincfg/README.md
@@ -1,19 +1,15 @@
btcnet
======
chaincfg
========

[![Build Status](http://img.shields.io/travis/btcsuite/btcnet.svg)]
(https://travis-ci.org/btcsuite/btcnet) [![Coverage Status]
(https://img.shields.io/coveralls/btcsuite/btcnet.svg)]
(https://coveralls.io/r/btcsuite/btcnet?branch=master) [![ISC License]
[![Build Status](http://img.shields.io/travis/btcsuite/btcd.svg)]
(https://travis-ci.org/btcsuite/btcd) [![ISC License]
(http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)

Package btcnet defines the network parameters for the three standard Bitcoin
networks and provides the ability for callers to define their own custom
Package chaincfg defines chain configuration parameters for the three standard
Bitcoin networks and provides the ability for callers to define their own custom
Bitcoin networks.

This package is one of the core packages from btcd, an alternative full-node
implementation of Bitcoin which is under active development by Conformal.
Although it was primarily written for btcd, this package has intentionally been
Although this package was primarily written for btcd, it has intentionally been
designed so it can be used as a standalone package for any projects needing to
use parameters for the standard Bitcoin networks or for projects needing to
define their own network.
Expand All @@ -29,27 +25,27 @@ import (
"log"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcd/chaincfg"
)

var testnet = flag.Bool("testnet", false, "operate on the testnet Bitcoin network")

// By default (without -testnet), use mainnet.
var netParams = &btcnet.MainNetParams
var chainParams = &chaincfg.MainNetParams

func main() {
flag.Parse()

// Modify active network parameters if operating on testnet.
if *testnet {
netParams = &btcnet.TestNet3Params
chainParams = &chaincfg.TestNet3Params
}

// later...

// Create and print new payment address, specific to the active network.
pubKeyHash := make([]byte, 20)
addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, netParams)
addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, chainParams)
if err != nil {
log.Fatal(err)
}
Expand All @@ -60,20 +56,20 @@ func main() {
## Documentation

[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)]
(http://godoc.org/github.com/btcsuite/btcnet)
(http://godoc.org/github.com/btcsuite/btcd/chaincfg)

Full `go doc` style documentation for the project can be viewed online without
installing this package by using the GoDoc site
[here](http://godoc.org/github.com/btcsuite/btcnet).
[here](http://godoc.org/github.com/btcsuite/btcd/chaincfg).

You can also view the documentation locally once the package is installed with
the `godoc` tool by running `godoc -http=":6060"` and pointing your browser to
http://localhost:6060/pkg/github.com/btcsuite/btcnet
http://localhost:6060/pkg/github.com/btcsuite/btcd/chaincfg

## Installation

```bash
$ go get github.com/btcsuite/btcnet
$ go get github.com/btcsuite/btcd/chaincfg
```

## GPG Verification Key
Expand All @@ -98,5 +94,5 @@ signature perform the following:

## License

Package btcnet is licensed under the [copyfree](http://copyfree.org) ISC
Package chaincfg is licensed under the [copyfree](http://copyfree.org) ISC
License.
22 changes: 10 additions & 12 deletions doc.go → chaincfg/doc.go
@@ -1,6 +1,4 @@
// Package btcnet defines the network parameters for the three standard Bitcoin
// networks and provides the ability for callers to define their own custom
// Bitcoin networks.
// Package chaincfg defines chain configuration parameters.
//
// In addition to the main Bitcoin network, which is intended for the transfer
// of monetary value, there also exists two currently active standard networks:
Expand All @@ -9,11 +7,11 @@
// handle errors where input intended for one network is used on an application
// instance running on a different network.
//
// For library packages, btcnet provides the ability to lookup chain parameters
// and encoding magics when passed a *Params. Older APIs not updated to the new
// convention of passing a *Params may lookup the parameters for a
// For library packages, chaincfg provides the ability to lookup chain
// parameters and encoding magics when passed a *Params. Older APIs not updated
// to the new convention of passing a *Params may lookup the parameters for a
// wire.BitcoinNet using ParamsForNet, but be aware that this usage is
// deprecated and will be removed from btcnet in the future.
// deprecated and will be removed from chaincfg in the future.
//
// For main packages, a (typically global) var may be assigned the address of
// one of the standard Param vars for use as the application's "active" network.
Expand All @@ -28,27 +26,27 @@
// "log"
//
// "github.com/btcsuite/btcutil"
// "github.com/btcsuite/btcnet"
// "github.com/btcsuite/btcd/chaincfg"
// )
//
// var testnet = flag.Bool("testnet", false, "operate on the testnet Bitcoin network")
//
// // By default (without -testnet), use mainnet.
// var netParams = &btcnet.MainNetParams
// var chainParams = &chaincfg.MainNetParams
//
// func main() {
// flag.Parse()
//
// // Modify active network parameters if operating on testnet.
// if *testnet {
// netParams = &btcnet.TestNet3Params
// chainParams = &chaincfg.TestNet3Params
// }
//
// // later...
//
// // Create and print new payment address, specific to the active network.
// pubKeyHash := make([]byte, 20)
// addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, netParams)
// addr, err := btcutil.NewAddressPubKeyHash(pubKeyHash, chainParams)
// if err != nil {
// log.Fatal(err)
// }
Expand All @@ -60,4 +58,4 @@
// non-standard network. As a general rule of thumb, all network parameters
// should be unique to the network, but parameter collisions can still occur
// (unfortunately, this is the case with regtest and testnet3 sharing magics).
package btcnet
package chaincfg
2 changes: 1 addition & 1 deletion genesis.go → chaincfg/genesis.go
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcnet
package chaincfg

import (
"time"
Expand Down
36 changes: 18 additions & 18 deletions genesis_test.go → chaincfg/genesis_test.go
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcnet_test
package chaincfg_test

import (
"bytes"
"testing"

"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcd/chaincfg"
"github.com/davecgh/go-spew/spew"
)

Expand All @@ -17,7 +17,7 @@ import (
func TestGenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := btcnet.MainNetParams.GenesisBlock.Serialize(&buf)
err := chaincfg.MainNetParams.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestGenesisBlock: %v", err)
}
Expand All @@ -30,14 +30,14 @@ func TestGenesisBlock(t *testing.T) {
}

// Check hash of the block against expected hash.
hash, err := btcnet.MainNetParams.GenesisBlock.BlockSha()
hash, err := chaincfg.MainNetParams.GenesisBlock.BlockSha()
if err != nil {
t.Fatalf("BlockSha: %v", err)
}
if !btcnet.MainNetParams.GenesisHash.IsEqual(&hash) {
if !chaincfg.MainNetParams.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestGenesisBlock: Genesis block hash does not "+
"appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(btcnet.MainNetParams.GenesisHash))
spew.Sdump(chaincfg.MainNetParams.GenesisHash))
}
}

Expand All @@ -46,7 +46,7 @@ func TestGenesisBlock(t *testing.T) {
func TestRegTestGenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := btcnet.RegressionNetParams.GenesisBlock.Serialize(&buf)
err := chaincfg.RegressionNetParams.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestRegTestGenesisBlock: %v", err)
}
Expand All @@ -60,14 +60,14 @@ func TestRegTestGenesisBlock(t *testing.T) {
}

// Check hash of the block against expected hash.
hash, err := btcnet.RegressionNetParams.GenesisBlock.BlockSha()
hash, err := chaincfg.RegressionNetParams.GenesisBlock.BlockSha()
if err != nil {
t.Errorf("BlockSha: %v", err)
}
if !btcnet.RegressionNetParams.GenesisHash.IsEqual(&hash) {
if !chaincfg.RegressionNetParams.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestRegTestGenesisBlock: Genesis block hash does "+
"not appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(btcnet.RegressionNetParams.GenesisHash))
spew.Sdump(chaincfg.RegressionNetParams.GenesisHash))
}
}

Expand All @@ -76,7 +76,7 @@ func TestRegTestGenesisBlock(t *testing.T) {
func TestTestNet3GenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := btcnet.TestNet3Params.GenesisBlock.Serialize(&buf)
err := chaincfg.TestNet3Params.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestTestNet3GenesisBlock: %v", err)
}
Expand All @@ -90,14 +90,14 @@ func TestTestNet3GenesisBlock(t *testing.T) {
}

// Check hash of the block against expected hash.
hash, err := btcnet.TestNet3Params.GenesisBlock.BlockSha()
hash, err := chaincfg.TestNet3Params.GenesisBlock.BlockSha()
if err != nil {
t.Fatalf("BlockSha: %v", err)
}
if !btcnet.TestNet3Params.GenesisHash.IsEqual(&hash) {
if !chaincfg.TestNet3Params.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestTestNet3GenesisBlock: Genesis block hash does "+
"not appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(btcnet.TestNet3Params.GenesisHash))
spew.Sdump(chaincfg.TestNet3Params.GenesisHash))
}
}

Expand All @@ -106,7 +106,7 @@ func TestTestNet3GenesisBlock(t *testing.T) {
func TestSimNetGenesisBlock(t *testing.T) {
// Encode the genesis block to raw bytes.
var buf bytes.Buffer
err := btcnet.SimNetParams.GenesisBlock.Serialize(&buf)
err := chaincfg.SimNetParams.GenesisBlock.Serialize(&buf)
if err != nil {
t.Fatalf("TestSimNetGenesisBlock: %v", err)
}
Expand All @@ -120,14 +120,14 @@ func TestSimNetGenesisBlock(t *testing.T) {
}

// Check hash of the block against expected hash.
hash, err := btcnet.SimNetParams.GenesisBlock.BlockSha()
hash, err := chaincfg.SimNetParams.GenesisBlock.BlockSha()
if err != nil {
t.Fatalf("BlockSha: %v", err)
}
if !btcnet.SimNetParams.GenesisHash.IsEqual(&hash) {
if !chaincfg.SimNetParams.GenesisHash.IsEqual(&hash) {
t.Fatalf("TestSimNetGenesisBlock: Genesis block hash does "+
"not appear valid - got %v, want %v", spew.Sdump(hash),
spew.Sdump(btcnet.SimNetParams.GenesisHash))
spew.Sdump(chaincfg.SimNetParams.GenesisHash))
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal_test.go → chaincfg/internal_test.go
@@ -1,4 +1,4 @@
package btcnet
package chaincfg

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion params.go → chaincfg/params.go
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcnet
package chaincfg

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions register_test.go → chaincfg/register_test.go
@@ -1,11 +1,11 @@
package btcnet_test
package chaincfg_test

import (
"bytes"
"reflect"
"testing"

. "github.com/btcsuite/btcnet"
. "github.com/btcsuite/btcd/chaincfg"
)

// Define some of the required parameters for a user-registered
Expand Down

0 comments on commit 40df138

Please sign in to comment.