Documentation ¶
Overview ¶
Package wire implements the decred wire protocol.
For the complete details of the decred 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 decred 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.
Decred Message Overview ¶
The decred protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it such as which decred network it is a part of, its type, how big it is, and a checksum to verify validity. All encoding and decoding of message headers is handled by this package.
To accomplish this, there is a generic interface for decred messages named Message which allows messages of any type to be read, written, or passed around through channels, functions, etc. In addition, concrete implementations of most of the currently supported decred messages are provided. For these supported messages, all of the details of marshalling and unmarshalling to and from the wire using decred encoding are handled so the caller doesn't have to concern themselves with the specifics.
Message Interaction ¶
The following provides a quick summary of how the decred 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 decred 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 decred 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.
Decred Network ¶
The decred network is a magic number which is used to identify the start of a message and which decred network the message applies to. This package provides the following constants:
wire.MainNet wire.TestNet (Test network version 3) wire.SimNet (Simulation test network)
Determining Message Type ¶
As discussed in the decred message overview section, this package reads and writes decred 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 decred messages from the wire, use the ReadMessage function. It accepts any io.Reader, but typically this will be a net.Conn to a remote node running a decred peer. Example syntax is:
// Reads and validates the next decred message from conn using the // protocol version pver and the decred 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 decred messages to the wire, use the WriteMessage function. It accepts any io.Writer, but typically this will be a net.Conn to a remote node running a decred peer. Example syntax to request addresses from a remote peer is:
// Create a new getaddr decred message. msg := wire.NewMsgGetAddr() // Writes a decred message msg to conn using the protocol version // pver, and the decred network 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)
Index ¶
- Constants
- Variables
- func DefaultMsgTxVersion() int32
- func IsSupportedMsgTxVersion(msgTx *MsgTx) bool
- func NoWitnessMsgTxVersion() int32
- func RandomUint64() (uint64, error)
- func ReadOutPoint(r io.Reader, pver uint32, version int32, op *OutPoint) error
- func ReadVarString(r io.Reader, pver uint32) (string, error)
- func VarIntSerializeSize(val uint64) int
- func WitnessOnlyMsgTxVersion() int32
- func WitnessSigningMsgTxVersion() int32
- func WitnessValueSigningMsgTxVersion() int32
- func WriteMessage(w io.Writer, msg Message, pver uint32, dcrnet CurrencyNet) error
- func WriteMessageN(w io.Writer, msg Message, pver uint32, dcrnet CurrencyNet) (int, error)
- func WriteOutPoint(w io.Writer, pver uint32, version int32, op *OutPoint) error
- func WriteVarString(w io.Writer, pver uint32, str string) error
- type Alert
- type BlockHeader
- func (h *BlockHeader) BlockSha() chainhash.Hash
- func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32) error
- func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32) error
- func (h *BlockHeader) Bytes() ([]byte, error)
- func (h *BlockHeader) Deserialize(r io.Reader) error
- func (h *BlockHeader) Serialize(w io.Writer) error
- type BloomUpdateType
- type CurrencyNet
- type InvType
- type InvVect
- type Message
- 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) error
- func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgAddr) ClearAddresses()
- func (msg *MsgAddr) Command() string
- func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint32
- type MsgAlert
- type MsgBlock
- func (msg *MsgBlock) AddSTransaction(tx *MsgTx) error
- func (msg *MsgBlock) AddTransaction(tx *MsgTx) error
- func (msg *MsgBlock) BlockSha() chainhash.Hash
- func (msg *MsgBlock) BtcDecode(r io.Reader, pver uint32) error
- func (msg *MsgBlock) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgBlock) Bytes() ([]byte, error)
- func (msg *MsgBlock) ClearSTransactions()
- func (msg *MsgBlock) ClearTransactions()
- func (msg *MsgBlock) Command() string
- func (msg *MsgBlock) Deserialize(r io.Reader) error
- func (msg *MsgBlock) DeserializeTxLoc(r *bytes.Buffer) ([]TxLoc, []TxLoc, error)
- func (msg *MsgBlock) FromBytes(b []byte) error
- func (msg *MsgBlock) MaxPayloadLength(pver uint32) uint32
- func (msg *MsgBlock) STxShas() []chainhash.Hash
- func (msg *MsgBlock) Serialize(w io.Writer) error
- func (msg *MsgBlock) SerializeSize() int
- func (msg *MsgBlock) TxShas() []chainhash.Hash
- 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) error
- func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgGetBlocks) Command() string
- func (msg *MsgGetBlocks) MaxPayloadLength(pver uint32) uint32
- type MsgGetData
- type MsgGetHeaders
- func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *chainhash.Hash) error
- func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32) error
- func (msg *MsgGetHeaders) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgGetHeaders) Command() string
- func (msg *MsgGetHeaders) MaxPayloadLength(pver uint32) uint32
- type MsgGetMiningState
- type MsgHeaders
- type MsgInv
- type MsgMemPool
- type MsgMerkleBlock
- func (msg *MsgMerkleBlock) AddSTxHash(hash *chainhash.Hash) error
- func (msg *MsgMerkleBlock) AddTxHash(hash *chainhash.Hash) error
- func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error
- func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgMerkleBlock) Command() string
- func (msg *MsgMerkleBlock) MaxPayloadLength(pver uint32) uint32
- type MsgMiningState
- func (msg *MsgMiningState) AddBlockHash(hash *chainhash.Hash) error
- func (msg *MsgMiningState) AddVoteHash(hash *chainhash.Hash) error
- func (msg *MsgMiningState) BtcDecode(r io.Reader, pver uint32) error
- func (msg *MsgMiningState) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgMiningState) Command() string
- func (msg *MsgMiningState) MaxPayloadLength(pver uint32) uint32
- type MsgNotFound
- type MsgPing
- type MsgPong
- type MsgReject
- type MsgTx
- func (msg *MsgTx) AddTxIn(ti *TxIn)
- func (msg *MsgTx) AddTxOut(to *TxOut)
- func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error
- func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgTx) Bytes() ([]byte, error)
- func (msg *MsgTx) BytesPrefix() ([]byte, error)
- func (msg *MsgTx) BytesWitness() ([]byte, error)
- func (msg *MsgTx) CachedTxSha() *chainhash.Hash
- func (msg *MsgTx) Command() string
- func (msg *MsgTx) Copy() *MsgTx
- func (msg *MsgTx) Deserialize(r io.Reader) error
- func (msg *MsgTx) FromBytes(b []byte) error
- func (msg *MsgTx) LegacyBtcDecode(r io.Reader, pver uint32) error
- func (msg *MsgTx) LegacyBtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgTx) LegacyDeserialize(r io.Reader) error
- func (msg *MsgTx) LegacyPkScriptLocs() []int
- func (msg *MsgTx) LegacySerialize(w io.Writer) error
- func (msg *MsgTx) LegacySerializeSize() int
- func (msg *MsgTx) MaxPayloadLength(pver uint32) uint32
- func (msg *MsgTx) PkScriptLocs() []int
- func (msg *MsgTx) RecacheTxSha() *chainhash.Hash
- func (msg *MsgTx) Serialize(w io.Writer) error
- func (msg *MsgTx) SerializeSize() int
- func (msg *MsgTx) TxSha() chainhash.Hash
- func (msg *MsgTx) TxShaFull() chainhash.Hash
- func (msg *MsgTx) TxShaLegacy() chainhash.Hash
- func (msg *MsgTx) TxShaWitness() chainhash.Hash
- func (msg *MsgTx) TxShaWitnessSigning() chainhash.Hash
- func (msg *MsgTx) TxShaWitnessValueSigning() 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) error
- func (msg *MsgVersion) BtcEncode(w io.Writer, pver uint32) error
- func (msg *MsgVersion) Command() string
- func (msg *MsgVersion) HasService(service ServiceFlag) bool
- func (msg *MsgVersion) MaxPayloadLength(pver uint32) uint32
- type NetAddress
- type OutPoint
- type RejectCode
- type ServiceFlag
- type TxIn
- type TxLoc
- type TxOut
- type TxSerializeType
Constants ¶
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" CmdAlert = "alert" CmdMemPool = "mempool" CmdMiningState = "miningstate" CmdGetMiningState = "getminings" CmdFilterAdd = "filteradd" CmdFilterClear = "filterclear" CmdFilterLoad = "filterload" CmdMerkleBlock = "merkleblock" CmdReject = "reject" )
Commands used in 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. TxVersion uint16 = 1 // 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 // NoExpiryValue is the value of expiry that indicates the transaction // has no expiry. NoExpiryValue uint32 = 0 // NullValueIn is a null value for an input witness. NullValueIn int64 = -1 // NullBlockHeight is the null value for an input witness. It references // the genesis block. NullBlockHeight uint32 = 0x00000000 // NullBlockIndex is the null transaction index in a block for an input // witness. NullBlockIndex uint32 = 0xffffffff // DefaultPkScriptVersion is the default pkScript version, referring to // extended Decred script. DefaultPkScriptVersion uint16 = 0x0000 )
const ( TxSerializeFull = TxSerializeType(iota) TxSerializeNoWitness TxSerializeOnlyWitness TxSerializeWitnessSigning TxSerializeWitnessValueSigning )
The differente possible values for TxSerializeType.
const ( // InitialProcotolVersion is the initial protocol version for the // network. InitialProcotolVersion uint32 = 1 // ProtocolVersion is the latest protocol version this package supports. ProtocolVersion uint32 = 2 // BIP0111Version is the protocol version which added the SFNodeBloom // service flag. BIP0111Version uint32 = 2 )
const CommandSize = 12
CommandSize is the fixed size of all commands in the common decred message header. Shorter commands must be zero padded.
const DefaultUserAgent = "/dcrwire:0.1.0/"
DefaultUserAgent for wire in the stack
const MaxAddrPerMsg = 1000
MaxAddrPerMsg is the maximum number of addresses that can be in a single bitcoin addr message (MsgAddr).
const MaxBlockHeaderPayload = 16 + (chainhash.HashSize * 2) + 64 + 36
MaxBlockHeaderPayload is the max size of the header which comes from: Version 4 bytes + Bits 4 bytes + PrevBlock and MerkleRoot hashes + 32 StakeRoot bytes + 2 VoteBits bytes + 6 FinalState bytes + 2 Voters bytes + 1 FreshStake byte + 1 Revocations byte + 8 SBits bytes + 4 PoolSize bytes + 4 Height bytes + 4 Size bytes + Timestamp 4 bytes + 4 bytes nonce. --> Total 180 bytes.
const MaxBlockHeadersPerMsg = 2000
MaxBlockHeadersPerMsg is the maximum number of block headers that can be in a single decred headers message.
const MaxBlockLocatorsPerMsg = 500
MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.
const MaxBlockPayload = 1000000 // Not actually 1MB which would be 1024 * 1024
MaxBlockPayload is the maximum bytes a block message can be in bytes.
const MaxBlocksPerMsg = 500
MaxBlocksPerMsg is the maximum number of blocks allowed per message.
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 ( // MaxInvPerMsg is the maximum number of inventory vectors that can be in a // single decred inv message. MaxInvPerMsg = 50000 )
const MaxMSBlocksAtHeadPerMsg = 8
MaxMSBlocksAtHeadPerMsg is the maximum number of block hashes allowed per message.
const MaxMSVotesAtHeadPerMsg = 40 // 8 * 5
MaxMSVotesAtHeadPerMsg is the maximum number of votes at head per message.
const MaxMessagePayload = (1024 * 1024 * 32) // 32MB
MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.
const MaxTxPerTxTree = ((MaxBlockPayload / minTxPayload) / 2) + 1
MaxTxPerTxTree is the maximum number of transactions that could possibly fit into a block per each merkle root.
const MaxUserAgentLen = 2000
MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).
const MaxVarIntPayload = 9
MaxVarIntPayload is the maximum payload size for a variable length integer.
const MessageHeaderSize = 24
MessageHeaderSize is the number of bytes in a decred message header. Decred network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.
Variables ¶
var ErrInvalidNetAddr = errors.New("provided net.Addr is not a net.TCPAddr")
ErrInvalidNetAddr describes an error that indicates the caller didn't specify a TCP address as required.
Functions ¶
func DefaultMsgTxVersion ¶
func DefaultMsgTxVersion() int32
DefaultMsgTxVersion returns the default version int32 (serialize the tx fully, version number 1).
func IsSupportedMsgTxVersion ¶
IsSupportedMsgTxVersion returns if a transaction version is supported or not. Currently, inclusion into the memory pool (and thus blocks) only supports the DefaultMsgTxVersion.
func NoWitnessMsgTxVersion ¶
func NoWitnessMsgTxVersion() int32
NoWitnessMsgTxVersion returns the witness free serializing int32 (serialize the tx without witness, version number 1).
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
func ReadOutPoint ¶
ReadOutPoint reads the next sequence of bytes from r as an OutPoint.
func ReadVarString ¶ added in v0.0.6
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 WitnessOnlyMsgTxVersion ¶
func WitnessOnlyMsgTxVersion() int32
WitnessOnlyMsgTxVersion returns the witness only version int32 (serialize the tx witness, version number 1).
func WitnessSigningMsgTxVersion ¶
func WitnessSigningMsgTxVersion() int32
WitnessSigningMsgTxVersion returns the witness only version int32 (serialize the tx witness for signing, version number 1).
func WitnessValueSigningMsgTxVersion ¶
func WitnessValueSigningMsgTxVersion() int32
WitnessValueSigningMsgTxVersion returns the witness only version int32 (serialize the tx witness for signing with value, version number 1).
func WriteMessage ¶
WriteMessage writes a decred 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 decred 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 WriteOutPoint ¶
WriteOutPoint encodes op to the decred protocol encoding for an OutPoint to w.
Types ¶
type Alert ¶
type Alert struct { // Alert format version Version int32 // Timestamp beyond which nodes should stop relaying this alert RelayUntil int64 // Timestamp beyond which this alert is no longer in effect and // should be ignored Expiration int64 // A unique ID number for this alert ID int32 // All alerts with an ID less than or equal to this number should // cancelled, deleted and not accepted in the future Cancel int32 // All alert IDs contained in this set should be cancelled as above SetCancel []int32 // This alert only applies to versions greater than or equal to this // version. Other versions should still relay it. MinVer int32 // This alert only applies to versions less than or equal to this version. // Other versions should still relay it. MaxVer int32 // If this set contains any elements, then only nodes that have their // subVer contained in this set are affected by the alert. Other versions // should still relay it. SetSubVer []string // Relative priority compared to other alerts Priority int32 // A comment on the alert that is not displayed Comment string // The alert message that is displayed to the user StatusBar string // Reserved Reserved string }
Alert contains the data deserialized from the MsgAlert payload.
func NewAlert ¶
func NewAlert(version int32, relayUntil int64, expiration int64, id int32, cancel int32, setCancel []int32, minVer int32, maxVer int32, setSubVer []string, priority int32, comment string, statusBar string) *Alert
NewAlert returns an new Alert with values provided.
func NewAlertFromPayload ¶
NewAlertFromPayload returns an Alert with values deserialized from the serialized payload.
func (*Alert) Deserialize ¶
Deserialize decodes from r into the receiver using the alert protocol encoding format.
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 in the block chain. PrevBlock chainhash.Hash // Merkle tree reference to hash of all transactions for the block. MerkleRoot chainhash.Hash // Merkle tree reference to hash of all stake transactions for the block. StakeRoot chainhash.Hash // Votes on the previous merkleroot and yet undecided parameters. (TODO) VoteBits uint16 // Final state of the PRNG used for ticket selection in the lottery. FinalState [6]byte // Number of participating voters for this block. Voters uint16 // Number of new sstx in this block. FreshStake uint8 // Number of ssrtx present in this block. Revocations uint8 // Size of the ticket pool. PoolSize uint32 // Difficulty target for the block. Bits uint32 // Stake difficulty target. SBits int64 // Height is the block height in the block chain. Height uint32 // Size is the size of the serialized block in its entirety. Size uint32 // Time the block was created. This is, unfortunately, encoded as a // uint32 on the wire and therefore is limited to 2106. Timestamp time.Time // Nonce is technically a part of ExtraData, but we use it as the // classical 4-byte nonce here. Nonce uint32 // ExtraData is used to encode the nonce or any other extra data // that might be used later on in consensus. ExtraData [36]byte }
BlockHeader defines information about a block and is used in the decred block (MsgBlock) and headers (MsgHeaders) messages.
func NewBlockHeader ¶
func NewBlockHeader(version int32, prevHash *chainhash.Hash, merkleRootHash *chainhash.Hash, stakeRoot *chainhash.Hash, voteBits uint16, finalState [6]byte, voters uint16, freshStake uint8, revocations uint8, poolsize uint32, bits uint32, sbits int64, height uint32, size uint32, nonce uint32, extraData [36]byte) *BlockHeader
NewBlockHeader returns a new BlockHeader using the provided previous block hash, merkle root hash, difficulty bits, and nonce used to generate the block with defaults for the remaining fields.
func (*BlockHeader) BlockSha ¶
func (h *BlockHeader) BlockSha() chainhash.Hash
BlockSha computes the block identifier hash for the given block header.
func (*BlockHeader) BtcDecode ¶ added in v0.1.4
func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the bitcoin 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 ¶ added in v0.1.4
func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32) error
BtcEncode encodes the receiver to w using the bitcoin 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) Bytes ¶
func (h *BlockHeader) Bytes() ([]byte, error)
Bytes returns a byte slice containing the serialized contents of the block header.
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 specifies how the filter is updated when a match is found
const ( // BloomUpdateNone indicates the filter is not adjusted when a match is // found. BloomUpdateNone BloomUpdateType = 0 // BloomUpdateAll indicates if the filter matches any data element in a // public key script, the outpoint is serialized and inserted into the // filter. BloomUpdateAll BloomUpdateType = 1 // BloomUpdateP2PubkeyOnly indicates if the filter matches a data // element in a public key script and the script is of the standard // pay-to-pubkey or multisig, the outpoint is serialized and inserted // into the filter. BloomUpdateP2PubkeyOnly BloomUpdateType = 2 )
type CurrencyNet ¶
type CurrencyNet uint32
CurrencyNet represents which decred network a message belongs to.
const ( // MainNet represents the main decred network. MainNet CurrencyNet = 0xd9b400f9 // TestNet represents the regression test network. RegTest CurrencyNet = 0xdab500fa // TestNet represents the test network (version 3). TestNet CurrencyNet = 0x0709000b // SimNet represents the simulation test network. SimNet CurrencyNet = 0x12141c16 )
Constants used to indicate the message decred 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 (CurrencyNet) String ¶
func (n CurrencyNet) String() string
String returns the CurrencyNet in human-readable form.
type InvType ¶
type InvType uint32
InvType represents the allowed types of inventory vectors. See InvVect.
type InvVect ¶
InvVect defines a decred inventory vector which is used to describe data, as specified by the Type field, that a peer wants, has, or does not have to another peer.
type Message ¶
type Message interface { BtcDecode(io.Reader, uint32) error BtcEncode(io.Writer, uint32) error Command() string MaxPayloadLength(uint32) uint32 }
Message is an interface that describes a decred 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 decred Message from r for the provided protocol version and decred 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 decred Message from r for the provided protocol version and decred 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.
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 decred 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 MsgAlert ¶
type MsgAlert struct { // SerializedPayload is the alert payload serialized as a string so that the // version can change but the Alert can still be passed on by older // clients. SerializedPayload []byte // Signature is the ECDSA signature of the message. Signature []byte // Deserialized Payload Payload *Alert }
MsgAlert implements the Message interface and defines a decred alert message.
This is a signed message that provides notifications that the client should display if the signature matches the key. bitcoind/bitcoin-qt only checks against a signature from the core developers.
func NewMsgAlert ¶
NewMsgAlert returns a new decred alert message that conforms to the Message interface. See MsgAlert for details.
func (*MsgAlert) BtcDecode ¶
BtcDecode decodes r using the decred protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgAlert) BtcEncode ¶
BtcEncode encodes the receiver to w using the decred protocol encoding. This is part of the Message interface implementation.
func (*MsgAlert) Command ¶
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgAlert) 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 STransactions []*MsgTx }
MsgBlock implements the Message interface and represents a decred 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 decred block message that conforms to the Message interface. See MsgBlock for details.
func (*MsgBlock) AddSTransaction ¶
AddSTransaction adds a stake transaction to the message.
func (*MsgBlock) AddTransaction ¶
AddTransaction adds a transaction to the message.
func (*MsgBlock) BtcDecode ¶
BtcDecode decodes r using the decred 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 decred 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) ClearSTransactions ¶
func (msg *MsgBlock) ClearSTransactions()
ClearSTransactions removes all stake transactions from the message.
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 decred 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) 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) STxShas ¶
STxShas returns a slice of hashes of all of stake transactions in this block.
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 decred 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) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the the block.
type MsgFilterAdd ¶
type MsgFilterAdd struct {
Data []byte
}
MsgFilterAdd implements the Message interface and represents a decred 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 decred filteradd message that conforms to the Message interface. See MsgFilterAdd for details.
func (*MsgFilterAdd) BtcDecode ¶
func (msg *MsgFilterAdd) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred filterclear message that conforms to the Message interface. See MsgFilterClear for details.
func (*MsgFilterClear) BtcDecode ¶
func (msg *MsgFilterClear) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred filterload message that conforms to the Message interface. See MsgFilterLoad for details.
func (*MsgFilterLoad) BtcDecode ¶
func (msg *MsgFilterLoad) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred getaddr message that conforms to the Message interface. See MsgGetAddr for details.
func (*MsgGetAddr) BtcDecode ¶
func (msg *MsgGetAddr) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred 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) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred getdata message that conforms to the Message interface. See MsgGetData for details.
func NewMsgGetDataSizeHint ¶
func NewMsgGetDataSizeHint(sizeHint uint) *MsgGetData
NewMsgGetDataSizeHint returns a new decred 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) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 resonable 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 decred 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) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 MsgGetMiningState ¶
type MsgGetMiningState struct{}
MsgGetMiningState implements the Message interface and represents a getminingstate message. It is used to request the current mining state from a peer.
func NewMsgGetMiningState ¶
func NewMsgGetMiningState() *MsgGetMiningState
NewMsgGetMiningState returns a new decred pong message that conforms to the Message interface. See MsgPong for details.
func (*MsgGetMiningState) BtcDecode ¶
func (msg *MsgGetMiningState) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the decred protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgGetMiningState) BtcEncode ¶
func (msg *MsgGetMiningState) BtcEncode(w io.Writer, pver uint32) error
BtcEncode encodes the receiver to w using the decred protocol encoding. This is part of the Message interface implementation.
func (*MsgGetMiningState) Command ¶
func (msg *MsgGetMiningState) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgGetMiningState) MaxPayloadLength ¶
func (msg *MsgGetMiningState) 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 decred 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 decred 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) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred inv message that conforms to the Message interface. See MsgInv for details.
func NewMsgInvSizeHint ¶
NewMsgInvSizeHint returns a new decred 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 decred protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgInv) BtcEncode ¶
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred pong message that conforms to the Message interface. See MsgPong for details.
func (*MsgMemPool) BtcDecode ¶
func (msg *MsgMemPool) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 STransactions uint32 SHashes []*chainhash.Hash Flags []byte }
MsgMerkleBlock implements the Message interface and represents a decred 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 decred merkleblock message that conforms to the Message interface. See MsgMerkleBlock for details.
func (*MsgMerkleBlock) AddSTxHash ¶
func (msg *MsgMerkleBlock) AddSTxHash(hash *chainhash.Hash) error
AddSTxHash adds a new stake transaction hash to the message.
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) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 MsgMiningState ¶
type MsgMiningState struct { Version uint32 Height uint32 BlockHashes []*chainhash.Hash VoteHashes []*chainhash.Hash }
MsgMiningState implements the Message interface and represents a mining state message. It is used to request a list of blocks located at the chain tip along with all votes for those blocks. The list is returned is limited by the maximum number of blocks per message and the maximum number of votes per message.
func NewMsgMiningState ¶
func NewMsgMiningState() *MsgMiningState
NewMsgMiningState returns a new decred miningstate message that conforms to the Message interface using the defaults for the fields.
func (*MsgMiningState) AddBlockHash ¶
func (msg *MsgMiningState) AddBlockHash(hash *chainhash.Hash) error
AddBlockHash adds a new block hash to the message.
func (*MsgMiningState) AddVoteHash ¶
func (msg *MsgMiningState) AddVoteHash(hash *chainhash.Hash) error
AddVoteHash adds a new vote hash to the message.
func (*MsgMiningState) BtcDecode ¶
func (msg *MsgMiningState) BtcDecode(r io.Reader, pver uint32) error
BtcDecode decodes r using the protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgMiningState) BtcEncode ¶
func (msg *MsgMiningState) BtcEncode(w io.Writer, pver uint32) error
BtcEncode encodes the receiver to w using the protocol encoding. This is part of the Message interface implementation.
func (*MsgMiningState) Command ¶
func (msg *MsgMiningState) Command() string
Command returns the protocol command string for the message. This is part of the Message interface implementation.
func (*MsgMiningState) MaxPayloadLength ¶
func (msg *MsgMiningState) 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 decred 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 decred 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) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred ping message that conforms to the Message interface. See MsgPing for details.
func (*MsgPing) BtcDecode ¶
BtcDecode decodes r using the decred protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgPing) BtcEncode ¶
BtcEncode encodes the receiver to w using the decred 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 decred pong message which is used primarily to confirm that a connection is still valid in response to a decred ping message (MsgPing).
This message was not added until protocol versions AFTER BIP0031Version.
func NewMsgPong ¶
NewMsgPong returns a new decred pong message that conforms to the Message interface. See MsgPong for details.
func (*MsgPong) BtcDecode ¶
BtcDecode decodes r using the decred protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgPong) BtcEncode ¶
BtcEncode encodes the receiver to w using the decred 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 decred 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 decred reject message that conforms to the Message interface. See MsgReject for details.
func (*MsgReject) BtcDecode ¶
BtcDecode decodes r using the decred protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgReject) BtcEncode ¶
BtcEncode encodes the receiver to w using the decred 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 MsgTx ¶
type MsgTx struct { CachedHash *chainhash.Hash Version int32 TxIn []*TxIn TxOut []*TxOut LockTime uint32 Expiry uint32 }
MsgTx implements the Message interface and represents a decred 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 ¶
func NewMsgTx() *MsgTx
NewMsgTx returns a new decred 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 decred 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 Decred 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) BytesPrefix ¶
BytesPrefix returns the serialized form of the transaction prefix in bytes.
func (*MsgTx) BytesWitness ¶
BytesWitness returns the serialized form of the transaction prefix in bytes.
func (*MsgTx) CachedTxSha ¶
CachedTxSha generates the Hash name for the transaction prefix and stores it if it does not exist. The cached hash is then returned. It can be recalculated later with RecacheTxSha.
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. This function differs from BtcDecode in that BtcDecode decodes from the Decred 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 transaction at all. As of the time this comment was written, the encoded transaction 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 (*MsgTx) LegacyBtcDecode ¶
LegacyBtcDecode decodes r using the decred protocol encoding into the receiver. This is used for the decoding of legacy serialized transactions.
func (*MsgTx) LegacyBtcEncode ¶
LegacyBtcEncode encodes the receiver to w using the Decred protocol encoding. This is for transactions encoded in the legacy encoding, for compatibility.
func (*MsgTx) LegacyDeserialize ¶
LegacyDeserialize decodes a transaction that has been encoded in the legacy Decred format.
func (*MsgTx) LegacyPkScriptLocs ¶
LegacyPkScriptLocs returns a slice containing the start of each public key script within the raw serialized transaction. The caller can easily obtain the length of each script by using len on the script available via the appropriate transaction output entry. This is for legacy decred format.
func (*MsgTx) LegacySerialize ¶
LegacySerialize encodes the transaction in decred legacy format, for compatibility.
func (*MsgTx) LegacySerializeSize ¶
LegacySerializeSize returns the number of bytes it would take to serialize the transaction.
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) PkScriptLocs ¶
PkScriptLocs returns a slice containing the start of each public key script within the raw serialized transaction. The caller can easily obtain the length of each script by using len on the script available via the appropriate transaction output entry. TODO: Make this work for all serialization types, not just the full serialization type.
func (*MsgTx) RecacheTxSha ¶
RecacheTxSha generates the Hash name for the transaction prefix and stores it. The cached hash is then returned.
func (*MsgTx) Serialize ¶
Serialize encodes the transaction to w using a format that suitable for long-term storage such as a database while respecting the Version field in the transaction. This function differs from BtcEncode in that BtcEncode encodes the transaction to the decred 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 transaction at all. As of the time this comment was written, the encoded transaction 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 (*MsgTx) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the the transaction.
func (*MsgTx) TxShaFull ¶
TxShaFull generates the Hash name for the transaction prefix || witness. It first obtains the hashes for both the transaction prefix and witness, then concatenates them and hashes these 64 bytes. Note that the inputs to the hashes, serialized prefix and serialized witnesses, have different uint32 versions because version is now actually two uint16s, with the last 16 bits referring to the serialization type. The first 16 bits refer to the actual version, and these must be the same in both serializations.
func (*MsgTx) TxShaLegacy ¶
TxShaLegacy generates the legacy transaction hash, for software compatibility.
func (*MsgTx) TxShaWitness ¶
TxShaWitness generates the Hash name for the transaction witness.
func (*MsgTx) TxShaWitnessSigning ¶
TxShaWitnessSigning generates the Hash name for the transaction witness with the malleable portions (AmountIn, BlockHeight, BlockIndex) removed. These are verified and set by the miner instead.
func (*MsgTx) TxShaWitnessValueSigning ¶
TxShaWitnessValueSigning generates the Hash name for the transaction witness with BlockHeight and BlockIndex removed, allowing the signer to specify the ValueIn.
type MsgVerAck ¶
type MsgVerAck struct{}
MsgVerAck defines a decred verack message which is used for a peer to acknowledge a version message (MsgVersion) after it has used the information to negotiate parameters. It implements the Message interface.
This message has no payload.
func NewMsgVerAck ¶
func NewMsgVerAck() *MsgVerAck
NewMsgVerAck returns a new decred verack message that conforms to the Message interface.
func (*MsgVerAck) BtcDecode ¶
BtcDecode decodes r using the decred protocol encoding into the receiver. This is part of the Message interface implementation.
func (*MsgVerAck) BtcEncode ¶
BtcEncode encodes the receiver to w using the decred 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 messsage. 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 decred 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 decred version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.
func NewMsgVersionFromConn ¶
NewMsgVersionFromConn is a convenience function that extracts the remote and local address from conn and returns a new decred version message that conforms to the Message interface. See NewMsgVersion.
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) error
BtcDecode decodes r using the decred 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) error
BtcEncode encodes the receiver to w using the decred 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 decred 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.Addr, services ServiceFlag) (*NetAddress, error)
NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.
Note that addr must be a net.TCPAddr. An ErrInvalidNetAddr is returned if it is not.
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 (*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.
func (*NetAddress) SetAddress ¶
func (na *NetAddress) SetAddress(ip net.IP, port uint16)
SetAddress is a convenience function to set the IP address and port in one call.
type OutPoint ¶
OutPoint defines a decred data type that is used to track previous transaction outputs.
func NewOutPoint ¶
NewOutPoint returns a new decred transaction outpoint point with the provided hash and 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 decred peer.
const ( // SFNodeNetwork is a flag used to indicate a peer is a full node. SFNodeNetwork ServiceFlag = 1 << iota // SFNodeBloom is a flag used to indiciate a peer supports bloom // filtering. SFNodeBloom )
func (ServiceFlag) String ¶
func (f ServiceFlag) String() string
String returns the ServiceFlag in human-readable form.
type TxIn ¶
type TxIn struct { // Non-witness PreviousOutPoint OutPoint Sequence uint32 // Witness ValueIn int64 BlockHeight uint32 BlockIndex uint32 SignatureScript []byte }
TxIn defines a decred transaction input.
func NewTxIn ¶
NewTxIn returns a new decred transaction input with the provided previous outpoint point and signature script with a default sequence of MaxTxInSequenceNum.
func (*TxIn) LegacySerializeSize ¶
LegacySerializeSize returns the number of bytes it would take to serialize the the transaction input.
func (*TxIn) SerializeSizePrefix ¶
SerializeSizePrefix returns the number of bytes it would take to serialize the transaction input for a prefix.
func (*TxIn) SerializeSizeWitness ¶
SerializeSizeWitness returns the number of bytes it would take to serialize the transaction input for a witness.
func (*TxIn) SerializeSizeWitnessSigning ¶
SerializeSizeWitnessSigning returns the number of bytes it would take to serialize the transaction input for a witness used in signing.
func (*TxIn) SerializeSizeWitnessValueSigning ¶
SerializeSizeWitnessValueSigning returns the number of bytes it would take to serialize the transaction input for a witness used in signing with value included.
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 decred transaction output.
func NewTxOut ¶
NewTxOut returns a new decred transaction output with the provided transaction value and public key script.
func (*TxOut) SerializeSize ¶
SerializeSize returns the number of bytes it would take to serialize the the transaction output.
type TxSerializeType ¶
type TxSerializeType uint16
TxSerializeType is a uint16 representing the serialized type of transaction this msgTx is. You can use a bitmask for this too, but Decred just splits the int32 version into 2x uint16s so that you have:
{ uint16 type uint16 version }
Source Files ¶
- blockheader.go
- common.go
- doc.go
- error.go
- invvect.go
- message.go
- msgaddr.go
- msgalert.go
- msgblock.go
- msgfilteradd.go
- msgfilterclear.go
- msgfilterload.go
- msggetaddr.go
- msggetblocks.go
- msggetdata.go
- msggetheaders.go
- msggetminingstate.go
- msgheaders.go
- msginv.go
- msgmempool.go
- msgmerkleblock.go
- msgminingstate.go
- msgnotfound.go
- msgping.go
- msgpong.go
- msgreject.go
- msgtx.go
- msgverack.go
- msgversion.go
- netaddress.go
- protocol.go