appmessage

package
v0.6.4-rc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2020 License: ISC Imports: 16 Imported by: 16

README

wire

ISC License GoDoc

Package wire implements the kaspa wire protocol.

Kaspa Message Overview

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

Reading Messages Example

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

	// Use the most recent protocol version supported by the package and the
	// main kaspa network.
	pver := wire.ProtocolVersion
	kaspanet := wire.Mainnet

	// Reads and validates the next kaspa message from conn using the
	// protocol version pver and the kaspa network kaspanet. The returns
	// are a appmessage.Message, a []byte which contains the unmarshalled
	// raw payload, and a possible error.
	msg, rawPayload, err := wire.ReadMessage(conn, pver, kaspanet)
	if err != nil {
		// Log and handle the error
	}

See the package documentation for details on determining the message type.

Writing Messages Example

In order to marshal kaspa 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 kaspa peer. Example syntax to request addresses from a remote peer is:

	// Use the most recent protocol version supported by the package and the
	// main bitcoin network.
	pver := wire.ProtocolVersion
	kaspanet := wire.Mainnet

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

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

Documentation

Overview

Package appmessage implements the kaspa appmessage protocol.

At a high level, this package provides support for marshalling and unmarshalling supported kaspa messages to and from the appmessage. 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.

Kaspa Message Overview

The kaspa protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it such as which kaspa 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 kaspa 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 kaspa messages are provided. For these supported messages, all of the details of marshalling and unmarshalling to and from the appmessage using kaspa 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 kaspa messages are intended to interact with one another. As stated above, these interactions are not directly handled by this package.

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 (MsgRequestAddresses)       addr message (MsgAddresses)
getblockinvs message (MsgGetBlockInvs)  inv message (MsgInv)
inv message (MsgInv)                    getdata message (MsgGetData)
getdata message (MsgGetData)            block message (MsgBlock) -or-
                                        tx message (MsgTx) -or-
                                        notfound message (MsgNotFound)
ping message (MsgPing)                  pong message (MsgPong)

Common Parameters

There are several common parameters that arise when using this package to read and write kaspa 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 appmessage.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.

Kaspa Network

The kaspa network is a magic number which is used to identify the start of a message and which kaspa network the message applies to. This package provides the following constants:

appmessage.Mainnet
appmessage.Testnet (Test network)
appmessage.Regtest (Regression test network)
appmessage.Simnet  (Simulation test network)
appmessage.Devnet  (Development network)

Determining Message Type

As discussed in the kaspa message overview section, this package reads and writes kaspa 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 *appmessage.MsgVersion:
	// The message is a pointer to a MsgVersion struct.
	fmt.Printf("Protocol version: %d", msg.ProtocolVersion)
case *appmessage.MsgBlock:
	// The message is a pointer to a MsgBlock struct.
	fmt.Printf("Number of tx in block: %d", msg.Header.TxnCount)
}

Reading Messages

In order to unmarshall kaspa messages from the appmessage, use the ReadMessage function. It accepts any io.Reader, but typically this will be a net.Conn to a remote node running a kaspa peer. Example syntax is:

// Reads and validates the next kaspa message from conn using the
// protocol version pver and the kaspa network kaspaNet. The returns
// are a appmessage.Message, a []byte which contains the unmarshalled
// raw payload, and a possible error.
msg, rawPayload, err := appmessage.ReadMessage(conn, pver, kaspaNet)
if err != nil {
	// Log and handle the error
}

Writing Messages

In order to marshall kaspa messages to the appmessage, use the WriteMessage function. It accepts any io.Writer, but typically this will be a net.Conn to a remote node running a kaspa peer. Example syntax to request addresses from a remote peer is:

// Create a new getaddr kaspa message.
msg := appmessage.NewMsgRequestAddresses()

// Writes a kaspa message msg to conn using the protocol version
// pver, and the kaspa network kaspaNet. The return is a possible
// error.
err := appmessage.WriteMessage(conn, msg, pver, kaspaNet)
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 appmessage.MessageError. This allows the caller to differentiate between general IO errors and malformed messages through type assertions.

Index

Constants

View Source
const (
	// TxVersion is the current latest supported transaction version.
	TxVersion = 1

	// MaxTxInSequenceNum is the maximum sequence number the sequence field
	// of a transaction input can be.
	MaxTxInSequenceNum uint64 = math.MaxUint64

	// 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 milliseconds-based relative time locks. When converting from milliseconds
	// to a sequence number, the value is right shifted by this amount,
	// therefore the granularity of relative time locks in 524288 or 2^19
	// seconds. Enforced relative lock times are multiples of 524288 milliseconds.
	SequenceLockTimeGranularity = 19

	// MinTxOutPayload is the minimum payload size for a transaction output.
	// Value 8 bytes + Varint for ScriptPubKey length 1 byte.
	MinTxOutPayload = 9
)
View Source
const BaseBlockHeaderPayload = 25 + 3*(daghash.HashSize)

BaseBlockHeaderPayload is the base number of bytes a block header can be, not including the list of parent block headers. Version 4 bytes + Timestamp 8 bytes + Bits 4 bytes + Nonce 8 bytes + + NumParentBlocks 1 byte + HashMerkleRoot hash + + AcceptedIDMerkleRoot hash + UTXOCommitment hash. To get total size of block header len(ParentHashes) * daghash.HashSize should be added to this value

View Source
const MaxAddressesPerMsg = 1000

MaxAddressesPerMsg is the maximum number of addresses that can be in a single kaspa Addresses message (MsgAddresses).

MaxBlockHeaderPayload is the maximum number of bytes a block header can be. BaseBlockHeaderPayload + up to MaxNumParentBlocks hashes of parent blocks

View Source
const MaxBlockLocatorsPerMsg = 500

MaxBlockLocatorsPerMsg is the maximum number of block locator hashes allowed per message.

View Source
const MaxInvPerMsg = 1 << 17

MaxInvPerMsg is the maximum number of inventory vectors that can be in any type of kaspa inv message.

View Source
const MaxInvPerRequestTransactionsMsg = MaxInvPerMsg

MaxInvPerRequestTransactionsMsg is the maximum number of hashes that can be in a single CmdInvTransaction message.

