tbcd

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 10 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.

Types

type Block

type Block struct {
	Hash  database.ByteArray
	Block database.ByteArray
}

Block contains a raw bitcoin block and its corresponding hash.

type BlockHash

type BlockHash [32]byte

BlockHash is a bitcoin transaction id. The underlying slice is reversed, only when using the stringer does it apear in human readable format.

func NewBlockHash

func NewBlockHash(x [32]byte) (blockHash BlockHash)

func NewBlockHashFromBytes

func NewBlockHashFromBytes(x []byte) (blockHash BlockHash, err error)

func (BlockHash) String

func (bh BlockHash) String() string

type BlockHeader

type BlockHeader struct {
	Hash   database.ByteArray
	Height uint64
	Header database.ByteArray
}

BlockHeader contains the first 80 raw bytes of a bitcoin block and its location information (hash+height).

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   database.ByteArray
}

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 [32]byte)

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
	BlockHeaderByHash(ctx context.Context, hash []byte) (*BlockHeader, error)
	BlockHeadersBest(ctx context.Context) ([]BlockHeader, error)
	BlockHeadersByHeight(ctx context.Context, height uint64) ([]BlockHeader, error)
	BlockHeadersInsert(ctx context.Context, bhs []BlockHeader) error

	// Block
	BlocksMissing(ctx context.Context, count int) ([]BlockIdentifier, error)
	BlockInsert(ctx context.Context, b *Block) (int64, error)
	// XXX replace BlockInsert with plural version
	// BlocksInsert(ctx context.Context, bs []*Block) (int64, error)
	BlockByHash(ctx context.Context, hash []byte) (*Block, error)

	// Transactions
	BlockUtxoUpdate(ctx context.Context, utxos map[Outpoint]CacheOutput) error
	BlockTxUpdate(ctx context.Context, txs map[TxKey]*TxValue) error
	BlocksByTxId(ctx context.Context, txId TxId) ([]BlockHash, error)
	SpendOutputsByTxId(ctx context.Context, txId TxId) ([]SpendInfo, error)

	// Peer manager
	PeersStats(ctx context.Context) (int, int)               // good, bad count
	PeersInsert(ctx context.Context, peers []Peer) error     // insert or update
	PeerDelete(ctx context.Context, host, port string) error // remove peer
	PeersRandom(ctx context.Context, count int) ([]Peer, 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 Outpoint

type Outpoint [37]byte // Outpoint Tx id

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.

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

func (o Outpoint) TxIndex() uint32

func (Outpoint) TxIndexBytes

func (o Outpoint) TxIndexBytes() []byte

type Peer

type Peer struct {
	Host      string
	Port      string
	LastAt    database.Timestamp `deep:"-"` // Last time connected
	CreatedAt database.Timestamp `deep:"-"`
}

Peer

type ScriptHash

type ScriptHash [32]byte

ScriptHash is a bitcoin transaction id. The underlying slice is reversed, only when using the stringer does it apear in human readable format.

func NewScriptHash

func NewScriptHash(x [32]byte) (scriptHash ScriptHash)

func NewScriptHashFromBytes

func NewScriptHashFromBytes(x []byte) (scriptHash ScriptHash, err error)

func (ScriptHash) String

func (bh ScriptHash) String() string

type SpendInfo

type SpendInfo struct {
	BlockHash  BlockHash
	TxId       TxId
	InputIndex uint32
}

type TxId

type TxId [32]byte

TxId is a bitcoin transaction id. The underlying slice is reversed, only when using the stringer does it apear in human readable format.

func NewTxId

func NewTxId(x [32]byte) (txId TxId)

func NewTxIdFromBytes

func NewTxIdFromBytes(x []byte) (txId TxId, err error)

func (TxId) String

func (t TxId) 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 + blockhash | [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 + blockhash | [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 [32]byte)

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