wire

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: ISC Imports: 14 Imported by: 1

README ΒΆ

πŸš€ go-wire

BSV Blockchain Wire Protocol

CIΒ /Β CD QualityΒ &Β Security DocsΒ &Β Meta Community
Latest Release
Build Status
CodeQL
SonarCloud
Go Report Card
Code Coverage
OpenSSF Scorecard
Security policy
Go version
Go docs
AGENTS.md rules
Makefile Supported
Dependabot
Contributors
Last commit
Sponsor

πŸ—‚οΈ Table of Contents


🧩 What's Inside

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

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


πŸ“¦ Installation

go-wire requires a supported release of Go.

go get -u github.com/bsv-blockchain/go-wire

πŸ“š Documentation


Repository Features
  • Continuous Integration on Autopilot with GitHub Actions – every push is built, tested, and reported in minutes.
  • Pull‑Request Flow That Merges Itself thanks to auto‑merge and hands‑free Dependabot auto‑merge.
  • One‑Command Builds powered by battle‑tested Make targets for linting, testing, releases, and more.
  • First‑Class Dependency Management using native Go Modules.
  • Uniform Code Style via gofumpt plus zero‑noise linting with golangci‑lint.
  • Confidence‑Boosting Tests with testify, the Go race detector, crystal‑clear HTML coverage snapshots, and automatic uploads to Codecov.
  • Hands‑Free Releases delivered by GoReleaser whenever you create a new Tag.
  • Relentless Dependency & Vulnerability Scans via Dependabot, Nancy, and govulncheck.
  • Security Posture by Default with CodeQL, OpenSSF Scorecard, and secret‑leak detection via gitleaks.
  • Automatic Syndication to pkg.go.dev on every release for instant godoc visibility.
  • Polished Community Experience using rich templates for Issues & PRs.
  • All the Right Meta Files (LICENSE, CONTRIBUTING.md, CODE_OF_CONDUCT.md, SUPPORT.md, SECURITY.md) pre‑filled and ready.
  • Code Ownership clarified through a CODEOWNERS file, keeping reviews fast and focused.
  • Zero‑Noise Dev Environments with tuned editor settings (.editorconfig) plus curated ignore files for VS Code, Docker, and Git.
  • Label Sync Magic: your repo labels stay in lock‑step with .github/labels.yml.
  • Friendly First PR Workflow – newcomers get a warm welcome thanks to a dedicated workflow.
  • Standards‑Compliant Docs adhering to the standard‑readme spec.
  • Instant Cloud Workspaces via Gitpod – spin up a fully configured dev environment with automatic linting and tests.
  • Out‑of‑the‑Box VS Code Happiness with a preconfigured Go workspace and .vscode folder with all the right settings.
  • Optional Release Broadcasts to your community via Slack, Discord, or Twitter – plug in your webhook.
  • AI Compliance Playbook – machine‑readable guidelines (AGENTS.md, CLAUDE.md, .cursorrules, sweep.yaml) keep ChatGPT, Claude, Cursor & Sweep aligned with your repo’s rules.
  • Pre-commit Hooks for Consistency powered by pre-commit and the .pre-commit-config.yaml fileβ€”run the same formatting, linting, and tests before every commit, just like CI.
  • Automated Hook Updates keep the .pre-commit-config.yaml current via a weekly workflow.
  • DevContainers for Instant Onboarding – Launch a ready-to-code environment in seconds with VS Code DevContainers and the included .devcontainer.json config.
Library Deployment

This project uses goreleaser for streamlined binary and library deployment to GitHub. To get started, install it via:

brew install goreleaser

The release process is defined in the .goreleaser.yml configuration file.

To generate a snapshot (non-versioned) release for testing purposes, run:

make release-snap

Then create and push a new Git tag using:

make tag version=x.y.z

This process ensures consistent, repeatable releases with properly versioned artifacts and citation metadata.

Makefile Commands

View all makefile commands

make help

List of all current commands:

bench                 ## Run all benchmarks in the Go application
build-go              ## Build the Go application (locally)
citation              ## Update version in CITATION.cff (use version=X.Y.Z)
clean-mods            ## Remove all the Go mod cache
coverage              ## Show test coverage
diff                  ## Show git diff and fail if uncommitted changes exist
fumpt                 ## Run fumpt to format Go code
generate              ## Run go generate in the base of the repo
godocs                ## Trigger GoDocs tag sync
govulncheck-install   ## Install govulncheck
help                  ## Display this help message
install-go            ## Install using go install with specific version
install-releaser      ## Install GoReleaser
install               ## Install the application binary
lint                  ## Run the golangci-lint application (install if not found)
release-snap          ## Build snapshot binaries
release-test          ## Run release dry-run (no publish)
release               ## Run production release (requires github_token)
run-fuzz-tests        ## Run fuzz tests for all packages
tag-remove            ## Remove local and remote tag (use version=X.Y.Z)
tag-update            ## Force-update tag to current commit (use version=X.Y.Z)
tag                   ## Create and push a new tag (use version=X.Y.Z)
test-ci-no-race       ## CI test suite without race detector
test-ci-short         ## CI unit-only short tests
test-ci               ## CI full test suite with coverage
test-no-lint          ## Run only tests (no lint)
test-short            ## Run tests excluding integration
test-unit             ## Runs tests and outputs coverage
test                  ## Run lint and all tests
uninstall             ## Uninstall the Go binary
update-linter         ## Upgrade golangci-lint (macOS only)
update-releaser       ## Reinstall GoReleaser
update                ## Update dependencies
vet                   ## Run go vet
GitHub Workflows
Workflow Name Description
auto-merge-on-approval.yml Automatically merges PRs after approval and all required checks, following strict rules.
check-for-leaks.yml Runs gitleaks to detect secrets on a daily schedule.
clean-runner-cache.yml Removes GitHub Actions caches tied to closed pull requests.
codeql-analysis.yml Analyzes code for security vulnerabilities using GitHub CodeQL.
delete-merged-branches.yml Deletes feature branches after their pull requests are merged.
dependabot-auto-merge.yml Automatically merges Dependabot PRs that meet all requirements.
pull-request-management.yml Labels PRs by branch prefix, assigns a default user if none is assigned, and welcomes new contributors with a comment.
release.yml Builds and publishes releases via GoReleaser when a semver tag is pushed.
run-tests.yml Runs linter, Go tests and dependency checks on every push and pull request.
scorecard.yml Runs OpenSSF Scorecard to assess supply chain security.
stale.yml Warns about (and optionally closes) inactive issues and PRs on a schedule or manual trigger.
sync-labels.yml Keeps GitHub labels in sync with the declarative manifest at .github/labels.yml.
update-pre-commit-hooks.yml Automatically update versions for pre-commit hooks
update-pip-requirements.yml Updates Python requirements for pre-commit hooks to the latest versions.
Updating Dependencies

To update all dependencies (Go modules, linters, and related tools), run:

make update

This command ensures all dependencies are brought up to date in a single step, including Go modules and any tools managed by the Makefile. It is the recommended way to keep your development environment and CI in sync with the latest versions.

Pre-commit Hooks

Set up the optional pre-commit hooks to run the same formatting, linting, and tests defined in AGENTS.md before every commit:

pip install pre-commit
pre-commit install

The hooks are configured in .pre-commit-config.yaml and mirror the CI pipeline.


πŸ§ͺ Examples & Tests

All unit tests and examples run via GitHub Actions and use Go version 1.24.x. View the configuration file.

Run all tests:

make test

⚑ Benchmarks

Run the Go benchmarks:

make bench

Benchmark Results
Benchmark Iterations ns/op B/op allocs/op
WriteVarInt1 39,459,027 29.66 0 0
WriteVarInt3 20,199,483 58.82 0 0
WriteVarInt5 19,839,806 60.09 0 0
WriteVarInt9 20,289,205 58.85 0 0
ReadVarInt1 34,616,506 34.46 0 0
ReadVarInt3 16,991,710 70.22 0 0
ReadVarInt5 17,296,663 69.03 0 0
ReadVarInt9 17,292,540 68.81 0 0
ReadVarStr4 19,168,129 61.24 8 2
ReadVarStr10 17,873,167 66.25 32 2
WriteVarStr4 26,292,486 44.63 8 1
WriteVarStr10 24,418,180 48.74 16 1
ReadOutPoint 28,408,053 41.95 0 0
WriteOutPoint 37,229,792 31.65 0 0
ReadTxOut 11,092,542 108.00 0 0
WriteTxOut 19,576,215 61.21 0 0
ReadTxIn 8,187,141 148.00 0 0
WriteTxIn 12,787,064 93.58 0 0
DeserializeTxSmall 2,368,681 510.50 208 5
SerializeTx 4,343,654 277.00 0 0
ReadBlockHeader 7,429,682 160.40 0 0
WriteBlockHeader 7,074,567 169.20 12 3
DecodeGetHeaders 198,742 5896.00 20480 2
DecodeHeaders 2,761 431936.00 229380 2
DecodeGetBlocks 197,142 5944.00 20480 2
DecodeAddr 8,107 144051.00 89730 1002
DecodeInv 464 2573857.00 2203667 2
DecodeNotFound 463 2583316.00 2203666 2
DecodeMerkleBlock 736,904 1598.00 4368 3
TxHash 2,120,943 566.40 256 2
DoubleHashB 6,433,498 186.70 32 1
DoubleHash 6,658,620 182.00 0 0

These benchmarks reflect fast, allocation-free lookups for most retrieval functions, ensuring optimal performance in production environments. Performance benchmarks for the core functions in this library, executed on an Apple M1 Max (ARM64).