View Source
const MaxInvPerTxInvMsg = MaxInvPerMsg

MaxInvPerTxInvMsg is the maximum number of hashes that can be in a single CmdInvTransaction message.

View Source
const MaxMassPerBlock = 10000000

MaxMassPerBlock is the maximum total transaction mass a block may have.

View Source
const MaxMassPerTx = MaxMassPerBlock / 2

MaxMassPerTx is the maximum total mass a transaction may have.

View Source
const MaxMessagePayload = (1024 * 1024 * 32) // 32MB

MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.

View Source
const MaxNumParentBlocks = 255

MaxNumParentBlocks is the maximum number of parent blocks a block can reference. Currently set to 255 as the maximum number NumParentBlocks can be due to it being a byte

View Source
const MaxTxPerBlock = (MaxMassPerBlock / minTxPayload) + 1

MaxTxPerBlock is the maximum number of transactions that could possibly fit into a block.

View Source
const MaxUserAgentLen = 256

MaxUserAgentLen is the maximum allowed length for the user agent field in a version message (MsgVersion).

View Source
const MaxVarIntPayload = 9

MaxVarIntPayload is the maximum payload size for a variable length integer.

View Source
const MsgRequestRelayBlocksHashes = MaxInvPerMsg

MsgRequestRelayBlocksHashes is the maximum number of hashes that can be in a single RequestRelayBlocks message.

View Source
const (
	// ProtocolVersion is the latest protocol version this package supports.
	ProtocolVersion uint32 = 1
)

XXX pedro: we will probably need to bump this.

Variables

View Source
var DefaultUserAgent = fmt.Sprintf("/kaspad:%s/", version.Version())

DefaultUserAgent for appmessage in the stack

View Source
var MessageCommandToString = map[MessageCommand]string{
	CmdVersion:              "Version",
	CmdVerAck:               "VerAck",
	CmdRequestAddresses:     "RequestAddresses",
	CmdAddresses:            "Addresses",
	CmdRequestIBDBlocks:     "RequestBlocks",
	CmdBlock:                "Block",
	CmdTx:                   "Tx",
	CmdPing:                 "Ping",
	CmdPong:                 "Pong",
	CmdRequestBlockLocator:  "RequestBlockLocator",
	CmdBlockLocator:         "BlockLocator",
	CmdSelectedTip:          "SelectedTip",
	CmdRequestSelectedTip:   "RequestSelectedTip",
	CmdInvRelayBlock:        "InvRelayBlock",
	CmdRequestRelayBlocks:   "RequestRelayBlocks",
	CmdInvTransaction:       "InvTransaction",
	CmdRequestTransactions:  "RequestTransactions",
	CmdIBDBlock:             "IBDBlock",
	CmdRequestNextIBDBlocks: "RequestNextIBDBlocks",
	CmdDoneIBDBlocks:        "DoneIBDBlocks",
	CmdTransactionNotFound:  "TransactionNotFound",
	CmdReject:               "Reject",
}

MessageCommandToString maps all MessageCommands to their string representation

Functions

func ReadElement

func ReadElement(r io.Reader, element interface{}) error

ReadElement reads the next sequence of bytes from r using little endian depending on the concrete type of element pointed to.

func ReadVarBytes

func ReadVarBytes(r io.Reader, pver uint32, maxAllowed uint32,
	fieldName string) ([]byte, error)

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 ReadVarInt

func ReadVarInt(r io.Reader) (uint64, error)

ReadVarInt reads a variable length integer from r and returns it as a uint64.

func ReadVarString

func ReadVarString(r io.Reader, pver uint32) (string, error)

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 ValidateUserAgent

func ValidateUserAgent(userAgent string) error

ValidateUserAgent checks userAgent length against MaxUserAgentLen

func VarIntSerializeSize

func VarIntSerializeSize(val uint64) int

VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.

func WriteElement

func WriteElement(w io.Writer, element interface{}) error

WriteElement writes the little endian representation of element to w.

func WriteTxOut

func WriteTxOut(w io.Writer, pver uint32, version int32, to *TxOut) error

WriteTxOut encodes to into the kaspa protocol encoding for a transaction output (TxOut) to w.

func WriteVarBytes

func WriteVarBytes(w io.Writer, pver uint32, bytes []byte) error

WriteVarBytes serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves.

func WriteVarInt

func WriteVarInt(w io.Writer, val uint64) error

WriteVarInt serializes val to w using a variable number of bytes depending on its value.

func WriteVarString

func WriteVarString(w io.Writer, str string) error

WriteVarString serializes str to w as a variable length integer containing the length of the string followed by the bytes that represent the string itself.

Types

type BlockHeader

type BlockHeader struct {
	// Version of the block. This is not the same as the protocol version.
	Version int32

	// Hashes of the parent block headers in the blockDAG.
	ParentHashes []*daghash.Hash

	// HashMerkleRoot is the merkle tree reference to hash of all transactions for the block.
	HashMerkleRoot *daghash.Hash

	// AcceptedIDMerkleRoot is merkle tree reference to hash all transactions
	// accepted form the block.Blues
	AcceptedIDMerkleRoot *daghash.Hash

	// UTXOCommitment is an ECMH UTXO commitment to the block UTXO.
	UTXOCommitment *daghash.Hash

	// Time the block was created.
	Timestamp mstime.Time

	// Difficulty target for the block.
	Bits uint32

	// Nonce used to generate the block.
	Nonce uint64
}

BlockHeader defines information about a block and is used in the kaspa block (MsgBlock) and headers (MsgHeader) messages.

func NewBlockHeader

func NewBlockHeader(version int32, parentHashes []*daghash.Hash, hashMerkleRoot *daghash.Hash,
	acceptedIDMerkleRoot *daghash.Hash, utxoCommitment *daghash.Hash, bits uint32, nonce uint64) *BlockHeader

NewBlockHeader returns a new BlockHeader using the provided version, previous block hash, hash merkle root, accepted ID merkle root, difficulty bits, and nonce used to generate the block with defaults or calclulated values for the remaining fields.

func (*BlockHeader) BlockHash

func (h *BlockHeader) BlockHash() *daghash.Hash

