msg

package
v0.0.0-...-25c57ca Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2018 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxAddressesCount = 1024
	MaxVarIntPayload  = 9
	MaxUserAgentLen   = 256
)
View Source
const (
	HeaderSize       = 80
	AllowedTimeDrift = 2 * 60 * 60
	MaxBlockSize     = 1 * 1000 * 1000
)
View Source
const (
	MaxInventoryMessage = 50000
	MaxInventoryPayload = 4 + HeaderSize
)
View Source
const (
	InventoryTypeError         protocol.InventoryType = 0
	InventoryTypeTx            protocol.InventoryType = 1
	InventoryTypeBlock         protocol.InventoryType = 2
	InventoryTypeFilteredBlock protocol.InventoryType = 3
)
View Source
const (
	CommandSize        = 12
	MaxRejectReasonLen = 250
	LockTimeTHreshold  = 5E8 // Tue Nov 5 00:53:20 1985 UTC
	SafeChars          = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@"
)
View Source
const (
	CommandVersion     = "version"
	CommandVersionAck  = "verack"
	CommandGetAddress  = "getaddr"
	CommandAddress     = "addr"
	CommandGetBlocks   = "getblocks"
	CommandInv         = "inv"
	CommandGetData     = "getdata"
	CommandNotFound    = "notfound"
	CommandBlock       = "block"
	CommandTx          = "tx"
	CommandGetHeaders  = "getheaders"
	CommandHeaders     = "headers"
	CommandPing        = "ping"
	CommandPong        = "pong"
	CommandAlert       = "alert"
	CommandMempool     = "mempool"
	CommandFilterAdd   = "filteradd"
	CommandFilterClear = "filterclear"
	CommandFilterLoad  = "filterrload"
	CommandMerkleBlock = "merkleblock"
	CommandReject      = "reject"
	CommandSendHeaders = "sendheaders"
)
View Source
const DefaultInventoryListAlloc = 1000
View Source
const MaxGetBlocksCount = 500
View Source
const (
	MessageHeaderSize = 24
)

Variables