πŸ› οΈ Code Standards

Read more about this Go project's code standards.


πŸ€– AI Compliance

This project documents expectations for AI assistants using a few dedicated files:

  • AGENTS.md β€” canonical rules for coding style, workflows, and pull requests used by Codex.
  • CLAUDE.md β€” quick checklist for the Claude agent.
  • .cursorrules β€” machine-readable subset of the policies for Cursor and similar tools.
  • sweep.yaml β€” rules for Sweep, a tool for code review and pull request management.

Edit AGENTS.md first when adjusting these policies, and keep the other files in sync within the same pull request.


πŸ‘₯ Maintainers

Siggi Oskarsson
Siggi

🀝 Contributing

View the contributing guidelines and please follow the code of conduct.

How can I help?

All kinds of contributions are welcome πŸ™Œ! The most basic way to show your support is to star 🌟 the project, or to raise issues πŸ’¬. You can also support this project by becoming a sponsor on GitHub πŸ‘ to ensure this journey continues indefinitely! πŸš€

Stars


πŸ“ License

License

Documentation ΒΆ

Overview ΒΆ

Package wire implements the bitcoin wire protocol.

For the complete details of the bitcoin protocol, see the official wiki entry at https://en.bitcoin.it/wiki/Protocol_specification. The following only serves as a quick overview to provide information on how to use the package.

At a high level, this package provides support for marshaling and unmarshalling supported bitcoin messages to and from the wire. This package does not deal with the specifics of message handling such as what to do when a message is received. This provides the caller with a high level of flexibility.

Bitcoin Message Overview ΒΆ

The Bitcoin protocol consists of exchanging messages between peers. Each message is preceded by a header which identifies information about it, such as which bitcoin network it is a part of, its type, how big it is, and a checksum to verify validity. This package handles all encoding and decoding of message headers.

To achieve this, there is a generic interface for Bitcoin messages named Message which allows messages of any type to be read, written, or passed around through channels, functions, etc. In addition, concrete implementations of most of the currently supported bitcoin messages are provided. For these supported messages, all the details of marshaling and unmarshalling to and from the wire using bitcoin encoding are handled so the caller doesn't have to concern themselves with the specifics.

Message Interaction ΒΆ

The following provides a quick summary of how the bitcoin messages are intended to interact with one another. As stated above, these interactions are not indirectly handled by this package. For more in-depth details about the appropriate interactions, see the official bitcoin protocol wiki entry at https://en.bitcoin.it/wiki/Protocol_specification.

The initial handshake consists of two peers sending each other a version message (MsgVersion) followed by responding with a verack message (MsgVerAck). Both peers use the information in the version message (MsgVersion) to negotiate things such as protocol version and supported services with each other. Once the initial handshake is complete, the following chart indicates message interactions in no particular order.

Peer A Sends                          Peer B Responds
----------------------------------------------------------------------------
getaddr message (MsgGetAddr)          addr message (MsgAddr)
getblocks message (MsgGetBlocks)      inv message (MsgInv)
inv message (MsgInv)                  getdata message (MsgGetData)
getdata message (MsgGetData)          block message (MsgBlock) -or-
                                      tx message (MsgTx) -or-
                                      notfound message (MsgNotFound)
getheaders message (MsgGetHeaders)    headers message (MsgHeaders)
ping message (MsgPing)                pong message (MsgHeaders)* -or-
                                      (none -- Ability to send message is enough)

NOTES:
* The pong message was not added until later protocol versions as defined
  in BIP0031.  The BIP0031Version constant can be used to detect a recent
  enough protocol version for this purpose (version > BIP0031Version).

Common Parameters ΒΆ

There are several common parameters that arise when using this package to read and write bitcoin messages. The following sections provide a quick overview of these parameters so the next sections can build on them.

Protocol Version ΒΆ

The protocol version should be negotiated with the remote peer at a higher level than this package via the version (MsgVersion) message exchange, however, this package provides the wire.ProtocolVersion constant which indicates the latest protocol version this package supports and is typically the value to use for all outbound connections before a potentially lower protocol version is negotiated.

Bitcoin (BSV) Network ΒΆ

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

wire.MainNet
wire.RegTestNet  (Regression test network)
wire.TestNet (Test network version 3)

Determining Message Type ΒΆ

As discussed in the bitcoin message overview section, this package reads and writes bitcoin messages using a generic interface named Message. In order to determine the actual concrete type of the message, use a type switch or type assertion. An example of a type switch follows:

// Assumes msg is already a valid concrete message such as one created
// via NewMsgVersion or read via ReadMessage.
switch msg := msg.(type) {
case *wire.MsgVersion:
	// The message is a pointer to a MsgVersion struct.
	fmt.Printf("Protocol version: %v", msg.ProtocolVersion)
case *wire.MsgBlock:
	// The message is a pointer to a MsgBlock struct.
	fmt.Printf("Number of tx in block: %v", msg.Header.TxnCount)
}

Reading Messages ΒΆ

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

// Reads and validates the next bitcoin message from conn using the
// protocol version pver and the bitcoin network bsvnet.  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, bsvnet)
if err != nil {
	// Log and handle the error
}

Writing Messages ΒΆ

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

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

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

Errors ΒΆ

Errors returned by this package are either the raw errors provided by underlying calls to read/write from streams such as io.EOF, io.ErrUnexpectedEOF, and io.ErrShortWrite, or of type wire.MessageError. This allows the caller to differentiate between general IO errors and malformed messages through type assertions.

Bitcoin Improvement Proposals ΒΆ

This package includes spec changes outlined by the following BIPs:

