An alternative full node bitcoin implementation written in Go (golang)
Go to file
Dave Collins 2458841855 Add tests for new size hint functions.
This brings the test coverage back up to 100%.
2014-01-08 17:43:18 -06:00
.gitignore Initial commit. 2013-05-08 14:16:41 -05:00
.travis.yml Configure TravisCI to pull pkgs needed for tests. 2013-12-10 16:13:08 -06:00
bench_test.go Add benchmark for writeBlockHeader. 2013-11-07 00:30:20 -06:00
blockheader_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
blockheader.go Optimize writeElement. 2013-11-07 00:56:20 -06:00
common_test.go Add negative tests for updated read/writeElement. 2013-11-07 05:37:48 -06:00
common.go use fastsha256 2013-11-19 09:26:22 -06:00
cov_report.sh Update gocov path in comments to correct path. 2013-05-10 15:58:05 -05:00
doc.go Fix doc example typo 2013-08-12 22:53:50 -05:00
error.go Add initial implementation of MessageError type. 2013-05-09 20:58:17 -05:00
fakeconn_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
fakemessage_test.go Enforce max block payload size of 1MB. 2013-05-16 09:07:04 -05:00
fixedIO_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
genesis_test.go Remove protocol version param from BlockSha/Txsha. 2013-08-05 18:08:57 -05:00
genesis.go Allow var defs to infer type from right-hand side. 2013-07-27 16:10:38 -05:00
internal_test.go Add tests for updated readElement/writeElement. 2013-11-07 05:17:17 -06:00
invvect_test.go Deprecate InvVect_* constants in favor of InvType*. 2013-10-08 15:44:48 -05:00
invvect.go Optimize writeElement. 2013-11-07 00:56:20 -06:00
legacy.go Add deprecated comments to legacy InvVect_* consts. 2013-10-08 15:51:34 -05:00
LICENSE Initial implementation. 2013-05-08 18:58:29 -05:00
message_test.go Enforce max block payload size of 1MB. 2013-05-16 09:07:04 -05:00
message.go Enforce max block payload size of 1MB. 2013-05-16 09:07:04 -05:00
msgaddr_test.go Correct several test error messages. 2013-05-11 12:55:50 -05:00
msgaddr.go Pre-allocate space for slices. 2013-09-25 14:38:28 -05:00
msgalert_test.go Add negative tests for MsgAlert. 2013-05-11 12:49:22 -05:00
msgalert.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgblock_test.go Add tests to exercise intential malicious overflow. 2013-10-25 08:57:39 -05:00
msgblock.go Add bounds checking to all variable length allocs. 2013-10-25 08:55:39 -05:00
msggetaddr_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetaddr.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetblocks_test.go Correct several test error messages. 2013-05-11 12:55:50 -05:00
msggetblocks.go Optimize writeElement. 2013-11-07 00:56:20 -06:00
msggetdata_test.go Add tests for new size hint functions. 2014-01-08 17:43:18 -06:00
msggetdata.go Add new funcs to allow size hints on getdata/inv. 2014-01-08 17:21:51 -06:00
msggetheaders_test.go Remove a couple of incorrect comments. 2013-07-24 00:35:16 -05:00
msggetheaders.go Optimize writeElement. 2013-11-07 00:56:20 -06:00
msgheaders_test.go Finish a TODO in the message headers tests. 2013-10-25 09:00:05 -05:00
msgheaders.go Pre-allocate space for slices. 2013-09-25 14:38:28 -05:00
msginv_test.go Add tests for new size hint functions. 2014-01-08 17:43:18 -06:00
msginv.go Add new funcs to allow size hints on getdata/inv. 2014-01-08 17:21:51 -06:00
msgmempool_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgmempool.go Update comments to fix typos and use proper form. 2013-07-27 16:18:13 -05:00
msgnotfound_test.go Deprecate InvVect_* constants in favor of InvType*. 2013-10-08 15:44:48 -05:00
msgnotfound.go Pre-allocate space for slices. 2013-09-25 14:38:28 -05:00
msgping_test.go Correct error output colon string placement. 2013-05-09 21:25:19 -05:00
msgping.go Fix typo: s/MsgPong/MsgPing/ 2013-05-09 12:26:23 -06:00
msgpong_test.go Add format specifier in pong test error output. 2013-07-27 15:56:17 -05:00
msgpong.go Convert MsgPong errors to MessageError type. 2013-05-10 21:31:56 -05:00
msgtx_test.go Add tests for the new SerializeSize functions. 2013-10-31 00:20:41 -05:00
msgtx.go Minor cleanup. 2013-11-07 06:21:44 -06:00
msgverack_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgverack.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgversion_test.go Allow var defs to infer type from right-hand side. 2013-07-27 16:10:38 -05:00
msgversion.go Convert MsgVersion errors to MessageError type. 2013-05-11 02:23:45 -05:00
netaddress_test.go Add negative tests for NetAddress. 2013-05-09 23:01:09 -05:00
netaddress.go Add new func NetAddressIPPort. 2013-08-07 13:05:25 -05:00
protocol_test.go Add tests for new BitcoinNet Stringer. 2014-01-03 08:36:11 -06:00
protocol.go Add Stringer to BitcoinNet. 2014-01-03 08:32:43 -06:00
README.md Add support for TravisCI. 2013-12-09 05:41:54 -06:00
shahash_test.go Use byte literals in tests to make go vet happy. 2013-07-27 15:55:06 -05:00
shahash.go Minor cleanup. 2013-11-07 06:21:44 -06:00
test_coverage.txt Add tests for new size hint functions. 2014-01-08 17:43:18 -06:00