View Source
var (
	RegisteredNets          = make(map[btcutil.BitcoinNet]struct{})
	PubKeyHashAddressIDs    = make(map[byte]struct{})
	ScriptHashAddressIDs    = make(map[byte]struct{})
	HDPrivateToPublicKeyIDs = make(map[[4]byte][]byte)
)
View Source
var ActiveNetParams = &MainNetParams
View Source
var GenesisBlock = BlockMessage{
	Block: &model.Block{
		Version:      1,
		PrevBlock:    "0000000000000000000000000000000000000000000000000000000000000000",
		MerkleRoot:   "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
		BlockTime:    time.Unix(0x495fab29, 0),
		Bits:         0x1d00ffff,
		Nonce:        0x7c2bac1d,
		Transactions: []*model.Tx{&GenesisCoinbasTx},
	},
}
View Source
var GenesisCoinbasTx = model.Tx{}
View Source
var GenesisHash = utils.Hash([utils.HashSize]byte{
	0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72,
	0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
	0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
	0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
})
View Source
var GenesisMerkleRoot = utils.Hash([utils.HashSize]byte{
	0x3b, 0xa3, 0xed, 0xfd, 0x7a, 0x7b, 0x12, 0xb2,
	0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61,
	0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32,
	0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a,
})
View Source
var MainNetParams = BitcoinParams{
	Name:        "mainnet",
	BitcoinNet:  btcutil.MainNet,
	DefaultPort: "8333",
	DNSSeeds: []btcutil.DNSSeed{
		{"seed.bitcoin.sipa.be", true},
		{"dnsseed.bluematt.me", true},
		{"seed.bitcoinstats.com", true},
		{"bitseed.xf2.org", true},
		{"seed.bitcoinstats.com", true},
		{"seed.bitnodes.io", false},
	},
	GenesisBlock:             &GenesisBlock,
	GenesisHash:              &GenesisHash,
	PowLimit:                 mainPowLimit,
	PowLimitBits:             GenesisBlock.Block.Bits,
	CoinbaseMaturity:         100,
	SubsidyReductionInterval: 210000,
	TargetTimespan:           time.Hour * 24 * 14,
	TargetTimePerBlock:       time.Minute * 10,
	RetargetAdjustmentFactor: 4,
	ReduceMinDifficulty:      false,
	MinDiffReductionTime:     0,
	GenerateSupported:        false,
	Checkpoints: []*model.Checkpoint{
		{11111, utils.HashFromString("0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")},
		{33333, utils.HashFromString("000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")},
		{74000, utils.HashFromString("0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")},
		{105000, utils.HashFromString("00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")},
		{134444, utils.HashFromString("00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")},
		{168000, utils.HashFromString("000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")},
		{193000, utils.HashFromString("000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")},
		{210000, utils.HashFromString("000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e")},
		{216116, utils.HashFromString("00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e")},
		{225430, utils.HashFromString("00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")},
		{250000, utils.HashFromString("000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")},
		{267300, utils.HashFromString("000000000000000a83fbd660e918f218bf37edd92b748ad940483c7c116179ac")},
		{279000, utils.HashFromString("0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")},
		{300255, utils.HashFromString("0000000000000000162804527c6e9b9f0563a280525f9d08c12041def0a0f3b2")},
		{319400, utils.HashFromString("000000000000000021c6052e9becade189495d1c539aa37c58917305fd15f13b")},
		{343185, utils.HashFromString("0000000000000000072b8bf361d01a6ba7d445dd024203fafc78768ed4368554")},
		{352940, utils.HashFromString("000000000000000010755df42dba556bb72be6a32f3ce0b6941ce4430152c9ff")},
		{382320, utils.HashFromString("00000000000000000a8dc6ed5b133d0eb2fd6af56203e4159789b092defd8ab2")},
	},

	BlockEnforceNumRequired: 750,
	BlockRejectNumRequired:  950,
	BlockUpgradeNumToCheck:  1000,

	RelayNonStdTxs:      false,
	PubKeyHashAddressID: 0x00,
	ScriptHashAddressID: 0x05,
	PrivatekeyID:        0x80,

	HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4},
	HDPublicKeyID:  [4]byte{0x04, 0x88, 0xb2, 0x1e},

	HDCoinType: 0,
}
View Source
var RegressionNetParams = BitcoinParams{
	Name:                     "regtest",
	BitcoinNet:               btcutil.TestNet,
	DefaultPort:              "18444",
	DNSSeeds:                 []btcutil.DNSSeed{},
	GenesisBlock:             &RegressionTestGenesisBlock,
	GenesisHash:              &RegressionTestGenesisHash,
	PowLimit:                 regressingPowLimit,
	PowLimitBits:             RegressionTestGenesisBlock.Block.Bits,
	CoinbaseMaturity:         100,
	SubsidyReductionInterval: 150,
	TargetTimespan:           time.Hour * 24 * 14,
	TargetTimePerBlock:       time.Minute * 10,
	RetargetAdjustmentFactor: 4,
	ReduceMinDifficulty:      true,
	MinDiffReductionTime:     time.Minute * 20,
	GenerateSupported:        true,
	Checkpoints:              nil,

	BlockEnforceNumRequired: 750,
	BlockRejectNumRequired:  950,
	BlockUpgradeNumToCheck:  1000,

	RelayNonStdTxs:      true,
	PubKeyHashAddressID: 0x6f,
	ScriptHashAddressID: 0xc4,
	PrivatekeyID:        0xef,

	HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94},
	HDPublicKeyID:  [4]byte{0x04, 0x35, 0x87, 0xcf},

	HDCoinType: 1,
}
View Source
var RegressionTestGeneisMerkleRoot = GenesisMerkleRoot
View Source
var RegressionTestGenesisBlock = BlockMessage{
	Block: &model.Block{
		Version:      1,
		PrevBlock:    "0000000000000000000000000000000000000000000000000000000000000000",
		MerkleRoot:   "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
		BlockTime:    time.Unix(1296688602, 0),
		Bits:         0x207fffff,
		Nonce:        2,
		Transactions: []*model.Tx{&GenesisCoinbasTx},
	},
}
View Source
var RegressionTestGenesisHash = utils.Hash([utils.HashSize]byte{
	0x06, 0x22, 0x6e, 0x46, 0x11, 0x1a, 0x0b, 0x59,
	0xca, 0xaf, 0x12, 0x60, 0x43, 0xeb, 0x5b, 0xbf,
	0x28, 0xc3, 0x4f, 0x3a, 0x5e, 0x33, 0x2a, 0x1f,
	0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f,
})
View Source
var SimNetGenesisBlock = BlockMessage{
	Block: &model.Block{
		Version:      1,
		PrevBlock:    "0000000000000000000000000000000000000000000000000000000000000000",
		MerkleRoot:   "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
		BlockTime:    time.Unix(1401292357, 0),
		Bits:         0x207fffff,
		Nonce:        2,
		Transactions: []*model.Tx{&GenesisCoinbasTx},
	},
}
View Source
var SimNetGenesisHash = utils.Hash([utils.HashSize]byte{
	0xf6, 0x7a, 0xd7, 0x69, 0x5d, 0x9b, 0x66, 0x2a,
	0x72, 0xff, 0x3d, 0x8e, 0xdb, 0xbb, 0x2d, 0xe0,
	0xbf, 0xa6, 0x7b, 0x13, 0x97, 0x4b, 0xb9, 0x91,
	0x0d, 0x11, 0x6d, 0x5c, 0xbd, 0x86, 0x3e, 0x68,
})
View Source
var SimNetGenesisMerkleRoot = GenesisMerkleRoot
View Source
var SimNetParams = BitcoinParams{
	Name:                     "simnet",
	BitcoinNet:               btcutil.SimNet,
	DefaultPort:              "18555",
	DNSSeeds:                 []btcutil.DNSSeed{},
	GenesisBlock:             &SimNetGenesisBlock,
	GenesisHash:              &SimNetGenesisHash,
	PowLimit:                 simNetPowlimit,
	PowLimitBits:             SimNetGenesisBlock.Block.Bits,
	CoinbaseMaturity:         100,
	SubsidyReductionInterval: 210000,
	TargetTimespan:           time.Hour * 24 * 14,
	TargetTimePerBlock:       time.Minute * 10,
	RetargetAdjustmentFactor: 4,
	ReduceMinDifficulty:      true,
	MinDiffReductionTime:     time.Minute * 20,
	GenerateSupported:        false,
	Checkpoints:              nil,

	BlockEnforceNumRequired: 51,
	BlockRejectNumRequired:  75,
	BlockUpgradeNumToCheck:  100,

	RelayNonStdTxs:      true,
	PubKeyHashAddressID: 0x3f,
	ScriptHashAddressID: 0x7b,
	PrivatekeyID:        0x64,

	HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x00},
	HDPublicKeyID:  [4]byte{0x04, 0x20, 0xbd, 0x3a},

	HDCoinType: 115,
}
View Source
var TestNet3GenesisBlock = BlockMessage{
	Block: &model.Block{
		Version:      1,
		PrevBlock:    "0000000000000000000000000000000000000000000000000000000000000000",
		MerkleRoot:   "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
		BlockTime:    time.Unix(1296688602, 0),
		Bits:         0x1d00ffff,
		Nonce:        0x18aea41a,
		Transactions: []*model.Tx{&GenesisCoinbasTx},
	},
}
View Source
var TestNet3GenesisHash = utils.Hash([utils.HashSize]byte{
	0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71,
	0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae,
	0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad,
	0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00,
})
View Source
var TestNet3GenesisMerkleRoot = GenesisMerkleRoot
View Source
var TestNet3Params = BitcoinParams{
	Name:        "testnet3",
	BitcoinNet:  btcutil.TestNet3,
	DefaultPort: "18333",
	DNSSeeds: []btcutil.DNSSeed{
		{"testnet-seed.bitcoin.schildbach.de", false},
		{"testnet-seed.bitcoin.petertodd.org", true},
		{"testnet-seed.bluematt.me", false},
	},
	GenesisBlock:             &TestNet3GenesisBlock,
	GenesisHash:              &TestNet3GenesisHash,
	PowLimit:                 testNet3PowLimit,
	PowLimitBits:             GenesisBlock.Block.Bits,
	CoinbaseMaturity:         100,
	SubsidyReductionInterval: 210000,
	TargetTimespan:           time.Hour * 24 * 14,
	TargetTimePerBlock:       time.Minute * 10,
	RetargetAdjustmentFactor: 4,
	ReduceMinDifficulty:      true,
	MinDiffReductionTime:     time.Minute * 20,
	GenerateSupported:        false,
	Checkpoints: []*model.Checkpoint{
		{546, utils.HashFromString("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")},
	},

	BlockEnforceNumRequired: 51,
	BlockRejectNumRequired:  75,
	BlockUpgradeNumToCheck:  100,

	RelayNonStdTxs:      true,
	PubKeyHashAddressID: 0x6f,
	ScriptHashAddressID: 0xc4,
	PrivatekeyID:        0xef,

	HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94},
	HDPublicKeyID:  [4]byte{0x04, 0x35, 0x87, 0xcf},

	HDCoinType: 1,
}