BIP0014 (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
BIP0031 (https://github.com/bitcoin/bips/blob/master/bip-0031.mediawiki)
BIP0035 (https://github.com/bitcoin/bips/blob/master/bip-0035.mediawiki)
BIP0037 (https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki)
BIP0111	(https://github.com/bitcoin/bips/blob/master/bip-0111.mediawiki)
BIP0130 (https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki)
BIP0133 (https://github.com/bitcoin/bips/blob/master/bip-0133.mediawiki)

Index ΒΆ

Constants ΒΆ

View Source
const (
	CmdVersion      = "version"
	CmdVerAck       = "verack"
	CmdGetAddr      = "getaddr"
	CmdAddr         = "addr"
	CmdGetBlocks    = "getblocks"
	CmdInv          = "inv"
	CmdGetData      = "getdata"
	CmdNotFound     = "notfound"
	CmdBlock        = "block"
	CmdTx           = "tx"
	CmdExtendedTx   = "exttx"
	CmdGetHeaders   = "getheaders"
	CmdHeaders      = "headers"
	CmdPing         = "ping"
	CmdPong         = "pong"
	CmdMemPool      = "mempool"
	CmdFilterAdd    = "filteradd"
	CmdFilterClear  = "filterclear"
	CmdFilterLoad   = "filterload"
	CmdMerkleBlock  = "merkleblock"
	CmdReject       = "reject"
	CmdSendHeaders  = "sendheaders"
	CmdFeeFilter    = "feefilter"
	CmdGetCFilters  = "getcfilters"
	CmdGetCFHeaders = "getcfheaders"
	CmdGetCFCheckpt = "getcfcheckpt"
	CmdCFilter      = "cfilter"
	CmdCFHeaders    = "cfheaders"
	CmdCFCheckpt    = "cfcheckpt"
	CmdProtoconf    = "protoconf"
	CmdExtMsg       = "extmsg"
	CmdSendcmpct    = "sendcmpct"
	CmdAuthch       = "authch"
	CmdAuthresp     = "authresp"
)

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

View Source
const (
	// MaxCFHeaderPayload is the maximum byte size of a committed
	// filter header.
	MaxCFHeaderPayload = chainhash.HashSize

	// MaxCFHeadersPerMsg is the maximum number of committed filter headers
	// that can be in a single bitcoin cfheaders message.
	MaxCFHeadersPerMsg = 2000
)
View Source
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
)
View Source
const (
	MaxProtoconfPayload       = 1024 * 1024
	MaxNumStreamPolicies      = 10
	DefaultStreamPolicy       = "Default"
	BlockPriorityStreamPolicy = "BlockPriority"

	// DefaultMaxRecvPayloadLength is the default maximum receive payload length
	DefaultMaxRecvPayloadLength uint32 = 2 * 1024 * 1024
)

MsgProtoconf implements the Message interface and represents a bitcoin protoconf message. It is sent after verack message directly to inform max receive payload length

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 uint32 = 0xffffffff

	// MaxPrevOutIndex is the maximum index the index field of a previous
	// outpointing can be.
	MaxPrevOutIndex uint32 = 0xffffffff

	// SequenceLockTimeDisabled is a flag that if set on a transaction
	// input's sequence number, the sequence number will not be interpreted
	// as a relative locktime.
	SequenceLockTimeDisabled = 1 << 31

	// SequenceLockTimeIsSeconds is a flag that if set on a transaction
	// input's sequence number, the relative locktime has units of 512
	// seconds.
	SequenceLockTimeIsSeconds = 1 << 22

	// SequenceLockTimeMask is a mask that extracts the relative locktime
	// when masked against the transaction input sequence number.
	SequenceLockTimeMask = 0x0000ffff

	// SequenceLockTimeGranularity is the defined time-based granularity
	// for seconds-based relative time locks. When converting from seconds
	// to a sequence number, the value is right shifted by this amount,
	// therefore the granularity of relative time locks in 512 or 2^9
	// seconds. Enforced relative lock times are multiples of 512 seconds.
	SequenceLockTimeGranularity = 9

	// MinTxOutPayload is the minimum payload size for a transaction output.
	// Value 8 bytes + Varint for PkScript length 1 byte.
	MinTxOutPayload = 9
)
View Source
const (
	// ProtocolVersion is the latest protocol version this package supports.
	// ProtocolVersion uint32 = 70013
	ProtocolVersion uint32 = 70016 // This version supports extended messages (>4GB)

	// MultipleAddressVersion is the protocol version which added multiple
	// addresses per message (pver >= MultipleAddressVersion).
	MultipleAddressVersion uint32 = 209

	// NetAddressTimeVersion is the protocol version which added the
	// timestamp field (pver >= NetAddressTimeVersion).
	NetAddressTimeVersion uint32 = 31402

	// BIP0031Version is the protocol version AFTER which a pong message
	// and nonce field in ping were added (pver > BIP0031Version).
	BIP0031Version uint32 = 60000

	// BIP0035Version is the protocol version which added the mempool
	// message (pver >= BIP0035Version).
	BIP0035Version uint32 = 60002

	// BIP0037Version is the protocol version which added new connection
	// bloom filtering related messages and extended the version message
	// with a relay flag (pver >= BIP0037Version).
	BIP0037Version uint32 = 70001

	// RejectVersion is the protocol version which added a new reject
	// message.
	RejectVersion uint32 = 70002

	// BIP0111Version is the protocol version which added the SFNodeBloom
	// service flag.
	BIP0111Version uint32 = 70011

	// SendHeadersVersion is the protocol version which added a new
	// sendheaders message.
	SendHeadersVersion uint32 = 70012

	// FeeFilterVersion is the protocol version which added a new
	// feefilter message.
	FeeFilterVersion uint32 = 70013

	// ProtoconfVersion is the protocol version which added a new
	// protoconf message
	ProtoconfVersion uint32 = 70013
)

XXX pedro: we will probably need to bump this.

View Source
const (
	// CFCheckptInterval is the gap (in number of blocks) between each
	// filter header checkpoint.
	CFCheckptInterval = 1000
)
View Source
const CommandSize = 12

CommandSize is the fixed size of all commands in the common bitcoin message header. Shorter commands must be zero padded.

View Source
const DefaultUserAgent = "/bsvwire:0.5.0/"

DefaultUserAgent for wire in the stack

View Source
const MaxAddrPerMsg = 1000

MaxAddrPerMsg is the maximum number of addresses that can be in a single bitcoin addr message (MsgAddr).

View Source
const MaxBlockHeaderPayload = 16 + (chainhash.HashSize * 2)

MaxBlockHeaderPayload is the maximum number of bytes a block header can be. Version 4 bytes + Timestamp 4 bytes + Bits 4 bytes + Nonce 4 bytes + PrevBlock and MerkleRoot hashes.

View Source
const MaxBlockHeadersPerMsg = 2000

MaxBlockHeadersPerMsg is the maximum number of block headers that can be in a single bitcoin headers message.

View Source
const MaxBlockLocatorsPerMsg = 500

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

View Source
const MaxBlocksPerMsg = 500

MaxBlocksPerMsg is the maximum number of blocks allowed per message.

View Source
const (
	// MaxCFilterDataSize is the maximum byte size of a committed filter.
	// The maximum size is currently defined as 256KiB.
	MaxCFilterDataSize = 256 * 1024
)
View Source
const MaxExtMsgPayload = 0xFFFFFFFFFFFFFFFF

MaxExtMsgPayload is the maximum number of bytes a protoconf can be. NumberOfFields 8 bytes + MaxRecvPayloadLength 4 bytes

View Source
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
)
View Source
const MaxGetCFiltersReqRange = 1000

MaxGetCFiltersReqRange the maximum number of filters that may be requested in a getcfheaders message.

View Source
const (
	// MaxInvPerMsg is the maximum number of inventory vectors that can be in a
	// single bitcoin inv message.
	MaxInvPerMsg = 50000
)
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 is the maximum payload size for a variable length integer.
	MaxVarIntPayload = 9
)
View Source
const MessageHeaderSize = 24

MessageHeaderSize is the number of bytes in a bitcoin message header. Bitcoin network (magic) 4 bytes + command 12 bytes + payload length 4 bytes + checksum 4 bytes.

Variables ΒΆ

View Source
var (
	SECP256K1_COMP_PUB_KEY_SIZE_IN_BYTES = 0x21 //nolint:revive // this is already being used in the code
	SECP256K1_DER_SIGN_MIN_SIZE_IN_BYTES = 0x46 //nolint:revive // this is already being used in the code
	SECP256K1_DER_SIGN_MAX_SIZE_IN_BYTES = 0x48 //nolint:revive // this is already being used in the code
)
View Source
var ErrInsaneCFHeaderCount = errors.New(
	"refusing to decode unreasonable number of filter headers")

ErrInsaneCFHeaderCount signals that we were asked to decode an unreasonable number of cfilter headers.

View Source
var LatestEncoding = BaseEncoding

LatestEncoding is the most recently specified encoding for the Bitcoin wire protocol.

Functions ΒΆ

func MaxBlockPayload ΒΆ

func MaxBlockPayload() uint64

MaxBlockPayload returns the maximum bytes a block message can be in bytes.

func RandomUint64 ΒΆ

func RandomUint64() (uint64, error)

RandomUint64 returns a cryptographically random uint64 value.

func ReadVarBytes ΒΆ

func ReadVarBytes(r io.Reader, pver uint32, maxAllowed uint64,
	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, _ uint32) (uint64, error)

ReadVarInt reads a variable length integer from r and returns it as an 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 SetExternalHandler ΒΆ

func SetExternalHandler(cmd string, handler func(io.Reader, uint64, int) (int, Message, []byte, error))

SetExternalHandler allows a third party to override the way a message is handled globally

func SetLimits ΒΆ

func SetLimits(excessiveBlockSize uint64)

SetLimits adjusts various message limits based on max block size configuration.

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 WriteMessage ΒΆ

func WriteMessage(w io.Writer, msg Message, pver uint32, bsvnet BitcoinNet) error

WriteMessage writes a bitcoin Message to w including the necessary header information. This function is the same as WriteMessageN except it 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 ΒΆ

func WriteMessageN(w io.Writer, msg Message, pver uint32, bsvnet BitcoinNet) (int, error)

WriteMessageN writes a bitcoin Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessage except it also returns the number of bytes written.

func WriteMessageWithEncodingN ΒΆ

func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
	bsvnet BitcoinNet, encoding MessageEncoding,
) (int, error)

WriteMessageWithEncodingN writes a bitcoin Message to w including the necessary header information and returns the number of bytes written. This function is the same as WriteMessageN except it also allows the caller to specify the message encoding format to be used when serializing wire messages.

func WriteTxOut ΒΆ

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

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

NOTE: This function is exported to allow txscript to compute the new sighashes for witness transactions (BIP0143).

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, _ uint32, 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, pver uint32, 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 BitcoinNet ΒΆ

type BitcoinNet uint32

BitcoinNet represents which bitcoin network a message belongs to.

const (
	// MainNet represents the main bitcoin network.
	MainNet BitcoinNet = 0xe8f3e1e3

	// RegTestNet represents the regression test network. No longer in use
	RegTestNet BitcoinNet = 0xfabfb5da

	// TestNet represents the test network (version 3). This is the SVNode testnet
	TestNet BitcoinNet = 0xf4f3e5f4

	// TeraTestNet represents the teranode test network. This is the teranode testnet
	TeraTestNet BitcoinNet = 0x0c09010d

	// TeraScalingTestNet represents the teranode scaling test network. This is the teranode scaling testnet
	TeraScalingTestNet BitcoinNet = 0x00000004

	Custom BitcoinNet = 0x00000001

	// STN represents the scaling test network.
	STN BitcoinNet = 0x00000000
)

Constants used to indicate the message bitcoin network. They can also be used to seek to the next message when a stream's state is unknown, but this package does not provide that functionality since it's generally a better idea to simply disconnect clients that are misbehaving over TCP.

func (BitcoinNet) String ΒΆ

func (n BitcoinNet) String() string

String returns the BitcoinNet in human-readable form.

type BlockHeader ΒΆ

type BlockHeader struct {
	// Version of the block.  This is different from the protocol version.
	Version int32

	// Hash of the previous block header in the blockchain.
	PrevBlock chainhash.Hash

	// Merkle tree reference to hash of all transactions for the block.
	MerkleRoot chainhash.Hash

	// Time the block was created.  This is, unfortunately, encoded as an
	// uint32 on the wire and therefore is limited to 2106.
	Timestamp time.Time

	// Difficulty target for the block.
	Bits uint32

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

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

func NewBlockHeader ΒΆ

func NewBlockHeader(version int32, prevHash, merkleRootHash *chainhash.Hash,
	bits, nonce uint32,
) *BlockHeader

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

func (*BlockHeader) BlockHash ΒΆ

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

BlockHash computes the block identifier hash for the given block header.

func (*BlockHeader) BsvEncode ΒΆ

func (h *BlockHeader) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode 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) Bsvdecode ΒΆ

func (h *BlockHeader) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode 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) 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) 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.

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 output 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 output is serialized and inserted
	// into the filter.
	BloomUpdateP2PubkeyOnly BloomUpdateType = 2
)

type ExtendedTxIn ΒΆ

type ExtendedTxIn struct {
	PreviousOutPoint   OutPoint
	PreviousTxSatoshis uint64
	PreviousTxScript   []byte
	SignatureScript    []byte
	Sequence           uint32
}