btcwire

[Build Status] (https://travis-ci.org/conformal/btcwire)

Package btcwire implements the bitcoin wire protocol. A comprehensive suite of tests with 100% test coverage is provided to ensure proper functionality. 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 btcwire is licensed under the liberal ISC license.

There is an associated blog post about the release of this package here.

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.

Documentation

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/conformal/btcwire

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/conformal/btcwire

Installation

$ go get github.com/conformal/btcwire

Bitcoin Message Overview

The bitcoin protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it such as which bitcoin network it is a part of, its type, how big it is, and a checksum to verify validity. All encoding and decoding of message headers is handled by this package.

To accomplish this, there is a generic interface for bitcoin messages named Message which allows messages of any type to be read, written, or passed around through channels, functions, etc. In addition, concrete implementations of most of the currently supported bitcoin messages are provided. For these supported messages, all of the details of marshalling and unmarshalling to and from the wire using bitcoin encoding are handled so the caller doesn't have to concern themselves with the specifics.

Reading Messages Example

In order to unmarshal bitcoin messages from the wire, use the ReadMessage function. It accepts any io.Reader, but typically this will be a net.Conn to a remote node running a bitcoin peer. Example syntax is:

	// Use the most recent protocol version supported by the package and the
	// main bitcoin network.
	pver := btcwire.ProtocolVersion
	btcnet := btcwire.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
	// raw payload, and a possible error.
	msg, rawPayload, err := btcwire.ReadMessage(conn, pver, btcnet)
	if err != nil {
		// Log and handle the error
	}

See the package documentation for details on determining the message type.

Writing Messages Example

In order to marshal bitcoin messages to the wire, use the WriteMessage function. It accepts any io.Writer, but typically this will be a net.Conn to a remote node running a bitcoin peer. Example syntax to request addresses from a remote peer is:

	// Use the most recent protocol version supported by the package and the
	// main bitcoin network.
	pver := btcwire.ProtocolVersion
	btcnet := btcwire.MainNet

	// Create a new getaddr bitcoin message.
	msg := btcwire.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)
	if err != nil {
		// Log and handle the error
	}

TODO

  • Implement functions for BIP 0014
  • Implement alert message decoding/encoding
  • Implement bloom filter messages (filterload, filteradd, filterclear, merkleblock) as defined in BIP 0037

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from Conformal. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

Package btcwire is licensed under the liberal ISC License.