BlockHash computes the block identifier hash for the given 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.

func (*BlockHeader) IsGenesis

func (h *BlockHeader) IsGenesis() bool

IsGenesis returns true iff this block is a genesis block

func (*BlockHeader) KaspaDecode

func (h *BlockHeader) KaspaDecode(r io.Reader, pver uint32) error

KaspaDecode decodes r using the kaspa 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 appmessage.

func (*BlockHeader) KaspaEncode

func (h *BlockHeader) KaspaEncode(w io.Writer, pver uint32) error

KaspaEncode encodes the receiver to w using the kaspa 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 appmessage.

func (*BlockHeader) NumParentBlocks

func (h *BlockHeader) NumParentBlocks() byte

NumParentBlocks return the number of entries in ParentHashes

func (*BlockHeader) Serialize

func (h *BlockHeader) Serialize(w io.Writer) error

Serialize encodes 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.

func (*BlockHeader) SerializeSize

func (h *BlockHeader) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the block header.

type KaspaNet

type KaspaNet uint32

KaspaNet represents which kaspa network a message belongs to.

const (
	// Mainnet represents the main kaspa network.
	Mainnet KaspaNet = 0x3ddcf71d

	// Testnet represents the test network.
	Testnet KaspaNet = 0xddb8af8f

	// Regtest represents the regression test network.
	Regtest KaspaNet = 0xf396cdd6

	// Simnet represents the simulation test network.
	Simnet KaspaNet = 0x374dcf1c

	// Devnet represents the development test network.
	Devnet KaspaNet = 0x732d87e1
)

Constants used to indicate the message kaspa 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 (KaspaNet) String

func (n KaspaNet) String() string

String returns the KaspaNet in human-readable form.

type Message

type Message interface {
	Command() MessageCommand
	MessageNumber() uint64
	SetMessageNumber(index uint64)
	ReceivedAt() time.Time
	SetReceivedAt(receivedAt time.Time)
}

Message is an interface that describes a kaspa 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.

type MessageCommand

type MessageCommand uint32

MessageCommand is a number in the header of a message that represents its type.

const (
	CmdVersion MessageCommand = iota
	CmdVerAck
	CmdRequestAddresses
	CmdAddresses
	CmdRequestIBDBlocks
	CmdBlock
	CmdTx
	CmdPing
	CmdPong
	CmdRequestBlockLocator
	CmdBlockLocator
	CmdSelectedTip
	CmdRequestSelectedTip
	CmdInvRelayBlock
	CmdRequestRelayBlocks
	CmdInvTransaction
	CmdRequestTransactions
	CmdIBDBlock
	CmdRequestNextIBDBlocks
	CmdDoneIBDBlocks
	CmdTransactionNotFound
	CmdReject
)

Commands used in kaspa message headers which describe the type of message.

func (MessageCommand) String

func (cmd MessageCommand) String() string

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 kaspa 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 MsgAddresses

type MsgAddresses struct {
	IncludeAllSubnetworks bool
	SubnetworkID          *subnetworkid.SubnetworkID
	AddrList              []*NetAddress
	// contains filtered or unexported fields
}

MsgAddresses implements the Message interface and represents a kaspa Addresses 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 Addresses message to another peer.

func NewMsgAddresses

func NewMsgAddresses(includeAllSubnetworks bool, subnetworkID *subnetworkid.SubnetworkID) *MsgAddresses

NewMsgAddresses returns a new kaspa Addresses message that conforms to the Message interface. See MsgAddresses for details.

func (*MsgAddresses) AddAddress

func (msg *MsgAddresses) AddAddress(na *NetAddress) error

AddAddress adds a known active peer to the message.

func (*MsgAddresses) AddAddresses

func (msg *MsgAddresses) AddAddresses(netAddrs ...*NetAddress) error

AddAddresses adds multiple known active peers to the message.

func (*MsgAddresses) ClearAddresses

func (msg *MsgAddresses) ClearAddresses()

ClearAddresses removes all addresses from the message.

func (*MsgAddresses) Command

func (msg *MsgAddresses) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgAddresses) MessageNumber

func (b *MsgAddresses) MessageNumber() uint64

func (*MsgAddresses) ReceivedAt

func (b *MsgAddresses) ReceivedAt() time.Time

func (*MsgAddresses) SetMessageNumber

func (b *MsgAddresses) SetMessageNumber(messageNumber uint64)

func (*MsgAddresses) SetReceivedAt

func (b *MsgAddresses) SetReceivedAt(receivedAt time.Time)

type MsgBlock

type MsgBlock struct {
	Header       BlockHeader
	Transactions []*MsgTx
	// contains filtered or unexported fields
}

MsgBlock implements the Message interface and represents a kaspa 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 kaspa block message that conforms to the Message interface. See MsgBlock for details.

func (*MsgBlock) AddTransaction

func (msg *MsgBlock) AddTransaction(tx *MsgTx)

AddTransaction adds a transaction to the message.

func (*MsgBlock) BlockHash

func (msg *MsgBlock) BlockHash() *daghash.Hash

BlockHash computes the block identifier hash for this block.

func (*MsgBlock) ClearTransactions

func (msg *MsgBlock) ClearTransactions()

ClearTransactions removes all transactions from the message.

func (*MsgBlock) Command

func (msg *MsgBlock) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgBlock) ConvertToPartial

func (msg *MsgBlock) ConvertToPartial(subnetworkID *subnetworkid.SubnetworkID)

ConvertToPartial clears out all the payloads of the subnetworks that are incompatible with the given subnetwork ID. Note: this operation modifies the block in place.

func (*MsgBlock) Deserialize

func (msg *MsgBlock) Deserialize(r io.Reader) error

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 KaspaDecode in that KaspaDecode decodes from the kaspa appmessage protocol as it was sent across the network. The appmessage 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

func (msg *MsgBlock) DeserializeTxLoc(r *bytes.Buffer) ([]TxLoc, error)

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) KaspaDecode

func (msg *MsgBlock) KaspaDecode(r io.Reader, pver uint32) error

KaspaDecode decodes r using the kaspa 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 appmessage.

func (*MsgBlock) KaspaEncode

