Skip to content

Commit

Permalink
Import btcchain repo into blockchain directory.
Browse files Browse the repository at this point in the history
This commit contains the entire btcchain repository along with several
changes needed to move all of the files into the blockchain 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 btcchain test files have been changed to
  the new location
- All references to btcchain as the package name have been changed to
  blockchain
  • Loading branch information
davecgh committed Jan 30, 2015
1 parent 3f177c9 commit b69a849
Show file tree
Hide file tree
Showing 43 changed files with 195 additions and 410 deletions.
28 changes: 0 additions & 28 deletions .gitignore

This file was deleted.

17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

13 changes: 0 additions & 13 deletions LICENSE

This file was deleted.

40 changes: 17 additions & 23 deletions README.md → blockchain/README.md
@@ -1,42 +1,40 @@
btcchain
========
blockchain
==========

[![Build Status](http://img.shields.io/travis/btcsuite/btcchain.svg)]
(https://travis-ci.org/btcsuite/btcchain) [![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 btcchain implements bitcoin block handling and chain selection rules.
Package blockchain implements bitcoin block handling and chain selection rules.
The test coverage is currently only around 60%, but will be increasing over
time. See `test_coverage.txt` for the gocov coverage report. Alternatively, if
you are running a POSIX OS, you can run the `cov_report.sh` script for a
real-time report. Package btcchain is licensed under the liberal ISC license.
real-time report. Package blockchain is licensed under the liberal ISC license.

There is an associated blog post about the release of this package
[here](https://blog.conformal.com/btcchain-the-bitcoin-chain-package-from-bctd/).

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
designed so it can be used as a standalone package for any projects needing to
handle processing of blocks into the bitcoin block chain.
This package has intentionally been designed so it can be used as a standalone
package for any projects needing to handle processing of blocks into the bitcoin
block chain.

## Documentation

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

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/btcchain
http://godoc.org/github.com/btcsuite/btcd/blockchain

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/btcchain
http://localhost:6060/pkg/github.com/btcsuite/btcd/blockchain

## Installation

```bash
$ go get github.com/btcsuite/btcchain
$ go get github.com/btcsuite/btcd/blockchain
```

## Bitcoin Chain Processing Overview
Expand Down Expand Up @@ -77,27 +75,23 @@ is by no means exhaustive:
## Examples

* [ProcessBlock Example]
(http://godoc.org/github.com/btcsuite/btcchain#example-BlockChain-ProcessBlock)
(http://godoc.org/github.com/btcsuite/btcd/blockchain#example-BlockChain-ProcessBlock)
Demonstrates how to create a new chain instance and use ProcessBlock to
attempt to attempt add a block to the chain. This example intentionally
attempts to insert a duplicate genesis block to illustrate how an invalid
block is handled.

* [CompactToBig Example]
(http://godoc.org/github.com/btcsuite/btcchain#example-CompactToBig)
(http://godoc.org/github.com/btcsuite/btcd/blockchain#example-CompactToBig)
Demonstrates how to convert the compact "bits" in a block header which
represent the target difficulty to a big integer and display it using the
typical hex notation.

* [BigToCompact Example]
(http://godoc.org/github.com/btcsuite/btcchain#example-BigToCompact)
(http://godoc.org/github.com/btcsuite/btcd/blockchain#example-BigToCompact)
Demonstrates how to convert how to convert a target difficulty into the
compact "bits" in a block header which represent that target difficulty.

## TODO

- Increase test coverage

## GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code
Expand All @@ -121,5 +115,5 @@ signature perform the following:
## License


Package btcchain is licensed under the [copyfree](http://copyfree.org) ISC
Package blockchain is licensed under the [copyfree](http://copyfree.org) ISC
License.
2 changes: 1 addition & 1 deletion accept.go → blockchain/accept.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 btcchain
package blockchain

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion blocklocator.go → blockchain/blocklocator.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 btcchain
package blockchain

import (
"github.com/btcsuite/btcwire"
Expand Down
2 changes: 1 addition & 1 deletion chain.go → blockchain/chain.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 btcchain
package blockchain

import (
"container/list"
Expand Down
12 changes: 6 additions & 6 deletions chain_test.go → blockchain/chain_test.go
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcchain_test
package blockchain_test

import (
"testing"

"github.com/btcsuite/btcchain"
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
Expand Down Expand Up @@ -46,12 +46,12 @@ func TestHaveBlock(t *testing.T) {
// Since we're not dealing with the real block chain, disable
// checkpoints and set the coinbase maturity to 1.
chain.DisableCheckpoints(true)
btcchain.TstSetCoinbaseMaturity(1)
blockchain.TstSetCoinbaseMaturity(1)

timeSource := btcchain.NewMedianTime()
timeSource := blockchain.NewMedianTime()
for i := 1; i < len(blocks); i++ {
isOrphan, err := chain.ProcessBlock(blocks[i], timeSource,
btcchain.BFNone)
blockchain.BFNone)
if err != nil {
t.Errorf("ProcessBlock fail on block %v: %v\n", i, err)
return
Expand All @@ -65,7 +65,7 @@ func TestHaveBlock(t *testing.T) {

// Insert an orphan block.
isOrphan, err := chain.ProcessBlock(btcutil.NewBlock(&Block100000),
timeSource, btcchain.BFNone)
timeSource, blockchain.BFNone)
if err != nil {
t.Errorf("Unable to process block: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion checkpoints.go → blockchain/checkpoints.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 btcchain
package blockchain

import (
"fmt"
Expand Down
14 changes: 7 additions & 7 deletions common_test.go → blockchain/common_test.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 btcchain_test
package blockchain_test

import (
"compress/bzip2"
Expand All @@ -13,7 +13,7 @@ import (
"path/filepath"
"strings"

"github.com/btcsuite/btcchain"
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
_ "github.com/btcsuite/btcd/database/memdb"
Expand Down Expand Up @@ -54,7 +54,7 @@ func isSupportedDbType(dbType string) bool {
// chainSetup is used to create a new db and chain instance with the genesis
// block already inserted. In addition to the new chain instnce, it returns
// a teardown function the caller should invoke when done testing to clean up.
func chainSetup(dbName string) (*btcchain.BlockChain, func(), error) {
func chainSetup(dbName string) (*blockchain.BlockChain, func(), error) {
if !isSupportedDbType(testDbType) {
return nil, nil, fmt.Errorf("unsupported db type %v", testDbType)
}
Expand Down Expand Up @@ -116,12 +116,12 @@ func chainSetup(dbName string) (*btcchain.BlockChain, func(), error) {
return nil, nil, err
}

chain := btcchain.New(db, &btcnet.MainNetParams, nil)
chain := blockchain.New(db, &btcnet.MainNetParams, nil)
return chain, teardown, nil
}

// loadTxStore returns a transaction store loaded from a file.
func loadTxStore(filename string) (btcchain.TxStore, error) {
func loadTxStore(filename string) (blockchain.TxStore, error) {
// The txstore file format is:
// <num tx data entries> <tx length> <serialized tx> <blk height>
// <num spent bits> <spent bits>
Expand Down Expand Up @@ -150,10 +150,10 @@ func loadTxStore(filename string) (btcchain.TxStore, error) {
return nil, err
}

txStore := make(btcchain.TxStore)
txStore := make(blockchain.TxStore)
var uintBuf uint32
for height := uint32(0); height < numItems; height++ {
txD := btcchain.TxData{}
txD := blockchain.TxData{}

// Serialized transaction length.
err = binary.Read(r, binary.LittleEndian, &uintBuf)
Expand Down
2 changes: 1 addition & 1 deletion difficulty.go → blockchain/difficulty.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 btcchain
package blockchain

import (
"fmt"
Expand Down
10 changes: 5 additions & 5 deletions difficulty_test.go → blockchain/difficulty_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 btcchain_test
package blockchain_test

import (
"math/big"
"testing"

"github.com/btcsuite/btcchain"
"github.com/btcsuite/btcd/blockchain"
)

func TestBigToCompact(t *testing.T) {
Expand All @@ -22,7 +22,7 @@ func TestBigToCompact(t *testing.T) {

for x, test := range tests {
n := big.NewInt(test.in)
r := btcchain.BigToCompact(n)
r := blockchain.BigToCompact(n)
if r != test.out {
t.Errorf("TestBigToCompact test #%d failed: got %d want %d\n",
x, r, test.out)
Expand All @@ -40,7 +40,7 @@ func TestCompactToBig(t *testing.T) {
}

for x, test := range tests {
n := btcchain.CompactToBig(test.in)
n := blockchain.CompactToBig(test.in)
want := big.NewInt(test.out)
if n.Cmp(want) != 0 {
t.Errorf("TestCompactToBig test #%d failed: got %d want %d\n",
Expand All @@ -61,7 +61,7 @@ func TestCalcWork(t *testing.T) {
for x, test := range tests {
bits := uint32(test.in)

r := btcchain.CalcWork(bits)
r := blockchain.CalcWork(bits)
if r.Int64() != test.out {
t.Errorf("TestCalcWork test #%d failed: got %v want %d\n",
x, r.Int64(), test.out)
Expand Down
8 changes: 4 additions & 4 deletions doc.go → blockchain/doc.go
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

/*
Package btcchain implements bitcoin block handling and chain selection rules.
Package blockchain implements bitcoin block handling and chain selection rules.
The bitcoin block handling and chain selection rules are an integral, and quite
likely the most important, part of bitcoin. Unfortunately, at the time of
Expand Down Expand Up @@ -64,11 +64,11 @@ is by no means exhaustive:
Errors
Errors returned by this package are either the raw errors provided by underlying
calls or of type btcchain.RuleError. This allows the caller to differentiate
calls or of type blockchain.RuleError. This allows the caller to differentiate
between unexpected errors, such as database errors, versus errors due to rule
violations through type assertions. In addition, callers can programmatically
determine the specific rule violation by examining the ErrorCode field of the
type asserted btcchain.RuleError.
type asserted blockchain.RuleError.
Bitcoin Improvement Proposals
Expand All @@ -78,4 +78,4 @@ This package includes spec changes outlined by the following BIPs:
BIP0030 (https://en.bitcoin.it/wiki/BIP_0030)
BIP0034 (https://en.bitcoin.it/wiki/BIP_0034)
*/
package btcchain
package blockchain
2 changes: 1 addition & 1 deletion error.go → blockchain/error.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 btcchain
package blockchain

import (
"fmt"
Expand Down

0 comments on commit b69a849

Please sign in to comment.