package
1.2.0
Repository: https://github.com/chappjc/dcrd.git
Documentation: pkg.go.dev

# README

wire

Build Status ISC License GoDoc

Package wire implements the Decred wire protocol. A comprehensive suite of tests with 100% test coverage is provided to ensure proper functionality.

This package has intentionally been designed so it can be used as a standalone package for any projects needing to interface with Decred peers at the wire protocol level.

Installation and Updating

$ go get -u github.com/decred/dcrd/wire

Decred Message Overview

The Decred protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it such as which decred 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 Decred 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 Decred messages are provided. For these supported messages, all of the details of marshalling and unmarshalling to and from the wire using Decred encoding are handled so the caller doesn't have to concern themselves with the specifics.

Reading Messages Example

In order to unmarshal Decred 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 Decred peer. Example syntax is:

	// Use the most recent protocol version supported by the package and the
	// main Decred network.
	pver := wire.ProtocolVersion
	dcrnet := wire.MainNet

	// Reads and validates the next Decred message from conn using the
	// protocol version pver and the Decred network dcrnet.  The returns
	// are a wire.Message, a []byte which contains the unmarshalled
	// raw payload, and a possible error.
	msg, rawPayload, err := wire.ReadMessage(conn, pver, dcrnet)
	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 Decred 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 Decred peer. Example syntax to request addresses from a remote peer is:

	// Use the most recent protocol version supported by the package and the
	// main Decred network.
	pver := wire.ProtocolVersion
	dcrnet := wire.MainNet

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

	// Writes a Decred message msg to conn using the protocol version
	// pver, and the Decred network dcrnet.  The return is a possible
	// error.
	err := wire.WriteMessage(conn, msg, pver, dcrnet)
	if err != nil {
		// Log and handle the error
	}

License

Package wire is licensed under the copyfree ISC License.

# Functions

MaxTxPerTxTree returns the maximum number of transactions that could possibly fit into a block per each merkle root for the given protocol version.
NewBlockHeader returns a new BlockHeader using the provided previous block hash, merkle root hash, difficulty bits, and nonce used to generate the block with defaults for the remaining fields.
NewInvVect returns a new InvVect using the provided type and hash.
NewMsgAddr returns a new bitcoin addr message that conforms to the Message interface.
NewMsgBlock returns a new Decred block message that conforms to the Message interface.
NewMsgCFHeaders returns a new cfheaders message that conforms to the Message interface.
NewMsgCFilter returns a new cfilter message that conforms to the Message interface.
NewMsgCFTypes returns a new cftypes message that conforms to the Message interface.
NewMsgFeeFilter returns a new feefilter message that conforms to the Message interface.
NewMsgFilterAdd returns a new Decred filteradd message that conforms to the Message interface.
NewMsgFilterClear returns a new Decred filterclear message that conforms to the Message interface.
NewMsgFilterLoad returns a new Decred filterload message that conforms to the Message interface.
NewMsgGetAddr returns a new Decred getaddr message that conforms to the Message interface.
NewMsgGetBlocks returns a new Decred getblocks message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
NewMsgGetCFHeaders returns a new getcfheader message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
NewMsgGetCFilter returns a new getcfilter message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
NewMsgGetCFTypes returns a new getcftypes message that conforms to the Message interface.
NewMsgGetData returns a new Decred getdata message that conforms to the Message interface.
NewMsgGetDataSizeHint returns a new Decred getdata message that conforms to the Message interface.
NewMsgGetHeaders returns a new Decred getheaders message that conforms to the Message interface.
NewMsgGetMiningState returns a new Decred pong message that conforms to the Message interface.
NewMsgHeaders returns a new Decred headers message that conforms to the Message interface.
NewMsgInv returns a new Decred inv message that conforms to the Message interface.
NewMsgInvSizeHint returns a new Decred inv message that conforms to the Message interface.
NewMsgMemPool returns a new Decred pong message that conforms to the Message interface.
NewMsgMerkleBlock returns a new Decred merkleblock message that conforms to the Message interface.
NewMsgMiningState returns a new Decred miningstate message that conforms to the Message interface using the defaults for the fields.
NewMsgNotFound returns a new Decred notfound message that conforms to the Message interface.
NewMsgPing returns a new Decred ping message that conforms to the Message interface.
NewMsgPong returns a new Decred pong message that conforms to the Message interface.
NewMsgReject returns a new Decred reject message that conforms to the Message interface.
NewMsgSendHeaders returns a new bitcoin sendheaders message that conforms to the Message interface.
NewMsgTx returns a new Decred tx message that conforms to the Message interface.
NewMsgVerAck returns a new Decred verack message that conforms to the Message interface.
NewMsgVersion returns a new Decred version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
NewMsgVersionFromConn is a convenience function that extracts the remote and local address from conn and returns a new Decred version message that conforms to the Message interface.
NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.
NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and supported services with defaults for the remaining fields.
NewNetAddressTimestamp returns a new NetAddress using the provided timestamp, IP, port, and supported services.
NewOutPoint returns a new Decred transaction outpoint point with the provided hash and index.
NewTxIn returns a new Decred transaction input with the provided previous outpoint point and signature script with a default sequence of MaxTxInSequenceNum.
NewTxOut returns a new Decred transaction output with the provided transaction value and public key script.
RandomUint64 returns a cryptographically random uint64 value.
ReadMessage reads, validates, and parses the next Decred Message from r for the provided protocol version and Decred network.
ReadMessageN reads, validates, and parses the next Decred Message from r for the provided protocol version and Decred network.
ReadOutPoint reads the next sequence of bytes from r as an OutPoint.
ReadVarBytes reads a variable length byte array.
ReadVarInt reads a variable length integer from r and returns it as a uint64.
ReadVarString reads a variable length string from r and returns it as a Go string.
VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
WriteMessage writes a Decred Message to w including the necessary header information.
WriteMessageN writes a Decred Message to w including the necessary header information and returns the number of bytes written.
WriteOutPoint encodes op to the Decred protocol encoding for an OutPoint to w.
WriteVarBytes serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves.
WriteVarInt serializes val to w using a variable number of bytes depending on its value.
WriteVarString serializes str to w as a variable length integer containing the length of the string followed by the bytes that represent the string itself.