func (msg *MsgBlock) KaspaEncode(w io.Writer, pver uint32) error

KaspaEncode encodes the receiver to w using the kaspa 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 appmessage.

func (*MsgBlock) MaxPayloadLength

func (msg *MsgBlock) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

func (*MsgBlock) MessageNumber

func (b *MsgBlock) MessageNumber() uint64

func (*MsgBlock) ReceivedAt

func (b *MsgBlock) ReceivedAt() time.Time

func (*MsgBlock) Serialize

func (msg *MsgBlock) Serialize(w io.Writer) error

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 KaspaEncode in that KaspaEncode encodes the block to the kaspa appmessage protocol in order to be sent across the network. The appmessage 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

func (msg *MsgBlock) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the block.

func (*MsgBlock) SetMessageNumber

func (b *MsgBlock) SetMessageNumber(messageNumber uint64)

func (*MsgBlock) SetReceivedAt

func (b *MsgBlock) SetReceivedAt(receivedAt time.Time)

type MsgBlockLocator

type MsgBlockLocator struct {
	BlockLocatorHashes []*daghash.Hash
	// contains filtered or unexported fields
}

MsgBlockLocator implements the Message interface and represents a kaspa locator message. It is used to find the blockLocator of a peer that is syncing with you.

func NewMsgBlockLocator

func NewMsgBlockLocator(locatorHashes []*daghash.Hash) *MsgBlockLocator

NewMsgBlockLocator returns a new kaspa locator message that conforms to the Message interface. See MsgBlockLocator for details.

func (*MsgBlockLocator) Command

func (msg *MsgBlockLocator) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgBlockLocator) MessageNumber

func (b *MsgBlockLocator) MessageNumber() uint64

func (*MsgBlockLocator) ReceivedAt

func (b *MsgBlockLocator) ReceivedAt() time.Time

func (*MsgBlockLocator) SetMessageNumber

func (b *MsgBlockLocator) SetMessageNumber(messageNumber uint64)

func (*MsgBlockLocator) SetReceivedAt

func (b *MsgBlockLocator) SetReceivedAt(receivedAt time.Time)

type MsgDoneIBDBlocks

type MsgDoneIBDBlocks struct {
	// contains filtered or unexported fields
}

MsgDoneIBDBlocks implements the Message interface and represents a kaspa DoneIBDBlocks message. It is used to notify the IBD syncing peer that the syncer sent all the requested blocks.

This message has no payload.

func NewMsgDoneIBDBlocks

func NewMsgDoneIBDBlocks() *MsgDoneIBDBlocks

NewMsgDoneIBDBlocks returns a new kaspa DoneIBDBlocks message that conforms to the Message interface.

func (*MsgDoneIBDBlocks) Command

func (msg *MsgDoneIBDBlocks) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgDoneIBDBlocks) MessageNumber

func (b *MsgDoneIBDBlocks) MessageNumber() uint64

func (*MsgDoneIBDBlocks) ReceivedAt

func (b *MsgDoneIBDBlocks) ReceivedAt() time.Time

func (*MsgDoneIBDBlocks) SetMessageNumber

func (b *MsgDoneIBDBlocks) SetMessageNumber(messageNumber uint64)

func (*MsgDoneIBDBlocks) SetReceivedAt

func (b *MsgDoneIBDBlocks) SetReceivedAt(receivedAt time.Time)

type MsgIBDBlock

type MsgIBDBlock struct {
	*MsgBlock
	// contains filtered or unexported fields
}

MsgIBDBlock implements the Message interface and represents a kaspa ibdblock message. It is used to deliver block and transaction information in response to a RequestIBDBlocks message (MsgRequestIBDBlocks).

func NewMsgIBDBlock

func NewMsgIBDBlock(msgBlock *MsgBlock) *MsgIBDBlock

NewMsgIBDBlock returns a new kaspa ibdblock message that conforms to the Message interface. See MsgIBDBlock for details.

func (*MsgIBDBlock) Command

func (msg *MsgIBDBlock) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgIBDBlock) MaxPayloadLength

func (msg *MsgIBDBlock) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

func (*MsgIBDBlock) MessageNumber

func (b *MsgIBDBlock) MessageNumber() uint64

func (*MsgIBDBlock) ReceivedAt

func (b *MsgIBDBlock) ReceivedAt() time.Time

func (*MsgIBDBlock) SetMessageNumber

func (b *MsgIBDBlock) SetMessageNumber(messageNumber uint64)

func (*MsgIBDBlock) SetReceivedAt

func (b *MsgIBDBlock) SetReceivedAt(receivedAt time.Time)

type MsgInvRelayBlock

type MsgInvRelayBlock struct {
	Hash *daghash.Hash
	// contains filtered or unexported fields
}

MsgInvRelayBlock implements the Message interface and represents a kaspa block inventory message. It is used to notify the network about new block by sending their hash, and let the receiving node decide if it needs it.

func NewMsgInvBlock

func NewMsgInvBlock(hash *daghash.Hash) *MsgInvRelayBlock

NewMsgInvBlock returns a new kaspa invrelblk message that conforms to the Message interface. See MsgInvRelayBlock for details.

func (*MsgInvRelayBlock) Command

func (msg *MsgInvRelayBlock) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgInvRelayBlock) MessageNumber

func (b *MsgInvRelayBlock) MessageNumber() uint64

func (*MsgInvRelayBlock) ReceivedAt

func (b *MsgInvRelayBlock) ReceivedAt() time.Time

func (*MsgInvRelayBlock) SetMessageNumber

func (b *MsgInvRelayBlock) SetMessageNumber(messageNumber uint64)

func (*MsgInvRelayBlock) SetReceivedAt

func (b *MsgInvRelayBlock) SetReceivedAt(receivedAt time.Time)

type MsgInvTransaction

type MsgInvTransaction struct {
	TxIDs []*daghash.TxID
	// contains filtered or unexported fields
}

MsgInvTransaction implements the Message interface and represents a kaspa TxInv message. It is used to notify the network about new transactions by sending their ID, and let the receiving node decide if it needs it.

func NewMsgInvTransaction

