block

package
Version: v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: Unlicense Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const BlockHeightUnknown = int32(-1)

BlockHeightUnknown is the value returned for a block height that is unknown. This is typically because the block has not been inserted into the main chain yet.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

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

Block defines a bitcoin block that provides easier and more efficient manipulation of raw blocks. It also memorizes hashes for the block and its transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.

func NewBlock

func NewBlock(msgBlock *wire.Block) *Block

NewBlock returns a new instance of a bitcoin block given an underlying wire.Block. See Block.

func NewFromBlockAndBytes

func NewFromBlockAndBytes(msgBlock *wire.Block, serializedBlock []byte) *Block

NewFromBlockAndBytes returns a new instance of a bitcoin block given an underlying wire.Block and the serialized bytes for it. See Block.

func NewFromBytes

func NewFromBytes(serializedBlock []byte) (*Block, error)

NewFromBytes returns a new instance of a bitcoin block given the serialized bytes. See Block.

func NewFromReader

func NewFromReader(r io.Reader) (*Block, error)

NewFromReader returns a new instance of a bitcoin block given a Reader to deserialize the block. See Block.

func (*Block) Bytes

func (b *Block) Bytes() ([]byte, error)

Bytes returns the serialized bytes for the Block. This is equivalent to calling Serialize on the underlying wire.Block, however it caches the result so subsequent calls are more efficient.

func (*Block) BytesNoWitness

func (b *Block) BytesNoWitness() ([]byte, error)

BytesNoWitness returns the serialized bytes for the block with transactions encoded without any witness data.

func (*Block) Hash

func (b *Block) Hash() *chainhash.Hash

Hash returns the block identifier hash for the Block. This is equivalent to calling BlockHash on the underlying wire.Block, however it caches the result so subsequent calls are more efficient.

func (*Block) Height

func (b *Block) Height() int32

Height returns the saved height of the block in the block chain. This value will be BlockHeightUnknown if it hasn't already explicitly been set.

func (*Block) SetBlockBytes

func (b *Block) SetBlockBytes(buf []byte)

SetBlockBytes sets the internal serialized block byte buffer to the passed buffer. It is used to inject errors and is only available to the test package.

func (*Block) SetHeight

func (b *Block) SetHeight(height int32)

SetHeight sets the height of the block in the block chain.

func (*Block) Transactions

func (b *Block) Transactions() []*util.Tx

Transactions returns a slice of wrapped transactions (util.Tx) for all transactions in the Block. This is nearly equivalent to accessing the raw transactions (wire.MsgTx) in the underlying wire.Block, however it instead provides easy access to wrapped versions (util.Tx) of them.

func (*Block) Tx

func (b *Block) Tx(txNum int) (*util.Tx, error)

Tx returns a wrapped transaction (util.Tx) for the transaction at the specified index in the Block. The supplied index is 0 based. That is to say, the first transaction in the block is txNum 0. This is nearly equivalent to accessing the raw transaction (wire.MsgTx) from the underlying wire.Block, however the wrapped transaction has some helpful properties such as caching the hash so subsequent calls are more efficient.

func (*Block) TxHash

func (b *Block) TxHash(txNum int) (*chainhash.Hash, error)

TxHash returns the hash for the requested transaction number in the Block. The supplied index is 0 based. That is to say, the first transaction in the block is txNum 0. This is equivalent to calling TxHash on the underlying wire.MsgTx, however it caches the result so subsequent calls are more efficient.

func (*Block) TxLoc

func (b *Block) TxLoc() ([]wire.TxLoc, error)

TxLoc returns the offsets and lengths of each transaction in a raw block. It is used to allow fast indexing into transactions within the raw byte stream.

func (*Block) WireBlock

func (b *Block) WireBlock() *wire.Block

WireBlock returns the underlying wire.Block for the Block.

type OutOfRangeError

type OutOfRangeError string

OutOfRangeError describes an error due to accessing an element that is out of range.

func (OutOfRangeError) Error

func (e OutOfRangeError) Error() string

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

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL