message

package
v0.0.0-...-e728bab Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSG_TX                     = 1
	MSG_BLOCK                  = 2
	MSG_FILTERED_BLOCK         = 3
	MSG_CMPCT_BLOCK            = 4
	MSG_WITNESS_FLAG           = 1 << 30
	MSG_WITNESS_TX             = MSG_TX | MSG_WITNESS_FLAG
	MSG_WITNESS_BLOCK          = MSG_BLOCK | MSG_WITNESS_FLAG
	MSG_FILTERED_WITNESS_BLOCK = MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG
)

https://developer.bitcoin.org/reference/p2p_networking.html#data-messages

View Source
const HashL = 32
View Source
const InvMaxItemCount = 50_000

Variables

View Source
var MerkleBlockNotEnoughFlags = errors.New("MerkleBlockNotEnoughFlags")
View Source
var MerkleBlockNotEnoughHash = errors.New("MerkleBlockNotEnoughHash")
View Source
var MerkleBlockTooManyFlags = errors.New("MerkleBlockTooManyFlags")
View Source
var MerkleBlockTooManyHashes = errors.New("MerkleBlockTooManyHashes")

Functions

func MakeMerkleTree

func MakeMerkleTree(TS []Transaction) (res [32]byte)

func MakeMerkleTreeFromHashes

func MakeMerkleTreeFromHashes(hashes []byte) (res [32]byte)

Types

type AddrMsg

type AddrMsg struct {
	Addrs []NetworkIPAddress
}

func (*AddrMsg) LoadBuffer

func (a *AddrMsg) LoadBuffer(reader utils.BufReader) (err error)

func (*AddrMsg) PutBuffer

func (a *AddrMsg) PutBuffer(writer utils.BufWriter) (err error)

type Block

type Block struct {
	Version                    int32
	Previous_block_header_hash [32]byte
	Merkle_root_hash           [32]byte
	Time                       uint32
	NBits                      uint32
	Nonce                      uint32
}

func CreateBlock

func CreateBlock(version int32, previous_block_header_hash [32]byte, TS []Transaction, nBits uint32, nonce uint32) Block

func (*Block) LoadBuffer

func (b *Block) LoadBuffer(reader utils.BufReader) (err error)

func (*Block) PutBuffer

func (b *Block) PutBuffer(writer utils.BufWriter) (err error)

type GetBlocksMsg

type GetBlocksMsg struct {
	Version uint32
	// Hashes should be provided in reverse order of block height,
	// so highest-height hashes are listed first and lowest-height hashes are listed last.
	BlockHeaderHashes [][32]byte
	// if all zero, request an "inv" message
	// otherwise its the last header hash being requested
	// not included in the array above
	StopHash [32]byte
}

https://developer.bitcoin.org/reference/p2p_networking.html#getblocks

func (*GetBlocksMsg) LoadBuffer

func (ret *GetBlocksMsg) LoadBuffer(reader utils.BufReader) (err error)

func (*GetBlocksMsg) PutBuffer

func (b *GetBlocksMsg) PutBuffer(writer utils.BufWriter) (err error)

type InvMsg

type InvMsg struct {
	Inv []Inventory
}

Inventory https://developer.bitcoin.org/reference/p2p_networking.html#inv

func (*InvMsg) LoadBuffer

func (ret *InvMsg) LoadBuffer(reader utils.BufReader) (err error)

func (*InvMsg) PutBuffer

func (m *InvMsg) PutBuffer(writer utils.BufWriter) (err error)

type Inventory

type Inventory struct {
	Type uint32
	Hash [32]byte
}

func NewInventory

func NewInventory(reader utils.BufReader) (ret Inventory, err error)

func (*Inventory) PutBuffer

func (o *Inventory) PutBuffer(writer utils.BufWriter) (err error)

type MerkleBlockMsg

type MerkleBlockMsg struct {
	// TODO: Block header
	TxCount uint32
	// contains filtered or unexported fields
}

func NewMerkleBlockMsg

func NewMerkleBlockMsg(reader utils.BufReader) (ret MerkleBlockMsg, err error)

type MerkleTree

type MerkleTree struct {
	Hash       [32]byte
	Lson, Rson *MerkleTree
	IsLeaf     bool
	// "Used" means that this transaction is included in this Merkle Tree
	// Unused nodes appear in the tree because they are needed for hash calculation
	// This variable makes sense only if IsLeaf is true
	Used bool
}

type NetworkIPAddress

type NetworkIPAddress struct {
	Ipv6 [16]byte
	Port uint16
	// contains filtered or unexported fields
}

func (*NetworkIPAddress) LoadBuffer

func (a *NetworkIPAddress) LoadBuffer(reader utils.BufReader) (err error)

func (*NetworkIPAddress) PutBuffer

func (a *NetworkIPAddress) PutBuffer(writer utils.BufWriter) (err error)

type Outpoint

type Outpoint struct {
	Hash  [32]byte
	Index uint32
}

func NewOutPoint

func NewOutPoint(hash [32]byte, index uint32) Outpoint

func (*Outpoint) LoadBuffer

func (o *Outpoint) LoadBuffer(reader utils.BufReader) (err error)

func (*Outpoint) PutBuffer

func (o *Outpoint) PutBuffer(writer utils.BufWriter) (err error)

type SerializedBlock

type SerializedBlock struct {
	Header     Block
	HeaderHash [32]byte
	Txns       []Transaction
}

https://developer.bitcoin.org/reference/block_chain.html#serialized-blocks

func CreateSerialBlock

func CreateSerialBlock(block Block, tx []Transaction) (sb SerializedBlock, err error)

func (*SerializedBlock) HexString

func (b *SerializedBlock) HexString() string

func (*SerializedBlock) LoadBuffer

func (b *SerializedBlock) LoadBuffer(reader utils.BufReader) (err error)

func (*SerializedBlock) PutBuffer

func (b *SerializedBlock) PutBuffer(writer utils.BufWriter) (err error)

type Transaction

type Transaction struct {
	Version   int32
	Tx_in     []TxIn
	Tx_out    []TxOut
	Lock_time uint32
}

func CreateTransaction

func CreateTransaction(version int32, tx_in []TxIn, tx_out []TxOut, lock_time uint32) Transaction

func (*Transaction) LoadBuffer

func (tx *Transaction) LoadBuffer(reader utils.BufReader) (err error)

func (*Transaction) PutBuffer

func (t *Transaction) PutBuffer(writer utils.BufWriter) (err error)

type TxIn

type TxIn struct {
	Previous_output  Outpoint
	Signature_script []byte
	Sequence         uint32
}

func NewtxIn

func NewtxIn(previous_output Outpoint, script_bytes uint64, signature_script []byte, sequence uint32) TxIn

func (*TxIn) LoadBuffer

func (data *TxIn) LoadBuffer(reader utils.BufReader) (err error)

func (*TxIn) PutBuffer

func (t *TxIn) PutBuffer(writer utils.BufWriter) (err error)

type TxOut

type TxOut struct {
	Value     int64
	Pk_script []byte
}

func NewtxOut

func NewtxOut(value int64, pk_script string) TxOut

func (*TxOut) LoadBuffer

func (t *TxOut) LoadBuffer(reader utils.BufReader) (err error)

func (*TxOut) PutBuffer

func (t *TxOut) PutBuffer(writer utils.BufWriter) (err error)

Jump to

Keyboard shortcuts

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