Functions

func DiscardInput

func DiscardInput(reader io.Reader, n uint32)

func HDPrivateKeyToPublicKeyID

func HDPrivateKeyToPublicKeyID(id []byte) ([]byte, error)

func InventorySummary

func InventorySummary(invList []*InventoryVector) string

func InventoryTypeToString

func InventoryTypeToString(inventoryType protocol.InventoryType) string

func IsPublicKeyHashAddressID

func IsPublicKeyHashAddressID(id byte) bool

func IsScriptHashAddressid

func IsScriptHashAddressid(id byte) bool

func LocatorSummary

func LocatorSummary(locator []*utils.Hash, stopHash *utils.Hash) string

func LockTimeToString

func LockTimeToString(lockTime uint32) string

func MessageSummary

func MessageSummary(msg Message) string

func ReadInventoryVector

func ReadInventoryVector(r io.Reader, pver uint32, iv *InventoryVector) error

func Register

func Register(bitcoinParams *BitcoinParams) error

func SanitizeString

func SanitizeString(str string, maxLength uint) string

func WriteInvVect

func WriteInvVect(w io.Writer, pver uint32, iv *InventoryVector) error

func WriteMessage

func WriteMessage(w io.Writer, message Message, pver uint32, net btcutil.BitcoinNet) (int, error)

