Documentation
¶
Overview ¶
Package btcutil provides bitcoin-specific convenience functions and types.
Block Overview ¶
A Block defines a bitcoin block that provides easier and more efficient manipulation of raw wire protocol blocks. It also memoizes hashes for the block and its transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.
Index ¶
- Constants
- type Block
- func (b *Block) Bytes() ([]byte, uint32, error)
- func (b *Block) Height() int64
- func (b *Block) MsgBlock() *btcwire.MsgBlock
- func (b *Block) ProtocolVersion() uint32
- func (b *Block) SetHeight(height int64)
- func (b *Block) Sha() (*btcwire.ShaHash, error)
- func (b *Block) TxLoc() (txlocD []btcwire.TxLoc, err error)
- func (b *Block) TxSha(txNum int) (*btcwire.ShaHash, error)
- func (b *Block) TxShas() ([]*btcwire.ShaHash, error)
- type OutOfRangeError
Constants ¶
const BlockHeightUnknown = int64(-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 wire protocol blocks. It also memoizes 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 ¶
NewBlock returns a new instance of a bitcoin block given an underlying btcwire.MsgBlock and protocol version. See Block.
func NewBlockFromBlockAndBytes ¶
NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given an underlying btcwire.MsgBlock, protocol version and raw Block. See Block.
func NewBlockFromBytes ¶
NewBlockFromBytes returns a new instance of a bitcoin block given the raw wire encoded bytes and protocol version used to encode those bytes. See Block.
func (*Block) Bytes ¶
Bytes returns the raw wire protocol encoded bytes for the Block and the protocol version used to encode it. This is equivalent to calling BtcEncode on the underlying btcwire.MsgBlock, however it caches the result so subsequent calls are more efficient.
func (*Block) Height ¶
Height returns the saved height of the block in the blockchain. This value will be BlockHeightUnknown if it hasn't already explicitly been set.
func (*Block) ProtocolVersion ¶
ProtocolVersion returns the protocol version that was used to create the underlying btcwire.MsgBlock.
func (*Block) Sha ¶
Sha returns the block identifier hash for the Block. This is equivalent to calling BlockSha on the underlying btcwire.MsgBlock, however it caches the result so subsequent calls are more efficient.
func (*Block) TxLoc ¶
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) TxSha ¶
TxSha returns the hash for the requested transaction number in the Block. The supplied index is 0 based. That is to say, the first transaction is the block is txNum 0. This is equivalent to calling TxSha on the underlying btcwire.MsgTx, however it caches the result so subsequent calls are more efficient.
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.