ExtendedTxIn defines an extended bitcoin transaction input.

func NewExtendedTxIn ΒΆ

func NewExtendedTxIn(prevOut *OutPoint, signatureScript []byte, previousTxSatoshis uint64, previousTxScript []byte) *ExtendedTxIn

NewExtendedTxIn returns a new bitcoin transaction input with the provided previous output point and signature script with a default sequence of MaxTxInSequenceNum.

func (*ExtendedTxIn) SerializeSize ΒΆ

func (t *ExtendedTxIn) SerializeSize() int

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

type FilterType ΒΆ

type FilterType uint8

FilterType is used to represent a filter type.

const (
	// GCSFilterRegular is the regular filter type.
	GCSFilterRegular FilterType = iota
)

type InvType ΒΆ

type InvType uint32

InvType represents the allowed types of inventory vectors. See InvVect.

const (
	InvTypeError         InvType = 0
	InvTypeTx            InvType = 1
	InvTypeBlock         InvType = 2
	InvTypeFilteredBlock InvType = 3
)

These constants define the various supported inventory vector types.

func (InvType) String ΒΆ

func (invtype InvType) String() string

String returns the InvType in human-readable form.

type InvVect ΒΆ

type InvVect struct {
	Type InvType        // Type of data
	Hash chainhash.Hash // Hash of the data
}

InvVect defines a bitcoin inventory vector which is used to describe data, as specified by the Type field, that a peer wants, has, or does not have to another peer.

func NewInvVect ΒΆ

func NewInvVect(typ InvType, hash *chainhash.Hash) *InvVect

NewInvVect returns a new InvVect using the provided type and hash.

type Message ΒΆ

type Message interface {
	Bsvdecode(r io.Reader, val uint32, enc MessageEncoding) error
	BsvEncode(w io.Writer, val uint32, enc MessageEncoding) error
	Command() string
	MaxPayloadLength(val uint32) uint64
}

Message is an interface that describes a bitcoin message. A type that implements Message has complete control over the representation of its data and may therefore contain additional or fewer fields than those which are used directly in the protocol encoded message.

func ReadMessage ΒΆ

func ReadMessage(r io.Reader, pver uint32, bsvnet BitcoinNet) (Message, []byte, error)

ReadMessage reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the parsed Message and raw bytes which comprise the message. This function only differs from ReadMessageN in that it doesn't return the number of bytes read. This function is mainly provided for backwards compatibility with the original API, but it's also useful for callers that don't care about byte counts.

func ReadMessageN ΒΆ

func ReadMessageN(r io.Reader, pver uint32, bsvnet BitcoinNet) (int, Message, []byte, error)

ReadMessageN reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessage except it also returns the number of bytes read.

func ReadMessageWithEncodingN ΒΆ

func ReadMessageWithEncodingN(r io.Reader, pver uint32, bsvnet BitcoinNet, enc MessageEncoding) (int, Message, []byte, error)

ReadMessageWithEncodingN reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessageN except it allows the caller to specify which message encoding is to consult when decoding wire messages.

type MessageEncoding ΒΆ

type MessageEncoding uint32

MessageEncoding represents the wire message encoding format to be used.

const (
	// BaseEncoding encodes all messages in the default format specified
	// for the Bitcoin wire protocol.
	BaseEncoding MessageEncoding = 1 << iota
)

type MessageError ΒΆ

type MessageError struct {
	Func        string // Function name
	Description string // Human readable description of the issue
}

MessageError describes an issue with a message. An example of some potential issues are messages from the wrong bitcoin network, invalid commands, mismatched checksums, and exceeding max payloads.

This provides a mechanism for the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that resulted from malformed messages.

func (*MessageError) Error ΒΆ

func (e *MessageError) Error() string

Error satisfies the error interface and prints human-readable errors.

type MsgAddr ΒΆ

type MsgAddr struct {
	AddrList []*NetAddress
}

MsgAddr implements the Message interface and represents a Bitcoin addr message. It is used to provide a list of known active peers on the network. An active peer is considered one that has transmitted a message within the last 3 hours. Nodes which have not transmitted in that time frame should be forgotten. Each message is limited to a maximum number of addresses, which is currently 1000. As a result, multiple messages must be used to relay the full list.

Use the AddAddress function to build up the list of known addresses when sending an addr message to another peer.

func NewMsgAddr ΒΆ

func NewMsgAddr() *MsgAddr

NewMsgAddr returns a new bitcoin addr message that conforms to the Message interface. See MsgAddr for details.

func (*MsgAddr) AddAddress ΒΆ

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

AddAddress adds a known active peer to the message.

func (*MsgAddr) AddAddresses ΒΆ

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

AddAddresses adds multiple known active peers to the message.

func (*MsgAddr) BsvEncode ΒΆ

func (msg *MsgAddr) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgAddr) Bsvdecode ΒΆ

func (msg *MsgAddr) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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 ΒΆ

func (msg *MsgAddr) Command() string

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

func (*MsgAddr) MaxPayloadLength ΒΆ

func (msg *MsgAddr) MaxPayloadLength(pver uint32) uint64

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

type MsgAuthch ΒΆ

type MsgAuthch struct {
	Version   int32
	Length    uint32
	Challenge []byte
}

MsgAuthch authentication handshake message

func NewMsgAuthch ΒΆ

func NewMsgAuthch(message string) *MsgAuthch

NewMsgAuthch returns a new auth challenge message

func (*MsgAuthch) BsvEncode ΒΆ

func (msg *MsgAuthch) BsvEncode(w io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgAuthch) Bsvdecode ΒΆ

func (msg *MsgAuthch) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgAuthch) Command ΒΆ

func (msg *MsgAuthch) Command() string

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

func (*MsgAuthch) MaxPayloadLength ΒΆ

func (msg *MsgAuthch) MaxPayloadLength(_ uint32) uint64

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

type MsgAuthresp ΒΆ

type MsgAuthresp struct {
	PublicKeyLength uint32
	PublicKey       []byte
	ClientNonce     uint64
	SignatureLength uint32
	Signature       []byte
}

MsgAuthresp authentication response message

func NewMsgAuthresp ΒΆ

func NewMsgAuthresp(publickKey, signature []byte) *MsgAuthresp

NewMsgAuthresp returns a new auth challenge message

func (*MsgAuthresp) BsvEncode ΒΆ

func (msg *MsgAuthresp) BsvEncode(w io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgAuthresp) Bsvdecode ΒΆ

func (msg *MsgAuthresp) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgAuthresp) Command ΒΆ

func (msg *MsgAuthresp) Command() string

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

func (*MsgAuthresp) MaxPayloadLength ΒΆ

func (msg *MsgAuthresp) MaxPayloadLength(_ uint32) uint64

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

type MsgBlock ΒΆ

type MsgBlock struct {
	Header       BlockHeader
	Transactions []*MsgTx
}

MsgBlock implements the Message interface and represents a bitcoin block message. It is used to deliver block and transaction information in response to a getdata message (MsgGetData) for a given block hash.

func NewMsgBlock ΒΆ

func NewMsgBlock(blockHeader *BlockHeader) *MsgBlock

NewMsgBlock returns a new bitcoin block message that conforms to the Message interface. See MsgBlock for details.

func (*MsgBlock) AddTransaction ΒΆ

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

AddTransaction adds a transaction to the message.

func (*MsgBlock) BlockHash ΒΆ

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

BlockHash computes the block identifier hash for this block.

func (*MsgBlock) BsvEncode ΒΆ

func (msg *MsgBlock) BsvEncode(w io.Writer, pver uint32, enc MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation. See Serialize for encoding blocks to be stored to disk, such as in a database, as opposed to encoding blocks for the wire.

func (*MsgBlock) Bsvdecode ΒΆ

func (msg *MsgBlock) Bsvdecode(r io.Reader, pver uint32, enc MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation. See Deserialize for decoding blocks stored to disk, such as in a database, as opposed to decoding blocks from the wire.

func (*MsgBlock) ClearTransactions ΒΆ

func (msg *MsgBlock) ClearTransactions()

ClearTransactions removes all transactions from the message.

func (*MsgBlock) Command ΒΆ

func (msg *MsgBlock) Command() string

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

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 Bsvdecode in that Bsvdecode decodes from the bitcoin wire protocol as it was sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored block at all. As of the time this comment was written, the encoded block is the same in both instances, but there is a distinct difference and separating the two allows the API to be flexible enough to deal with changes.

func (*MsgBlock) 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) MaxPayloadLength ΒΆ

func (msg *MsgBlock) MaxPayloadLength(_ uint32) uint64

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

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 BsvEncode in that BsvEncode encodes the block to the bitcoin wire protocol 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 ΒΆ

func (msg *MsgBlock) SerializeSize() int

SerializeSize returns the number of bytes it would take to serialize the block, factoring in any witness data within transaction.

func (*MsgBlock) TxHashes ΒΆ

func (msg *MsgBlock) TxHashes() ([]chainhash.Hash, error)

TxHashes returns a slice of hashes of all the transactions in this block.

type MsgCFCheckpt ΒΆ

type MsgCFCheckpt struct {
	FilterType    FilterType
	StopHash      chainhash.Hash
	FilterHeaders []*chainhash.Hash
}

MsgCFCheckpt implements the Message interface and represents a bitcoin cfcheckpt message. It is used to deliver committed filter header information in response to a getcfcheckpt message (MsgGetCFCheckpt). See MsgGetCFCheckpt for details on requesting the headers.

func NewMsgCFCheckpt ΒΆ

func NewMsgCFCheckpt(filterType FilterType, stopHash *chainhash.Hash,
	headersCount int,
) *MsgCFCheckpt

NewMsgCFCheckpt returns a new bitcoin cfheaders message that conforms to the Message interface. See MsgCFCheckpt for details.

func (*MsgCFCheckpt) AddCFHeader ΒΆ

func (msg *MsgCFCheckpt) AddCFHeader(header *chainhash.Hash) error

AddCFHeader adds a new committed filter header to the message.

func (*MsgCFCheckpt) BsvEncode ΒΆ

func (msg *MsgCFCheckpt) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgCFCheckpt) Bsvdecode ΒΆ