func NewMsgInvTransaction(ids []*daghash.TxID) *MsgInvTransaction

NewMsgInvTransaction returns a new kaspa TxInv message that conforms to the Message interface. See MsgInvTransaction for details.

func (*MsgInvTransaction) Command

func (msg *MsgInvTransaction) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgInvTransaction) MessageNumber

func (b *MsgInvTransaction) MessageNumber() uint64

func (*MsgInvTransaction) ReceivedAt

func (b *MsgInvTransaction) ReceivedAt() time.Time

func (*MsgInvTransaction) SetMessageNumber

func (b *MsgInvTransaction) SetMessageNumber(messageNumber uint64)

func (*MsgInvTransaction) SetReceivedAt

func (b *MsgInvTransaction) SetReceivedAt(receivedAt time.Time)

type MsgPing

type MsgPing struct {

	// Unique value associated with message that is used to identify
	// specific ping message.
	Nonce uint64
	// contains filtered or unexported fields
}

MsgPing implements the Message interface and represents a kaspa 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

func NewMsgPing(nonce uint64) *MsgPing

NewMsgPing returns a new kaspa ping message that conforms to the Message interface. See MsgPing for details.

func (*MsgPing) Command

func (msg *MsgPing) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgPing) MessageNumber

func (b *MsgPing) MessageNumber() uint64

func (*MsgPing) ReceivedAt

func (b *MsgPing) ReceivedAt() time.Time

func (*MsgPing) SetMessageNumber

func (b *MsgPing) SetMessageNumber(messageNumber uint64)

func (*MsgPing) SetReceivedAt

func (b *MsgPing) SetReceivedAt(receivedAt time.Time)

type MsgPong

type MsgPong struct {

	// Unique value associated with message that is used to identify
	// specific ping message.
	Nonce uint64
	// contains filtered or unexported fields
}

MsgPong implements the Message interface and represents a kaspa pong message which is used primarily to confirm that a connection is still valid in response to a kaspa ping message (MsgPing).

This message was not added until protocol versions AFTER BIP0031Version.

func NewMsgPong

func NewMsgPong(nonce uint64) *MsgPong

NewMsgPong returns a new kaspa pong message that conforms to the Message interface. See MsgPong for details.

func (*MsgPong) Command

func (msg *MsgPong) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgPong) MessageNumber

func (b *MsgPong) MessageNumber() uint64

func (*MsgPong) ReceivedAt

func (b *MsgPong) ReceivedAt() time.Time

func (*MsgPong) SetMessageNumber

func (b *MsgPong) SetMessageNumber(messageNumber uint64)

func (*MsgPong) SetReceivedAt

func (b *MsgPong) SetReceivedAt(receivedAt time.Time)

type MsgReject

type MsgReject struct {
	Reason string
	// contains filtered or unexported fields
}

MsgReject implements the Message interface and represents a kaspa Reject message. It is used to notify peers why they are banned.

func NewMsgReject

func NewMsgReject(reason string) *MsgReject

NewMsgReject returns a new kaspa Reject message that conforms to the Message interface.

func (*MsgReject) Command

func (msg *MsgReject) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgReject) MessageNumber

func (b *MsgReject) MessageNumber() uint64

func (*MsgReject) ReceivedAt

func (b *MsgReject) ReceivedAt() time.Time

func (*MsgReject) SetMessageNumber

func (b *MsgReject) SetMessageNumber(messageNumber uint64)

func (*MsgReject) SetReceivedAt

func (b *MsgReject) SetReceivedAt(receivedAt time.Time)

type MsgRequestAddresses

type MsgRequestAddresses struct {
	IncludeAllSubnetworks bool
	SubnetworkID          *subnetworkid.SubnetworkID
	// contains filtered or unexported fields
}

MsgRequestAddresses implements the Message interface and represents a kaspa RequestAddresses 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 (MsgAddresses).

This message has no payload.

func NewMsgRequestAddresses

func NewMsgRequestAddresses(includeAllSubnetworks bool, subnetworkID *subnetworkid.SubnetworkID) *MsgRequestAddresses

NewMsgRequestAddresses returns a new kaspa RequestAddresses message that conforms to the Message interface. See MsgRequestAddresses for details.

func (*MsgRequestAddresses) Command

func (msg *MsgRequestAddresses) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRequestAddresses) MessageNumber

func (b *MsgRequestAddresses) MessageNumber() uint64

func (*MsgRequestAddresses) ReceivedAt

func (b *MsgRequestAddresses) ReceivedAt() time.Time

func (*MsgRequestAddresses) SetMessageNumber

func (b *MsgRequestAddresses) SetMessageNumber(messageNumber uint64)

func (*MsgRequestAddresses) SetReceivedAt

func (b *MsgRequestAddresses) SetReceivedAt(receivedAt time.Time)

type MsgRequestBlockLocator

type MsgRequestBlockLocator struct {
	HighHash *daghash.Hash
	LowHash  *daghash.Hash
	// contains filtered or unexported fields
}

MsgRequestBlockLocator implements the Message interface and represents a kaspa RequestBlockLocator message. It is used to request a block locator between high and low hash. The locator is returned via a locator message (MsgBlockLocator).

func NewMsgRequestBlockLocator

func NewMsgRequestBlockLocator(highHash, lowHash *daghash.Hash) *MsgRequestBlockLocator

NewMsgRequestBlockLocator returns a new RequestBlockLocator message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgRequestBlockLocator) Command

func (msg *MsgRequestBlockLocator) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRequestBlockLocator) MessageNumber

func (b *MsgRequestBlockLocator) MessageNumber() uint64

func (*MsgRequestBlockLocator) ReceivedAt

func (b *MsgRequestBlockLocator) ReceivedAt() time.Time

func (*MsgRequestBlockLocator) SetMessageNumber

func (b *MsgRequestBlockLocator) SetMessageNumber(messageNumber uint64)

func (*MsgRequestBlockLocator) SetReceivedAt

func (b *MsgRequestBlockLocator) SetReceivedAt(receivedAt time.Time)

type MsgRequestIBDBlocks

type MsgRequestIBDBlocks struct {
	LowHash  *daghash.Hash
	HighHash *daghash.Hash
	// contains filtered or unexported fields
}

