utxo

package
v1.0.24 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const SpentTxOutFeesValueSize = 8
View Source
const SpentTxOutTxInIndexSize = 4

The bytes of TxInIndex

View Source
const SpentTxOutTxIndexSize = 4

The bytes of TxIndex

View Source
const SpentTxoutAmountCoinIDSize = 2

The bytes of Amount's CoinId

View Source
const SpentTxoutFeesCoinIDSize = 2

The bytes of Fees field

View Source
const UtxoEntryAmountCoinIDSize = 2

Variables

This section is empty.

Functions

func DBPutSpendJournalEntry

func DBPutSpendJournalEntry(dbTx database.Tx, blockHash *hash.Hash, stxos []SpentTxOut) error

dbPutSpendJournalEntry uses an existing database transaction to update the spend journal entry for the given block hash using the provided slice of spent txouts. The spent txouts slice must contain an entry for every txout the transactions in the block spend in the order they are spent.

func DBRemoveSpendJournalEntry

func DBRemoveSpendJournalEntry(dbTx database.Tx, blockHash *hash.Hash) error

dbRemoveSpendJournalEntry uses an existing database transaction to remove the spend journal entry for the passed block hash.

func OutpointKey

func OutpointKey(outpoint types.TxOutPoint) *[]byte

func RecycleOutpointKey

func RecycleOutpointKey(key *[]byte)

func SerializeUtxoEntry

func SerializeUtxoEntry(entry *UtxoEntry) ([]byte, error)

Types

type SpentTxOut

type SpentTxOut struct {
	Amount     types.Amount // The total amount of the output.
	PkScript   []byte       // The public key script for the output.
	BlockHash  hash.Hash
	IsCoinBase bool         // Whether creating tx is a coinbase.
	TxIndex    uint32       // The index of tx in block.
	TxInIndex  uint32       // The index of TxInput in the tx.
	Fees       types.Amount // The fees of block
}

SpentTxOut contains a spent transaction output and potentially additional contextual information such as whether or not it was contained in a coinbase transaction, the txVersion of the transaction it was contained in, and which block height the containing transaction was included in. As described in the comments above, the additional contextual information will only be valid when this spent txout is spending the last unspent output of the containing transaction.

The struct is aligned for memory efficiency.

func DBFetchSpendJournalEntry

func DBFetchSpendJournalEntry(dbTx database.Tx, block *types.SerializedBlock) ([]SpentTxOut, error)

dbFetchSpendJournalEntry fetches the spend journal entry for the passed block and deserializes it into a slice of spent txout entries. The provided view MUST have the utxos referenced by all of the transactions available for the passed block since that information is required to reconstruct the spent txouts.

func GetStxo

func GetStxo(txIndex uint32, txInIndex uint32, stxos []SpentTxOut) *SpentTxOut

type UtxoEntry

type UtxoEntry struct {
	// contains filtered or unexported fields
}

utxoOutput houses details about an individual unspent transaction output such as whether or not it is spent, its public key script, and how much it pays.

Standard public key scripts are stored in the database using a compressed format. Since the vast majority of scripts are of the standard form, a fairly significant savings is achieved by discarding the portions of the standard scripts that can be reconstructed.

Also, since it is common for only a specific output in a given utxo entry to be referenced from a redeeming transaction, the script and amount for a given output is not uncompressed until the first time it is accessed. This provides a mechanism to avoid the overhead of needlessly uncompressing all outputs for a given utxo entry at the time of load.

The struct is aligned for memory efficiency.

func DBFetchUtxoEntry

func DBFetchUtxoEntry(dbTx database.Tx, outpoint types.TxOutPoint) (*UtxoEntry, error)

func DeserializeUtxoEntry

func DeserializeUtxoEntry(serialized []byte) (*UtxoEntry, error)

deserializeUtxoEntry decodes a utxo entry from the passed serialized byte slice into a new UtxoEntry using a format that is suitable for long-term storage. The format is described in detail above.

func NewUtxoEntry

func NewUtxoEntry(amount types.Amount, pkScript []byte, blockHash *hash.Hash, isCoinBase bool) *UtxoEntry

func (*UtxoEntry) Amount

func (entry *UtxoEntry) Amount() types.Amount

Amount returns the amount of the output.

func (*UtxoEntry) BlockHash

func (entry *UtxoEntry) BlockHash() *hash.Hash

BlockHash returns the hash of the block containing the output.

func (*UtxoEntry) Clone

func (entry *UtxoEntry) Clone() *UtxoEntry

Clone returns a shallow copy of the utxo entry.

func (*UtxoEntry) CoinBase

func (entry *UtxoEntry) CoinBase()

func (*UtxoEntry) IsCoinBase

