Documentation ¶
Index ¶
- Variables
- func B2H(header []byte) (*wire.BlockHeader, error)
- func HeaderHash(header []byte) *chainhash.Hash
- func HeaderParentHash(header []byte) *chainhash.Hash
- func NewTxSpent(blockHash, txId, inPrevHash *chainhash.Hash, inPrevIndex, txInIndex uint32) (txKey TxKey, txValue TxValue)
- func TxIdBlockHashFromTxKey(txKey TxKey) (*chainhash.Hash, *chainhash.Hash, error)
- type BlockHeader
- type BlockIdentifier
- type CacheOutput
- func (c CacheOutput) Equal(x CacheOutput) bool
- func (c CacheOutput) IsDelete() bool
- func (c CacheOutput) OutputIndex() uint32
- func (c CacheOutput) OutputIndexBytes() []byte
- func (c CacheOutput) ScriptHash() (hash ScriptHash)
- func (c CacheOutput) ScriptHashSlice() []byte
- func (c CacheOutput) String() string
- func (c CacheOutput) Value() uint64
- func (c CacheOutput) ValueBytes() []byte
- type Database
- type InsertType
- type Outpoint
- type ScriptHash
- type SpentInfo
- type TxKey
- type TxValue
- type Utxo
Constants ¶
This section is empty.
Variables ¶
var DeleteUtxo = [8]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
DeleteUtxo is the max uint64 value which is used as a sentinel to indicate that a utxo should be reaped. The remaining fields must remain untouched since they are part of the lookup key of the utxo balance.
Functions ¶
func B2H ¶ added in v0.2.0
func B2H(header []byte) (*wire.BlockHeader, error)
B2H converts a raw block header to a wire block header structure.
func HeaderHash ¶ added in v0.2.0
HeaderHash return the block hash from a raw block header.
func HeaderParentHash ¶ added in v0.2.0
HeaderHash return the parent block hash from a raw block header.
Types ¶
type BlockHeader ¶
BlockHeader contains the first 80 raw bytes of a bitcoin block plus its location information (hash+height) and the cumulative difficulty.
func (BlockHeader) BlockHash ¶ added in v0.2.0
func (bh BlockHeader) BlockHash() *chainhash.Hash
func (BlockHeader) ParentHash ¶ added in v0.2.0
func (bh BlockHeader) ParentHash() *chainhash.Hash
func (BlockHeader) String ¶
func (bh BlockHeader) String() string
func (BlockHeader) Timestamp ¶
func (bh BlockHeader) Timestamp() time.Time
func (BlockHeader) Wire ¶
func (bh BlockHeader) Wire() (*wire.BlockHeader, error)
type BlockIdentifier ¶
BlockIdentifier uniquely identifies a block using it's hash and height.
type CacheOutput ¶
type CacheOutput [32 + 8 + 4]byte // script_hash + value + out_idx
CacheOutput is a densely packed representation of a bitcoin UTXo. The fields are script_hash + value + out_index. It is packed for memory conservation reasons.
func NewCacheOutput ¶
func NewCacheOutput(hash [32]byte, value uint64, outIndex uint32) (co CacheOutput)
func NewDeleteCacheOutput ¶
func NewDeleteCacheOutput(hash [32]byte, outIndex uint32) (co CacheOutput)
func (CacheOutput) Equal ¶
func (c CacheOutput) Equal(x CacheOutput) bool
func (CacheOutput) IsDelete ¶
func (c CacheOutput) IsDelete() bool
func (CacheOutput) OutputIndex ¶
func (c CacheOutput) OutputIndex() uint32
func (CacheOutput) OutputIndexBytes ¶
func (c CacheOutput) OutputIndexBytes() []byte
func (CacheOutput) ScriptHash ¶
func (c CacheOutput) ScriptHash() (hash ScriptHash)
func (CacheOutput) ScriptHashSlice ¶
func (c CacheOutput) ScriptHashSlice() []byte
func (CacheOutput) String ¶
func (c CacheOutput) String() string
String reutrns pretty printable CacheOutput. Hash is not reversed since it is an opaque pointer. It prints satoshis@script_hash:output_index
func (CacheOutput) Value ¶
func (c CacheOutput) Value() uint64
func (CacheOutput) ValueBytes ¶
func (c CacheOutput) ValueBytes() []byte
type Database ¶
type Database interface { database.Database // Metadata Version(ctx context.Context) (int, error) MetadataGet(ctx context.Context, key []byte) ([]byte, error) MetadataPut(ctx context.Context, key, value []byte) error // Block header BlockHeaderBest(ctx context.Context) (*BlockHeader, error) // return canonical BlockHeaderByHash(ctx context.Context, hash *chainhash.Hash) (*BlockHeader, error) BlockHeaderGenesisInsert(ctx context.Context, bh [80]byte) error // Block headers BlockHeadersByHeight(ctx context.Context, height uint64) ([]BlockHeader, error) BlockHeadersInsert(ctx context.Context, bhs [][80]byte) (InsertType, *BlockHeader, *BlockHeader, error) // Block BlocksMissing(ctx context.Context, count int) ([]BlockIdentifier, error) BlockInsert(ctx context.Context, b *btcutil.Block) (int64, error) // XXX replace BlockInsert with plural version // BlocksInsert(ctx context.Context, bs []*Block) (int64, error) BlockByHash(ctx context.Context, hash *chainhash.Hash) (*btcutil.Block, error) // Transactions BlockUtxoUpdate(ctx context.Context, direction int, utxos map[Outpoint]CacheOutput) error BlockTxUpdate(ctx context.Context, direction int, txs map[TxKey]*TxValue) error BlocksByTxId(ctx context.Context, txId *chainhash.Hash) ([]*chainhash.Hash, error) SpentOutputsByTxId(ctx context.Context, txId *chainhash.Hash) ([]SpentInfo, error) // ScriptHash returns the sha256 of PkScript for the provided outpoint. BalanceByScriptHash(ctx context.Context, sh ScriptHash) (uint64, error) ScriptHashByOutpoint(ctx context.Context, op Outpoint) (*ScriptHash, error) UtxosByScriptHash(ctx context.Context, sh ScriptHash, start uint64, count uint64) ([]Utxo, error) }
type InsertType ¶ added in v0.2.0
type InsertType int
const ( ITInvalid InsertType = 0 // Invalid insert ITChainExtend InsertType = 1 // Normal insert, does not require further action. ITChainFork InsertType = 2 // Chain forked, unwind and rewind indexes. ITForkExtend InsertType = 3 // Extended a fork, does not require further action. )
func (InsertType) String ¶ added in v0.2.0
func (it InsertType) String() string
type Outpoint ¶
type Outpoint [1 + 32 + 4]byte
Outpoint is a bitcoin structure that points to a transaction in a block. It is expressed as an array of bytes in order to pack it as dense as possible for memory conservation reasons.
The bytes contained by Outpoint is 'u' + txid + index.
func NewOutpoint ¶
func (Outpoint) TxIndexBytes ¶
type ScriptHash ¶
ScriptHash is a SHA256 hash that implements fmt.Stringer.
func NewScriptHashFromBytes ¶
func NewScriptHashFromBytes(hash []byte) (scriptHash ScriptHash, err error)
func NewScriptHashFromScript ¶ added in v0.3.0
func NewScriptHashFromScript(script []byte) (scriptHash ScriptHash)
func NewScriptHashFromString ¶ added in v0.3.0
func NewScriptHashFromString(hash string) (ScriptHash, error)
func (ScriptHash) String ¶
func (sh ScriptHash) String() string
type TxKey ¶
type TxKey [69]byte // Allocate max sized key, the prefix byte determines the lengths
Spent Transaction:
s + txin.PrevOutPoint.Hash + txin.PrevOutPoint.Index + blockhash = txid + txin_index | [1 + 32 + 4 + 32] = [32 + 4]
Transaction ID to Block mapping:
t + txid + blockhash = nil | [1 + 32 + 32] = nil
func NewTxMapping ¶
NewTxMapping returns a TxKey and TxValue that maps a tx id to a block hash.
type TxValue ¶
type TxValue [36]byte // allocate max sized value
Spent Transaction:
s + txin.PrevOutPoint.Hash + txin.PrevOutPoint.Index + blockhash = txid + txin_index | [1 + 32 + 4 + 32] = [32 + 4]
Transaction ID to Block mapping:
t + txid + blockhash = nil | [1 + 32 + 32] = nil
type Utxo ¶
type Utxo [32 + 8 + 4]byte // tx_id + value + out_idx
Utxo packs a transaction id, the value and the out index.
func (Utxo) Equal ¶
func (u Utxo) Equal(x CacheOutput) bool
func (Utxo) OutputIndex ¶
func (Utxo) OutputIndexBytes ¶
func (Utxo) ScriptHash ¶
func (u Utxo) ScriptHash() (hash ScriptHash)
func (Utxo) ScriptHashSlice ¶
func (Utxo) String ¶
String reutrns pretty printable CacheOutput. Hash is not reversed since it is an opaque pointer. It prints satoshis@script_hash:output_index