btcutil

package module
v0.0.0-...-af89ed1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2013 License: ISC Imports: 3 Imported by: 0

README

btcutil

Package btcutil provides bitcoin-specific convenience functions and types. The test coverage is currently ~76%, however it will improved to 100% in the near future. See test_coverage.txt for the gocov coverage report. Alternatively, if you are running a POSIX OS, you can run the cov_report.sh script for a real-time report. Package btcutil is licensed under the liberal ISC license.

This package was developed for btcd, an alternative full-node implementation of bitcoin which is under active development by Conformal. Although it was primarily written for btcd, this package has intentionally been designed so it can be used as a standalone package for any projects needing the functionality provided.

Documentation

Full go doc style documentation for the project can be viewed online without installing this package by using the GoDoc site here: http://godoc.org/github.com/conformal/btcutil

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/conformal/btcutil

Installation

$ go get github.com/conformal/btcutil

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from Conformal. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

Package btcutil is licensed under the liberal ISC License.

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

View Source
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

func NewBlock(msgBlock *btcwire.MsgBlock, pver uint32) *Block

NewBlock returns a new instance of a bitcoin block given an underlying btcwire.MsgBlock and protocol version. See Block.

func NewBlockFromBlockAndBytes

func NewBlockFromBlockAndBytes(msgBlock *btcwire.MsgBlock, rawBlock []byte, pver uint32) *Block

NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given an underlying btcwire.MsgBlock, protocol version and raw Block. See Block.

func NewBlockFromBytes

func NewBlockFromBytes(rawBlock []byte, pver uint32) (*Block, error)

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

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

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

func (b *Block) Height() int64

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

func (b *Block) MsgBlock() *btcwire.MsgBlock

MsgBlock returns the underlying btcwire.MsgBlock for the Block.

func (*Block) ProtocolVersion

func (b *Block) ProtocolVersion() uint32

ProtocolVersion returns the protocol version that was used to create the underlying btcwire.MsgBlock.

func (*Block) SetHeight

func (b *Block) SetHeight(height int64)

SetHeight sets the height of the block in the blockchain.

func (*Block) Sha

func (b *Block) Sha() (*btcwire.ShaHash, error)

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

func (b *Block) TxLoc() (txlocD []btcwire.TxLoc, err 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) TxSha

func (b *Block) TxSha(txNum int) (*btcwire.ShaHash, error)

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.

func (*Block) TxShas

func (b *Block) TxShas() ([]*btcwire.ShaHash, error)

TxShas returns a slice of hashes for all transactions in the Block. This is equivalent to calling TxSha on each 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.

Jump to

Keyboard shortcuts

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