Types

type AddressMessage

type AddressMessage struct {
	Message
	AddressList []*network.PeerAddress
}

func (*AddressMessage) AddPeerAddress

func (addressMessage *AddressMessage) AddPeerAddress(peerAddress *network.PeerAddress) error

func (*AddressMessage) AddPeerAddresses

func (addressMessage *AddressMessage) AddPeerAddresses(peerAddresses ...*network.PeerAddress) (err error)

func (*AddressMessage) BitcoinParse

func (addressMessage *AddressMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*AddressMessage) BitcoinSerialize

func (addressMessage *AddressMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*AddressMessage) ClearAddresses

func (addressMessage *AddressMessage) ClearAddresses()

func (*AddressMessage) Command

func (addressMessage *AddressMessage) Command() string

func (*AddressMessage) MaxPayloadLength

func (addressMessage *AddressMessage) MaxPayloadLength(version uint32) uint32

type AlertMessage

type AlertMessage struct {
}

func (*AlertMessage) BitcoinParse

func (alertMessage *AlertMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*AlertMessage) BitcoinSerialize

func (alertMessage *AlertMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*AlertMessage) Command

func (alertMessage *AlertMessage) Command() string

func (*AlertMessage) MaxPayloadLength

func (alertMessage *AlertMessage) MaxPayloadLength(size uint32) uint32