func (msg *MsgCFCheckpt) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgCFCheckpt) Command ΒΆ

func (msg *MsgCFCheckpt) Command() string

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

func (*MsgCFCheckpt) Deserialize ΒΆ

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

Deserialize decodes a filter header from r into the receiver using a format that is suitable for long-term storage such as a database. This function differs from Bsvdecode in that Bsvdecode decodes from the bitcoin wire protocol as it was sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored filter header at all. As of the time this comment was written, the encoded filter header 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 (*MsgCFCheckpt) MaxPayloadLength ΒΆ

func (msg *MsgCFCheckpt) MaxPayloadLength(_ uint32) uint64

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

type MsgCFHeaders ΒΆ

type MsgCFHeaders struct {
	FilterType       FilterType
	StopHash         chainhash.Hash
	PrevFilterHeader chainhash.Hash
	FilterHashes     []*chainhash.Hash
}

MsgCFHeaders implements the Message interface and represents a bitcoin cfheaders message. It is used to deliver committed filter header information in response to a getcfheaders message (MsgGetCFHeaders). The maximum number of committed filter headers per message is currently 2000. See MsgGetCFHeaders for details on requesting the headers.

func NewMsgCFHeaders ΒΆ

func NewMsgCFHeaders() *MsgCFHeaders

NewMsgCFHeaders returns a new bitcoin cfheaders message that conforms to the Message interface. See MsgCFHeaders for details.

func (*MsgCFHeaders) AddCFHash ΒΆ

func (msg *MsgCFHeaders) AddCFHash(hash *chainhash.Hash) error

AddCFHash adds a new filter hash to the message.

func (*MsgCFHeaders) BsvEncode ΒΆ

func (msg *MsgCFHeaders) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgCFHeaders) Bsvdecode ΒΆ

func (msg *MsgCFHeaders) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgCFHeaders) Command ΒΆ

func (msg *MsgCFHeaders) Command() string

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

func (*MsgCFHeaders) Deserialize ΒΆ

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

Deserialize decodes a filter header from r into the receiver using a format that is suitable for long-term storage such as a database. This function differs from Bsvdecode in that Bsvdecode decodes from the bitcoin wire protocol as it was sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored filter header at all. As of the time this comment was written, the encoded filter header 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 (*MsgCFHeaders) MaxPayloadLength ΒΆ

func (msg *MsgCFHeaders) MaxPayloadLength(_ uint32) uint64

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

type MsgCFilter ΒΆ

type MsgCFilter struct {
	FilterType FilterType
	BlockHash  chainhash.Hash
	Data       []byte
}

MsgCFilter implements the Message interface and represents a bitcoin cfilter message. It is used to deliver a committed filter in response to a getcfilters (MsgGetCFilters) message.

func NewMsgCFilter ΒΆ

func NewMsgCFilter(filterType FilterType, blockHash *chainhash.Hash,
	data []byte,
) *MsgCFilter

NewMsgCFilter returns a new bitcoin cfilter message that conforms to the Message interface. See MsgCFilter for details.

func (*MsgCFilter) BsvEncode ΒΆ

func (msg *MsgCFilter) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgCFilter) Bsvdecode ΒΆ

func (msg *MsgCFilter) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgCFilter) Command ΒΆ

func (msg *MsgCFilter) Command() string

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

func (*MsgCFilter) Deserialize ΒΆ

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

Deserialize decodes a filter from r into the receiver using a format that is suitable for long-term storage such as a database. This function differs from Bsvdecode in that Bsvdecode decodes from the bitcoin wire protocol as it was sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored filter at all. As of the time this comment was written, the encoded filter 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 (*MsgCFilter) MaxPayloadLength ΒΆ

func (msg *MsgCFilter) MaxPayloadLength(_ uint32) uint64

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

type MsgExtMsg ΒΆ

type MsgExtMsg struct {
	NumberOfFields       uint64 // numberOfFields is set to 1, increment if new properties are added
	MaxRecvPayloadLength uint64
}

MsgExtMsg implements the Message interface and represents a bitcoin extmsg message.

func NewMsgExtMsg ΒΆ

func NewMsgExtMsg(maxRecvPayloadLength uint64) *MsgExtMsg

NewMsgExtMsg returns a new bitcoin feefilter message that conforms to the Message interface. See MsgFeeFilter for details.

func (*MsgExtMsg) BsvEncode ΒΆ

func (msg *MsgExtMsg) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgExtMsg) Bsvdecode ΒΆ

func (msg *MsgExtMsg) Bsvdecode(_ io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgExtMsg) Command ΒΆ

func (msg *MsgExtMsg) Command() string

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

func (*MsgExtMsg) MaxPayloadLength ΒΆ

func (msg *MsgExtMsg) MaxPayloadLength(_ uint32) uint64

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

type MsgExtendedTx ΒΆ

type MsgExtendedTx struct {
	Version  int32
	TxIn     []*ExtendedTxIn
	TxOut    []*TxOut
	LockTime uint32
}

MsgExtendedTx implements the Message interface and represents a bitcoin 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 NewMsgExtendedTx ΒΆ

func NewMsgExtendedTx(version int32) *MsgExtendedTx

NewMsgExtendedTx returns a new extended bitcoin 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 the future.

func (*MsgExtendedTx) AddTxIn ΒΆ

func (msg *MsgExtendedTx) AddTxIn(ti *ExtendedTxIn)

AddTxIn adds a transaction input to the message.

func (*MsgExtendedTx) AddTxOut ΒΆ

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

AddTxOut adds a transaction output to the message.

func (*MsgExtendedTx) BsvEncode ΒΆ

func (msg *MsgExtendedTx) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin 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 (*MsgExtendedTx) Bsvdecode ΒΆ

func (msg *MsgExtendedTx) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin 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 (*MsgExtendedTx) Command ΒΆ

func (msg *MsgExtendedTx) Command() string

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

func (*MsgExtendedTx) Copy ΒΆ

func (msg *MsgExtendedTx) Copy() *MsgTx

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

func (*MsgExtendedTx) Deserialize ΒΆ

func (msg *MsgExtendedTx) 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 Bsvdecode in that Bsvdecode decodes from the bitcoin wire protocol as it was sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored 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 (*MsgExtendedTx) MaxPayloadLength ΒΆ

func (msg *MsgExtendedTx) MaxPayloadLength(_ uint32) uint64

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

func (*MsgExtendedTx) PkScriptLocs ΒΆ

func (msg *MsgExtendedTx) PkScriptLocs() []int

PkScriptLocs returns a slice containing the start of each public key script within the raw-serialized transaction. The caller can easily get the length of each script by using len on the script available via the appropriate transaction output entry.

func (*MsgExtendedTx) Serialize ΒΆ

func (msg *MsgExtendedTx) 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 BsvEncode in that BsvEncode encodes the transaction to the bitcoin wire protocol 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 (*MsgExtendedTx) SerializeSize ΒΆ

func (msg *MsgExtendedTx) SerializeSize() int

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

transaction.

func (*MsgExtendedTx) TxHash ΒΆ

func (msg *MsgExtendedTx) TxHash() chainhash.Hash

TxHash generates the Hash for the transaction.

type MsgFeeFilter ΒΆ

type MsgFeeFilter struct {
	MinFee int64
}

MsgFeeFilter implements the Message interface and represents a bitcoin feefilter message. It is used to request the receiving peer does not announce any transactions below the specified minimum fee rate.

This message was not added until protocol versions starting with FeeFilterVersion.

func NewMsgFeeFilter ΒΆ

func NewMsgFeeFilter(minFee int64) *MsgFeeFilter

NewMsgFeeFilter returns a new bitcoin feefilter message that conforms to the Message interface. See MsgFeeFilter for details.

func (*MsgFeeFilter) BsvEncode ΒΆ

func (msg *MsgFeeFilter) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFeeFilter) Bsvdecode ΒΆ

func (msg *MsgFeeFilter) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgFeeFilter) Command ΒΆ

func (msg *MsgFeeFilter) Command() string

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

func (*MsgFeeFilter) MaxPayloadLength ΒΆ

func (msg *MsgFeeFilter) MaxPayloadLength(_ uint32) uint64

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

type MsgFilterAdd ΒΆ

type MsgFilterAdd struct {
	Data []byte
}

MsgFilterAdd implements the Message interface and represents a bitcoin filteradd message. It is used to add a data element to an existing Bloom filter.

This message was not added until protocol version BIP0037Version.

func NewMsgFilterAdd ΒΆ

func NewMsgFilterAdd(data []byte) *MsgFilterAdd

NewMsgFilterAdd returns a new bitcoin filteradd message that conforms to the Message interface. See MsgFilterAdd for details.

func (*MsgFilterAdd) BsvEncode ΒΆ

func (msg *MsgFilterAdd) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFilterAdd) Bsvdecode ΒΆ

