tbcd

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

func NewTxSpent(blockHash, txId, inPrevHash *chainhash.Hash, inPrevIndex, txInIndex uint32) (txKey TxKey, txValue TxValue)

NewTxSpent returns a TxKey and TxValue that maps a spent transaction to a location in a block.

func TxIdBlockHashFromTxKey added in v0.2.8

func TxIdBlockHashFromTxKey(txKey TxKey) (*chainhash.Hash, *chainhash.Hash, error)

Types

type BlockHeader

type BlockHeader struct {
	Hash       chainhash.Hash
	Height     uint64
	Header     [80]byte
	Difficulty big.Int
}

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) HH added in v0.4.4

func (bh BlockHeader) HH() string

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

type BlockIdentifier struct {
	Height uint64
	Hash   *chainhash.Hash
}

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, wbh *wire.BlockHeader) error

	// Block headers
	BlockHeadersByHeight(ctx context.Context, height uint64) ([]BlockHeader, error)
	BlockHeadersInsert(ctx context.Context, bhs *wire.MsgHeaders) (InsertType, *BlockHeader, *BlockHeader, int, error)

	// Block
	BlocksMissing(ctx context.Context, count int) ([]BlockIdentifier, error)
	BlockMissingDelete(ctx context.Context, height int64, hash *chainhash.Hash) error
	BlockInsert(ctx context.Context, b *btcutil.Block) (int64, error)
	// BlocksInsert(ctx context.Context, bs []*btcutil.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
	BlockHashByTxId(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)
	BlockInTxIndex(ctx context.Context, hash *chainhash.Hash) (bool, 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 NewOutpoint(txid [32]byte, index uint32) (op Outpoint)

func (Outpoint) String

func (o Outpoint) String() string

String returns a reversed pretty printed outpoint.

func (Outpoint) TxId

func (o Outpoint) TxId() []byte

func (Outpoint) TxIdHash added in v0.3.0

func (o Outpoint) TxIdHash() *chainhash.Hash

func (Outpoint) TxIndex

func (o Outpoint) TxIndex() uint32

func (Outpoint) TxIndexBytes

func (o Outpoint) TxIndexBytes() []byte

type ScriptHash

type ScriptHash [sha256.Size]byte

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 SpentInfo added in v0.2.8

type SpentInfo struct {
	BlockHash  *chainhash.Hash
	TxId       *chainhash.Hash
	InputIndex uint32
}

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

func NewTxMapping(txId, blockHash *chainhash.Hash) (txKey TxKey)

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 NewUtxo

func NewUtxo(hash [32]byte, value uint64, outIndex uint32) (u Utxo)

func (Utxo) Equal

func (u Utxo) Equal(x CacheOutput) bool

func (Utxo) OutputIndex

func (u Utxo) OutputIndex() uint32

func (Utxo) OutputIndexBytes

func (u Utxo) OutputIndexBytes() []byte

func (Utxo) ScriptHash

func (u Utxo) ScriptHash() (hash ScriptHash)

func (Utxo) ScriptHashSlice

func (u Utxo) ScriptHashSlice() []byte

func (Utxo) String

func (u Utxo) 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 (Utxo) Value

func (u Utxo) Value() uint64

func (Utxo) ValueBytes

func (u Utxo) ValueBytes() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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