type BitcoinParams

type BitcoinParams struct {
	Name                     string
	BitcoinNet               btcutil.BitcoinNet
	DefaultPort              string
	DNSSeeds                 []btcutil.DNSSeed
	GenesisBlock             *BlockMessage
	GenesisHash              *utils.Hash
	PowLimit                 *big.Int
	PowLimitBits             uint32
	CoinbaseMaturity         uint16
	SubsidyReductionInterval int32
	TargetTimespan           time.Duration
	TargetTimePerBlock       time.Duration
	RetargetAdjustmentFactor int64
	ReduceMinDifficulty      bool
	MinDiffReductionTime     time.Duration
	GenerateSupported        bool
	Checkpoints              []*model.Checkpoint

	// Enforce current block version once network has
	// upgraded.  This is part of BIP0034.
	BlockEnforceNumRequired uint64

	// Reject previous block versions once network has
	// upgraded.  This is part of BIP0034.
	BlockRejectNumRequired uint64

	// The number of nodes to check.  This is part of BIP0034.
	BlockUpgradeNumToCheck uint64

	RelayNonStdTxs bool

	PubKeyHashAddressID byte
	ScriptHashAddressID byte
	PrivatekeyID        byte
	HDPrivateKeyID      [4]byte
	HDPublicKeyID       [4]byte
	HDCoinType          uint32
}

type BlockMessage

type BlockMessage struct {
	Message
	Block *model.Block
	Txs   []*TxMessage
}

func (*BlockMessage) AddTx

func (blockMessage *BlockMessage) AddTx(tx *TxMessage) error

func (*BlockMessage) BitcoinParse

func (blockMessage *BlockMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*BlockMessage) BitcoinSerialize

func (blockMessage *BlockMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*BlockMessage) ClearTxs

func (blockMessage *BlockMessage) ClearTxs()

func (*BlockMessage) Command

func (blockMessage *BlockMessage) Command() string

func (*BlockMessage) MaxPayloadLength

func (blockMessage *BlockMessage) MaxPayloadLength(size uint32) uint32

type FilterAddMessage

type FilterAddMessage struct {
}

func (*FilterAddMessage) BitcoinParse

func (filterAddMessage *FilterAddMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*FilterAddMessage) BitcoinSerialize

func (filterAddMessage *FilterAddMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*FilterAddMessage) Command

func (filterAddMessage *FilterAddMessage) Command() string

func (*FilterAddMessage) MaxPayloadLength

func (filterAddMessage *FilterAddMessage) MaxPayloadLength(size uint32) uint32

type FilterClearMessage

type FilterClearMessage struct {
}

func (*FilterClearMessage) BitcoinParse

func (filterClearMessage *FilterClearMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*FilterClearMessage) BitcoinSerialize

func (filterClearMessage *FilterClearMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*FilterClearMessage) Command

func (filterClearMessage *FilterClearMessage) Command() string

func (*FilterClearMessage) MaxPayloadLength

func (filterClearMessage *FilterClearMessage) MaxPayloadLength(size uint32) uint32

type FilterLoadMessage

type FilterLoadMessage struct {
}

func (*FilterLoadMessage) BitcoinParse

func (filterLoadMessage *FilterLoadMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*FilterLoadMessage) BitcoinSerialize

func (filterLoadMessage *FilterLoadMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*FilterLoadMessage) Command

func (filterLoadMessage *FilterLoadMessage) Command() string

func (*FilterLoadMessage) MaxPayloadLength

func (filterLoadMessage *FilterLoadMessage) MaxPayloadLength(size uint32) uint32

type GetAddressMessage

type GetAddressMessage struct {
}

func NewGetAddressMessage

func NewGetAddressMessage() *GetAddressMessage

func (*GetAddressMessage) BitcoinParse

func (getAddressMessage *GetAddressMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*GetAddressMessage) BitcoinSerialize