# Constants

BloomUpdateAll indicates if the filter matches any data element in a public key script, the outpoint is serialized and inserted into the filter.
BloomUpdateNone indicates the filter is not adjusted when a match is found.
BloomUpdateP2PubkeyOnly indicates if the filter matches a data element in a public key script and the script is of the standard pay-to-pubkey or multisig, the outpoint is serialized and inserted into the filter.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
Commands used in message headers which describe the type of message.
CommandSize is the fixed size of all commands in the common Decred message header.
DefaultPkScriptVersion is the default pkScript version, referring to extended Decred script.
DefaultUserAgent for wire in the stack.
FeeFilterVersion is the protocol version which added a new feefilter message.
GCSFilterExtended is the extended filter type.
GCSFilterRegular is the regular filter type.
InitialProcotolVersion is the initial protocol version for the network.
These constants define the various supported inventory vector types.
These constants define the various supported inventory vector types.
These constants define the various supported inventory vector types.
These constants define the various supported inventory vector types.
MainNet represents the main Decred network.
MaxAddrPerMsg is the maximum number of addresses that can be in a single bitcoin addr message (MsgAddr).
MaxBlockHeaderPayload is the maximum number of bytes a block header can be.
MaxBlockHeadersPerMsg is the maximum number of block headers that can be in a single Decred headers message.
MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.
1.25MB.
Not actually 1MB which would be 1024 * 1024.
MaxBlockSizeVersion is the protocol version which increased the original blocksize.
MaxBlocksPerMsg is the maximum number of blocks allowed per message.
MaxCFHeaderPayload is the maximum byte size of a committed filter header.
MaxCFHeadersPerMsg is the maximum number of committed filter headers that can be in a single cfheaders message.
MaxCFilterDataSize is the maximum byte size of a committed filter.
MaxFilterAddDataSize is the maximum byte size of a data element to add to the Bloom filter.
MaxFilterLoadFilterSize is the maximum size in bytes a filter may be.
MaxFilterLoadHashFuncs is the maximum number of hash functions to load into the Bloom filter.
MaxFilterTypesPerMsg is the maximum number of filter types allowed per message.
MaxInvPerMsg is the maximum number of inventory vectors that can be in a single Decred inv message.
32MB.
MaxMSBlocksAtHeadPerMsg is the maximum number of block hashes allowed per message.
8 * 5.
MaxPrevOutIndex is the maximum index the index field of a previous outpoint can be.
MaxTxInSequenceNum is the maximum sequence number the sequence field of a transaction input can be.
MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).
MaxVarIntPayload is the maximum payload size for a variable length integer.
MessageHeaderSize is the number of bytes in a Decred message header.
NodeBloomVersion is the protocol version which added the SFNodeBloom service flag.
NodeCFVersion is the protocol version which adds the SFNodeCF service flag and the cfheaders, cfilter, cftypes, getcfheaders, getcfilter and getcftypes messages.
NoExpiryValue is the value of expiry that indicates the transaction has no expiry.
NullBlockHeight is the null value for an input witness.
NullBlockIndex is the null transaction index in a block for an input witness.
NullValueIn is a null value for an input witness.
ProtocolVersion is the latest protocol version this package supports.
RegTest represents the regression test network.
These constants define the various supported reject codes.
These constants define the various supported reject codes.
These constants define the various supported reject codes.
These constants define the various supported reject codes.
These constants define the various supported reject codes.
These constants define the various supported reject codes.
These constants define the various supported reject codes.
These constants define the various supported reject codes.
SendHeadersVersion is the protocol version which added a new sendheaders message.
SequenceLockTimeDisabled is a flag that if set on a transaction input's sequence number, the sequence number will not be interpreted as a relative locktime.
SequenceLockTimeGranularity is the defined time based granularity for seconds-based relative time locks.
SequenceLockTimeIsSeconds is a flag that if set on a transaction input's sequence number, the relative locktime has units of 512 seconds.
SequenceLockTimeMask is a mask that extracts the relative locktime when masked against the transaction input sequence number.
SFNodeBloom is a flag used to indiciate a peer supports bloom filtering.
SFNodeCF is a flag used to indicate a peer supports committed filters (CFs).
SFNodeNetwork is a flag used to indicate a peer is a full node.
SimNet represents the simulation test network.
TestNet2 represents the 2nd test network.
TxSerializeFull indicates a transaction be serialized with the prefix and all witness data.
TxSerializeNoWitness indicates a transaction be serialized with only the prefix.
TxSerializeOnlyWitness indicates a transaction be serialized with only the witness data.
TxSerializeWitnessSigning indicates a transaction be serialized with only the witness scripts.
TxSerializeWitnessValueSigning indicates a transaction be serialized with only the witness input values and scripts.
TxTreeRegular is the value for a normal transaction tree for a transaction's location in a block.
TxTreeStake is the value for a stake transaction tree for a transaction's location in a block.
TxTreeUnknown is the value returned for a transaction tree that is unknown.
TxVersion is the current latest supported transaction version.