func (entry *UtxoEntry) IsCoinBase() bool

IsCoinBase returns whether or not the output was contained in a coinbase transaction.

func (*UtxoEntry) IsModified

func (entry *UtxoEntry) IsModified() bool

isModified returns whether or not the output has been modified since it was loaded.

func (*UtxoEntry) IsSpent

func (entry *UtxoEntry) IsSpent() bool

IsSpent returns whether or not the output has been spent based upon the current state of the unspent transaction output view it was obtained from.

func (*UtxoEntry) Modified

func (entry *UtxoEntry) Modified()

func (*UtxoEntry) PkScript

func (entry *UtxoEntry) PkScript() []byte

PkScript returns the public key script for the output.

func (*UtxoEntry) SetAmount

func (entry *UtxoEntry) SetAmount(amount types.Amount)

func (*UtxoEntry) SetBlockHash

func (entry *UtxoEntry) SetBlockHash(bh *hash.Hash)

func (*UtxoEntry) SetPkScript

func (entry *UtxoEntry) SetPkScript(pks []byte)

func (*UtxoEntry) Spend

func (entry *UtxoEntry) Spend()

Spend marks the output as spent. Spending an output that is already spent has no effect.

type UtxoViewpoint

type UtxoViewpoint struct {
	// contains filtered or unexported fields
}

UtxoViewpoint represents a view into the set of unspent transaction outputs from a specific point of view in the chain. For example, it could be for the end of the main chain, some point in the history of the main chain, or down a side chain.

The unspent outputs are needed by other transactions for things such as script validation and double spend prevention.

func NewUtxoViewpoint

func NewUtxoViewpoint() *UtxoViewpoint

NewUtxoViewpoint returns a new empty unspent transaction output view.

func (*UtxoViewpoint) AddEntry

func (view *UtxoViewpoint) AddEntry(outpoint types.TxOutPoint, entry *UtxoEntry)

func (*UtxoViewpoint) AddTokenTxOut

func (view *UtxoViewpoint) AddTokenTxOut(outpoint types.TxOutPoint, pkscript []byte)

func (*UtxoViewpoint) AddTxOut

func (view *UtxoViewpoint) AddTxOut(tx *types.Tx, txOutIdx uint32, blockHash *hash.Hash)

func (*UtxoViewpoint) AddTxOuts

func (view *UtxoViewpoint) AddTxOuts(tx *types.Tx, blockHash *hash.Hash)

AddTxOuts adds all outputs in the passed transaction which are not provably unspendable to the view. When the view already has entries for any of the outputs, they are simply marked unspent. All fields will be updated for existing entries since it's possible it has changed during a reorg.

func (*UtxoViewpoint) Clean

func (view *UtxoViewpoint) Clean()

func (*UtxoViewpoint) Commit

func (view *UtxoViewpoint) Commit()

commit prunes all entries marked modified that are now fully spent and marks all entries as unmodified.

func (*UtxoViewpoint) Entries

func (view *UtxoViewpoint) Entries() map[types.TxOutPoint]*UtxoEntry

Entries returns the underlying map that stores of all the utxo entries.

func (*UtxoViewpoint) FetchUtxosMain

func (view *UtxoViewpoint) FetchUtxosMain(db database.DB, outpoints map[types.TxOutPoint]struct{}) error

FetchUtxosMain fetches unspent transaction output data about the provided set of transactions from the point of view of the end of the main chain at the time of the call.

Upon completion of this function, the view will contain an entry for each requested transaction. Fully spent transactions, or those which otherwise don't exist, will result in a nil entry in the view.

func (*UtxoViewpoint) GetEntry

func (view *UtxoViewpoint) GetEntry(outpoint types.TxOutPoint) *UtxoEntry

func (*UtxoViewpoint) LookupEntry

func (view *UtxoViewpoint) LookupEntry(outpoint types.TxOutPoint) *UtxoEntry

LookupEntry returns information about a given transaction according to the current state of the view. It will return nil if the passed transaction hash does not exist in the view or is otherwise not available such as when it has been disconnected during a reorg.

func (*UtxoViewpoint) RemoveEntry

func (view *UtxoViewpoint) RemoveEntry(outpoint types.TxOutPoint)

func (*UtxoViewpoint) SetViewpoints

func (view *UtxoViewpoint) SetViewpoints(views []*hash.Hash)

SetViewpoints sets the hash of the viewpoint block in the chain the view currently respresents.

func (*UtxoViewpoint) Viewpoints

func (view *UtxoViewpoint) Viewpoints() []*hash.Hash

Viewpoints returns the hash of the viewpoint block in the chain the view currently respresents.

Jump to

Keyboard shortcuts

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