func (getAddressMessage *GetAddressMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*GetAddressMessage) Command

func (getAddressMessage *GetAddressMessage) Command() string

func (*GetAddressMessage) MaxPayloadLength

func (getAddressMessage *GetAddressMessage) MaxPayloadLength(size uint32) uint32

type GetBlocksMessage

type GetBlocksMessage struct {
	ProtocolVersion uint32
	BlockHashes     []*utils.Hash
	HashStop        *utils.Hash
}

func NewGetBlocksMessage

func NewGetBlocksMessage(hashStop *utils.Hash) *GetBlocksMessage

func (*GetBlocksMessage) AddBlockHash

func (getBlocksMessage *GetBlocksMessage) AddBlockHash(hash *utils.Hash) error

func (*GetBlocksMessage) BitcoinParse

func (getBlocksMessage *GetBlocksMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*GetBlocksMessage) BitcoinSerialize

func (getBlocksMessage *GetBlocksMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*GetBlocksMessage) Command

func (getBlocksMessage *GetBlocksMessage) Command() string

func (*GetBlocksMessage) MaxPayloadLength

func (getBlocksMessage *GetBlocksMessage) MaxPayloadLength(size uint32) uint32

type GetDataMessage

type GetDataMessage struct {
}

func (*GetDataMessage) BitcoinParse

func (getDataMessage *GetDataMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*GetDataMessage) BitcoinSerialize

func (getDataMessage *GetDataMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*GetDataMessage) Command

func (getDataMessage *GetDataMessage) Command() string

func (*GetDataMessage) MaxPayloadLength

func (getDataMessage *GetDataMessage) MaxPayloadLength(size uint32) uint32

type GetHeadersMessage

type GetHeadersMessage struct {
	ProtocolVersion uint32
	BlockHashes     []*utils.Hash
	HashStop        *utils.Hash
}

func NewGetHeadersMessage

func NewGetHeadersMessage() *GetHeadersMessage

func (*GetHeadersMessage) AddBlockHash

func (getHeadersMessage *GetHeadersMessage) AddBlockHash(hash *utils.Hash) error

func (*GetHeadersMessage) BitcoinParse

func (getHeadersMessage *GetHeadersMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*GetHeadersMessage) BitcoinSerialize

func (getHeadersMessage *GetHeadersMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*GetHeadersMessage) Command

func (getHeadersMessage *GetHeadersMessage) Command() string

func (*GetHeadersMessage) MaxPayloadLength

func (getHeadersMessage *GetHeadersMessage) MaxPayloadLength(size uint32) uint32

type HeadersMessage

type HeadersMessage struct {
	Blocks []*model.Block
}

func (*HeadersMessage) BitcoinParse

func (headersMessage *HeadersMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*HeadersMessage) BitcoinSerialize

func (headersMessage *HeadersMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*HeadersMessage) Command

func (headersMessage *HeadersMessage) Command() string

func (*HeadersMessage) MaxPayloadLength

func (headersMessage *HeadersMessage) MaxPayloadLength(size uint32) uint32

type InventoryMessage

type InventoryMessage struct {
	InventoryList []*InventoryVector
}

func NewInventoryMessageSizeHint

func NewInventoryMessageSizeHint(sizeHint uint) *InventoryMessage

func NewMessageInventory

func NewMessageInventory() *InventoryMessage

func (*InventoryMessage) AddInventoryVector

func (message *InventoryMessage) AddInventoryVector(iv *InventoryVector) error

func (*InventoryMessage) BitcoinParse

func (message *InventoryMessage) BitcoinParse(reader io.Reader, pver uint32) error

func (*InventoryMessage) BitcoinSerialize

func (message *InventoryMessage) BitcoinSerialize(w io.Writer, pver uint32) error

func (*InventoryMessage) Command

func (message *InventoryMessage) Command() string

func (*InventoryMessage) MaxPayloadLength

func (message *InventoryMessage) MaxPayloadLength(pver uint32) uint32