func (msg *MsgFilterAdd) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgFilterClear ΒΆ

type MsgFilterClear struct{}

MsgFilterClear implements the Message interface and represents a bitcoin filterclear message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version and has no payload.

func NewMsgFilterClear ΒΆ

func NewMsgFilterClear() *MsgFilterClear

NewMsgFilterClear returns a new bitcoin filterclear message that conforms to the Message interface. See MsgFilterClear for details.

func (*MsgFilterClear) BsvEncode ΒΆ

func (msg *MsgFilterClear) BsvEncode(_ io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFilterClear) Bsvdecode ΒΆ

func (msg *MsgFilterClear) Bsvdecode(_ io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgFilterLoad ΒΆ

type MsgFilterLoad struct {
	Filter    []byte
	HashFuncs uint32
	Tweak     uint32
	Flags     BloomUpdateType
}

MsgFilterLoad implements the Message interface and represents a bitcoin filterload message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version.

func NewMsgFilterLoad ΒΆ

func NewMsgFilterLoad(filter []byte, hashFuncs, tweak uint32, flags BloomUpdateType) *MsgFilterLoad

NewMsgFilterLoad returns a new bitcoin filterload message that conforms to the Message interface. See MsgFilterLoad for details.

func (*MsgFilterLoad) BsvEncode ΒΆ

func (msg *MsgFilterLoad) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgFilterLoad) Bsvdecode ΒΆ

func (msg *MsgFilterLoad) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgGetAddr ΒΆ

type MsgGetAddr struct{}

MsgGetAddr implements the Message interface and represents a bitcoin getaddr message. It is used to request a list of known active peers on the network from a peer to help identify potential nodes. The list is returned via one or more addr messages (MsgAddr).

This message has no payload.

func NewMsgGetAddr ΒΆ

func NewMsgGetAddr() *MsgGetAddr

NewMsgGetAddr returns a new bitcoin getaddr message that conforms to the Message interface. See MsgGetAddr for details.

func (*MsgGetAddr) BsvEncode ΒΆ

func (msg *MsgGetAddr) BsvEncode(_ io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetAddr) Bsvdecode ΒΆ

func (msg *MsgGetAddr) Bsvdecode(_ io.Reader, _ uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgGetBlocks ΒΆ

type MsgGetBlocks struct {
	ProtocolVersion    uint32
	BlockLocatorHashes []*chainhash.Hash
	HashStop           chainhash.Hash
}

MsgGetBlocks implements the Message interface and represents a bitcoin getblocks message. It is used to request a list of blocks starting after the last known hash in the slice of block locator hashes. The list is returned via an inv message (MsgInv) and is limited by a specific hash to stop at or the maximum number of blocks per message, which is currently 500.

Set the HashStop field to the hash at which to stop and use AddBlockLocatorHash to build up the list of block locator hashes.

The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. To keep the list of locator hashes to a reasonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.

func NewMsgGetBlocks ΒΆ

func NewMsgGetBlocks(hashStop *chainhash.Hash) *MsgGetBlocks

NewMsgGetBlocks returns a new bitcoin getblocks message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgGetBlocks) AddBlockLocatorHash ΒΆ

func (msg *MsgGetBlocks) AddBlockLocatorHash(hash *chainhash.Hash) error

AddBlockLocatorHash adds a new block locator hash to the message.

func (*MsgGetBlocks) BsvEncode ΒΆ

func (msg *MsgGetBlocks) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetBlocks) Bsvdecode ΒΆ

func (msg *MsgGetBlocks) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgGetCFCheckpt ΒΆ

type MsgGetCFCheckpt struct {
	FilterType FilterType
	StopHash   chainhash.Hash
}

MsgGetCFCheckpt is a request for filter headers at evenly spaced intervals throughout the blockchain history. It allows setting the FilterType field to get headers in the chain of basic (0x00) or extended (0x01) headers.

func NewMsgGetCFCheckpt ΒΆ

func NewMsgGetCFCheckpt(filterType FilterType, stopHash *chainhash.Hash) *MsgGetCFCheckpt

NewMsgGetCFCheckpt returns a new bitcoin getcfcheckpt message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgGetCFCheckpt) BsvEncode ΒΆ

func (msg *MsgGetCFCheckpt) BsvEncode(w io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetCFCheckpt) Bsvdecode ΒΆ

func (msg *MsgGetCFCheckpt) Bsvdecode(r io.Reader, _ uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetCFCheckpt) Command ΒΆ

func (msg *MsgGetCFCheckpt) Command() string

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

func (*MsgGetCFCheckpt) MaxPayloadLength ΒΆ

func (msg *MsgGetCFCheckpt) MaxPayloadLength(_ uint32) uint64

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

type MsgGetCFHeaders ΒΆ

type MsgGetCFHeaders struct {
	FilterType  FilterType
	StartHeight uint32
	StopHash    chainhash.Hash
}

MsgGetCFHeaders is a message similar to MsgGetHeaders, but for committed filter headers. It allows setting the FilterType field to get headers in the chain of basic (0x00) or extended (0x01) headers.

func NewMsgGetCFHeaders ΒΆ

func NewMsgGetCFHeaders(filterType FilterType, startHeight uint32,
	stopHash *chainhash.Hash,
) *MsgGetCFHeaders

NewMsgGetCFHeaders returns a new bitcoin getcfheader message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgGetCFHeaders) BsvEncode ΒΆ

func (msg *MsgGetCFHeaders) BsvEncode(w io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetCFHeaders) Bsvdecode ΒΆ

func (msg *MsgGetCFHeaders) Bsvdecode(r io.Reader, _ uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetCFHeaders) Command ΒΆ

func (msg *MsgGetCFHeaders) Command() string

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

func (*MsgGetCFHeaders) MaxPayloadLength ΒΆ

func (msg *MsgGetCFHeaders) MaxPayloadLength(_ uint32) uint64

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

type MsgGetCFilters ΒΆ

type MsgGetCFilters struct {
	FilterType  FilterType
	StartHeight uint32
	StopHash    chainhash.Hash
}

MsgGetCFilters implements the Message interface and represents a bitcoin getcfilters message. It is used to request committed filters for a range of blocks.

func NewMsgGetCFilters ΒΆ

func NewMsgGetCFilters(filterType FilterType, startHeight uint32,
	stopHash *chainhash.Hash,
) *MsgGetCFilters

NewMsgGetCFilters returns a new bitcoin getcfilters message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgGetCFilters) BsvEncode ΒΆ

func (msg *MsgGetCFilters) BsvEncode(w io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetCFilters) Bsvdecode ΒΆ

func (msg *MsgGetCFilters) Bsvdecode(r io.Reader, _ uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgGetCFilters) Command ΒΆ

func (msg *MsgGetCFilters) Command() string

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

func (*MsgGetCFilters) MaxPayloadLength ΒΆ

func (msg *MsgGetCFilters) MaxPayloadLength(_ uint32) uint64

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

type MsgGetData ΒΆ

type MsgGetData struct {
	InvList []*InvVect
}

MsgGetData implements the Message interface and represents a bitcoin getdata message. It is used to request data such as blocks and transactions from another peer. It should be used in response to the inv (MsgInv) message to request the actual data referenced by each inventory vector the receiving peer doesn't already have. Each message is limited to a maximum number of inventory vectors, which is currently 50,000. As a result, multiple messages must be used to request larger amounts of data.

Use the AddInvVect function to build up the list of inventory vectors when sending a getdata message to another peer.

func NewMsgGetData ΒΆ

func NewMsgGetData() *MsgGetData

NewMsgGetData returns a new bitcoin getdata message that conforms to the Message interface. See MsgGetData for details.

func NewMsgGetDataSizeHint ΒΆ

func NewMsgGetDataSizeHint(sizeHint uint) *MsgGetData

NewMsgGetDataSizeHint returns a new bitcoin getdata message that conforms to the Message interface. See MsgGetData for details. This function differs from NewMsgGetData in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large numbers 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) BsvEncode ΒΆ

func (msg *MsgGetData) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetData) Bsvdecode ΒΆ

func (msg *MsgGetData) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgGetHeaders ΒΆ

type MsgGetHeaders struct {
	ProtocolVersion    uint32
	BlockLocatorHashes []*chainhash.Hash
	HashStop           chainhash.Hash
}

MsgGetHeaders implements the Message interface and represents a bitcoin getheaders message. It is used to request a list of block headers for blocks starting after the last known hash in the slice of block locator hashes. The list is returned via a headers message (MsgHeaders) and is limited by a specific hash to stop at or the maximum number of block headers per message, which is currently 2000.

Set the HashStop field to the hash at which to stop and use AddBlockLocatorHash to build up the list of block locator hashes.

The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. To keep the list of locator hashes to a reasonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.

func NewMsgGetHeaders ΒΆ

func NewMsgGetHeaders() *MsgGetHeaders

NewMsgGetHeaders returns a new bitcoin getheaders message that conforms to the Message interface. See MsgGetHeaders for details.

func (*MsgGetHeaders) AddBlockLocatorHash ΒΆ

func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *chainhash.Hash) error

AddBlockLocatorHash adds a new block locator hash to the message.

func (*MsgGetHeaders) BsvEncode ΒΆ

func (msg *MsgGetHeaders) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgGetHeaders) Bsvdecode ΒΆ

func (msg *MsgGetHeaders) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgHeaders ΒΆ

type MsgHeaders struct {
	Headers []*BlockHeader
}