MsgRequestIBDBlocks implements the Message interface and represents a kaspa RequestIBDBlocks message. It is used to request a list of blocks starting after the low hash and until the high hash.

func NewMsgRequstIBDBlocks

func NewMsgRequstIBDBlocks(lowHash, highHash *daghash.Hash) *MsgRequestIBDBlocks

NewMsgRequstIBDBlocks returns a new kaspa RequestIBDBlocks message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgRequestIBDBlocks) Command

func (msg *MsgRequestIBDBlocks) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRequestIBDBlocks) MessageNumber

func (b *MsgRequestIBDBlocks) MessageNumber() uint64

func (*MsgRequestIBDBlocks) ReceivedAt

func (b *MsgRequestIBDBlocks) ReceivedAt() time.Time

func (*MsgRequestIBDBlocks) SetMessageNumber

func (b *MsgRequestIBDBlocks) SetMessageNumber(messageNumber uint64)

func (*MsgRequestIBDBlocks) SetReceivedAt

func (b *MsgRequestIBDBlocks) SetReceivedAt(receivedAt time.Time)

type MsgRequestNextIBDBlocks

type MsgRequestNextIBDBlocks struct {
	// contains filtered or unexported fields
}

MsgRequestNextIBDBlocks implements the Message interface and represents a kaspa RequestNextIBDBlocks message. It is used to notify the IBD syncer peer to send more blocks.

This message has no payload.

func NewMsgRequestNextIBDBlocks

func NewMsgRequestNextIBDBlocks() *MsgRequestNextIBDBlocks

NewMsgRequestNextIBDBlocks returns a new kaspa RequestNextIBDBlocks message that conforms to the Message interface.

func (*MsgRequestNextIBDBlocks) Command

func (msg *MsgRequestNextIBDBlocks) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRequestNextIBDBlocks) MessageNumber

func (b *MsgRequestNextIBDBlocks) MessageNumber() uint64

func (*MsgRequestNextIBDBlocks) ReceivedAt

func (b *MsgRequestNextIBDBlocks) ReceivedAt() time.Time

func (*MsgRequestNextIBDBlocks) SetMessageNumber

func (b *MsgRequestNextIBDBlocks) SetMessageNumber(messageNumber uint64)

func (*MsgRequestNextIBDBlocks) SetReceivedAt

func (b *MsgRequestNextIBDBlocks) SetReceivedAt(receivedAt time.Time)

type MsgRequestRelayBlocks

type MsgRequestRelayBlocks struct {
	Hashes []*daghash.Hash
	// contains filtered or unexported fields
}

MsgRequestRelayBlocks implements the Message interface and represents a kaspa RequestRelayBlocks message. It is used to request blocks as part of the block relay protocol.

func NewMsgRequestRelayBlocks

func NewMsgRequestRelayBlocks(hashes []*daghash.Hash) *MsgRequestRelayBlocks

NewMsgRequestRelayBlocks returns a new kaspa RequestRelayBlocks message that conforms to the Message interface. See MsgRequestRelayBlocks for details.

func (*MsgRequestRelayBlocks) Command

func (msg *MsgRequestRelayBlocks) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRequestRelayBlocks) MessageNumber

func (b *MsgRequestRelayBlocks) MessageNumber() uint64

func (*MsgRequestRelayBlocks) ReceivedAt

func (b *MsgRequestRelayBlocks) ReceivedAt() time.Time

func (*MsgRequestRelayBlocks) SetMessageNumber

func (b *MsgRequestRelayBlocks) SetMessageNumber(messageNumber uint64)

func (*MsgRequestRelayBlocks) SetReceivedAt

func (b *MsgRequestRelayBlocks) SetReceivedAt(receivedAt time.Time)

type MsgRequestSelectedTip

type MsgRequestSelectedTip struct {
	// contains filtered or unexported fields
}

MsgRequestSelectedTip implements the Message interface and represents a kaspa RequestSelectedTip message. It is used to request the selected tip of another peer.

This message has no payload.

func NewMsgRequestSelectedTip

func NewMsgRequestSelectedTip() *MsgRequestSelectedTip

NewMsgRequestSelectedTip returns a new kaspa RequestSelectedTip message that conforms to the Message interface.

func (*MsgRequestSelectedTip) Command

func (msg *MsgRequestSelectedTip) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRequestSelectedTip) MessageNumber

func (b *MsgRequestSelectedTip) MessageNumber() uint64

func (*MsgRequestSelectedTip) ReceivedAt

func (b *MsgRequestSelectedTip) ReceivedAt() time.Time

func (*MsgRequestSelectedTip) SetMessageNumber

func (b *MsgRequestSelectedTip) SetMessageNumber(messageNumber uint64)

func (*MsgRequestSelectedTip) SetReceivedAt

func (b *MsgRequestSelectedTip) SetReceivedAt(receivedAt time.Time)

type MsgRequestTransactions

type MsgRequestTransactions struct {
	IDs []*daghash.TxID
	// contains filtered or unexported fields
}

MsgRequestTransactions implements the Message interface and represents a kaspa RequestTransactions message. It is used to request transactions as part of the transactions relay protocol.

func NewMsgRequestTransactions

func NewMsgRequestTransactions(ids []*daghash.TxID) *MsgRequestTransactions

NewMsgRequestTransactions returns a new kaspa RequestTransactions message that conforms to the Message interface. See MsgRequestTransactions for details.

func (*MsgRequestTransactions) Command

func (msg *MsgRequestTransactions) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgRequestTransactions) MessageNumber

func (b *MsgRequestTransactions) MessageNumber() uint64

func (*MsgRequestTransactions) ReceivedAt

func (b *MsgRequestTransactions) ReceivedAt() time.Time

func (*MsgRequestTransactions) SetMessageNumber

func (b *MsgRequestTransactions) SetMessageNumber(messageNumber uint64)

func (*MsgRequestTransactions) SetReceivedAt

func (b *MsgRequestTransactions) SetReceivedAt(receivedAt time.Time)

type MsgSelectedTip

type MsgSelectedTip struct {

	// The selected tip hash of the generator of the message.
	SelectedTipHash *daghash.Hash
	// contains filtered or unexported fields
}