# Variables

ErrInvalidNetAddr describes an error that indicates the caller didn't specify a TCP address as required.

# Structs

BlockHeader defines information about a block and is used in the decred block (MsgBlock) and headers (MsgHeaders) messages.
InvVect defines a Decred inventory vector which is used to describe data, as specified by the Type field, that a peer wants, has, or does not have to another peer.
MessageError describes an issue with a message.
MsgAddr implements the Message interface and represents a bitcoin addr message.
MsgBlock implements the Message interface and represents a decred block message.
MsgCFHeaders implements the Message interface and represents a cfheaders message.
MsgCFilter implements the Message interface and represents a cfilter message.
MsgCFTypes is the cftypes message.
MsgFeeFilter implements the Message interface and represents a feefilter message.
MsgFilterAdd implements the Message interface and represents a decred filteradd message.
MsgFilterClear implements the Message interface and represents a decred filterclear message which is used to reset a Bloom filter.
MsgFilterLoad implements the Message interface and represents a decred filterload message which is used to reset a Bloom filter.
MsgGetAddr implements the Message interface and represents a decred getaddr message.
MsgGetBlocks implements the Message interface and represents a decred getblocks message.
MsgGetCFHeaders is a message similar to MsgGetHeaders, but for committed filter headers.
MsgGetCFilter implements the Message interface and represents a getcfilter message.
MsgGetCFTypes is the getcftypes message.
MsgGetData implements the Message interface and represents a decred getdata message.
MsgGetHeaders implements the Message interface and represents a decred getheaders message.
MsgGetMiningState implements the Message interface and represents a getminingstate message.
MsgHeaders implements the Message interface and represents a Decred headers message.
MsgInv implements the Message interface and represents a Decred inv message.
MsgMemPool implements the Message interface and represents a Decred mempool message.
MsgMerkleBlock implements the Message interface and represents a decred merkleblock message which is used to reset a Bloom filter.
MsgMiningState implements the Message interface and represents a mining state message.
MsgNotFound defines a Decred notfound message which is sent in response to a getdata message if any of the requested data in not available on the peer.
MsgPing implements the Message interface and represents a Decred ping message.
MsgPong implements the Message interface and represents a Decred pong message which is used primarily to confirm that a connection is still valid in response to a Decred ping message (MsgPing).
MsgReject implements the Message interface and represents a Decred reject message.
MsgSendHeaders implements the Message interface and represents a bitcoin sendheaders message.
MsgTx implements the Message interface and represents a Decred tx message.
MsgVerAck defines a Decred verack message which is used for a peer to acknowledge a version message (MsgVersion) after it has used the information to negotiate parameters.
MsgVersion implements the Message interface and represents a Decred version message.
NetAddress defines information about a peer on the network including the time it was last seen, the services it supports, its IP address, and port.
OutPoint defines a Decred data type that is used to track previous transaction outputs.
TxIn defines a Decred transaction input.
TxLoc holds locator data for the offset and length of where a transaction is located within a MsgBlock data buffer.
TxOut defines a Decred transaction output.

# Interfaces

Message is an interface that describes a Decred message.

# Type aliases

BloomUpdateType specifies how the filter is updated when a match is found.
CurrencyNet represents which Decred network a message belongs to.
FilterType is used to represent a filter type.
InvType represents the allowed types of inventory vectors.
RejectCode represents a numeric value by which a remote peer indicates why a message was rejected.
ServiceFlag identifies services supported by a Decred peer.
TxSerializeType represents the serialized type of a transaction.