MsgHeaders implements the Message interface and represents a bitcoin headers message. It is used to deliver block header information in response to a getheaders message (MsgGetHeaders). The maximum number of block headers per message is currently 2000. See MsgGetHeaders for details on requesting the headers.

func NewMsgHeaders ΒΆ

func NewMsgHeaders() *MsgHeaders

NewMsgHeaders returns a new bitcoin headers message that conforms to the Message interface. See MsgHeaders for details.

func (*MsgHeaders) AddBlockHeader ΒΆ

func (msg *MsgHeaders) AddBlockHeader(bh *BlockHeader) error

AddBlockHeader adds a new block header to the message.

func (*MsgHeaders) BsvEncode ΒΆ

func (msg *MsgHeaders) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgHeaders) Bsvdecode ΒΆ

func (msg *MsgHeaders) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgInv ΒΆ

type MsgInv struct {
	InvList []*InvVect
}

MsgInv implements the Message interface and represents a bitcoin inv message. It is used to advertise a peer's known data such as blocks and transactions through inventory vectors. It may be sent unsolicited to inform other peers of the data or in response to a getblocks message (MsgGetBlocks). Each message is limited to a maximum number of inventory vectors, which is currently 50,000.

Use the AddInvVect function to build up the list of inventory vectors when sending an inv message to another peer.

func NewMsgInv ΒΆ

func NewMsgInv() *MsgInv

NewMsgInv returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details.

func NewMsgInvSizeHint ΒΆ

func NewMsgInvSizeHint(sizeHint uint) *MsgInv

NewMsgInvSizeHint returns a new bitcoin inv message that conforms to the Message interface. See MsgInv for details. This function differs from NewMsgInv in that it allows a default allocation size for the backing array which houses the inventory vector list. This allows callers who know in advance how large the inventory list will grow to avoid the overhead of growing the internal backing array several times when appending large numbers 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 ΒΆ

func (msg *MsgInv) AddInvVect(iv *InvVect) error

AddInvVect adds an inventory vector to the message.

func (*MsgInv) BsvEncode ΒΆ

func (msg *MsgInv) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgInv) Bsvdecode ΒΆ

func (msg *MsgInv) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgInv) Command ΒΆ

func (msg *MsgInv) Command() string

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

func (*MsgInv) MaxPayloadLength ΒΆ

func (msg *MsgInv) MaxPayloadLength(_ uint32) uint64

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

type MsgMemPool ΒΆ

type MsgMemPool struct{}

MsgMemPool implements the Message interface and represents a bitcoin mempool message. It is used to request a list of transactions still in the active memory pool of a relay.

This message has no payload and was not added until protocol versions starting with BIP0035Version.

func NewMsgMemPool ΒΆ

func NewMsgMemPool() *MsgMemPool

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

func (*MsgMemPool) BsvEncode ΒΆ

func (msg *MsgMemPool) BsvEncode(_ io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgMemPool) Bsvdecode ΒΆ

func (msg *MsgMemPool) Bsvdecode(_ io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgMerkleBlock ΒΆ

type MsgMerkleBlock struct {
	Header       BlockHeader
	Transactions uint32
	Hashes       []*chainhash.Hash
	Flags        []byte
}

MsgMerkleBlock implements the Message interface and represents a bitcoin merkleblock message which is used to reset a Bloom filter.

This message was not added until protocol version BIP0037Version.

func NewMsgMerkleBlock ΒΆ

func NewMsgMerkleBlock(bh *BlockHeader) *MsgMerkleBlock

NewMsgMerkleBlock returns a new bitcoin merkleblock message that conforms to the Message interface. See MsgMerkleBlock for details.

func (*MsgMerkleBlock) AddTxHash ΒΆ

func (msg *MsgMerkleBlock) AddTxHash(hash *chainhash.Hash) error

AddTxHash adds a new transaction hash to the message.

func (*MsgMerkleBlock) BsvEncode ΒΆ

func (msg *MsgMerkleBlock) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgMerkleBlock) Bsvdecode ΒΆ

func (msg *MsgMerkleBlock) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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

type MsgNotFound ΒΆ

type MsgNotFound struct {
	InvList []*InvVect
}

MsgNotFound defines a bitcoin notfound message which is sent in response to a getdata message if any of the requested data is not available on the peer. Each message is limited to a maximum number of inventory vectors, which is currently 50,000.

Use the AddInvVect function to build up the list of inventory vectors when sending a notfound message to another peer.

func NewMsgNotFound ΒΆ

func NewMsgNotFound() *MsgNotFound

NewMsgNotFound returns a new bitcoin notfound message that conforms to the Message interface. See MsgNotFound for details.

func (*MsgNotFound) AddInvVect ΒΆ

func (msg *MsgNotFound) AddInvVect(iv *InvVect) error

AddInvVect adds an inventory vector to the message.

func (*MsgNotFound) BsvEncode ΒΆ

func (msg *MsgNotFound) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgNotFound) Bsvdecode ΒΆ

func (msg *MsgNotFound) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. 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(_ uint32) uint64

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 a message that is used to identify
	// a specific ping message.
	Nonce uint64
}

MsgPing implements the Message interface and represents a bitcoin ping message.

For versions BIP0031Version and earlier, it is used primarily to confirm that a connection is still valid. A transmission error is typically interpreted as a closed connection and that the peer should be removed. For versions AFTER BIP0031Version it contains an identifier which can be returned in the pong message to determine network timing.

The payload for this message just consists of a nonce used for identifying it later.

func NewMsgPing ΒΆ

func NewMsgPing(nonce uint64) *MsgPing

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

func (*MsgPing) BsvEncode ΒΆ

func (msg *MsgPing) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgPing) Bsvdecode ΒΆ

func (msg *MsgPing) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgPing) Command ΒΆ

func (msg *MsgPing) Command() string

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

func (*MsgPing) MaxPayloadLength ΒΆ

func (msg *MsgPing) MaxPayloadLength(pver uint32) uint64

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 a message that is used to identify
	// a specific ping message.
	Nonce uint64
}

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

This message was not added until protocol versions AFTER BIP0031Version.

func NewMsgPong ΒΆ

func NewMsgPong(nonce uint64) *MsgPong

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

func (*MsgPong) BsvEncode ΒΆ

func (msg *MsgPong) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgPong) Bsvdecode ΒΆ

func (msg *MsgPong) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgPong) Command ΒΆ

func (msg *MsgPong) Command() string

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

func (*MsgPong) MaxPayloadLength ΒΆ

func (msg *MsgPong) MaxPayloadLength(pver uint32) uint64

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

type MsgProtoconf ΒΆ

type MsgProtoconf struct {
	NumberOfFields       uint64
	MaxRecvPayloadLength uint32
	StreamPolicies       []string
}

MsgProtoconf is a message that is sent by the server to the client

func NewMsgProtoconf ΒΆ

func NewMsgProtoconf(maxRecvPayloadLength uint32, allowBlockPriority bool) *MsgProtoconf

NewMsgProtoconf returns a new bitcoin protoconf message that conforms to the Message interface. See MsgFeeFilter for details.

func (*MsgProtoconf) BsvEncode ΒΆ

func (msg *MsgProtoconf) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgProtoconf) Bsvdecode ΒΆ

func (msg *MsgProtoconf) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgProtoconf) Command ΒΆ

func (msg *MsgProtoconf) Command() string

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

func (*MsgProtoconf) MaxPayloadLength ΒΆ

func (msg *MsgProtoconf) MaxPayloadLength(_ uint32) uint64

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
	//  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 an uint8 on the wire.
	Code RejectCode

	// Reason is a human-readable string with specific details (over and
	// above the reject code) about why the command was rejected.
	Reason string

	// Hash identifies a specific block or transaction that was rejected
	// and therefore only applies the MsgBlock and MsgTx messages.
	Hash chainhash.Hash
}

MsgReject implements the Message interface and represents a bitcoin reject message.

This message was not added until protocol version RejectVersion.

func NewMsgReject ΒΆ

func NewMsgReject(command string, code RejectCode, reason string) *MsgReject

NewMsgReject returns a new bitcoin reject a message that conforms to the Message interface. See MsgReject for details.

func (*MsgReject) BsvEncode ΒΆ

func (msg *MsgReject) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgReject) Bsvdecode ΒΆ

func (msg *MsgReject) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgReject) Command ΒΆ

func (msg *MsgReject) Command() string

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

func (*MsgReject) MaxPayloadLength ΒΆ

func (msg *MsgReject) MaxPayloadLength(pver uint32) uint64

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

type MsgSendHeaders ΒΆ

type MsgSendHeaders struct{}

MsgSendHeaders implements the Message interface and represents a bitcoin sendheaders message. It is used to request the peer send block headers rather than inventory vectors.

This message has no payload and was not added until protocol versions starting with SendHeadersVersion.

func NewMsgSendHeaders ΒΆ

func NewMsgSendHeaders() *MsgSendHeaders

NewMsgSendHeaders returns a new bitcoin sendheaders message that conforms to the Message interface. See MsgSendHeaders for details.

func (*MsgSendHeaders) BsvEncode ΒΆ

func (msg *MsgSendHeaders) BsvEncode(_ io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgSendHeaders) Bsvdecode ΒΆ

func (msg *MsgSendHeaders) Bsvdecode(_ io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgSendHeaders) Command ΒΆ

func (msg *MsgSendHeaders) Command() string

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

func (*MsgSendHeaders) MaxPayloadLength ΒΆ

func (msg *MsgSendHeaders) MaxPayloadLength(_ uint32) uint64

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

type MsgSendcmpct ΒΆ