MsgSelectedTip implements the Message interface and represents a kaspa selectedtip message. It is used to answer getseltip messages and tell the asking peer what is the selected tip of this peer.

func NewMsgSelectedTip

func NewMsgSelectedTip(selectedTipHash *daghash.Hash) *MsgSelectedTip

NewMsgSelectedTip returns a new kaspa selectedtip message that conforms to the Message interface.

func (*MsgSelectedTip) Command

func (msg *MsgSelectedTip) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgSelectedTip) MessageNumber

func (b *MsgSelectedTip) MessageNumber() uint64

func (*MsgSelectedTip) ReceivedAt

func (b *MsgSelectedTip) ReceivedAt() time.Time

func (*MsgSelectedTip) SetMessageNumber

func (b *MsgSelectedTip) SetMessageNumber(messageNumber uint64)

func (*MsgSelectedTip) SetReceivedAt

func (b *MsgSelectedTip) SetReceivedAt(receivedAt time.Time)

type MsgTransactionNotFound

type MsgTransactionNotFound struct {
	ID *daghash.TxID
	// contains filtered or unexported fields
}

MsgTransactionNotFound defines a kaspa TransactionNotFound message which is sent in response to a RequestTransactions message if any of the requested data in not available on the peer.

func NewMsgTransactionNotFound

func NewMsgTransactionNotFound(id *daghash.TxID) *MsgTransactionNotFound

NewMsgTransactionNotFound returns a new kaspa transactionsnotfound message that conforms to the Message interface. See MsgTransactionNotFound for details.

func (*MsgTransactionNotFound) Command

func (msg *MsgTransactionNotFound) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgTransactionNotFound) MessageNumber

func (b *MsgTransactionNotFound) MessageNumber() uint64

func (*MsgTransactionNotFound) ReceivedAt

func (b *MsgTransactionNotFound) ReceivedAt() time.Time

func (*MsgTransactionNotFound) SetMessageNumber

func (b *MsgTransactionNotFound) SetMessageNumber(messageNumber uint64)

func (*MsgTransactionNotFound) SetReceivedAt

func (b *MsgTransactionNotFound) SetReceivedAt(receivedAt time.Time)

type MsgTx

type MsgTx struct {
	Version      int32
	TxIn         []*TxIn
	TxOut        []*TxOut
	LockTime     uint64
	SubnetworkID subnetworkid.SubnetworkID
	Gas          uint64
	PayloadHash  *daghash.Hash
	Payload      []byte
	// contains filtered or unexported fields
}

MsgTx implements the Message interface and represents a kaspa 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 NewNativeMsgTx

func NewNativeMsgTx(version int32, txIn []*TxIn, txOut []*TxOut) *MsgTx

NewNativeMsgTx returns a new tx message in the native subnetwork

func NewNativeMsgTxWithLocktime

func NewNativeMsgTxWithLocktime(version int32, txIn []*TxIn, txOut []*TxOut, locktime uint64) *MsgTx

NewNativeMsgTxWithLocktime returns a new tx message in the native subnetwork with a locktime.

See newMsgTx for further documntation of the parameters

func NewRegistryMsgTx

func NewRegistryMsgTx(version int32, txIn []*TxIn, txOut []*TxOut, gasLimit uint64) *MsgTx

NewRegistryMsgTx creates a new MsgTx that registers a new subnetwork

func NewSubnetworkMsgTx

func NewSubnetworkMsgTx(version int32, txIn []*TxIn, txOut []*TxOut, subnetworkID *subnetworkid.SubnetworkID,
	gas uint64, payload []byte) *MsgTx

NewSubnetworkMsgTx returns a new tx message in the specified subnetwork with specified gas and payload

func (*MsgTx) AddTxIn

func (msg *MsgTx) AddTxIn(ti *TxIn)

AddTxIn adds a transaction input to the message.

func (*MsgTx) AddTxOut

func (msg *MsgTx) AddTxOut(to *TxOut)

AddTxOut adds a transaction output to the message.

func (*MsgTx) Command

func (msg *MsgTx) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgTx) Copy

func (msg *MsgTx) Copy() *MsgTx

Copy creates a deep copy of a transaction so that the original does not get modified when the copy is manipulated.

func (*MsgTx) Deserialize

func (msg *MsgTx) Deserialize(r io.Reader) error

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 KaspaDecode in that KaspaDecode decodes from the kaspa appmessage protocol as it was sent across the network. The appmessage 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) IsCoinBase

func (msg *MsgTx) IsCoinBase() bool

IsCoinBase determines whether or not a transaction is a coinbase transaction. A coinbase transaction is a special transaction created by miners that distributes fees and block subsidy to the previous blocks' miners, and to specify the scriptPubKey that will be used to pay the current miner in future blocks. Each input of the coinbase transaction should set index to maximum value and reference the relevant block id, instead of previous transaction id.

func (*MsgTx) IsSubnetworkCompatible

func (msg *MsgTx) IsSubnetworkCompatible(subnetworkID *subnetworkid.SubnetworkID) bool

IsSubnetworkCompatible return true iff subnetworkID is one or more of the following: 1. The SupportsAll subnetwork (full node) 2. The native subnetwork 3. The transaction's subnetwork

func (*MsgTx) KaspaDecode

func (msg *MsgTx) KaspaDecode(r io.Reader, pver uint32) error

KaspaDecode decodes r using the kaspa 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 appmessage.

func (*MsgTx) KaspaEncode

func (msg *MsgTx) KaspaEncode(w io.Writer, pver uint32) error

KaspaEncode encodes the receiver to w using the kaspa 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 appmessage.

func (*MsgTx) MaxPayloadLength

func (msg *MsgTx) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message interface implementation.

func (*MsgTx) MessageNumber

func (b *MsgTx) MessageNumber() uint64

func (*MsgTx) ReceivedAt

func (b *MsgTx) ReceivedAt() time.Time

func (*MsgTx) ScriptPubKeyLocs

func (msg *MsgTx) ScriptPubKeyLocs() []int

ScriptPubKeyLocs 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.

func (*MsgTx) Serialize

