An alternative full node implementation of LBRY's blockchain written in Go (golang)
Find a file
Dave Collins 843e71515a Expose new SerializeSize API for blocks.
This commit adds a new function named SerializeSize to the public API for
MsgBlock which can be used to determine how many bytes the serialized data would
take without having to actually serialize it.  In addition, it makes the
exported BlockVersion an untyped constant as well as changes the block and
tx versions to a signed integer to more closely match the protocol.

Finally, this commit also adds tests for the new function.

The following benchmark shows the difference between using the new
function to get the serialize size for a typical block and serializing
into a temporary buffer and taking the length of it:

Bufffer: BenchmarkBlockSerializeSizeBuffer     200000          27050 ns/op
New:     BenchmarkBlockSerializeSizeNew     100000000             34 ns/op

Closes #19.
2014-06-29 17:43:54 -05:00
.gitignore add tmp wire file to .gitignore 2014-04-19 15:53:03 +05:30
.travis.yml Instruct TravisCI to install coverage report tool. 2014-04-19 14:41:52 -05:00
bench_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
blockheader.go Expose new SerializeSize API for blocks. 2014-06-29 17:43:54 -05:00
blockheader_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
common.go Make MaxMessagePayload an exported constant. 2014-06-06 22:33:39 -05:00
common_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
cov_report.sh Update gocov path in comments to correct path. 2013-05-10 15:58:05 -05:00
doc.go Update doc.go to reflect reality. 2014-06-02 12:35:00 -05:00
error.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
fakeconn_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
fakemessage_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
fixedIO_test.go Finish uncompleted comments in fixedIO_test.go. 2014-03-30 12:19:17 -05:00
internal_test.go Expose new SerializeSize API for blocks. 2014-06-29 17:43:54 -05:00
invvect.go Initial implementation of BIP0037. 2014-05-07 23:41:39 -05:00
invvect_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
LICENSE Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
message.go Make MaxMessagePayload an exported constant. 2014-06-06 22:33:39 -05:00
message_test.go Make MaxMessagePayload an exported constant. 2014-06-06 22:33:39 -05:00
msgaddr.go Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
msgaddr_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgalert.go Make MaxMessagePayload an exported constant. 2014-06-06 22:33:39 -05:00
msgalert_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgblock.go Expose new SerializeSize API for blocks. 2014-06-29 17:43:54 -05:00
msgblock_test.go Expose new SerializeSize API for blocks. 2014-06-29 17:43:54 -05:00
msgfilteradd.go Complete BIP0037 support started by dhill. 2014-05-07 23:57:55 -05:00
msgfilteradd_test.go Complete BIP0037 support started by dhill. 2014-05-07 23:57:55 -05:00
msgfilterclear.go Complete BIP0037 support started by dhill. 2014-05-07 23:57:55 -05:00
msgfilterclear_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgfilterload.go Complete BIP0037 support started by dhill. 2014-05-07 23:57:55 -05:00
msgfilterload_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msggetaddr.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msggetaddr_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msggetblocks.go Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
msggetblocks_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msggetdata.go Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
msggetdata_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msggetheaders.go Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
msggetheaders_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgheaders.go Export MaxBlockHeaderPayload. 2014-03-11 20:22:32 -05:00
msgheaders_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msginv.go Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
msginv_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgmempool.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgmempool_test.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgmerkleblock.go Complete BIP0037 support started by dhill. 2014-05-07 23:57:55 -05:00
msgmerkleblock_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgnotfound.go Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
msgnotfound_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgping.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgping_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgpong.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgpong_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgreject.go Make MaxMessagePayload an exported constant. 2014-06-06 22:33:39 -05:00
msgreject_test.go Make MaxMessagePayload an exported constant. 2014-06-06 22:33:39 -05:00
msgtx.go Expose new SerializeSize API for blocks. 2014-06-29 17:43:54 -05:00
msgtx_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgverack.go Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
msgverack_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
msgversion.go Improve comments on new AddUserAgent function. 2014-04-20 17:44:46 -05:00
msgversion_test.go Implemented BIP 0014 format for user agent 2014-04-21 02:36:13 +05:30
netaddress.go Limit generated timestamps to one second precision. 2014-02-24 09:55:02 -06:00
netaddress_test.go Use bytes.NewReader for deserialize when possible. 2014-06-04 23:39:03 -05:00
protocol.go Add bitcoin network type for simulation testing. 2014-05-29 12:50:17 -05:00
protocol_test.go Add bitcoin network type for simulation testing. 2014-05-29 12:50:17 -05:00
README.md Complete BIP0037 support started by dhill. 2014-05-07 23:57:55 -05:00
shahash.go Remove function name from ShaHash error message. 2014-04-21 10:53:22 -05:00
shahash_test.go Move genesis blocks to btcnet package. 2014-05-28 09:14:38 -05:00

btcwire

[Build Status] (https://travis-ci.org/conformal/btcwire) [![Coverage Status] (https://coveralls.io/repos/conformal/btcwire/badge.png?branch=master)] (https://coveralls.io/r/conformal/btcwire?branch=master)

Package btcwire 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.

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

[GoDoc] (http://godoc.org/github.com/conformal/btcwire)

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
	}

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.