type InventoryVector

type InventoryVector struct {
	Type protocol.InventoryType
	Hash *utils.Hash
}

func NewInventoryVecror

func NewInventoryVecror(typ protocol.InventoryType, hash *utils.Hash) *InventoryVector

type MempoolMessage

type MempoolMessage struct {
}

func (*MempoolMessage) BitcoinParse

func (mempoolMessage *MempoolMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*MempoolMessage) BitcoinSerialize

func (mempoolMessage *MempoolMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*MempoolMessage) Command

func (mempoolMessage *MempoolMessage) Command() string

func (*MempoolMessage) MaxPayloadLength

func (mempoolMessage *MempoolMessage) MaxPayloadLength(size uint32) uint32

type MerkleBlockMessage

type MerkleBlockMessage struct {
}

func (*MerkleBlockMessage) BitcoinParse

func (merkleBlockMessage *MerkleBlockMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*MerkleBlockMessage) BitcoinSerialize

func (merkleBlockMessage *MerkleBlockMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*MerkleBlockMessage) Command

func (merkleBlockMessage *MerkleBlockMessage) Command() string

func (*MerkleBlockMessage) MaxPayloadLength

func (merkleBlockMessage *MerkleBlockMessage) MaxPayloadLength(size uint32) uint32

type Message

type Message interface {
	BitcoinParse(reader io.Reader, size uint32) error
	BitcoinSerialize(writer io.Writer, size uint32) error
	MaxPayloadLength(version uint32) uint32
	Command() string
}

func ReadMessage

func ReadMessage(reader io.Reader, pver uint32, bitcoinNet btcutil.BitcoinNet) (int, Message, []byte, error)

type MessageHeader

type MessageHeader struct {
	Net      btcutil.BitcoinNet // 4 bytes
	Command  string             // 12 bytes
	Length   uint32             // 4 bytes
	Checksum [4]byte            // 4 bytes
}

func ReadMessageHeader

func ReadMessageHeader(reader io.Reader) (int, *MessageHeader, error)

type NotFoundMessage

type NotFoundMessage struct {
	InventoryList []*InventoryVector
}

func (*NotFoundMessage) BitcoinParse

func (notFoundMessage *NotFoundMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*NotFoundMessage) BitcoinSerialize

func (notFoundMessage *NotFoundMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*NotFoundMessage) Command

func (notFoundMessage *NotFoundMessage) Command() string

func (*NotFoundMessage) MaxPayloadLength

func (notFoundMessage *NotFoundMessage) MaxPayloadLength(size uint32) uint32

type OutMessage

type OutMessage struct {
	Message Message
	Done    chan<- struct{}
}

type PingMessage

type PingMessage struct {
	Nonce uint64
}

func InitPingMessage

func InitPingMessage(nonce uint64) *PingMessage

func (*PingMessage) BitcoinParse

func (pingMessage *PingMessage) BitcoinParse(reader io.Reader, pver uint32) error

func (*PingMessage) BitcoinSerialize

func (pingMessage *PingMessage) BitcoinSerialize(w io.Writer, pver uint32) error

func (*PingMessage) Command

func (pingMessage *PingMessage) Command() string

func (*PingMessage) MaxPayloadLength

func (pingMessage *PingMessage) MaxPayloadLength(pver uint32) uint32

type PongMessage

type PongMessage struct {
	Nonce uint64
}

func InitPondMessage

func InitPondMessage(nonce uint64) *PongMessage

func (*PongMessage) BitcoinParse

func (pongMessage *PongMessage) BitcoinParse(reader io.Reader, pver uint32) error

func (*PongMessage) BitcoinSerialize

func (pongMessage *PongMessage) BitcoinSerialize(w io.Writer, pver uint32) error

func (*PongMessage) Command

func (pongMessage *PongMessage) Command() string

func (*PongMessage) MaxPayloadLength

func (pongMessage *PongMessage) MaxPayloadLength(pver uint32) uint32

type RejectCode

type RejectCode uint8
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
)