type MsgSendcmpct struct {
	SendCmpct bool
	Version   uint64
}

MsgSendcmpct defines a bitcoin sendcmpct message which is used to negotiate the receipt of compact blocks. It was added in BIP0031.

func NewMsgSendcmpct ΒΆ

func NewMsgSendcmpct(sendcmpct bool) *MsgSendcmpct

NewMsgSendcmpct returns a new compact blocks negotiation message that conforms to the Message interface. See MsgSendcmpct for details.

func (*MsgSendcmpct) BsvEncode ΒΆ

func (msg *MsgSendcmpct) BsvEncode(w io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgSendcmpct) Bsvdecode ΒΆ

func (msg *MsgSendcmpct) Bsvdecode(r io.Reader, _ uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgSendcmpct) Command ΒΆ

func (msg *MsgSendcmpct) Command() string

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

func (*MsgSendcmpct) MaxPayloadLength ΒΆ

func (msg *MsgSendcmpct) MaxPayloadLength(_ uint32) uint64

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 {
	Version  int32
	TxIn     []*TxIn
	TxOut    []*TxOut
	LockTime uint32
}

MsgTx implements the Message interface and represents a bitcoin 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(version int32) *MsgTx

NewMsgTx returns a new bitcoin 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 the future.

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) BsvEncode ΒΆ

func (msg *MsgTx) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin 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) Bsvdecode ΒΆ

func (msg *MsgTx) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin 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) Command ΒΆ

func (msg *MsgTx) Command() string

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 Bsvdecode in that Bsvdecode decodes from the bitcoin wire protocol as it was sent across the network. The wire encoding can technically differ depending on the protocol version and doesn't even really need to match the format of a stored 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) MaxPayloadLength ΒΆ

func (msg *MsgTx) MaxPayloadLength(_ uint32) uint64

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

func (*MsgTx) PkScriptLocs ΒΆ

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

PkScriptLocs returns a slice containing the start of each public key script within the raw-serialized transaction. The caller can easily get 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 BsvEncode in that BsvEncode encodes the transaction to the bitcoin wire protocol 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 ΒΆ

func (msg *MsgTx) SerializeSize() int

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

transaction.

func (*MsgTx) TxHash ΒΆ

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

TxHash generates the Hash for the transaction.

type MsgVerAck ΒΆ

type MsgVerAck struct{}

MsgVerAck defines a bitcoin verack message which is used for a peer to acknowledge a version message (MsgVersion) after it has used the information to negotiate parameters. It implements the Message interface.

This message has no payload.

func NewMsgVerAck ΒΆ

func NewMsgVerAck() *MsgVerAck

NewMsgVerAck returns a new bitcoin verack message that conforms to the Message interface.

func (*MsgVerAck) BsvEncode ΒΆ

func (msg *MsgVerAck) BsvEncode(_ io.Writer, _ uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgVerAck) Bsvdecode ΒΆ

func (msg *MsgVerAck) Bsvdecode(_ io.Reader, _ uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface implementation.

func (*MsgVerAck) Command ΒΆ

func (msg *MsgVerAck) Command() string

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

func (*MsgVerAck) MaxPayloadLength ΒΆ

func (msg *MsgVerAck) MaxPayloadLength(_ uint32) uint64

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 a message that is used to detect self-connections.
	Nonce uint64

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

	// Last block seen by the generator of the version message.
	LastBlock int32

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

MsgVersion implements the Message interface and represents a bitcoin version message. It is used for a peer to advertise itself as soon as an outbound connection is made. The remote peer then uses this information along with its own to negotiate. The remote peer must then respond with a version message of its own containing the negotiated values followed by a verack message (MsgVerAck). This exchange must take place before any further communication is allowed to proceed.

func NewMsgVersion ΒΆ

func NewMsgVersion(me, you *NetAddress, nonce uint64,
	lastBlock int32,
) *MsgVersion

NewMsgVersion returns a new bitcoin version message that conforms to the Message interface using the passed parameters and defaults for the remaining fields.

func (*MsgVersion) AddService ΒΆ

func (msg *MsgVersion) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*MsgVersion) AddUserAgent ΒΆ

func (msg *MsgVersion) AddUserAgent(name, 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) BsvEncode ΒΆ

func (msg *MsgVersion) BsvEncode(w io.Writer, pver uint32, _ MessageEncoding) error

BsvEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface implementation.

func (*MsgVersion) Bsvdecode ΒΆ

func (msg *MsgVersion) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error

Bsvdecode decodes r using the bitcoin protocol encoding into the receiver. The version message is special in that the protocol version hasn't been negotiated yet. As a result, the pver field is ignored and any fields that are added in new versions are optional. This also means that r must be a *bytes.Buffer so the number of remaining bytes can be figured out.

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

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

type NetAddress ΒΆ

type NetAddress struct {
	// Last time the address was seen.  This is, unfortunately, encoded as a
	// uint32 on the wire and therefore is limited to 2106.  This field is
	// not present in the bitcoin version message (MsgVersion) nor was it
	// added until protocol version >= NetAddressTimeVersion.
	Timestamp time.Time

	// Bitfield which identifies the services supported by the address.
	Services ServiceFlag

	// IP address of the peer.
	IP net.IP

	// Port the peer is using.  This is encoded in big endian on the wire
	// which differs from most everything else.
	Port uint16
}

NetAddress defines information about a peer on the network including the time it was last seen, the services it supports, its IP address, and port.

func NewNetAddress ΒΆ

func NewNetAddress(addr *net.TCPAddr, services ServiceFlag) *NetAddress

NewNetAddress returns a new NetAddress using the provided TCP address and supported services with defaults for the remaining fields.

func NewNetAddressIPPort ΒΆ

func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress

NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and supported services with defaults for the remaining fields.

func NewNetAddressTimestamp ΒΆ

func NewNetAddressTimestamp(
	timestamp time.Time, services ServiceFlag, ip net.IP, port uint16,
) *NetAddress

NewNetAddressTimestamp returns a new NetAddress using the provided timestamp, IP, port, and supported services. The timestamp is rounded to single second precision.

func (*NetAddress) AddService ΒΆ

func (na *NetAddress) AddService(service ServiceFlag)

AddService adds service as a supported service by the peer generating the message.

func (*NetAddress) HasService ΒΆ

func (na *NetAddress) HasService(service ServiceFlag) bool

HasService returns whether the specified service is supported by the address.

type OutPoint ΒΆ

type OutPoint struct {
	Hash  chainhash.Hash
	Index uint32
}

OutPoint defines a bitcoin data type used to track previous transaction outputs.

func NewOutPoint ΒΆ

func NewOutPoint(hash *chainhash.Hash, index uint32) *OutPoint

NewOutPoint returns a new bitcoin 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 "hash:index".

type RejectCode ΒΆ

type RejectCode uint8

RejectCode represents a numeric value by which a remote peer indicates why a message was rejected.

const (
	RejectMalformed       RejectCode = 0x01
	RejectInvalid         RejectCode = 0x10
	RejectObsolete        RejectCode = 0x11
	RejectDuplicate       RejectCode = 0x12
	RejectNonstandard     RejectCode = 0x40
	RejectDust            RejectCode = 0x41
	RejectInsufficientFee RejectCode = 0x42
	RejectCheckpoint      RejectCode = 0x43
)

These constants define the various supported reject codes.

func (RejectCode) String ΒΆ

func (code RejectCode) String() string

String returns the RejectCode in human-readable form.

type ServiceFlag ΒΆ

type ServiceFlag uint64

ServiceFlag identifies services supported by a bitcoin 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

	// SFNodeWitness is a flag used to indicate a peer supports blocks
	// and transactions including witness data (BIP0144).
	SFNodeWitness

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

	// SFNodeBitcoinCash indicates a node is running on the Bitcoin (BSV)
	// network. Bitcoin Core peers should disconnect upon seeing this service bit.
	// Technically this is no longer needed as Bitcoin (BSV) has a different
	// network magic than Bitcoin Core so connections should not be possible.
	SFNodeBitcoinCash

	// SFNodeGraphene is a flag used to indicate a peer supports graphene block relay.
	SFNodeGraphene

	// SFNodeWeakBlocks is a flag used to indicate a peer supports the weak block protocol.
	SFNodeWeakBlocks

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

	// SFNodeXThinner is a placeholder for the xthinner block compression protocol being
	// developed by Johnathan Toomim.
	SFNodeXThinner

	// SFNodeNetworkLimited is used to indicate the node is a pruned node and may only
	// be capable of limited services. In particular it is only guaranteed to be able
	// to serve the last 288 blocks though it will respond to requests for earlier blocks
	// if it has them.
	SFNodeNetworkLimited
)

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         uint32
}

TxIn defines a bitcoin transaction input.

func NewTxIn ΒΆ

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

NewTxIn returns a new bitcoin transaction input with the provided previous outpointed 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

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    int64
	PkScript []byte
}

TxOut defines a bitcoin transaction output.

func NewTxOut ΒΆ

func NewTxOut(value int64, pkScript []byte) *TxOut

NewTxOut returns a new bitcoin 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

transaction output.

Directories ΒΆ

Path Synopsis
examples
read_message
Package main demonstrates how to read a bitcoin message from a bytes.Reader using the go-wire package.
Package main demonstrates how to read a bitcoin message from a bytes.Reader using the go-wire package.
write_message
Package main provides an example of how to write a bitcoin message using the go-wire package.
Package main provides an example of how to write a bitcoin message using the go-wire package.

Jump to

Keyboard shortcuts

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