Skip to content

Commit

Permalink
Import btcwire repo into wire directory.
Browse files Browse the repository at this point in the history
This commit contains the entire btcwire repository along with several
changes needed to move all of the files into the wire 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 btcwire test files have been changed to the
  new location
- All references to btcwire as the package name have been chagned to
  wire
- 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 Jan 31, 2015
1 parent cb858fd commit 2eef372
Show file tree
Hide file tree
Showing 68 changed files with 1,305 additions and 1,391 deletions.
34 changes: 0 additions & 34 deletions .gitignore

This file was deleted.

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

This file was deleted.

13 changes: 0 additions & 13 deletions LICENSE

This file was deleted.

17 changes: 0 additions & 17 deletions cov_report.sh

This file was deleted.

47 changes: 21 additions & 26 deletions README.md → wire/README.md
@@ -1,42 +1,37 @@
btcwire
=======
wire
====

[![Build Status](http://img.shields.io/travis/btcsuite/btcwire.svg)]
(https://travis-ci.org/btcsuite/btcwire) [![Coverage Status]
(https://img.shields.io/coveralls/btcsuite/btcwire.svg)]
(https://coveralls.io/r/btcsuite/btcwire?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 btcwire implements the bitcoin wire protocol. A comprehensive suite of
Package wire implements the bitcoin wire protocol. A comprehensive suite of
tests with 100% test coverage is provided to ensure proper functionality.
Package btcwire is licensed under the liberal ISC license.

There is an associated blog post about the release of this package
[here](https://blog.conformal.com/btcwire-the-bitcoin-wire-protocol-package-from-btcd/).

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
interface with bitcoin peers at the wire protocol level.
This package has intentionally been designed so it can be used as a standalone
package for any projects needing to interface with bitcoin peers at the wire
protocol level.

## Documentation

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

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

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

## Installation

```bash
$ go get github.com/btcsuite/btcwire
$ go get github.com/btcsuite/btcd/wire
```

## Bitcoin Message Overview
Expand Down Expand Up @@ -64,14 +59,14 @@ to a remote node running a bitcoin peer. Example syntax is:
```Go
// Use the most recent protocol version supported by the package and the
// main bitcoin network.
pver := btcwire.ProtocolVersion
btcnet := btcwire.MainNet
pver := wire.ProtocolVersion
btcnet := wire.MainNet

// Reads and validates the next bitcoin message from conn using the
// protocol version pver and the bitcoin network btcnet. The returns
// are a btcwire.Message, a []byte which contains the unmarshalled
// are a wire.Message, a []byte which contains the unmarshalled
// raw payload, and a possible error.
msg, rawPayload, err := btcwire.ReadMessage(conn, pver, btcnet)
msg, rawPayload, err := wire.ReadMessage(conn, pver, btcnet)
if err != nil {
// Log and handle the error
}
Expand All @@ -89,16 +84,16 @@ from a remote peer is:
```Go
// Use the most recent protocol version supported by the package and the
// main bitcoin network.
pver := btcwire.ProtocolVersion
btcnet := btcwire.MainNet
pver := wire.ProtocolVersion
btcnet := wire.MainNet

// Create a new getaddr bitcoin message.
msg := btcwire.NewMsgGetAddr()
msg := wire.NewMsgGetAddr()

// Writes a bitcoin message msg to conn using the protocol version
// pver, and the bitcoin network btcnet. The return is a possible
// error.
err := btcwire.WriteMessage(conn, msg, pver, btcnet)
err := wire.WriteMessage(conn, msg, pver, btcnet)
if err != nil {
// Log and handle the error
}
Expand Down Expand Up @@ -126,5 +121,5 @@ signature perform the following:

## License

Package btcwire is licensed under the [copyfree](http://copyfree.org) ISC
Package wire is licensed under the [copyfree](http://copyfree.org) ISC
License.
4 changes: 2 additions & 2 deletions bench_test.go → wire/bench_test.go
@@ -1,8 +1,8 @@
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Copyright (c) 2013-2015 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcwire
package wire

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions blockheader.go → wire/blockheader.go
@@ -1,8 +1,8 @@
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Copyright (c) 2013-2015 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcwire
package wire

import (
"bytes"
Expand Down
46 changes: 23 additions & 23 deletions blockheader_test.go → wire/blockheader_test.go
@@ -1,22 +1,22 @@
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Copyright (c) 2013-2015 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcwire_test
package wire_test

import (
"bytes"
"reflect"
"testing"
"time"

"github.com/btcsuite/btcwire"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
)

// TestBlockHeader tests the BlockHeader API.
func TestBlockHeader(t *testing.T) {
nonce64, err := btcwire.RandomUint64()
nonce64, err := wire.RandomUint64()
if err != nil {
t.Errorf("RandomUint64: Error generating nonce: %v", err)
}
Expand All @@ -25,7 +25,7 @@ func TestBlockHeader(t *testing.T) {
hash := mainNetGenesisHash
merkleHash := mainNetGenesisMerkleRoot
bits := uint32(0x1d00ffff)
bh := btcwire.NewBlockHeader(&hash, &merkleHash, bits, nonce)
bh := wire.NewBlockHeader(&hash, &merkleHash, bits, nonce)

// Ensure we get the same data back out.
if !bh.PrevBlock.IsEqual(&hash) {
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestBlockHeaderWire(t *testing.T) {

// baseBlockHdr is used in the various tests as a baseline BlockHeader.
bits := uint32(0x1d00ffff)
baseBlockHdr := &btcwire.BlockHeader{
baseBlockHdr := &wire.BlockHeader{
Version: 1,
PrevBlock: mainNetGenesisHash,
MerkleRoot: mainNetGenesisMerkleRoot,
Expand All @@ -79,57 +79,57 @@ func TestBlockHeaderWire(t *testing.T) {
}

tests := []struct {
in *btcwire.BlockHeader // Data to encode
out *btcwire.BlockHeader // Expected decoded data
buf []byte // Wire encoding
pver uint32 // Protocol version for wire encoding
in *wire.BlockHeader // Data to encode
out *wire.BlockHeader // Expected decoded data
buf []byte // Wire encoding
pver uint32 // Protocol version for wire encoding
}{
// Latest protocol version.
{
baseBlockHdr,
baseBlockHdr,
baseBlockHdrEncoded,
btcwire.ProtocolVersion,
wire.ProtocolVersion,
},

// Protocol version BIP0035Version.
{
baseBlockHdr,
baseBlockHdr,
baseBlockHdrEncoded,
btcwire.BIP0035Version,
wire.BIP0035Version,
},

// Protocol version BIP0031Version.
{
baseBlockHdr,
baseBlockHdr,
baseBlockHdrEncoded,
btcwire.BIP0031Version,
wire.BIP0031Version,
},

// Protocol version NetAddressTimeVersion.
{
baseBlockHdr,
baseBlockHdr,
baseBlockHdrEncoded,
btcwire.NetAddressTimeVersion,
wire.NetAddressTimeVersion,
},

// Protocol version MultipleAddressVersion.
{
baseBlockHdr,
baseBlockHdr,
baseBlockHdrEncoded,
btcwire.MultipleAddressVersion,
wire.MultipleAddressVersion,
},
}

t.Logf("Running %d tests", len(tests))
for i, test := range tests {
// Encode to wire format.
var buf bytes.Buffer
err := btcwire.TstWriteBlockHeader(&buf, test.pver, test.in)
err := wire.TstWriteBlockHeader(&buf, test.pver, test.in)
if err != nil {
t.Errorf("writeBlockHeader #%d error %v", i, err)
continue
Expand All @@ -141,9 +141,9 @@ func TestBlockHeaderWire(t *testing.T) {
}

// Decode the block header from wire format.
var bh btcwire.BlockHeader
var bh wire.BlockHeader
rbuf := bytes.NewReader(test.buf)
err = btcwire.TstReadBlockHeader(rbuf, test.pver, &bh)
err = wire.TstReadBlockHeader(rbuf, test.pver, &bh)
if err != nil {
t.Errorf("readBlockHeader #%d error %v", i, err)
continue
Expand All @@ -162,7 +162,7 @@ func TestBlockHeaderSerialize(t *testing.T) {

// baseBlockHdr is used in the various tests as a baseline BlockHeader.
bits := uint32(0x1d00ffff)
baseBlockHdr := &btcwire.BlockHeader{
baseBlockHdr := &wire.BlockHeader{
Version: 1,
PrevBlock: mainNetGenesisHash,
MerkleRoot: mainNetGenesisMerkleRoot,
Expand All @@ -188,9 +188,9 @@ func TestBlockHeaderSerialize(t *testing.T) {
}

tests := []struct {
in *btcwire.BlockHeader // Data to encode
out *btcwire.BlockHeader // Expected decoded data
buf []byte // Serialized data
in *wire.BlockHeader // Data to encode
out *wire.BlockHeader // Expected decoded data
buf []byte // Serialized data
}{
{
baseBlockHdr,
Expand All @@ -215,7 +215,7 @@ func TestBlockHeaderSerialize(t *testing.T) {
}

// Deserialize the block header.
var bh btcwire.BlockHeader
var bh wire.BlockHeader
rbuf := bytes.NewReader(test.buf)
err = bh.Deserialize(rbuf)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions common.go → wire/common.go
@@ -1,8 +1,8 @@
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Copyright (c) 2013-2015 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package btcwire
package wire

import (
"crypto/rand"
Expand Down

0 comments on commit 2eef372

Please sign in to comment.