func (msg *MsgTx) Serialize(w io.Writer) error

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 KaspaEncode in that KaspaEncode encodes the transaction to the kaspa appmessage protocol in order to be sent across the network. The appmessage 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

func (msg *MsgTx) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the transaction.

func (*MsgTx) SetMessageNumber

func (b *MsgTx) SetMessageNumber(messageNumber uint64)

func (*MsgTx) SetReceivedAt

func (b *MsgTx) SetReceivedAt(receivedAt time.Time)

func (*MsgTx) TxHash

func (msg *MsgTx) TxHash() *daghash.Hash

TxHash generates the Hash for the transaction.

func (*MsgTx) TxID

func (msg *MsgTx) TxID() *daghash.TxID

TxID generates the Hash for the transaction without the signature script, gas and payload fields.

type MsgVerAck

type MsgVerAck struct {
	// contains filtered or unexported fields
}

MsgVerAck defines a kaspa 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 kaspa verack message that conforms to the Message interface.

func (*MsgVerAck) Command

func (msg *MsgVerAck) Command() MessageCommand

Command returns the protocol command string for the message. This is part of the Message interface implementation.

func (*MsgVerAck) MessageNumber

func (b *MsgVerAck) MessageNumber() uint64

func (*MsgVerAck) ReceivedAt

func (b *MsgVerAck) ReceivedAt() time.Time

func (*MsgVerAck) SetMessageNumber

func (b *MsgVerAck) SetMessageNumber(messageNumber uint64)

func (*MsgVerAck) SetReceivedAt

func (b *MsgVerAck) SetReceivedAt(receivedAt time.Time)

type MsgVersion

type MsgVersion struct {

	// Version of the protocol the node is using.
	ProtocolVersion uint32

	// The peer's network (mainnet, testnet, etc.)
	Network string

	// Bitfield which identifies the enabled services.
	Services ServiceFlag

	// Time the message was generated. This is encoded as an int64 on the appmessage.
	Timestamp mstime.Time

	// Address of the local peer.
	Address *NetAddress

	// The peer unique ID
	ID *id.ID

	// The user agent that generated messsage. This is a encoded as a varString
	// on the appmessage. This has a max length of MaxUserAgentLen.
	UserAgent string

	// The selected tip hash of the generator of the version message.
	SelectedTipHash *daghash.Hash

	// Don't announce transactions to peer.
	DisableRelayTx bool

	// The subnetwork of the generator of the version message. Should be nil in full nodes
	SubnetworkID *subnetworkid.SubnetworkID
	// contains filtered or unexported fields
}

MsgVersion implements the Message interface and represents a kaspa 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(addr *NetAddress, id *id.ID, network string,
	selectedTipHash *daghash.Hash, subnetworkID *subnetworkid.SubnetworkID) *MsgVersion

NewMsgVersion returns a new kaspa 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)

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) Command

func (msg *MsgVersion) Command() MessageCommand

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) MessageNumber

func (b *MsgVersion) MessageNumber() uint64

func (*MsgVersion) ReceivedAt

func (b *MsgVersion) ReceivedAt() time.Time

func (*MsgVersion) SetMessageNumber

func (b *MsgVersion) SetMessageNumber(messageNumber uint64)

func (*MsgVersion) SetReceivedAt

func (b *MsgVersion) SetReceivedAt(receivedAt time.Time)

type NetAddress

type NetAddress struct {
	// Last time the address was seen.
	Timestamp mstime.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 appmessage
	// 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 mstime.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 millisecond 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.

func (*NetAddress) TCPAddress

func (na *NetAddress) TCPAddress() *net.TCPAddr

TCPAddress converts the NetAddress to *net.TCPAddr

type Outpoint

type Outpoint struct {
	TxID  daghash.TxID
	Index uint32
}

Outpoint defines a kaspa data type that is used to track previous transaction outputs.

func NewOutpoint

func NewOutpoint(txID *daghash.TxID, index uint32) *Outpoint

NewOutpoint returns a new kaspa transaction outpoint point with the provided hash and index.

func (Outpoint) String

func (o Outpoint) String() string

String returns the Outpoint in the human-readable form "txID:index".

type ServiceFlag

type ServiceFlag uint64

ServiceFlag identifies services supported by a kaspa peer.

const (
	// SFNodeNetwork is a flag used to indicate a peer is a full node.
	SFNodeNetwork ServiceFlag = 1 << iota

	// SFNodeGetUTXO is a flag used to indicate a peer supports the
	// getutxos and utxos commands (BIP0064).
	SFNodeGetUTXO

	// SFNodeBloom is a flag used to indicate a peer supports bloom
	// filtering.
	SFNodeBloom

	// SFNodeXthin is a flag used to indicate a peer supports xthin blocks.
	SFNodeXthin

	// SFNodeBit5 is a flag used to indicate a peer supports a service
	// defined by bit 5.
	SFNodeBit5

	// SFNodeCF is a flag used to indicate a peer supports committed
	// filters (CFs).
	SFNodeCF
)

func (ServiceFlag) String

func (f ServiceFlag) String() string

String returns the ServiceFlag in human-readable form.

type TxIn

type TxIn struct {
	PreviousOutpoint Outpoint
	SignatureScript  []byte
	Sequence         uint64
}

TxIn defines a kaspa transaction input.

func NewTxIn

func NewTxIn(prevOut *Outpoint, signatureScript []byte) *TxIn

NewTxIn returns a new kaspa transaction input with the provided previous outpoint point and signature script with a default sequence of MaxTxInSequenceNum.

func (*TxIn) SerializeSize

func (t *TxIn) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the transaction input.

type TxLoc

type TxLoc struct {
	TxStart int
	TxLen   int
}

TxLoc holds locator data for the offset and length of where a transaction is located within a MsgBlock data buffer.

type TxOut

type TxOut struct {
	Value        uint64
	ScriptPubKey []byte
}

TxOut defines a kaspa transaction output.

func NewTxOut

func NewTxOut(value uint64, scriptPubKey []byte) *TxOut

NewTxOut returns a new kaspa transaction output with the provided transaction value and public key script.

func (*TxOut) SerializeSize

func (t *TxOut) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the the transaction output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL