An alternative full node implementation of LBRY's blockchain written in Go (golang)
Find a file
2013-05-09 18:12:11 -05:00
.gitignore Initial commit. 2013-05-08 14:16:41 -05:00
blockheader.go Fix a few comment typos. 2013-05-09 00:02:07 -05:00
blockheader_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
common.go Initial implementation. 2013-05-08 18:58:29 -05:00
common_test.go Correct error output string colon placement. 2013-05-09 11:36:29 -05:00
cov_report.sh Display correct import path for gocov. 2013-05-09 13:19:09 -05:00
doc.go Fix a minor typo in the package overview doco. 2013-05-09 13:57:44 -05:00
fakeconn_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
fakemessage_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
fixedIO_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
genesis.go Initial implementation. 2013-05-08 18:58:29 -05:00
genesis_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
internal_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
invvect.go Initial implementation. 2013-05-08 18:58:29 -05:00
invvect_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
LICENSE Initial implementation. 2013-05-08 18:58:29 -05:00
message.go Remove dead error check. 2013-05-09 15:23:31 -05:00
message_test.go Add message tests for MsgAlert and MsgMemPool. 2013-05-09 00:01:29 -05:00
msgaddr.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgaddr_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgalert.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgalert_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgblock.go Fix a few comment typos. 2013-05-09 00:02:07 -05:00
msgblock_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetaddr.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetaddr_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetblocks.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetblocks_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetdata.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetdata_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetheaders.go Initial implementation. 2013-05-08 18:58:29 -05:00
msggetheaders_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgheaders.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgheaders_test.go Remove a few unused variables and constants. 2013-05-08 22:59:45 -05:00
msginv.go Initial implementation. 2013-05-08 18:58:29 -05:00
msginv_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgmempool.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgmempool_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgnotfound.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgnotfound_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgping.go Fix typo: s/MsgPong/MsgPing/ 2013-05-09 12:26:23 -06:00
msgping_test.go Add negative tests for MsgPing. 2013-05-09 10:42:52 -05:00
msgpong.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgpong_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgtx.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgtx_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgverack.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgverack_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgversion.go Initial implementation. 2013-05-08 18:58:29 -05:00
msgversion_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
netaddress.go Initial implementation. 2013-05-08 18:58:29 -05:00
netaddress_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
protocol.go Initial implementation. 2013-05-08 18:58:29 -05:00
protocol_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
README.md Initial implementation. 2013-05-08 18:58:29 -05:00
shahash.go Fix comment typo. 2013-05-09 18:12:11 -05:00
shahash_test.go Initial implementation. 2013-05-08 18:58:29 -05:00
test_coverage.txt Add negative tests for MsgPing. 2013-05-09 10:42:52 -05:00

btcwire

Package btcwire implements the bitcoin wire protocol. A comprehensive suite of tests 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.

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 verison 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 verison 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
  • Increase test coverage to 100%

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.