Documentation
¶
Overview ¶
Package wire implements the bitcoin wire protocol.
For the complete details of the bitcoin protocol, see the official wiki entry at https://en.bitcoin.it/wiki/Protocol_specification. The following only serves as a quick overview to provide information on how to use the package.
At a high level, this package provides support for marshalling and unmarshalling supported bitcoin messages to and from the wire. This package does not deal with the specifics of message handling such as what to do when a message is received. This provides the caller with a high level of flexibility.
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.
Message Interaction ¶
The following provides a quick summary of how the bitcoin messages are intended to interact with one another. As stated above, these interactions are not directly handled by this package. For more in-depth details about the appropriate interactions, see the official bitcoin protocol wiki entry at https://en.bitcoin.it/wiki/Protocol_specification.
The initial handshake consists of two peers sending each other a version message (MsgVersion) followed by responding with a verack message (MsgVerAck). Both peers use the information in the version message (MsgVersion) to negotiate things such as protocol version and supported services with each other. Once the initial handshake is complete, the following chart indicates message interactions in no particular order.
Peer A Sends Peer B Responds
----------------------------------------------------------------------------
getaddr message (MsgGetAddr) addr message (MsgAddr)
getblocks message (MsgGetBlocks) inv message (MsgInv)
inv message (MsgInv) getdata message (MsgGetData)
getdata message (MsgGetData) block message (MsgBlock) -or-
tx message (MsgTx) -or-
notfound message (MsgNotFound)
getheaders message (MsgGetHeaders) headers message (MsgHeaders)
ping message (MsgPing) pong message (MsgHeaders)* -or-
(none -- Ability to send message is enough)
NOTES:
* The pong message was not added until later protocol versions as defined
in BIP0031. The BIP0031Version constant can be used to detect a recent
enough protocol version for this purpose (version > BIP0031Version).
Common Parameters ¶
There are several common parameters that arise when using this package to read and write bitcoin messages. The following sections provide a quick overview of these parameters so the next sections can build on them.
Protocol Version ¶
The protocol version should be negotiated with the remote peer at a higher level than this package via the version (MsgVersion) message exchange, however, this package provides the wire.ProtocolVersion constant which indicates the latest protocol version this package supports and is typically the value to use for all outbound connections before a potentially lower protocol version is negotiated.
Bitcoin Network ¶
The bitcoin network is a magic number which is used to identify the start of a message and which bitcoin network the message applies to. This package provides the following constants:
wire.MainNet wire.TestNet (Regression test network) wire.TestNet3 (Test network version 3) wire.SigNet (Signet, default) wire.SimNet (Simulation test network)
Determining Message Type ¶
As discussed in the bitcoin message overview section, this package reads and writes bitcoin messages using a generic interface named Message. In order to determine the actual concrete type of the message, use a type switch or type assertion. An example of a type switch follows:
// Assumes msg is already a valid concrete message such as one created
// via NewMsgVersion or read via ReadMessage.
switch msg := msg.(type) {
case *wire.MsgVersion:
// The message is a pointer to a MsgVersion struct.
fmt.Printf("Protocol version: %v", msg.ProtocolVersion)
case *wire.MsgBlock:
// The message is a pointer to a MsgBlock struct.
fmt.Printf("Number of tx in block: %v", msg.Header.TxnCount)
}
Reading Messages ¶
In order to unmarshall 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:
// Reads and validates the next bitcoin message from conn using the
// protocol version pver and the bitcoin network btcnet. 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, btcnet)
if err != nil {
// Log and handle the error
}
Writing Messages ¶
In order to marshall 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:
// Create a new getaddr bitcoin message.
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 := wire.WriteMessage(conn, msg, pver, btcnet)
if err != nil {
// Log and handle the error
}
Errors ¶
Errors returned by this package are either the raw errors provided by underlying calls to read/write from streams such as io.EOF, io.ErrUnexpectedEOF, and io.ErrShortWrite, or of type wire.MessageError. This allows the caller to differentiate between general IO errors and malformed messages through type assertions.
Bitcoin Improvement Proposals ¶
This package includes spec changes outlined by the following BIPs:
BIP0014 (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki) BIP0031 (https://github.com/bitcoin/bips/blob/master/bip-0031.mediawiki) BIP0035 (https://github.com/bitcoin/bips/blob/master/bip-0035.mediawiki) BIP0037 (https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki) BIP0111 (https://github.com/bitcoin/bips/blob/master/bip-0111.mediawiki) BIP0130 (https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki) BIP0133 (https://github.com/bitcoin/bips/blob/master/bip-0133.mediawiki)
Index ¶
- Constants
- Variables
- func EncodeHnsMessage(msg HandshakeMessage, networkMagic uint32) ([]byte, error)
- func MaxHnsPayloadLength(msgType HnsMsgType) uint32
- func RandomUint64() (uint64, error)
- func ReadTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error
- func ReadVarBytes(r io.Reader, pver uint32, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarBytesBuf(r io.Reader, pver uint32, buf []byte, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarInt(r io.Reader, pver uint32) (uint64, error)
- func ReadVarIntBuf(r io.Reader, pver uint32, buf []byte) (uint64, error)
- func ReadVarString(r io.Reader, pver uint32) (string, error)
- func VarIntSerializeSize(val uint64) int
- func WriteHandshakeMessageN(w io.Writer, msg HandshakeMessage, hnsnet BitcoinNet) (int, error)
- func WriteHnsMessage(w io.Writer, msg HandshakeMessage, hnsnet BitcoinNet) error
- func WriteHnsMessageN(w io.Writer, msg HandshakeMessage, hnsnet BitcoinNet) (int, error)
- func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) error
- func WriteMessageN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet) (int, error)
- func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet, ...) (int, error)
- func WriteOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error
- func WriteTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error
- func WriteTxOutBuf(w io.Writer, pver uint32, version uint32, to *TxOut, buf []byte) error
- func WriteVarBytes(w io.Writer, pver uint32, bytes []byte) error
- func WriteVarBytesBuf(w io.Writer, pver uint32, bytes, buf []byte) error
- func WriteVarInt(w io.Writer, pver uint32, val uint64) error
- func WriteVarIntBuf(w io.Writer, pver uint32, val uint64, buf []byte) error
- func WriteVarString(w io.Writer, pver uint32, str string) error
- type Address
- func (a *Address) Decode(r io.Reader) error
- func (a *Address) Encode(w io.Writer) error
- func (a *Address) IsNulldata() bool
- func (a *Address) IsUnknown() bool
- func (a *Address) IsUnspendable() bool
- func (a *Address) OutputKey() []byte
- func (a *Address) SerializeSize() int
- func (a *Address) WitnessProgram() []byte
- type BitcoinNet
- type BlockHeader
- func (h *BlockHeader) BlockHash() chainhash.Hash
- func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (h *BlockHeader) Deserialize(r io.Reader) error
- func (h *BlockHeader) Serialize(w io.Writer) error
- type BloomUpdateType
- type Covenant
- func (c *Covenant) Decode(r io.Reader) error
- func (c *Covenant) Encode(w io.Writer) error
- func (c *Covenant) IsDustworthy() bool
- func (c *Covenant) IsKnown() bool
- func (c *Covenant) IsUnknown() bool
- func (c *Covenant) IsUnspendable() bool
- func (c *Covenant) SerializeSize() int
- func (c *Covenant) String() string
- type DomainRecord
- type DomainResourceData
- type DsDomainRecord
- type FilterType
- type Glue4DomainRecord
- type Glue6DomainRecord
- type HandshakeMessage
- func DecodeHnsMessage(data []byte) (HandshakeMessage, uint32, error)
- func ReadHandshakeMessageN(r io.Reader, hnsnet BitcoinNet) (int, HandshakeMessage, []byte, error)
- func ReadHnsMessage(r io.Reader, hnsnet BitcoinNet) (HandshakeMessage, []byte, error)
- func ReadHnsMessageN(r io.Reader, hnsnet BitcoinNet) (int, HandshakeMessage, []byte, error)
- type HnsInvItem
- type HnsMsgAddr
- type HnsMsgAirDrop
- type HnsMsgBlock
- type HnsMsgBlockTxn
- type HnsMsgClaim
- type HnsMsgCmpctBlock
- type HnsMsgFeeFilter
- type HnsMsgFilterAdd
- type HnsMsgFilterClear
- type HnsMsgFilterLoad
- type HnsMsgGetAddr
- type HnsMsgGetBlockTxn
- type HnsMsgGetBlocks
- type HnsMsgGetData
- type HnsMsgGetHeaders
- type HnsMsgGetProof
- type HnsMsgHeaders
- type HnsMsgInv
- type HnsMsgMemPool
- type HnsMsgMerkleBlock
- type HnsMsgNotFound
- type HnsMsgPing
- type HnsMsgPong
- type HnsMsgProof
- type HnsMsgReject
- type HnsMsgSendCmpct
- type HnsMsgSendHeaders
- type HnsMsgTx
- type HnsMsgType
- type HnsMsgUnknown
- type HnsMsgVerack
- type HnsMsgVersion
- type HnsNetAddress
- type InvType
- type InvVect
- type Message
- func ReadMessage(r io.Reader, pver uint32, btcnet BitcoinNet) (Message, []byte, error)
- func ReadMessageN(r io.Reader, pver uint32, btcnet BitcoinNet) (int, Message, []byte, error)
- func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet BitcoinNet, enc MessageEncoding) (int, Message, []byte, error)
- type MessageEncoding
- type MessageError
- type MsgAddr
- func (msg *MsgAddr) AddAddress(na *NetAddress) error
- func (msg *MsgAddr) AddAddresses(netAddrs ...*NetAddress) error
- func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgAddr) ClearAddresses()
- func (msg *MsgAddr) Command() string
- func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint32
- type MsgBlock
- func (msg *MsgBlock) AddTransaction(tx *MsgTx) error
- func (msg *MsgBlock) BlockHash() chainhash.Hash
- func (msg *MsgBlock) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgBlock) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgBlock) ClearTransactions()
- func (msg *MsgBlock) Command() string
- func (msg *MsgBlock) Copy() *MsgBlock
- func (msg *MsgBlock) Deserialize(r io.Reader) error
- func (msg *MsgBlock) DeserializeNoWitness(r io.Reader) error
- func (msg *MsgBlock) DeserializeTxLoc(r *bytes.Buffer) ([]TxLoc, error)
- func (msg *MsgBlock) MaxPayloadLength(pver uint32) uint32
- func (msg *MsgBlock) Serialize(w io.Writer) error
- func (msg *MsgBlock) SerializeNoWitness(w io.Writer) error
- func (msg *MsgBlock) SerializeSize() int
- func (msg *MsgBlock) SerializeSizeStripped() int
- func (msg *MsgBlock) TxHashes() ([]chainhash.Hash, error)
- type MsgFeeFilter
- type MsgFilterAdd
- type MsgFilterClear
- type MsgFilterLoad
- type MsgGetAddr
- type MsgGetBlocks
- func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *chainhash.Hash) error
- func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgGetBlocks) Command() string
- func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32
- type MsgGetData
- func (msg *MsgGetData) AddInvVect(iv *InvVect) error
- func (msg *MsgGetData) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgGetData) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgGetData) Command() string
- func (msg *MsgGetData) MaxPayloadLength(pver uint32) uint32
- type MsgGetHeaders
- func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *chainhash.Hash) error
- func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgGetHeaders) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgGetHeaders) Command() string
- func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32
- type MsgHeaders
- func (msg *MsgHeaders) AddBlockHeader(bh *BlockHeader) error
- func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgHeaders) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgHeaders) Command() string
- func (msg *MsgHeaders) MaxPayloadLength(pver uint32) uint32
- type MsgInv
- func (msg *MsgInv) AddInvVect(iv *InvVect) error
- func (msg *MsgInv) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgInv) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgInv) Command() string
- func (msg *MsgInv) MaxPayloadLength(pver uint32) uint32
- type MsgMemPool
- type MsgMerkleBlock
- func (msg *MsgMerkleBlock) AddTxHash(hash *chainhash.Hash) error
- func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgMerkleBlock) Command() string
- func (msg *MsgMerkleBlock) MaxPayloadLength(pver uint32) uint32
- type MsgNotFound
- func (msg *MsgNotFound) AddInvVect(iv *InvVect) error
- func (msg *MsgNotFound) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgNotFound) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgNotFound) Command() string
- func (msg *MsgNotFound) MaxPayloadLength(pver uint32) uint32
- type MsgPing
- type MsgPong
- type MsgReject
- type MsgSendHeaders
- type MsgTx
- func (msg *MsgTx) AddTxIn(ti *TxIn)
- func (msg *MsgTx) AddTxOut(to *TxOut)
- func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgTx) Command() string
- func (msg *MsgTx) Copy() *MsgTx
- func (msg *MsgTx) Deserialize(r io.Reader) error
- func (msg *MsgTx) DeserializeNoWitness(r io.Reader) error
- func (msg *MsgTx) HasWitness() bool
- func (msg *MsgTx) MaxPayloadLength(pver uint32) uint32
- func (msg *MsgTx) Serialize(w io.Writer) error
- func (msg *MsgTx) SerializeNoWitness(w io.Writer) error
- func (msg *MsgTx) SerializeSize() int
- func (msg *MsgTx) SerializeSizeStripped() int
- func (msg *MsgTx) TxHash() chainhash.Hash
- func (msg *MsgTx) TxID() string
- func (msg *MsgTx) WitnessHash() chainhash.Hash
- type MsgVerAck
- type MsgVersion
- func (msg *MsgVersion) AddService(service ServiceFlag)
- func (msg *MsgVersion) AddUserAgent(name string, version string, comments ...string) error
- func (msg *MsgVersion) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
- func (msg *MsgVersion) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
- func (msg *MsgVersion) Command() string
- func (msg *MsgVersion) HasService(service ServiceFlag) bool
- func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32
- type NetAddress
- type NetAddressV2
- func (na *NetAddressV2) AddService(service ServiceFlag)
- func (na *NetAddressV2) BrontideKey() []byte
- func (na *NetAddressV2) HasService(service ServiceFlag) bool
- func (na *NetAddressV2) IsTorV3() bool
- func (na *NetAddressV2) SetBrontideKey(key []byte)
- func (na *NetAddressV2) ToLegacy() *NetAddress
- func (na *NetAddressV2) TorV3Key() byte
- type NsDomainRecord
- type OutPoint
- type RejectCode
- type ServiceFlag
- type Synth4DomainRecord
- type Synth6DomainRecord
- type TextDomainRecord
- type TxIn
- type TxLoc
- type TxOut
- type TxWitness
- type UnsupportedHnsMsgTypeError
Constants ¶
const ( // CovenantNone represents a transaction with no name covenant action. CovenantNone uint8 = 0 // CovenantClaim represents an ICANN/Alexa reserved name claim. CovenantClaim uint8 = 1 // CovenantOpen represents the opening of a name auction. CovenantOpen uint8 = 2 // CovenantBid represents a bid in a name auction. CovenantBid uint8 = 3 // CovenantReveal represents revealing a bid's true value. CovenantReveal uint8 = 4 // CovenantRedeem represents reclaiming a losing bid's coins. CovenantRedeem uint8 = 5 // CovenantRegister represents registering a won name with DNS data. CovenantRegister uint8 = 6 // CovenantUpdate represents updating a name's DNS data. CovenantUpdate uint8 = 7 // CovenantRenew represents renewing a name to prevent expiry. CovenantRenew uint8 = 8 // CovenantTransfer represents initiating a name transfer. CovenantTransfer uint8 = 9 // CovenantFinalize represents finalizing a name transfer. CovenantFinalize uint8 = 10 // CovenantRevoke represents revoking a name. CovenantRevoke uint8 = 11 // MaxCovenantItems is the maximum number of items a covenant can have. // This matches hsd's consensus MAX_SCRIPT_STACK bound. MaxCovenantItems = 1000 )
const ( // DnsMaxName is the maximum length of an encoded DNS name in bytes. DnsMaxName = 255 // DnsMaxLabel is the maximum length of a single DNS label in bytes. DnsMaxLabel = 63 )
DNS name limits per RFC 1035. Handshake follows the same bounds.
const ( // RecordTypeDS is the DNSSEC delegation signer record. RecordTypeDS uint8 = 0 // RecordTypeNS is a nameserver record. RecordTypeNS uint8 = 1 // RecordTypeGLUE4 is an IPv4 glue record (nameserver + A address). RecordTypeGLUE4 uint8 = 2 // RecordTypeGLUE6 is an IPv6 glue record (nameserver + AAAA address). RecordTypeGLUE6 uint8 = 3 // RecordTypeSYNTH4 is a synthesized IPv4 record. RecordTypeSYNTH4 uint8 = 4 // RecordTypeSYNTH6 is a synthesized IPv6 record. RecordTypeSYNTH6 uint8 = 5 // RecordTypeTEXT is a TXT record. RecordTypeTEXT uint8 = 6 )
Handshake DNS resource record type identifiers. These are the 1-byte tags that prefix each record inside a DomainResourceData blob.
const ( // HnsMaxClaimProofSize is hsd's maximum serialized ownership proof size. HnsMaxClaimProofSize = 10000 // HnsMaxClaimPayload includes the uint16 length prefix around an ownership // proof in a claim packet. HnsMaxClaimPayload = 2 + HnsMaxClaimProofSize // HnsMaxAirdropProofSize is hsd's maximum serialized airdrop proof size. HnsMaxAirdropProofSize = 3400 )
const ( HnsInvTypeTx uint32 = 1 HnsInvTypeBlock uint32 = 2 HnsInvTypeFilteredBlock uint32 = 3 HnsInvTypeCmpctBlock uint32 = 4 HnsInvTypeClaim uint32 = 5 HnsInvTypeAirDrop uint32 = 6 )
const ( // MaxInvPerMsg is the maximum number of inventory vectors that can be in a // single bitcoin inv message. MaxInvPerMsg = 50000 // InvWitnessFlag denotes that the inventory vector type is requesting, // or sending a version which includes witness data. InvWitnessFlag = 1 << 30 )
const ( CmdVersion = "version" CmdVerAck = "verack" CmdGetAddr = "getaddr" CmdAddr = "addr" CmdGetBlocks = "getblocks" CmdInv = "inv" CmdGetData = "getdata" CmdNotFound = "notfound" CmdBlock = "block" CmdTx = "tx" CmdGetHeaders = "getheaders" CmdHeaders = "headers" CmdPing = "ping" CmdPong = "pong" CmdMemPool = "mempool" CmdFilterAdd = "filteradd" CmdFilterClear = "filterclear" CmdFilterLoad = "filterload" CmdMerkleBlock = "merkleblock" CmdReject = "reject" CmdSendHeaders = "sendheaders" CmdFeeFilter = "feefilter" )
Commands used in bitcoin message headers which describe the type of message.
const ( // MaxFilterLoadHashFuncs is the maximum number of hash functions to // load into the Bloom filter. MaxFilterLoadHashFuncs = 50 // MaxFilterLoadFilterSize is the maximum size in bytes a filter may be. MaxFilterLoadFilterSize = 36000 )
const ( // TxVersion is the current latest supported transaction version. // Handshake uses version 0 for most transactions. TxVersion = 0 // MaxTxInSequenceNum is the maximum sequence number the sequence field // of a transaction input can be. MaxTxInSequenceNum uint32 = 0xffffffff // MaxPrevOutIndex is the maximum index the index field of a previous // outpoint can be. MaxPrevOutIndex uint32 = 0xffffffff // 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. SequenceLockTimeDisabled = 1 << 31 // SequenceLockTimeIsSeconds is a flag that if set on a transaction // input's sequence number, the relative locktime has units of 512 // seconds. SequenceLockTimeIsSeconds = 1 << 22 // SequenceLockTimeMask is a mask that extracts the relative locktime // when masked against the transaction input sequence number. SequenceLockTimeMask = 0x0000ffff // SequenceLockTimeGranularity is the defined time based granularity // for seconds-based relative time locks. When converting from seconds // to a sequence number, the value is right shifted by this amount, // therefore the granularity of relative time locks in 512 or 2^9 // seconds. Enforced relative lock times are multiples of 512 seconds. SequenceLockTimeGranularity = 9 // MinTxOutPayload is the minimum payload size for a transaction output. // Value (8 bytes) + address version (1 byte) + address hash length (1 byte) // + covenant type (1 byte) + covenant items varint (1 byte) = 12 bytes. MinTxOutPayload = 12 )
const ( // TorV2EncodedSize is the size of a torv2 address encoded in base32 // with the ".onion" suffix. TorV2EncodedSize = 22 // TorV3EncodedSize is the size of a torv3 address encoded in base32 // with the ".onion" suffix. TorV3EncodedSize = 62 )
const ( // HnsProtocolVersion is the latest Handshake protocol version this // package supports for live peer negotiation. HnsProtocolVersion uint32 = 3 // HnsMinProtocolVersion is the lowest Handshake protocol version this // package will accept from peers. HnsMinProtocolVersion uint32 = 1 // ProtocolVersion is the latest legacy Bitcoin protocol version retained // by the btcd-shaped serializers. Live peer negotiation uses // HnsProtocolVersion. ProtocolVersion uint32 = 70016 // MultipleAddressVersion is the protocol version which added multiple // addresses per message (pver >= MultipleAddressVersion). MultipleAddressVersion uint32 = 209 // NetAddressTimeVersion is the protocol version which added the // timestamp field (pver >= NetAddressTimeVersion). NetAddressTimeVersion uint32 = 31402 // BIP0031Version is the protocol version AFTER which a pong message // and nonce field in ping were added (pver > BIP0031Version). BIP0031Version uint32 = 60000 // BIP0035Version is the protocol version which added the mempool // message (pver >= BIP0035Version). BIP0035Version uint32 = 60002 // BIP0037Version is the protocol version which added new connection // bloom filtering related messages and extended the version message // with a relay flag (pver >= BIP0037Version). BIP0037Version uint32 = 70001 // RejectVersion is the protocol version which added a new reject // message. RejectVersion uint32 = 70002 // BIP0111Version is the protocol version which added the SFNodeBloom // service flag. BIP0111Version uint32 = 70011 // SendHeadersVersion is the protocol version which added a new // sendheaders message. SendHeadersVersion uint32 = 70012 // FeeFilterVersion is the protocol version which added a new // feefilter message. FeeFilterVersion uint32 = 70013 // AddrV2Version is the protocol version which added two new messages. // sendaddrv2 is sent during the version-verack handshake and signals // support for sending and receiving the addrv2 message. In the future, // new messages that occur during the version-verack handshake will not // come with a protocol version bump. AddrV2Version uint32 = 70016 )
const CommandSize = 12
CommandSize is the fixed size of all commands in the common bitcoin message header. Shorter commands must be zero padded.
const DefaultUserAgent = "/handshake-node:0.5.0/"
DefaultUserAgent for wire in the stack.
const HnsBrontideKeySize = 33
HnsBrontideKeySize is the compressed secp256k1 static key size carried in a Handshake NetAddress for Brontide transport.
const HnsInvItemSize = 36
const HnsMaxMessagePayload = 8 * 1000 * 1000
HnsMaxMessagePayload is the maximum allowed Handshake P2P message payload size, matching hsd's `MAX_MESSAGE` (8 MB). This is independent of the btcd-derived MaxMessagePayload used elsewhere in this package while the migration to the Handshake envelope is in progress.
const HnsMaxUserAgentLen = math.MaxUint8
HnsMaxUserAgentLen is the maximum on-wire length of the Agent field. The length is encoded as a single byte.
const HnsMessageHeaderSize = 9
HnsMessageHeaderSize is the size in bytes of the Handshake P2P message header: 4-byte network magic + 1-byte message type + 4-byte payload length. Handshake does not use the 4-byte SHA-256d checksum that Bitcoin appends.
const HnsNetAddressSize = 88
HnsNetAddressSize is the on-wire size in bytes of a Handshake NetAddress. Layout (little-endian unless noted):
[0:8] Time uint64 [8:16] Services uint64 [16] address type byte (always 0) [17:33] Host 16 bytes (IPv4-mapped or IPv6) [33:53] Reserved 20 bytes [53:55] Port uint16 big-endian [55:88] Key 33 bytes (compressed secp256k1)
const MaxAddrPerMsg = 1000
MaxAddrPerMsg is the maximum number of addresses that can be in a single bitcoin addr message (MsgAddr).
const MaxBlockHeaderPayload = 236
MaxBlockHeaderPayload is the maximum number of bytes a block header can be. Nonce(4) + Time(8) + PrevBlock(32) + NameRoot(32) + ExtraNonce(24) + ReservedRoot(32) + WitnessRoot(32) + MerkleRoot(32) + Version(4) + Bits(4) + Mask(32) = 236
const MaxBlockHeadersPerMsg = 2000
MaxBlockHeadersPerMsg is the maximum number of block headers that can be in a single bitcoin headers message.
const MaxBlockLocatorsPerMsg = MaxInvPerMsg
MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message by the Handshake protocol. hsd applies the same limit used for inventory messages.
const MaxBlockPayload = 4000000
MaxBlockPayload is the maximum bytes a block message can be in bytes. After Segregated Witness, the max block payload has been raised to 4MB.
const MaxBlocksPerMsg = 500
MaxBlocksPerMsg is the maximum number of blocks allowed per message.
const (
// MaxCFilterDataSize is the maximum byte size of a committed filter.
MaxCFilterDataSize = 256 * 1024
)
const ( // MaxFilterAddDataSize is the maximum byte size of a data // element to add to the Bloom filter. It is equal to the // maximum element size of a script. MaxFilterAddDataSize = 520 )
const MaxMessagePayload = (1024 * 1024 * 32) // 32MiB
MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves. This is used as a serialization bound for all contexts (disk, RPC, network, etc.).
const MaxProtocolMessageLength = (4 * 1000 * 1000) // ~4MB
MaxProtocolMessageLength is the maximum length of an incoming/outgoing p2p protocol message. This is separate from MaxMessagePayload which is used as a general serialization bound. No current valid p2p message exceeds 4MB. This mirrors Bitcoin Core's MAX_PROTOCOL_MESSAGE_LENGTH introduced in bitcoin/bitcoin#5843.
const MaxUserAgentLen = 256
MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).
const (
// MaxVarIntPayload is the maximum payload size for a variable length integer.
MaxVarIntPayload = 9
)
const MessageHeaderSize = 24
MessageHeaderSize is the number of bytes in a bitcoin message header. Bitcoin network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.
const ( // NodeNetworkLimitedBlockThreshold is the number of blocks that a node // broadcasting SFNodeNetworkLimited MUST be able to serve from the tip. NodeNetworkLimitedBlockThreshold = 288 )
const (
// TorV3Size is the size of a torv3 address in bytes.
TorV3Size = 32
)
Variables ¶
var ( // ErrInvalidAddressSize is an error that means an incorrect address // size was decoded for a networkID or that the address exceeded the // maximum size for an unknown networkID. ErrInvalidAddressSize = fmt.Errorf("invalid address size") // ErrSkippedNetworkID is returned when the cjdns, i2p, or unknown // networks are encountered during decoding. handshake-node does not // support i2p or cjdns addresses. In the case of an unknown networkID, // this is so that a future BIP reserving a new networkID does not cause // older addrv2-supporting software to disconnect upon receiving the new // addresses. This error can also be returned when an OnionCat-encoded // torv2 address is received with the ipv6 networkID. This error // signals to the caller to continue reading. ErrSkippedNetworkID = fmt.Errorf("skipped networkID") )
var ErrInvalidHandshake = fmt.Errorf("invalid message during handshake")
ErrInvalidHandshake is the error returned when a peer sends us a known message that does not belong in the version-verack handshake.
var ErrUnknownMessage = fmt.Errorf("received unknown message")
ErrUnknownMessage is the error returned when decoding an unknown message.
var LatestEncoding = WitnessEncoding
LatestEncoding is the most recently specified encoding for the Bitcoin wire protocol.
Functions ¶
func EncodeHnsMessage ¶
func EncodeHnsMessage(msg HandshakeMessage, networkMagic uint32) ([]byte, error)
EncodeHnsMessage serializes msg with the Handshake envelope (9-byte header followed by the encoded payload). Returns an error if the encoded payload exceeds HnsMaxMessagePayload.
func MaxHnsPayloadLength ¶
func MaxHnsPayloadLength(msgType HnsMsgType) uint32
MaxHnsPayloadLength returns the largest valid payload for the provided Handshake message type.
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
func ReadTxOut ¶
ReadTxOut reads the next sequence of bytes from r as a Handshake transaction output (TxOut): value(8) + address + covenant.
func ReadVarBytes ¶
ReadVarBytes reads a variable length byte array. A byte array is encoded as a varInt containing the length of the array followed by the bytes themselves. An error is returned if the length is greater than the passed maxAllowed parameter which helps protect against memory exhaustion attacks and forced panics through malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error.
func ReadVarBytesBuf ¶
func ReadVarBytesBuf(r io.Reader, pver uint32, buf []byte, maxAllowed uint32, fieldName string) ([]byte, error)
ReadVarBytesBuf reads a variable length byte array. A byte array is encoded as a varInt containing the length of the array followed by the bytes themselves. An error is returned if the length is greater than the passed maxAllowed parameter which helps protect against memory exhaustion attacks and forced panics through malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error. If b is non-nil, the provided buffer will be used for serializing small values. Otherwise a buffer will be drawn from the binarySerializer's pool and return when the method finishes.
func ReadVarInt ¶
ReadVarInt reads a variable length integer from r and returns it as a uint64.
func ReadVarIntBuf ¶
ReadVarIntBuf reads a variable length integer from r using a preallocated scratch buffer and returns it as a uint64.
NOTE: buf MUST at least an 8-byte slice.
func ReadVarString ¶
ReadVarString reads a variable length string from r and returns it as a Go string. A variable length string is encoded as a variable length integer containing the length of the string followed by the bytes that represent the string itself. An error is returned if the length is greater than the maximum block payload size since it helps protect against memory exhaustion attacks and forced panics through malformed messages.
func VarIntSerializeSize ¶
VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
func WriteHandshakeMessageN ¶
func WriteHandshakeMessageN(w io.Writer, msg HandshakeMessage, hnsnet BitcoinNet) (int, error)
WriteHandshakeMessageN is retained as a compatibility alias while callers migrate to WriteHnsMessageN.
func WriteHnsMessage ¶
func WriteHnsMessage(w io.Writer, msg HandshakeMessage, hnsnet BitcoinNet) error
WriteHnsMessage writes a Handshake message to w using the 9-byte Handshake envelope.
func WriteHnsMessageN ¶
func WriteHnsMessageN(w io.Writer, msg HandshakeMessage, hnsnet BitcoinNet) (int, error)
WriteHnsMessageN writes a Handshake message to w using the 9-byte Handshake envelope and returns the number of bytes written, including the envelope.
func WriteMessage ¶
WriteMessage writes a bitcoin Message to w including the necessary header information. This function is the same as WriteMessageN except it doesn't doesn't return the number of bytes written. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.
func WriteMessageN ¶
WriteMessageN writes a bitcoin Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessage except it also returns the number of bytes written.
func WriteMessageWithEncodingN ¶
func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32, btcnet BitcoinNet, encoding MessageEncoding) (int, error)
WriteMessageWithEncodingN writes a bitcoin Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessageN except it also allows the caller to specify the message encoding format to be used when serializing wire messages.
func WriteOutPoint ¶
WriteOutPoint encodes op to the Handshake protocol encoding for an OutPoint to w.
func WriteTxOut ¶
WriteTxOut encodes to into the Handshake protocol encoding for a transaction output (TxOut) to w: value(8) + address + covenant.
NOTE: This function is exported in order to allow txscript to compute sighashes.
func WriteTxOutBuf ¶
WriteTxOutBuf encodes to into the Handshake protocol encoding for a transaction output (TxOut) to w: value(8) + address + covenant.
NOTE: This function is exported in order to allow txscript to compute sighashes.
func WriteVarBytes ¶
WriteVarBytes serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves.
func WriteVarBytesBuf ¶
WriteVarBytesBuf serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves. If b is non-nil, the provided buffer will be used for serializing small values. Otherwise a buffer will be drawn from the binarySerializer's pool and return when the method finishes.
func WriteVarInt ¶
WriteVarInt serializes val to w using a variable number of bytes depending on its value.
func WriteVarIntBuf ¶
WriteVarIntBuf serializes val to w using a variable number of bytes depending on its value using a preallocated scratch buffer.
NOTE: buf MUST at least an 8-byte slice.
Types ¶
type Address ¶
Address represents a Handshake output address consisting of a witness program version and hash. Version 0 addresses use 20-byte (P2WPKH) or 32-byte (P2WSH) hashes. Handshake wire addresses are valid for versions 0 through 31. Version 31 is nulldata and is provably unspendable.
Wire format: version(1 byte) + hashLen(1 byte) + hash(N bytes)
func NewAddress ¶
NewAddress creates a new Address with validation. It returns an error if the version or hash length is invalid. The zero-value address (version 0, empty hash) is rejected by this constructor; callers wanting a placeholder should construct the literal directly.
func (*Address) Encode ¶
Encode serializes the address to w.
Wire format: version(1) + hashLen(1) + hash
func (*Address) IsNulldata ¶
IsNulldata returns whether the address is Handshake's native nulldata address type. Version 31 outputs are provably unspendable and carry data rather than a witness program.
func (*Address) IsUnknown ¶
IsUnknown returns whether the address uses a witness program version that is not currently defined by Handshake. Version 0 is defined only for 20-byte pubkey hashes and 32-byte script hashes, while version 31 is the native nulldata type. Versions 1 through 30 are reserved for future use.
func (*Address) IsUnspendable ¶
IsUnspendable returns whether the address is provably unspendable.
func (*Address) OutputKey ¶
OutputKey returns bytes suitable for identifying this address in output indexes, compact filters, and deterministic sorting. It returns the legacy witness-program script view when the address version can be represented as OP_0 through OP_16. For versions 17 through 31, it falls back to the native Handshake address encoding: version || hashLen || hash.
The fallback form is not a script and must not be passed to script execution or script-classification APIs.
func (*Address) SerializeSize ¶
SerializeSize returns the number of bytes needed to serialize the address.
func (*Address) WitnessProgram ¶
WitnessProgram returns the legacy Bitcoin-style script view for this address. For version 0, the result is [OP_0, len(hash), hash...]. For versions 1 through 16, the result is [OP_N, len(hash), hash...]. Versions 17 through 31 are valid Handshake wire addresses, but there is no small-int opcode representation for them, so nil is returned. Version 31 nulldata outputs are not witness programs.
type BitcoinNet ¶
type BitcoinNet uint32
BitcoinNet represents which Handshake network a message belongs to. The type name is kept for btcd API compatibility.
const ( // MainNet represents the Handshake mainnet. MainNet BitcoinNet = 0x5B6EF2D3 // TestNet represents the regression test network. TestNet BitcoinNet = 0xAE3895CF )
Constants used to indicate the message network. They can also be used to seek to the next message when a stream's state is unknown, but this package does not provide that functionality since it's generally a better idea to simply disconnect clients that are misbehaving over TCP.
func (BitcoinNet) String ¶
func (n BitcoinNet) String() string
String returns the BitcoinNet in human-readable form.
type BlockHeader ¶
type BlockHeader struct {
// Version of the block. This is not the same as the protocol version.
Version int32
// Hash of the previous block header in the block chain.
PrevBlock chainhash.Hash
// Merkle tree reference to hash of all transactions for the block.
MerkleRoot chainhash.Hash
// Time the block was created. Encoded as uint64 on wire.
Timestamp time.Time
// Difficulty target for the block.
Bits uint32
// Nonce used to generate the block.
Nonce uint32
// NameRoot is the root hash of the Urkel name trie.
NameRoot chainhash.Hash
// ExtraNonce provides additional nonce space for miners.
ExtraNonce [24]byte
// ReservedRoot is reserved for future use (e.g., soft-fork commitments).
ReservedRoot chainhash.Hash
// WitnessRoot is the root hash of the witness commitment tree.
WitnessRoot chainhash.Hash
// Mask is XORed with the share hash to produce the PoW hash.
Mask chainhash.Hash
}
BlockHeader defines information about a block and is used in the Handshake block (MsgBlock) and headers (MsgHeaders) messages.
func NewBlockHeader ¶
func NewBlockHeader(version int32, prevHash, merkleRootHash, nameRoot, witnessRoot *chainhash.Hash, bits uint32, nonce uint32) *BlockHeader
NewBlockHeader returns a new BlockHeader using the provided version, previous block hash, merkle root hash, name root, witness root, difficulty bits, and nonce used to generate the block with defaults for the remaining fields.
func (*BlockHeader) BlockHash ¶
func (h *BlockHeader) BlockHash() chainhash.Hash
BlockHash computes the block identifier hash for the given block header using the Handshake PoW hash chain (Blake2b + SHA3).
func (*BlockHeader) BtcDecode ¶
func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation. See Deserialize for decoding block headers stored to disk, such as in a database, as opposed to decoding block headers from the wire.
func (*BlockHeader) BtcEncode ¶
func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation. See Serialize for encoding block headers to be stored to disk, such as in a database, as opposed to encoding block headers for the wire.
func (*BlockHeader) Deserialize ¶
func (h *BlockHeader) Deserialize(r io.Reader) error
Deserialize decodes a block header from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field.
type BloomUpdateType ¶
type BloomUpdateType uint8
BloomUpdateType is the legacy BIP-37 update selector carried by Handshake's filterload payload. hsd preserves the value for wire compatibility but does not use it to gate updates: every matched Handshake output adds its outpoint to the filter.
const ( // BloomUpdateNone is the legacy no-update selector value. BloomUpdateNone BloomUpdateType = 0 // BloomUpdateAll is the legacy update-all selector value. BloomUpdateAll BloomUpdateType = 1 // BloomUpdateP2PubkeyOnly is the legacy pubkey-only selector value. BloomUpdateP2PubkeyOnly BloomUpdateType = 2 )
type Covenant ¶
Covenant represents a Handshake name covenant attached to a transaction output. Covenants encode the state transitions of the Handshake name auction system.
Wire format:
type(1 byte) + varint(itemCount) + for each item: varint(itemLen) + itemBytes
func NewCovenant ¶
NewCovenant returns a new Covenant with the given type and items.
func (*Covenant) Encode ¶
Encode serializes the covenant to w.
Wire format: type(1) + varint(itemCount) + for each item: varint(len) + bytes
func (*Covenant) IsDustworthy ¶
IsDustworthy returns whether outputs with this covenant are subject to the dust policy rule. Plain payments, bids, and future covenant types are dustworthy. Other known name covenants carry protocol state and are exempt.
func (*Covenant) IsKnown ¶
IsKnown returns whether the covenant type is one of the currently defined Handshake covenant types.
func (*Covenant) IsUnknown ¶
IsUnknown returns whether the covenant type is reserved for a future Handshake covenant extension.
func (*Covenant) IsUnspendable ¶
IsUnspendable returns whether outputs with this covenant are provably unspendable.
func (*Covenant) SerializeSize ¶
SerializeSize returns the number of bytes needed to serialize the covenant.
type DomainRecord ¶
type DomainRecord interface {
// Type returns the 1-byte record type tag.
Type() uint8
// contains filtered or unexported methods
}
DomainRecord is implemented by every Handshake DNS resource record type carried inside a DomainResourceData payload.
type DomainResourceData ¶
type DomainResourceData struct {
Version uint8
Records []DomainRecord
}
DomainResourceData is the parsed form of the resource-record payload carried by Handshake name covenants (e.g. the UPDATE covenant). It holds the protocol version byte followed by a list of DNS-style records.
Wire format:
version(1 byte) + concatenated records
Each record begins with a 1-byte type tag; records continue until the stream is exhausted or an unknown record type is encountered. To match hsd's behavior, decoding is lenient: if the stream ends mid-record or an unknown type appears, the records successfully parsed so far are retained and no error is returned.
func NewDomainResourceDataFromBytes ¶
func NewDomainResourceDataFromBytes(data []byte) (*DomainResourceData, error)
NewDomainResourceDataFromBytes parses a DomainResourceData from a byte slice. This mirrors the constructor from cdnsd for convenience.
func (*DomainResourceData) Decode ¶
func (d *DomainResourceData) Decode(r io.Reader) error
Decode deserializes resource data from r.
The entire reader contents are consumed because Handshake DNS name compression references earlier byte offsets in the blob; random access to the original buffer is required to resolve pointers. Callers should pass a reader that supplies exactly one resource-data payload.
func (*DomainResourceData) Encode ¶
func (d *DomainResourceData) Encode(w io.Writer) error
Encode serializes the resource data to w in Handshake wire format.
Records are written uncompressed. The decoder accepts both compressed and uncompressed forms, so round-trips through Encode/Decode are lossless for record contents even when the input used name compression.
func (*DomainResourceData) SerializeSize ¶
func (d *DomainResourceData) SerializeSize() int
SerializeSize returns the number of bytes needed to serialize the resource data in uncompressed form (matching what Encode produces).
type DsDomainRecord ¶
DsDomainRecord is a DNSSEC Delegation Signer record.
type FilterType ¶
type FilterType uint8
FilterType represents a committed filter type. The Bitcoin compact-filter P2P packets are not part of Handshake's message table, but the filter index and RPC surface still key filters by type.
const ( // GCSFilterRegular is the regular filter type. GCSFilterRegular FilterType = iota )
type Glue4DomainRecord ¶
Glue4DomainRecord is an IPv4 nameserver glue record: a DNS name bound to an IPv4 address.
func (*Glue4DomainRecord) Type ¶
func (*Glue4DomainRecord) Type() uint8
Type returns the record type tag.
type Glue6DomainRecord ¶
Glue6DomainRecord is an IPv6 nameserver glue record: a DNS name bound to an IPv6 address.
func (*Glue6DomainRecord) Type ¶
func (*Glue6DomainRecord) Type() uint8
Type returns the record type tag.
type HandshakeMessage ¶
type HandshakeMessage interface {
Type() HnsMsgType
Encode() []byte
Decode([]byte) error
}
HandshakeMessage is the interface implemented by every Handshake P2P message. The byte-slice Encode/Decode shape mirrors cdnsd's reference implementation; it differs from btcd's `Message` interface by design while the wire package straddles both protocols.
func DecodeHnsMessage ¶
func DecodeHnsMessage(data []byte) (HandshakeMessage, uint32, error)
DecodeHnsMessage parses a complete Handshake message (header + payload) from data and returns the decoded message and the network magic from the header. Callers are responsible for verifying the magic against the expected network. The data slice must contain exactly one full message.
func ReadHandshakeMessageN ¶
func ReadHandshakeMessageN(r io.Reader, hnsnet BitcoinNet) (int, HandshakeMessage, []byte, error)
ReadHandshakeMessageN is retained as a compatibility alias while callers migrate to ReadHnsMessageN.
func ReadHnsMessage ¶
func ReadHnsMessage(r io.Reader, hnsnet BitcoinNet) (HandshakeMessage, []byte, error)
ReadHnsMessage reads, validates, and parses the next Handshake message from r. It is the same as ReadHnsMessageN except it does not return the number of bytes read.
func ReadHnsMessageN ¶
func ReadHnsMessageN(r io.Reader, hnsnet BitcoinNet) (int, HandshakeMessage, []byte, error)
ReadHnsMessageN reads, validates, and parses the next Handshake message from r. It returns the number of bytes read, the parsed message, and the raw payload bytes which comprise the message body.
type HnsInvItem ¶
HnsInvItem identifies an object by type and hash in Handshake inventory messages.
func NewHnsInvItem ¶
func NewHnsInvItem(iv *InvVect) HnsInvItem
NewHnsInvItem converts an in-memory inventory vector into its Handshake wire representation.
func (*HnsInvItem) Decode ¶
func (i *HnsInvItem) Decode(data []byte) error
func (*HnsInvItem) Encode ¶
func (i *HnsInvItem) Encode() []byte
func (*HnsInvItem) InvVect ¶
func (i *HnsInvItem) InvVect() *InvVect
InvVect converts the Handshake inventory item into the in-memory inventory vector representation shared with the rest of the codebase.
type HnsMsgAddr ¶
type HnsMsgAddr struct {
Peers []HnsNetAddress
}
HnsMsgAddr is the Handshake "addr" message. It advertises peers using the Handshake 88-byte NetAddress shape, which includes each peer's static key.
func (*HnsMsgAddr) Decode ¶
func (m *HnsMsgAddr) Decode(data []byte) error
func (*HnsMsgAddr) Encode ¶
func (m *HnsMsgAddr) Encode() []byte
func (*HnsMsgAddr) Type ¶
func (*HnsMsgAddr) Type() HnsMsgType
type HnsMsgAirDrop ¶
type HnsMsgAirDrop struct {
Payload []byte
}
HnsMsgAirDrop is the Handshake "airdrop" message. The native airdrop proof parser belongs with Phase 4 claim/airdrop verification, so the packet body is retained opaquely at the wire envelope layer.
func (*HnsMsgAirDrop) Decode ¶
func (m *HnsMsgAirDrop) Decode(data []byte) error
func (*HnsMsgAirDrop) Encode ¶
func (m *HnsMsgAirDrop) Encode() []byte
func (*HnsMsgAirDrop) Type ¶
func (*HnsMsgAirDrop) Type() HnsMsgType
type HnsMsgBlock ¶
type HnsMsgBlock struct {
Block MsgBlock
}
HnsMsgBlock is the Handshake "block" message. It reuses the existing Handshake-shaped MsgBlock serializer from Phase 1.
func (*HnsMsgBlock) Decode ¶
func (m *HnsMsgBlock) Decode(data []byte) error
func (*HnsMsgBlock) Encode ¶
func (m *HnsMsgBlock) Encode() []byte
func (*HnsMsgBlock) Type ¶
func (*HnsMsgBlock) Type() HnsMsgType
type HnsMsgBlockTxn ¶
type HnsMsgBlockTxn struct {
Payload []byte
}
HnsMsgBlockTxn is the Handshake "blocktxn" message. The compact-block transaction response body is retained opaquely until compact block relay is implemented.
func (*HnsMsgBlockTxn) Decode ¶
func (m *HnsMsgBlockTxn) Decode(data []byte) error
func (*HnsMsgBlockTxn) Encode ¶
func (m *HnsMsgBlockTxn) Encode() []byte
func (*HnsMsgBlockTxn) Type ¶
func (*HnsMsgBlockTxn) Type() HnsMsgType
type HnsMsgClaim ¶
type HnsMsgClaim struct {
Claim []byte
}
HnsMsgClaim is the Handshake "claim" message. It carries a raw encoded name claim with a uint16 little-endian length prefix.
func (*HnsMsgClaim) Decode ¶
func (m *HnsMsgClaim) Decode(data []byte) error
func (*HnsMsgClaim) Encode ¶
func (m *HnsMsgClaim) Encode() []byte
func (*HnsMsgClaim) Type ¶
func (*HnsMsgClaim) Type() HnsMsgType
type HnsMsgCmpctBlock ¶
type HnsMsgCmpctBlock struct {
Payload []byte
}
HnsMsgCmpctBlock is the Handshake "cmpctblock" message. Compact block structures depend on the block-relay migration in Phase 5, so the body is intentionally preserved as an opaque payload for now.
func (*HnsMsgCmpctBlock) Decode ¶
func (m *HnsMsgCmpctBlock) Decode(data []byte) error
func (*HnsMsgCmpctBlock) Encode ¶
func (m *HnsMsgCmpctBlock) Encode() []byte
func (*HnsMsgCmpctBlock) Type ¶
func (*HnsMsgCmpctBlock) Type() HnsMsgType
type HnsMsgFeeFilter ¶
type HnsMsgFeeFilter struct {
Rate int64
}
HnsMsgFeeFilter is the Handshake "feefilter" message. Rate is encoded as a signed 64-bit fee rate in dollarydoos per kilobyte.
func (*HnsMsgFeeFilter) Decode ¶
func (m *HnsMsgFeeFilter) Decode(data []byte) error
func (*HnsMsgFeeFilter) Encode ¶
func (m *HnsMsgFeeFilter) Encode() []byte
func (*HnsMsgFeeFilter) Type ¶
func (*HnsMsgFeeFilter) Type() HnsMsgType
type HnsMsgFilterAdd ¶
type HnsMsgFilterAdd struct {
Data []byte
}
HnsMsgFilterAdd is the Handshake "filteradd" message. It appends one item to the peer's loaded bloom filter.
func (*HnsMsgFilterAdd) Decode ¶
func (m *HnsMsgFilterAdd) Decode(data []byte) error
func (*HnsMsgFilterAdd) Encode ¶
func (m *HnsMsgFilterAdd) Encode() []byte
func (*HnsMsgFilterAdd) Type ¶
func (*HnsMsgFilterAdd) Type() HnsMsgType
type HnsMsgFilterClear ¶
type HnsMsgFilterClear struct{}
HnsMsgFilterClear is the Handshake "filterclear" message. It clears the peer's loaded bloom filter and carries no payload.
func (*HnsMsgFilterClear) Decode ¶
func (*HnsMsgFilterClear) Decode(data []byte) error
func (*HnsMsgFilterClear) Encode ¶
func (*HnsMsgFilterClear) Encode() []byte
func (*HnsMsgFilterClear) Type ¶
func (*HnsMsgFilterClear) Type() HnsMsgType
type HnsMsgFilterLoad ¶
type HnsMsgFilterLoad struct {
Filter []byte
HashFuncs uint32
Tweak uint32
Flags BloomUpdateType
}
HnsMsgFilterLoad is the Handshake "filterload" message. hsd uses the same BIP-37 bloom filter payload shape: varbytes filter, hash function count, tweak, and update flags.
func (*HnsMsgFilterLoad) Decode ¶
func (m *HnsMsgFilterLoad) Decode(data []byte) error
func (*HnsMsgFilterLoad) Encode ¶
func (m *HnsMsgFilterLoad) Encode() []byte
func (*HnsMsgFilterLoad) Type ¶
func (*HnsMsgFilterLoad) Type() HnsMsgType
type HnsMsgGetAddr ¶
type HnsMsgGetAddr struct{}
HnsMsgGetAddr is the Handshake "getaddr" message, requesting known peers from the remote node. It carries no payload.
func (*HnsMsgGetAddr) Decode ¶
func (*HnsMsgGetAddr) Decode(data []byte) error
func (*HnsMsgGetAddr) Encode ¶
func (*HnsMsgGetAddr) Encode() []byte
func (*HnsMsgGetAddr) Type ¶
func (*HnsMsgGetAddr) Type() HnsMsgType
type HnsMsgGetBlockTxn ¶
type HnsMsgGetBlockTxn struct {
Payload []byte
}
HnsMsgGetBlockTxn is the Handshake "getblocktxn" message. The compact-block transaction request body is retained opaquely until compact block relay is implemented.
func (*HnsMsgGetBlockTxn) Decode ¶
func (m *HnsMsgGetBlockTxn) Decode(data []byte) error
func (*HnsMsgGetBlockTxn) Encode ¶
func (m *HnsMsgGetBlockTxn) Encode() []byte
func (*HnsMsgGetBlockTxn) Type ¶
func (*HnsMsgGetBlockTxn) Type() HnsMsgType
type HnsMsgGetBlocks ¶
HnsMsgGetBlocks is the Handshake "getblocks" message. It requests block inventory after one of the locator hashes, stopping at StopHash when set.
func (*HnsMsgGetBlocks) AddBlockLocatorHash ¶
func (m *HnsMsgGetBlocks) AddBlockLocatorHash(hash *chainhash.Hash) error
AddBlockLocatorHash appends a block locator hash. It returns an error when the message already carries the maximum number of locator hashes.
func (*HnsMsgGetBlocks) Decode ¶
func (m *HnsMsgGetBlocks) Decode(data []byte) error
func (*HnsMsgGetBlocks) Encode ¶
func (m *HnsMsgGetBlocks) Encode() []byte
func (*HnsMsgGetBlocks) LocatorHashes ¶
func (m *HnsMsgGetBlocks) LocatorHashes() []*chainhash.Hash
LocatorHashes returns the block locator as chain hashes.
func (*HnsMsgGetBlocks) Type ¶
func (*HnsMsgGetBlocks) Type() HnsMsgType
type HnsMsgGetData ¶
type HnsMsgGetData struct {
Inventory []HnsInvItem
}
HnsMsgGetData is the Handshake "getdata" message. It requests inventory items previously announced by a peer.
func NewHnsMsgGetData ¶
func NewHnsMsgGetData() *HnsMsgGetData
NewHnsMsgGetData returns a new Handshake getdata message.
func NewHnsMsgGetDataSizeHint ¶
func NewHnsMsgGetDataSizeHint(invListHint uint) *HnsMsgGetData
NewHnsMsgGetDataSizeHint returns a new Handshake getdata message with the backing inventory slice sized for the given hint, limited to the maximum allowed per message.
func (*HnsMsgGetData) AddInvVect ¶
func (m *HnsMsgGetData) AddInvVect(iv *InvVect) error
AddInvVect appends an inventory vector to the message. It returns an error when the message already carries the maximum number of inventory items.
func (*HnsMsgGetData) Decode ¶
func (m *HnsMsgGetData) Decode(data []byte) error
func (*HnsMsgGetData) Encode ¶
func (m *HnsMsgGetData) Encode() []byte
func (*HnsMsgGetData) InvVects ¶
func (m *HnsMsgGetData) InvVects() []*InvVect
InvVects returns the message inventory as in-memory inventory vectors.
func (*HnsMsgGetData) Type ¶
func (*HnsMsgGetData) Type() HnsMsgType
type HnsMsgGetHeaders ¶
HnsMsgGetHeaders is the Handshake "getheaders" message. It requests a header chain after one of the locator hashes, stopping at StopHash when set.
func (*HnsMsgGetHeaders) AddBlockLocatorHash ¶
func (m *HnsMsgGetHeaders) AddBlockLocatorHash(hash *chainhash.Hash) error
AddBlockLocatorHash appends a block locator hash. It returns an error when the message already carries the maximum number of locator hashes.
func (*HnsMsgGetHeaders) Decode ¶
func (m *HnsMsgGetHeaders) Decode(data []byte) error
func (*HnsMsgGetHeaders) Encode ¶
func (m *HnsMsgGetHeaders) Encode() []byte
func (*HnsMsgGetHeaders) LocatorHashes ¶
func (m *HnsMsgGetHeaders) LocatorHashes() []*chainhash.Hash
LocatorHashes returns the block locator as chain hashes.
func (*HnsMsgGetHeaders) Type ¶
func (*HnsMsgGetHeaders) Type() HnsMsgType
type HnsMsgGetProof ¶
HnsMsgGetProof is the Handshake "getproof" message. It requests an Urkel proof for Key at Root.
func (*HnsMsgGetProof) Decode ¶
func (m *HnsMsgGetProof) Decode(data []byte) error
func (*HnsMsgGetProof) Encode ¶
func (m *HnsMsgGetProof) Encode() []byte
func (*HnsMsgGetProof) Type ¶
func (*HnsMsgGetProof) Type() HnsMsgType
type HnsMsgHeaders ¶
type HnsMsgHeaders struct {
Headers []*BlockHeader
}
HnsMsgHeaders is the Handshake "headers" message. It carries a count followed by raw 236-byte Handshake block headers.
func (*HnsMsgHeaders) Decode ¶
func (m *HnsMsgHeaders) Decode(data []byte) error
func (*HnsMsgHeaders) Encode ¶
func (m *HnsMsgHeaders) Encode() []byte
func (*HnsMsgHeaders) Type ¶
func (*HnsMsgHeaders) Type() HnsMsgType
type HnsMsgInv ¶
type HnsMsgInv struct {
Inventory []HnsInvItem
}
HnsMsgInv is the Handshake "inv" message. It announces inventory available from the peer.
func NewHnsMsgInv ¶
func NewHnsMsgInv() *HnsMsgInv
NewHnsMsgInv returns a new Handshake inv message.
func NewHnsMsgInvSizeHint ¶
NewHnsMsgInvSizeHint returns a new Handshake inv message with the backing inventory slice sized for the given hint, limited to the maximum allowed per message.
func (*HnsMsgInv) AddInvVect ¶
AddInvVect appends an inventory vector to the message. It returns an error when the message already carries the maximum number of inventory items.
func (*HnsMsgInv) Type ¶
func (*HnsMsgInv) Type() HnsMsgType
type HnsMsgMemPool ¶
type HnsMsgMemPool struct{}
HnsMsgMemPool is the Handshake "mempool" message. It requests the peer's mempool inventory and carries no payload.
func (*HnsMsgMemPool) Decode ¶
func (*HnsMsgMemPool) Decode(data []byte) error
func (*HnsMsgMemPool) Encode ¶
func (*HnsMsgMemPool) Encode() []byte
func (*HnsMsgMemPool) Type ¶
func (*HnsMsgMemPool) Type() HnsMsgType
type HnsMsgMerkleBlock ¶
type HnsMsgMerkleBlock struct {
MerkleBlock MsgMerkleBlock
}
HnsMsgMerkleBlock is the Handshake "merkleblock" message. It reuses the existing filtered block serializer while the surrounding codebase still exposes the btcd-shaped merkle block type.
func (*HnsMsgMerkleBlock) Decode ¶
func (m *HnsMsgMerkleBlock) Decode(data []byte) error
func (*HnsMsgMerkleBlock) Encode ¶
func (m *HnsMsgMerkleBlock) Encode() []byte
func (*HnsMsgMerkleBlock) Type ¶
func (*HnsMsgMerkleBlock) Type() HnsMsgType
type HnsMsgNotFound ¶
type HnsMsgNotFound struct {
Inventory []HnsInvItem
}
HnsMsgNotFound is the Handshake "notfound" message. It returns requested inventory items that the peer could not provide.
func NewHnsMsgNotFound ¶
func NewHnsMsgNotFound() *HnsMsgNotFound
NewHnsMsgNotFound returns a new Handshake notfound message.
func (*HnsMsgNotFound) AddInvVect ¶
func (m *HnsMsgNotFound) AddInvVect(iv *InvVect) error
AddInvVect appends an inventory vector to the message. It returns an error when the message already carries the maximum number of inventory items.
func (*HnsMsgNotFound) Decode ¶
func (m *HnsMsgNotFound) Decode(data []byte) error
func (*HnsMsgNotFound) Encode ¶
func (m *HnsMsgNotFound) Encode() []byte
func (*HnsMsgNotFound) InvVects ¶
func (m *HnsMsgNotFound) InvVects() []*InvVect
InvVects returns the message inventory as in-memory inventory vectors.
func (*HnsMsgNotFound) Type ¶
func (*HnsMsgNotFound) Type() HnsMsgType
type HnsMsgPing ¶
type HnsMsgPing struct {
Nonce [8]byte
}
HnsMsgPing is the Handshake "ping" message. The 8-byte nonce lets the receiver match a Pong response to the originating Ping.
func NewHnsMsgPing ¶
func NewHnsMsgPing(nonce uint64) *HnsMsgPing
NewHnsMsgPing returns a ping message carrying the given nonce in the little-endian byte order used on the wire.
func (*HnsMsgPing) Decode ¶
func (m *HnsMsgPing) Decode(data []byte) error
func (*HnsMsgPing) Encode ¶
func (m *HnsMsgPing) Encode() []byte
func (*HnsMsgPing) NonceUint64 ¶
func (m *HnsMsgPing) NonceUint64() uint64
NonceUint64 returns the ping nonce as a little-endian uint64.
func (*HnsMsgPing) Type ¶
func (*HnsMsgPing) Type() HnsMsgType
type HnsMsgPong ¶
type HnsMsgPong struct {
Nonce [8]byte
}
HnsMsgPong is the Handshake "pong" message, echoing the nonce from a Ping.
func (*HnsMsgPong) Decode ¶
func (m *HnsMsgPong) Decode(data []byte) error
func (*HnsMsgPong) Encode ¶
func (m *HnsMsgPong) Encode() []byte
func (*HnsMsgPong) NonceUint64 ¶
func (m *HnsMsgPong) NonceUint64() uint64
NonceUint64 returns the pong nonce as a little-endian uint64.
func (*HnsMsgPong) Type ¶
func (*HnsMsgPong) Type() HnsMsgType
type HnsMsgProof ¶
HnsMsgProof is the Handshake "proof" message. The proof body uses the hsd-compatible Urkel proof encoding verified by the blockchain package.
func (*HnsMsgProof) Decode ¶
func (m *HnsMsgProof) Decode(data []byte) error
func (*HnsMsgProof) Encode ¶
func (m *HnsMsgProof) Encode() []byte
func (*HnsMsgProof) Type ¶
func (*HnsMsgProof) Type() HnsMsgType
type HnsMsgReject ¶
type HnsMsgReject struct {
Message HnsMsgType
Code RejectCode
Reason string
Hash [32]byte
}
HnsMsgReject is the Handshake "reject" message. Unlike Bitcoin's reject payload, hsd encodes the rejected message as a one-byte Handshake packet type and the reason as a one-byte length-prefixed string. Block, tx, claim, and airdrop rejects carry the rejected object's hash.
func (*HnsMsgReject) Decode ¶
func (m *HnsMsgReject) Decode(data []byte) error
func (*HnsMsgReject) Encode ¶
func (m *HnsMsgReject) Encode() []byte
func (*HnsMsgReject) Type ¶
func (*HnsMsgReject) Type() HnsMsgType
type HnsMsgSendCmpct ¶
HnsMsgSendCmpct is the Handshake "sendcmpct" message. It negotiates compact block announcements.
func (*HnsMsgSendCmpct) Decode ¶
func (m *HnsMsgSendCmpct) Decode(data []byte) error
func (*HnsMsgSendCmpct) Encode ¶
func (m *HnsMsgSendCmpct) Encode() []byte
func (*HnsMsgSendCmpct) Type ¶
func (*HnsMsgSendCmpct) Type() HnsMsgType
type HnsMsgSendHeaders ¶
type HnsMsgSendHeaders struct{}
HnsMsgSendHeaders is the Handshake "sendheaders" message. It requests that peers announce new blocks with Headers messages instead of Inv messages.
func (*HnsMsgSendHeaders) Decode ¶
func (*HnsMsgSendHeaders) Decode(data []byte) error
func (*HnsMsgSendHeaders) Encode ¶
func (*HnsMsgSendHeaders) Encode() []byte
func (*HnsMsgSendHeaders) Type ¶
func (*HnsMsgSendHeaders) Type() HnsMsgType
type HnsMsgTx ¶
type HnsMsgTx struct {
Tx MsgTx
}
HnsMsgTx is the Handshake "tx" message. It reuses the existing Handshake-shaped MsgTx serializer from Phase 1.
func (*HnsMsgTx) Type ¶
func (*HnsMsgTx) Type() HnsMsgType
type HnsMsgType ¶
type HnsMsgType uint8
HnsMsgType identifies a Handshake P2P message in the wire envelope. Values match hsd's `lib/net/packets.js` `types` enum.
const ( HnsMsgTypeVersion HnsMsgType = 0 HnsMsgTypeVerack HnsMsgType = 1 HnsMsgTypePing HnsMsgType = 2 HnsMsgTypePong HnsMsgType = 3 HnsMsgTypeGetAddr HnsMsgType = 4 HnsMsgTypeAddr HnsMsgType = 5 HnsMsgTypeInv HnsMsgType = 6 HnsMsgTypeGetData HnsMsgType = 7 HnsMsgTypeNotFound HnsMsgType = 8 HnsMsgTypeGetBlocks HnsMsgType = 9 HnsMsgTypeGetHeaders HnsMsgType = 10 HnsMsgTypeHeaders HnsMsgType = 11 HnsMsgTypeSendHeaders HnsMsgType = 12 HnsMsgTypeBlock HnsMsgType = 13 HnsMsgTypeTx HnsMsgType = 14 HnsMsgTypeReject HnsMsgType = 15 HnsMsgTypeMempool HnsMsgType = 16 HnsMsgTypeFilterLoad HnsMsgType = 17 HnsMsgTypeFilterAdd HnsMsgType = 18 HnsMsgTypeFilterClear HnsMsgType = 19 HnsMsgTypeMerkleBlock HnsMsgType = 20 HnsMsgTypeFeeFilter HnsMsgType = 21 HnsMsgTypeSendCmpct HnsMsgType = 22 HnsMsgTypeCmpctBlock HnsMsgType = 23 HnsMsgTypeGetBlockTxn HnsMsgType = 24 HnsMsgTypeBlockTxn HnsMsgType = 25 HnsMsgTypeGetProof HnsMsgType = 26 HnsMsgTypeProof HnsMsgType = 27 HnsMsgTypeClaim HnsMsgType = 28 HnsMsgTypeAirDrop HnsMsgType = 29 HnsMsgTypeUnknown HnsMsgType = 30 )
func (HnsMsgType) String ¶
func (t HnsMsgType) String() string
String returns the hsd packet name for the message type.
type HnsMsgUnknown ¶
type HnsMsgUnknown struct {
Payload []byte
}
HnsMsgUnknown is the hsd type-30 unknown packet. It preserves the payload without interpreting it.
func (*HnsMsgUnknown) Decode ¶
func (m *HnsMsgUnknown) Decode(data []byte) error
func (*HnsMsgUnknown) Encode ¶
func (m *HnsMsgUnknown) Encode() []byte
func (*HnsMsgUnknown) Type ¶
func (*HnsMsgUnknown) Type() HnsMsgType
type HnsMsgVerack ¶
type HnsMsgVerack struct{}
HnsMsgVerack is the Handshake "verack" message, sent in response to a Version message to acknowledge the protocol handshake. It carries no payload.
func (*HnsMsgVerack) Decode ¶
func (*HnsMsgVerack) Decode(data []byte) error
func (*HnsMsgVerack) Encode ¶
func (*HnsMsgVerack) Encode() []byte
func (*HnsMsgVerack) Type ¶
func (*HnsMsgVerack) Type() HnsMsgType
type HnsMsgVersion ¶
type HnsMsgVersion struct {
Version uint32
Services uint64
Time uint64
Remote HnsNetAddress
Nonce [8]byte
Agent string
Height uint32
NoRelay bool
}
HnsMsgVersion is the Handshake "version" message exchanged at the start of every peer connection to negotiate protocol version, services, and node identity. It is type 0 in the Handshake message-type table.
func (*HnsMsgVersion) Decode ¶
func (m *HnsMsgVersion) Decode(data []byte) error
func (*HnsMsgVersion) Encode ¶
func (m *HnsMsgVersion) Encode() []byte
Encode serializes the message. Agent is capped to HnsMaxUserAgentLen because the Handshake packet stores its length in one byte.
func (*HnsMsgVersion) NonceUint64 ¶
func (m *HnsMsgVersion) NonceUint64() uint64
NonceUint64 returns the connection nonce as a little-endian uint64.
func (*HnsMsgVersion) SetNonce ¶
func (m *HnsMsgVersion) SetNonce(nonce uint64)
SetNonce stores the given nonce in the little-endian byte order used on the wire.
func (*HnsMsgVersion) Type ¶
func (*HnsMsgVersion) Type() HnsMsgType
type HnsNetAddress ¶
type HnsNetAddress struct {
Time uint64
Services uint64
Host net.IP
Reserved [20]byte
Port uint16
Key [HnsBrontideKeySize]byte
}
HnsNetAddress is a Handshake P2P network address. Unlike btcd's NetAddress it always carries the peer's static identity key and a 20-byte reserved region, totaling 88 bytes on the wire.
func NewHnsNetAddress ¶
func NewHnsNetAddress(na *NetAddress) HnsNetAddress
NewHnsNetAddress converts the in-memory NetAddress representation into a Handshake wire address. The reserved region and identity key are zeroed; nodes that have not learned a peer's key advertise it as all zeroes.
func (*HnsNetAddress) Decode ¶
func (n *HnsNetAddress) Decode(data []byte) error
Decode parses an HnsNetAddressSize-byte payload into n. IPv4-mapped hosts are normalized to their 4-byte representation so encode/decode round-trips are byte-equal.
func (*HnsNetAddress) Encode ¶
func (n *HnsNetAddress) Encode() []byte
Encode serializes the address into HnsNetAddressSize bytes. IPv4 hosts are written as IPv4-mapped IPv6; nil or zero-length hosts are written as the IPv6 unspecified address.
func (*HnsNetAddress) NetAddress ¶
func (n *HnsNetAddress) NetAddress() *NetAddress
NetAddress converts the Handshake wire address into the in-memory NetAddress representation shared with the address manager.
func (*HnsNetAddress) NetAddressV2 ¶
func (n *HnsNetAddress) NetAddressV2() *NetAddressV2
NetAddressV2 converts the Handshake wire address into the in-memory NetAddressV2 representation while preserving the advertised Brontide static key.
type InvType ¶
type InvType uint32
InvType represents the allowed types of inventory vectors. See InvVect.
const ( InvTypeError InvType = 0 InvTypeTx InvType = 1 InvTypeBlock InvType = 2 InvTypeFilteredBlock InvType = 3 InvTypeClaim InvType = 5 InvTypeAirDrop InvType = 6 InvTypeWitnessBlock InvType = InvTypeBlock | InvWitnessFlag InvTypeWitnessTx InvType = InvTypeTx | InvWitnessFlag InvTypeFilteredWitnessBlock InvType = InvTypeFilteredBlock | InvWitnessFlag )
These constants define the various supported inventory vector types.
type InvVect ¶
InvVect defines a bitcoin 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.
type Message ¶
type Message interface {
BtcDecode(io.Reader, uint32, MessageEncoding) error
BtcEncode(io.Writer, uint32, MessageEncoding) error
Command() string
MaxPayloadLength(uint32) uint32
}
Message is an interface that describes a bitcoin message. A type that implements Message has complete control over the representation of its data and may therefore contain additional or fewer fields than those which are used directly in the protocol encoded message.
func ReadMessage ¶
ReadMessage reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the parsed Message and raw bytes which comprise the message. This function only differs from ReadMessageN in that it doesn't return the number of bytes read. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.
func ReadMessageN ¶
ReadMessageN reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessage except it also returns the number of bytes read.
func ReadMessageWithEncodingN ¶
func ReadMessageWithEncodingN(r io.Reader, pver uint32, btcnet BitcoinNet, enc MessageEncoding) (int, Message, []byte, error)
ReadMessageWithEncodingN reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessageN except it allows the caller to specify which message encoding is to to consult when decoding wire messages.
type MessageEncoding ¶
type MessageEncoding uint32
MessageEncoding represents the wire message encoding format to be used.
const ( // BaseEncoding encodes all messages in the default format specified // for the Bitcoin wire protocol. BaseEncoding MessageEncoding = 1 << iota // WitnessEncoding encodes all messages other than transaction messages // using the default Bitcoin wire protocol specification. For transaction // messages, the new encoding format detailed in BIP0144 will be used. WitnessEncoding )
type MessageError ¶
type MessageError struct {
Func string // Function name
Description string // Human readable description of the issue
}
MessageError describes an issue with a message. An example of some potential issues are messages from the wrong bitcoin network, invalid commands, mismatched checksums, and exceeding max payloads.
This provides a mechanism for the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that resulted from malformed messages.
func (*MessageError) Error ¶
func (e *MessageError) Error() string
Error satisfies the error interface and prints human-readable errors.
type MsgAddr ¶
type MsgAddr struct {
AddrList []*NetAddress
}
MsgAddr implements the Message interface and represents a bitcoin addr message. It is used to provide a list of known active peers on the network. An active peer is considered one that has transmitted a message within the last 3 hours. Nodes which have not transmitted in that time frame should be forgotten. Each message is limited to a maximum number of addresses, which is currently 1000. As a result, multiple messages must be used to relay the full list.
Use the AddAddress function to build up the list of known addresses when sending an addr message to another peer.
func NewMsgAddr ¶
func NewMsgAddr() *MsgAddr
NewMsgAddr returns a new bitcoin addr message that conforms to the Message interface. See MsgAddr for details.
func (*MsgAddr) AddAddress ¶
func (msg *MsgAddr) AddAddress(na *NetAddress) error
AddAddress adds a known active peer to the message.
func (*MsgAddr) AddAddresses ¶
func (msg *MsgAddr) AddAddresses(netAddrs ...*NetAddress) error
AddAddresses adds multiple known active peers to the message.
func (*MsgAddr) BtcDecode ¶
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgAddr) BtcEncode ¶
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgAddr) ClearAddresses ¶
func (msg *MsgAddr) ClearAddresses()
ClearAddresses removes all addresses from the message.
func (*MsgAddr) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgAddr) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgBlock ¶
type MsgBlock struct {
Header BlockHeader
Transactions []*MsgTx
}
MsgBlock implements the Message interface and represents a bitcoin block message. It is used to deliver block and transaction information in response to a getdata message (MsgGetData) for a given block hash.
func NewMsgBlock ¶
func NewMsgBlock(blockHeader *BlockHeader) *MsgBlock
NewMsgBlock returns a new bitcoin block message that conforms to the Message interface. See MsgBlock for details.
func (*MsgBlock) AddTransaction ¶
AddTransaction adds a transaction to the message.
func (*MsgBlock) BtcDecode ¶
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation. See Deserialize for decoding blocks stored to disk, such as in a database, as opposed to decoding blocks from the wire.
func (*MsgBlock) BtcEncode ¶
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation. See Serialize for encoding blocks to be stored to disk, such as in a database, as opposed to encoding blocks for the wire.
func (*MsgBlock) ClearTransactions ¶
func (msg *MsgBlock) ClearTransactions()
ClearTransactions removes all transactions from the message.
func (*MsgBlock) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgBlock) Deserialize ¶
Deserialize decodes a block from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field in the block. This function differs from BtcDecode in that BtcDecode decodes from the bitcoin wire protocol as it was sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored block at all. As of the time this comment was written, the encoded block is the same in both instances, but there is a distinct difference and separating the two allows the API to be flexible enough to deal with changes.
func (*MsgBlock) DeserializeNoWitness ¶
DeserializeNoWitness decodes a block from r into the receiver similar to Deserialize, however DeserializeWitness strips all (if any) witness data from the transactions within the block before encoding them.
func (*MsgBlock) DeserializeTxLoc ¶
DeserializeTxLoc decodes r in the same manner Deserialize does, but it takes a byte buffer instead of a generic reader and returns a slice containing the start and length of each transaction within the raw data that is being deserialized.
func (*MsgBlock) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgBlock) Serialize ¶
Serialize encodes the block to w using a format that suitable for long-term storage such as a database while respecting the Version field in the block. This function differs from BtcEncode in that BtcEncode encodes the block to the bitcoin wire protocol in order to be sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored block at all. As of the time this comment was written, the encoded block is the same in both instances, but there is a distinct difference and separating the two allows the API to be flexible enough to deal with changes.
func (*MsgBlock) SerializeNoWitness ¶
SerializeNoWitness encodes a block to w using an identical format to Serialize, with all (if any) witness data stripped from all transactions. This method is provided in addition to the regular Serialize, in order to allow one to selectively encode transaction witness data to non-upgraded peers which are unaware of the new encoding.
func (*MsgBlock) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the block, factoring in any witness data within transaction.
func (*MsgBlock) SerializeSizeStripped ¶
SerializeSizeStripped returns the number of bytes it would take to serialize the block, excluding any witness data (if any).
type MsgFeeFilter ¶
type MsgFeeFilter struct {
MinFee int64
}
MsgFeeFilter implements the Message interface and represents a bitcoin feefilter message. It is used to request the receiving peer does not announce any transactions below the specified minimum fee rate.
This message was not added until protocol versions starting with FeeFilterVersion.
func NewMsgFeeFilter ¶
func NewMsgFeeFilter(minfee int64) *MsgFeeFilter
NewMsgFeeFilter returns a new bitcoin feefilter message that conforms to the Message interface. See MsgFeeFilter for details.
func (*MsgFeeFilter) BtcDecode ¶
func (msg *MsgFeeFilter) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgFeeFilter) BtcEncode ¶
func (msg *MsgFeeFilter) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgFeeFilter) Command ¶
func (msg *MsgFeeFilter) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgFeeFilter) MaxPayloadLength ¶
func (msg *MsgFeeFilter) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgFilterAdd ¶
type MsgFilterAdd struct {
Data []byte
}
MsgFilterAdd implements the Message interface and represents a bitcoin filteradd message. It is used to add a data element to an existing Bloom filter.
This message was not added until protocol version BIP0037Version.
func NewMsgFilterAdd ¶
func NewMsgFilterAdd(data []byte) *MsgFilterAdd
NewMsgFilterAdd returns a new bitcoin filteradd message that conforms to the Message interface. See MsgFilterAdd for details.
func (*MsgFilterAdd) BtcDecode ¶
func (msg *MsgFilterAdd) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgFilterAdd) BtcEncode ¶
func (msg *MsgFilterAdd) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgFilterAdd) Command ¶
func (msg *MsgFilterAdd) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgFilterAdd) MaxPayloadLength ¶
func (msg *MsgFilterAdd) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgFilterClear ¶
type MsgFilterClear struct{}
MsgFilterClear implements the Message interface and represents a bitcoin filterclear message which is used to reset a Bloom filter.
This message was not added until protocol version BIP0037Version and has no payload.
func NewMsgFilterClear ¶
func NewMsgFilterClear() *MsgFilterClear
NewMsgFilterClear returns a new bitcoin filterclear message that conforms to the Message interface. See MsgFilterClear for details.
func (*MsgFilterClear) BtcDecode ¶
func (msg *MsgFilterClear) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgFilterClear) BtcEncode ¶
func (msg *MsgFilterClear) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgFilterClear) Command ¶
func (msg *MsgFilterClear) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgFilterClear) MaxPayloadLength ¶
func (msg *MsgFilterClear) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgFilterLoad ¶
type MsgFilterLoad struct {
Filter []byte
HashFuncs uint32
Tweak uint32
Flags BloomUpdateType
}
MsgFilterLoad implements the Message interface and represents a bitcoin filterload message which is used to reset a Bloom filter.
This message was not added until protocol version BIP0037Version.
func NewMsgFilterLoad ¶
func NewMsgFilterLoad(filter []byte, hashFuncs uint32, tweak uint32, flags BloomUpdateType) *MsgFilterLoad
NewMsgFilterLoad returns a new bitcoin filterload message that conforms to the Message interface. See MsgFilterLoad for details.
func (*MsgFilterLoad) BtcDecode ¶
func (msg *MsgFilterLoad) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgFilterLoad) BtcEncode ¶
func (msg *MsgFilterLoad) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgFilterLoad) Command ¶
func (msg *MsgFilterLoad) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgFilterLoad) MaxPayloadLength ¶
func (msg *MsgFilterLoad) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetAddr ¶
type MsgGetAddr struct{}
MsgGetAddr implements the Message interface and represents a bitcoin getaddr message. It is used to request a list of known active peers on the network from a peer to help identify potential nodes. The list is returned via one or more addr messages (MsgAddr).
This message has no payload.
func NewMsgGetAddr ¶
func NewMsgGetAddr() *MsgGetAddr
NewMsgGetAddr returns a new bitcoin getaddr message that conforms to the Message interface. See MsgGetAddr for details.
func (*MsgGetAddr) BtcDecode ¶
func (msg *MsgGetAddr) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetAddr) BtcEncode ¶
func (msg *MsgGetAddr) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgGetAddr) Command ¶
func (msg *MsgGetAddr) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetAddr) MaxPayloadLength ¶
func (msg *MsgGetAddr) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetBlocks ¶
type MsgGetBlocks struct {
ProtocolVersion uint32
BlockLocatorHashes []*chainhash.Hash
HashStop chainhash.Hash
}
MsgGetBlocks implements the Message interface and represents a bitcoin getblocks message. It is used to request a list of blocks starting after the last known hash in the slice of block locator hashes. The list is returned via an inv message (MsgInv) and is limited by a specific hash to stop at or the maximum number of blocks per message, which is currently 500.
Set the HashStop field to the hash at which to stop and use AddBlockLocatorHash to build up the list of block locator hashes.
The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. In order to keep the list of locator hashes to a reasonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.
func NewMsgGetBlocks ¶
func NewMsgGetBlocks(hashStop *chainhash.Hash) *MsgGetBlocks
NewMsgGetBlocks returns a new bitcoin getblocks message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgGetBlocks) AddBlockLocatorHash ¶
func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *chainhash.Hash) error
AddBlockLocatorHash adds a new block locator hash to the message.
func (*MsgGetBlocks) BtcDecode ¶
func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetBlocks) BtcEncode ¶
func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgGetBlocks) Command ¶
func (msg *MsgGetBlocks) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetBlocks) MaxPayloadLength ¶
func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetData ¶
type MsgGetData struct {
InvList []*InvVect
}
MsgGetData implements the Message interface and represents a bitcoin getdata message. It is used to request data such as blocks and transactions from another peer. It should be used in response to the inv (MsgInv) message to request the actual data referenced by each inventory vector the receiving peer doesn't already have. Each message is limited to a maximum number of inventory vectors, which is currently 50,000. As a result, multiple messages must be used to request larger amounts of data.
Use the AddInvVect function to build up the list of inventory vectors when sending a getdata message to another peer.
func NewMsgGetData ¶
func NewMsgGetData() *MsgGetData
NewMsgGetData returns a new bitcoin getdata message that conforms to the Message interface. See MsgGetData for details.
func NewMsgGetDataSizeHint ¶
func NewMsgGetDataSizeHint(sizeHint uint) *MsgGetData
NewMsgGetDataSizeHint returns a new bitcoin getdata message that conforms to the Message interface. See MsgGetData for details. This function differs from NewMsgGetData in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large amounts of inventory vectors with AddInvVect. Note that the specified hint is just that - a hint that is used for the default allocation size. Adding more (or less) inventory vectors will still work properly. The size hint is limited to MaxInvPerMsg.
func (*MsgGetData) AddInvVect ¶
func (msg *MsgGetData) AddInvVect(iv *InvVect) error
AddInvVect adds an inventory vector to the message.
func (*MsgGetData) BtcDecode ¶
func (msg *MsgGetData) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetData) BtcEncode ¶
func (msg *MsgGetData) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgGetData) Command ¶
func (msg *MsgGetData) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetData) MaxPayloadLength ¶
func (msg *MsgGetData) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgGetHeaders ¶
type MsgGetHeaders struct {
ProtocolVersion uint32
BlockLocatorHashes []*chainhash.Hash
HashStop chainhash.Hash
}
MsgGetHeaders implements the Message interface and represents a bitcoin getheaders message. It is used to request a list of block headers for blocks starting after the last known hash in the slice of block locator hashes. The list is returned via a headers message (MsgHeaders) and is limited by a specific hash to stop at or the maximum number of block headers per message, which is currently 2000.
Set the HashStop field to the hash at which to stop and use AddBlockLocatorHash to build up the list of block locator hashes.
The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. In order to keep the list of locator hashes to a reasonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.
func NewMsgGetHeaders ¶
func NewMsgGetHeaders() *MsgGetHeaders
NewMsgGetHeaders returns a new bitcoin getheaders message that conforms to the Message interface. See MsgGetHeaders for details.
func (*MsgGetHeaders) AddBlockLocatorHash ¶
func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *chainhash.Hash) error
AddBlockLocatorHash adds a new block locator hash to the message.
func (*MsgGetHeaders) BtcDecode ¶
func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetHeaders) BtcEncode ¶
func (msg *MsgGetHeaders) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgGetHeaders) Command ¶
func (msg *MsgGetHeaders) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetHeaders) MaxPayloadLength ¶
func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgHeaders ¶
type MsgHeaders struct {
Headers []*BlockHeader
}
MsgHeaders implements the Message interface and represents a bitcoin headers message. It is used to deliver block header information in response to a getheaders message (MsgGetHeaders). The maximum number of block headers per message is currently 2000. See MsgGetHeaders for details on requesting the headers.
func NewMsgHeaders ¶
func NewMsgHeaders() *MsgHeaders
NewMsgHeaders returns a new bitcoin headers message that conforms to the Message interface. See MsgHeaders for details.
func (*MsgHeaders) AddBlockHeader ¶
func (msg *MsgHeaders) AddBlockHeader(bh *BlockHeader) error
AddBlockHeader adds a new block header to the message.
func (*MsgHeaders) BtcDecode ¶
func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgHeaders) BtcEncode ¶
func (msg *MsgHeaders) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgHeaders) Command ¶
func (msg *MsgHeaders) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgHeaders) MaxPayloadLength ¶
func (msg *MsgHeaders) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgInv ¶
type MsgInv struct {
InvList []*InvVect
}
MsgInv implements the Message interface and represents a bitcoin inv message. It is used to advertise a peer's known data such as blocks and transactions through inventory vectors. It may be sent unsolicited to inform other peers of the data or in response to a getblocks message (MsgGetBlocks). Each message is limited to a maximum number of inventory vectors, which is currently 50,000.
Use the AddInvVect function to build up the list of inventory vectors when sending an inv message to another peer.
func NewMsgInv ¶
func NewMsgInv() *MsgInv
NewMsgInv returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details.
func NewMsgInvSizeHint ¶
NewMsgInvSizeHint returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details. This function differs from NewMsgInv in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large amounts of inventory vectors with AddInvVect. Note that the specified hint is just that - a hint that is used for the default allocation size. Adding more (or less) inventory vectors will still work properly. The size hint is limited to MaxInvPerMsg.
func (*MsgInv) AddInvVect ¶
AddInvVect adds an inventory vector to the message.
func (*MsgInv) BtcDecode ¶
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgInv) BtcEncode ¶
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgInv) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgInv) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgMemPool ¶
type MsgMemPool struct{}
MsgMemPool implements the Message interface and represents a bitcoin mempool message. It is used to request a list of transactions still in the active memory pool of a relay.
This message has no payload and was not added until protocol versions starting with BIP0035Version.
func NewMsgMemPool ¶
func NewMsgMemPool() *MsgMemPool
NewMsgMemPool returns a new bitcoin pong message that conforms to the Message interface. See MsgPong for details.
func (*MsgMemPool) BtcDecode ¶
func (msg *MsgMemPool) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgMemPool) BtcEncode ¶
func (msg *MsgMemPool) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgMemPool) Command ¶
func (msg *MsgMemPool) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgMemPool) MaxPayloadLength ¶
func (msg *MsgMemPool) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgMerkleBlock ¶
type MsgMerkleBlock struct {
Header BlockHeader
Transactions uint32
Hashes []*chainhash.Hash
Flags []byte
}
MsgMerkleBlock implements the Message interface and represents a bitcoin merkleblock message which is used to reset a Bloom filter.
This message was not added until protocol version BIP0037Version.
func NewMsgMerkleBlock ¶
func NewMsgMerkleBlock(bh *BlockHeader) *MsgMerkleBlock
NewMsgMerkleBlock returns a new bitcoin merkleblock message that conforms to the Message interface. See MsgMerkleBlock for details.
func (*MsgMerkleBlock) AddTxHash ¶
func (msg *MsgMerkleBlock) AddTxHash(hash *chainhash.Hash) error
AddTxHash adds a new transaction hash to the message.
func (*MsgMerkleBlock) BtcDecode ¶
func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgMerkleBlock) BtcEncode ¶
func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgMerkleBlock) Command ¶
func (msg *MsgMerkleBlock) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgMerkleBlock) MaxPayloadLength ¶
func (msg *MsgMerkleBlock) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgNotFound ¶
type MsgNotFound struct {
InvList []*InvVect
}
MsgNotFound defines a bitcoin notfound message which is sent in response to a getdata message if any of the requested data in not available on the peer. Each message is limited to a maximum number of inventory vectors, which is currently 50,000.
Use the AddInvVect function to build up the list of inventory vectors when sending a notfound message to another peer.
func NewMsgNotFound ¶
func NewMsgNotFound() *MsgNotFound
NewMsgNotFound returns a new bitcoin notfound message that conforms to the Message interface. See MsgNotFound for details.
func (*MsgNotFound) AddInvVect ¶
func (msg *MsgNotFound) AddInvVect(iv *InvVect) error
AddInvVect adds an inventory vector to the message.
func (*MsgNotFound) BtcDecode ¶
func (msg *MsgNotFound) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgNotFound) BtcEncode ¶
func (msg *MsgNotFound) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgNotFound) Command ¶
func (msg *MsgNotFound) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgNotFound) MaxPayloadLength ¶
func (msg *MsgNotFound) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgPing ¶
type MsgPing struct {
// Unique value associated with message that is used to identify
// specific ping message.
Nonce uint64
}
MsgPing implements the Message interface and represents a bitcoin ping message.
For versions BIP0031Version and earlier, it is used primarily to confirm that a connection is still valid. A transmission error is typically interpreted as a closed connection and that the peer should be removed. For versions AFTER BIP0031Version it contains an identifier which can be returned in the pong message to determine network timing.
The payload for this message just consists of a nonce used for identifying it later.
func NewMsgPing ¶
NewMsgPing returns a new bitcoin ping message that conforms to the Message interface. See MsgPing for details.
func (*MsgPing) BtcDecode ¶
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgPing) BtcEncode ¶
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgPing) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgPing) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgPong ¶
type MsgPong struct {
// Unique value associated with message that is used to identify
// specific ping message.
Nonce uint64
}
MsgPong implements the Message interface and represents a bitcoin pong message which is used primarily to confirm that a connection is still valid in response to a bitcoin ping message (MsgPing).
This message was not added until protocol versions AFTER BIP0031Version.
func NewMsgPong ¶
NewMsgPong returns a new bitcoin pong message that conforms to the Message interface. See MsgPong for details.
func (*MsgPong) BtcDecode ¶
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgPong) BtcEncode ¶
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgPong) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgPong) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgReject ¶
type MsgReject struct {
// Cmd is the command for the message which was rejected such as
// as CmdBlock or CmdTx. This can be obtained from the Command function
// of a Message.
Cmd string
// RejectCode is a code indicating why the command was rejected. It
// is encoded as a uint8 on the wire.
Code RejectCode
// Reason is a human-readable string with specific details (over and
// above the reject code) about why the command was rejected.
Reason string
// Hash identifies a specific block or transaction that was rejected
// and therefore only applies the MsgBlock and MsgTx messages.
Hash chainhash.Hash
}
MsgReject implements the Message interface and represents a bitcoin reject message.
This message was not added until protocol version RejectVersion.
func NewMsgReject ¶
func NewMsgReject(command string, code RejectCode, reason string) *MsgReject
NewMsgReject returns a new bitcoin reject message that conforms to the Message interface. See MsgReject for details.
func (*MsgReject) BtcDecode ¶
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgReject) BtcEncode ¶
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgReject) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgReject) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgSendHeaders ¶
type MsgSendHeaders struct{}
MsgSendHeaders implements the Message interface and represents a bitcoin sendheaders message. It is used to request the peer send block headers rather than inventory vectors.
This message has no payload and was not added until protocol versions starting with SendHeadersVersion.
func NewMsgSendHeaders ¶
func NewMsgSendHeaders() *MsgSendHeaders
NewMsgSendHeaders returns a new bitcoin sendheaders message that conforms to the Message interface. See MsgSendHeaders for details.
func (*MsgSendHeaders) BtcDecode ¶
func (msg *MsgSendHeaders) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgSendHeaders) BtcEncode ¶
func (msg *MsgSendHeaders) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgSendHeaders) Command ¶
func (msg *MsgSendHeaders) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgSendHeaders) MaxPayloadLength ¶
func (msg *MsgSendHeaders) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgTx ¶
MsgTx implements the Message interface and represents a Handshake tx message. It is used to deliver transaction information in response to a getdata message (MsgGetData) for a given transaction.
Use the AddTxIn and AddTxOut functions to build up the list of transaction inputs and outputs.
func NewMsgTx ¶
NewMsgTx returns a new Handshake tx message that conforms to the Message interface. The return instance has a default version of TxVersion and there are no transaction inputs or outputs. Also, the lock time is set to zero to indicate the transaction is valid immediately as opposed to some time in future.
func (*MsgTx) BtcDecode ¶
BtcDecode decodes r using the Handshake protocol encoding into the receiver. This is part of the Message interface implementation. See Deserialize for decoding transactions stored to disk, such as in a database, as opposed to decoding transactions from the wire.
func (*MsgTx) BtcEncode ¶
BtcEncode encodes the receiver to w using the Handshake protocol encoding. This is part of the Message interface implementation. See Serialize for encoding transactions to be stored to disk, such as in a database, as opposed to encoding transactions for the wire.
func (*MsgTx) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgTx) Copy ¶
Copy creates a deep copy of a transaction so that the original does not get modified when the copy is manipulated.
func (*MsgTx) Deserialize ¶
Deserialize decodes a transaction from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field in the transaction.
func (*MsgTx) DeserializeNoWitness ¶
DeserializeNoWitness decodes a transaction from r into the receiver, where the transaction encoding format within r MUST NOT include witness data.
func (*MsgTx) HasWitness ¶
HasWitness returns false if none of the inputs within the transaction contain witness data, true otherwise.
func (*MsgTx) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
func (*MsgTx) Serialize ¶
Serialize encodes the transaction to w using a format that is suitable for long-term storage such as a database while respecting the Version field in the transaction.
func (*MsgTx) SerializeNoWitness ¶
SerializeNoWitness encodes the transaction to w without witness data. This is used for computing the transaction hash (TxHash).
func (*MsgTx) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the transaction (including witness data).
func (*MsgTx) SerializeSizeStripped ¶
SerializeSizeStripped returns the number of bytes it would take to serialize the transaction, excluding any included witness data.
func (*MsgTx) TxHash ¶
TxHash generates the Hash for the transaction using Blake2b-256. The hash covers version through locktime (no witness data).
func (*MsgTx) WitnessHash ¶
WitnessHash generates the witness-committed hash of the transaction. It is Blake2b-256(txHash || Blake2b-256(witnessData)).
type MsgVerAck ¶
type MsgVerAck struct{}
MsgVerAck defines a bitcoin verack message which is used for a peer to acknowledge a version message (MsgVersion) after it has used the information to negotiate parameters. It implements the Message interface.
This message has no payload.
func NewMsgVerAck ¶
func NewMsgVerAck() *MsgVerAck
NewMsgVerAck returns a new bitcoin verack message that conforms to the Message interface.
func (*MsgVerAck) BtcDecode ¶
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgVerAck) BtcEncode ¶
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgVerAck) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgVerAck) MaxPayloadLength ¶
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type MsgVersion ¶
type MsgVersion struct {
// Version of the protocol the node is using.
ProtocolVersion int32
// Bitfield which identifies the enabled services.
Services ServiceFlag
// Time the message was generated. This is encoded as an int64 on the wire.
Timestamp time.Time
// Address of the remote peer.
AddrYou NetAddress
// Address of the local peer.
AddrMe NetAddress
// Unique value associated with message that is used to detect self
// connections.
Nonce uint64
// The user agent that generated message. This is a encoded as a varString
// on the wire. This has a max length of MaxUserAgentLen.
UserAgent string
// Last block seen by the generator of the version message.
LastBlock int32
// Don't announce transactions to peer.
DisableRelayTx bool
}
MsgVersion implements the Message interface and represents a bitcoin version message. It is used for a peer to advertise itself as soon as an outbound connection is made. The remote peer then uses this information along with its own to negotiate. The remote peer must then respond with a version message of its own containing the negotiated values followed by a verack message (MsgVerAck). This exchange must take place before any further communication is allowed to proceed.
func NewMsgVersion ¶
func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64, lastBlock int32) *MsgVersion
NewMsgVersion returns a new bitcoin version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func (*MsgVersion) AddService ¶
func (msg *MsgVersion) AddService(service ServiceFlag)
AddService adds service as a supported service by the peer generating the message.
func (*MsgVersion) AddUserAgent ¶
func (msg *MsgVersion) AddUserAgent(name string, version string, comments ...string) error
AddUserAgent adds a user agent to the user agent string for the version message. The version string is not defined to any strict format, although it is recommended to use the form "major.minor.revision" e.g. "2.6.41".
func (*MsgVersion) BtcDecode ¶
func (msg *MsgVersion) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error
BtcDecode decodes r using the bitcoin protocol encoding into the receiver. The version message is special in that the protocol version hasn't been negotiated yet. As a result, the pver field is ignored and any fields which are added in new versions are optional. This also mean that r must be a *bytes.Buffer so the number of remaining bytes can be ascertained.
This is part of the Message interface implementation.
func (*MsgVersion) BtcEncode ¶
func (msg *MsgVersion) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error
BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.
func (*MsgVersion) Command ¶
func (msg *MsgVersion) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgVersion) HasService ¶
func (msg *MsgVersion) HasService(service ServiceFlag) bool
HasService returns whether the specified service is supported by the peer that generated the message.
func (*MsgVersion) MaxPayloadLength ¶
func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32
MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.
type NetAddress ¶
type NetAddress struct {
// Last time the address was seen. This is, unfortunately, encoded as a
// uint32 on the wire and therefore is limited to 2106. This field is
// not present in the bitcoin version message (MsgVersion) nor was it
// added until protocol version >= NetAddressTimeVersion.
Timestamp time.Time
// Bitfield which identifies the services supported by the address.
Services ServiceFlag
// IP address of the peer.
IP net.IP
// Port the peer is using. This is encoded in big endian on the wire
// which differs from most everything else.
Port uint16
}
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.
func NewNetAddress ¶
func NewNetAddress(addr *net.TCPAddr, services ServiceFlag) *NetAddress
NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.
func NewNetAddressIPPort ¶
func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress
NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and supported services with defaults for the remaining fields.
func NewNetAddressTimestamp ¶
func NewNetAddressTimestamp( timestamp time.Time, services ServiceFlag, ip net.IP, port uint16) *NetAddress
NewNetAddressTimestamp returns a new NetAddress using the provided timestamp, IP, port, and supported services. The timestamp is rounded to single second precision.
func (*NetAddress) AddService ¶
func (na *NetAddress) AddService(service ServiceFlag)
AddService adds service as a supported service by the peer generating the message.
func (*NetAddress) HasService ¶
func (na *NetAddress) HasService(service ServiceFlag) bool
HasService returns whether the specified service is supported by the address.
type NetAddressV2 ¶
type NetAddressV2 struct {
// Last time the address was seen. This is, unfortunately, encoded as a
// uint32 on the wire and therefore is limited to 2106. This field is
// not present in the bitcoin version message (MsgVersion) nor was it
// added until protocol version >= NetAddressTimeVersion.
Timestamp time.Time
// Services is a bitfield which identifies the services supported by
// the address. This is encoded in CompactSize.
Services ServiceFlag
// Addr is the network address of the peer. This is a variable-length
// address. Network() returns the BIP-155 networkID which is a uint8
// encoded as a string. String() returns the address as a string.
Addr net.Addr
// Port is the port of the address. This is 0 if the network doesn't
// use ports.
Port uint16
// contains filtered or unexported fields
}
NetAddressV2 defines information about a peer on the network including the last time it was seen, the services it supports, its address, and port. The type is retained for address-manager and RPC compatibility; Handshake P2P addr packets use HnsNetAddress on the wire.
func NetAddressV2FromBytes ¶
func NetAddressV2FromBytes(timestamp time.Time, services ServiceFlag, addrBytes []byte, port uint16) *NetAddressV2
NetAddressV2FromBytes creates a NetAddressV2 from a byte slice. It will also handle a torv2 address using the OnionCat encoding.
func (*NetAddressV2) AddService ¶
func (na *NetAddressV2) AddService(service ServiceFlag)
AddService adds a service to the Services bitfield.
func (*NetAddressV2) BrontideKey ¶
func (na *NetAddressV2) BrontideKey() []byte
BrontideKey returns a copy of the Handshake Brontide static public key learned for this address, or nil when no usable key is known.
func (*NetAddressV2) HasService ¶
func (na *NetAddressV2) HasService(service ServiceFlag) bool
HasService returns whether the specified service is supported by the address.
func (*NetAddressV2) IsTorV3 ¶
func (na *NetAddressV2) IsTorV3() bool
IsTorV3 returns a bool that signals to the caller whether or not this is a torv3 address.
func (*NetAddressV2) SetBrontideKey ¶
func (na *NetAddressV2) SetBrontideKey(key []byte)
SetBrontideKey stores a copy of a Handshake Brontide static public key on this address. Invalid lengths or all-zero keys clear the stored key.
func (*NetAddressV2) ToLegacy ¶
func (na *NetAddressV2) ToLegacy() *NetAddress
ToLegacy attempts to convert a NetAddressV2 to a legacy NetAddress. This only works for ipv4, ipv6, or torv2 addresses as they can be encoded with the OnionCat encoding. If this method is called on a torv3 address, nil will be returned.
func (*NetAddressV2) TorV3Key ¶
func (na *NetAddressV2) TorV3Key() byte
TorV3Key returns the first byte of the v3 public key. This is used in the addrmgr to calculate a key from a network group.
type NsDomainRecord ¶
type NsDomainRecord struct {
Name string
}
NsDomainRecord is a nameserver record: a DNS name with no address.
type OutPoint ¶
OutPoint defines a transaction outpoint used to track previous transaction outputs.
func NewOutPoint ¶
NewOutPoint returns a new transaction outpoint with the provided hash and index.
func NewOutPointFromString ¶
NewOutPointFromString returns a new transaction outpoint parsed from the provided string, which should be in the format "hash:index".
type RejectCode ¶
type RejectCode uint8
RejectCode represents a numeric value by which a remote peer indicates why a message was rejected.
const ( RejectMalformed RejectCode = 0x01 RejectInvalid RejectCode = 0x10 RejectObsolete RejectCode = 0x11 RejectDuplicate RejectCode = 0x12 RejectNonstandard RejectCode = 0x40 RejectDust RejectCode = 0x41 RejectInsufficientFee RejectCode = 0x42 RejectCheckpoint RejectCode = 0x43 )
These constants define the various supported reject codes.
func (RejectCode) String ¶
func (code RejectCode) String() string
String returns the RejectCode in human-readable form.
type ServiceFlag ¶
type ServiceFlag uint64
ServiceFlag identifies services supported by a Handshake peer.
const ( // SFNodeNetwork is a flag used to indicate a peer is a full node. SFNodeNetwork ServiceFlag = 1 << 0 // SFNodeBloom is a flag used to indicate a peer supports bloom filtering. SFNodeBloom ServiceFlag = 1 << 1 // SFNodeGetUTXO is a legacy Bitcoin-only flag retained for API // compatibility while the fork is migrated. SFNodeGetUTXO ServiceFlag = 1 << 2 // SFNodeWitness is a legacy Bitcoin-only flag retained for API // compatibility while the fork is migrated. SFNodeWitness ServiceFlag = 1 << 3 // SFNodeXthin is a legacy Bitcoin-only flag retained for API // compatibility while the fork is migrated. SFNodeXthin ServiceFlag = 1 << 4 // SFNodeBit5 is a legacy Bitcoin-only flag retained for API // compatibility while the fork is migrated. SFNodeBit5 ServiceFlag = 1 << 5 // SFNodeCF is a legacy Bitcoin-only flag retained for API compatibility // while the fork is migrated. SFNodeCF ServiceFlag = 1 << 6 // SFNode2X is a legacy Bitcoin-only flag retained for API compatibility // while the fork is migrated. SFNode2X ServiceFlag = 1 << 7 // SFNodeNetWorkLimited is a legacy Bitcoin-only flag retained for API // compatibility while the fork is migrated. SFNodeNetworkLimited ServiceFlag = 1 << 10 // SFNodeP2PV2 is a legacy Bitcoin-only flag retained for API // compatibility while the fork is migrated. SFNodeP2PV2 ServiceFlag = 1 << 11 )
func (ServiceFlag) HasFlag ¶
func (f ServiceFlag) HasFlag(s ServiceFlag) bool
HasFlag returns a bool indicating if the service has the given flag.
func (ServiceFlag) String ¶
func (f ServiceFlag) String() string
String returns the ServiceFlag in human-readable form.
type Synth4DomainRecord ¶
Synth4DomainRecord is a synthesized IPv4 record, consisting only of an address with no name.
func (*Synth4DomainRecord) Type ¶
func (*Synth4DomainRecord) Type() uint8
Type returns the record type tag.
type Synth6DomainRecord ¶
Synth6DomainRecord is a synthesized IPv6 record, consisting only of an address with no name.
func (*Synth6DomainRecord) Type ¶
func (*Synth6DomainRecord) Type() uint8
Type returns the record type tag.
type TextDomainRecord ¶
type TextDomainRecord struct {
Items [][]byte
}
TextDomainRecord is a TXT record, holding a list of byte strings. Each string and the list itself are limited to 255 entries/bytes by the 1-byte length prefixes.
func (*TextDomainRecord) Type ¶
func (*TextDomainRecord) Type() uint8
Type returns the record type tag.
type TxIn ¶
TxIn defines a Handshake transaction input. Unlike Bitcoin, Handshake inputs do not have a SignatureScript field; all witness data lives in the Witness field which is serialized after the locktime.
func NewTxIn ¶
NewTxIn returns a new Handshake transaction input with the provided previous outpoint and sequence number. If witness is non-nil, it is set on the input.
func (*TxIn) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the transaction input (without witness, which is serialized separately).
type TxLoc ¶
TxLoc holds locator data for the offset and length of where a transaction is located within a MsgBlock data buffer.
type TxOut ¶
TxOut defines a Handshake transaction output. Unlike Bitcoin, outputs have an Address and Covenant instead of a PkScript.
func NewTxOut ¶
NewTxOut returns a new Handshake transaction output with the provided transaction value, address, and covenant.
func (*TxOut) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the transaction output.
type TxWitness ¶
type TxWitness [][]byte
TxWitness defines the witness for a TxIn. A witness is to be interpreted as a slice of byte slices, or a stack with one or many elements.
func (TxWitness) Encode ¶
Encode serializes the witness to w.
Wire format: varint(itemCount) + for each item: varint(itemLen) + itemBytes
func (TxWitness) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the transaction input's witness.
func (TxWitness) ToHexStrings ¶
ToHexStrings formats the witness stack as a slice of hex-encoded strings.
type UnsupportedHnsMsgTypeError ¶
type UnsupportedHnsMsgTypeError struct {
MessageType HnsMsgType
}
UnsupportedHnsMsgTypeError is returned when a Handshake message of an unrecognized type is received over the wire.
func (UnsupportedHnsMsgTypeError) Error ¶
func (e UnsupportedHnsMsgTypeError) Error() string
func (UnsupportedHnsMsgTypeError) Is ¶
func (e UnsupportedHnsMsgTypeError) Is(target error) bool
Is identifies unsupported Handshake packet types as unknown messages. This lets peer loops ignore future packet types after consuming their bounded payload, matching hsd's UnknownPacket behavior.
Source Files
¶
- address.go
- blockheader.go
- common.go
- covenant.go
- doc.go
- domain.go
- error.go
- filtertype.go
- hnsmsg.go
- hnsmsg_errors.go
- hnsmsgio.go
- hnsmsgversion.go
- hnsnetaddress.go
- invvect.go
- message.go
- msgaddr.go
- msgblock.go
- msgfeefilter.go
- msgfilteradd.go
- msgfilterclear.go
- msgfilterload.go
- msggetaddr.go
- msggetblocks.go
- msggetdata.go
- msggetheaders.go
- msgheaders.go
- msginv.go
- msgmempool.go
- msgmerkleblock.go
- msgnotfound.go
- msgping.go
- msgpong.go
- msgreject.go
- msgsendheaders.go
- msgtx.go
- msgverack.go
- msgversion.go
- netaddress.go
- netaddressv2.go
- protocol.go