func (RejectCode) ToString

func (code RejectCode) ToString() string

type RejectMessage

type RejectMessage struct {
	Cmd    string
	Code   RejectCode
	Reason string
	Hash   *utils.Hash
}

func NewRejectMessage

func NewRejectMessage(command string, code RejectCode, reason string) *RejectMessage

func (*RejectMessage) BitcoinParse

func (rejectMessage *RejectMessage) BitcoinParse(reader io.Reader, pver uint32) error

func (*RejectMessage) BitcoinSerialize

func (rejectMessage *RejectMessage) BitcoinSerialize(w io.Writer, pver uint32) error

func (*RejectMessage) Command

func (rejectMessage *RejectMessage) Command() string

func (*RejectMessage) MaxPayloadLength

func (rejectMessage *RejectMessage) MaxPayloadLength(pver uint32) uint32

type SendHeadersMessage

type SendHeadersMessage struct {
}

func (*SendHeadersMessage) BitcoinParse

func (sendHeadersMessage *SendHeadersMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*SendHeadersMessage) BitcoinSerialize

func (sendHeadersMessage *SendHeadersMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*SendHeadersMessage) Command

func (sendHeadersMessage *SendHeadersMessage) Command() string

func (*SendHeadersMessage) MaxPayloadLength

func (sendHeadersMessage *SendHeadersMessage) MaxPayloadLength(size uint32) uint32

type TxMessage

type TxMessage struct {
	Tx model.Tx
}

func (*TxMessage) BitcoinParse

func (txMessage *TxMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*TxMessage) BitcoinSerialize

func (txMessage *TxMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*TxMessage) Command

func (txMessage *TxMessage) Command() string

func (*TxMessage) MaxPayloadLength

func (txMessage *TxMessage) MaxPayloadLength(size uint32) uint32

type VersionACKMessage

type VersionACKMessage struct {
}

func InitVersionACKMessage

func InitVersionACKMessage() *VersionACKMessage

func (*VersionACKMessage) BitcoinParse

func (versionACKMessage *VersionACKMessage) BitcoinParse(reader io.Reader, size uint32) error

func (*VersionACKMessage) BitcoinSerialize

func (versionACKMessage *VersionACKMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*VersionACKMessage) Command

func (versionACKMessage *VersionACKMessage) Command() string

func (*VersionACKMessage) MaxPayloadLength

func (versionACKMessage *VersionACKMessage) MaxPayloadLength(size uint32) uint32

type VersionMessage

type VersionMessage struct {
	Message
	ProtocolVersion uint32
	ServiceFlag     protocol.ServiceFlag
	Timestamp       time.Time
	RemoteAddress   *network.PeerAddress
	LocalAddress    *network.PeerAddress
	Nonce           uint64
	UserAgent       string
	LastBlock       int32
	DisableRelayTx  bool
}

func GetNewVersionMessage

func GetNewVersionMessage(localAddr *network.PeerAddress, remoteAddr *network.PeerAddress, nonce uint64, lastBlock int32) *VersionMessage

func (*VersionMessage) AddService

func (versionMessage *VersionMessage) AddService(serviceFlag protocol.ServiceFlag)

func (*VersionMessage) AddUserAgent

func (versionMessage *VersionMessage) AddUserAgent(name string, version string, notes ...string) error

func (*VersionMessage) BitcoinParse

func (versionMessage *VersionMessage) BitcoinParse(reader io.Reader, pver uint32) error

func (*VersionMessage) BitcoinSerialize

func (versionMessage *VersionMessage) BitcoinSerialize(w io.Writer, size uint32) error

func (*VersionMessage) Command

func (versionMessage *VersionMessage) Command() string

func (*VersionMessage) HasService

func (versionMessage *VersionMessage) HasService(serviceFlag protocol.ServiceFlag) bool

func (*VersionMessage) MaxPayloadLength

func (versionMessage *VersionMessage) MaxPayloadLength(pver uint32) uint32

Jump to

Keyboard shortcuts

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