Documentation ¶
Index ¶
- Constants
- func DBPutSpendJournalEntry(db model.DataBase, blockHash *hash.Hash, stxos []SpentTxOut) error
- func DBRemoveSpendJournalEntry(db model.DataBase, blockHash *hash.Hash) error
- func OutpointKey(outpoint types.TxOutPoint) *[]byte
- func OutpointKeyNoPool(outpoint types.TxOutPoint) []byte
- func RecycleOutpointKey(key *[]byte)
- func SerializeUtxoEntry(entry *UtxoEntry) ([]byte, error)
- type SpentTxOut
- type UtxoEntry
- func (entry *UtxoEntry) Amount() types.Amount
- func (entry *UtxoEntry) BlockHash() *hash.Hash
- func (entry *UtxoEntry) Clone() *UtxoEntry
- func (entry *UtxoEntry) CoinBase()
- func (entry *UtxoEntry) IsCoinBase() bool
- func (entry *UtxoEntry) IsModified() bool
- func (entry *UtxoEntry) IsSpent() bool
- func (entry *UtxoEntry) Modified()
- func (entry *UtxoEntry) PkScript() []byte
- func (entry *UtxoEntry) SetAmount(amount types.Amount)
- func (entry *UtxoEntry) SetBlockHash(bh *hash.Hash)
- func (entry *UtxoEntry) SetPkScript(pks []byte)
- func (entry *UtxoEntry) Spend()
- type UtxoViewpoint
- func (view *UtxoViewpoint) AddEntry(outpoint types.TxOutPoint, entry *UtxoEntry)
- func (view *UtxoViewpoint) AddTokenTxOut(outpoint types.TxOutPoint, pkscript []byte)
- func (view *UtxoViewpoint) AddTxOut(tx *types.Tx, txOutIdx uint32, blockHash *hash.Hash)
- func (view *UtxoViewpoint) AddTxOuts(tx *types.Tx, blockHash *hash.Hash)
- func (view *UtxoViewpoint) Clean()
- func (view *UtxoViewpoint) Commit()
- func (view *UtxoViewpoint) Entries() map[types.TxOutPoint]*UtxoEntry
- func (view *UtxoViewpoint) FetchUtxosMain(db model.DataBase, outpoints map[types.TxOutPoint]struct{}) error
- func (view *UtxoViewpoint) GetEntry(outpoint types.TxOutPoint) *UtxoEntry
- func (view *UtxoViewpoint) LookupEntry(outpoint types.TxOutPoint) *UtxoEntry
- func (view *UtxoViewpoint) RemoveEntry(outpoint types.TxOutPoint)
- func (view *UtxoViewpoint) SetViewpoints(views []*hash.Hash)
- func (view *UtxoViewpoint) Viewpoints() []*hash.Hash
Constants ¶
const SpentTxOutFeesValueSize = 8
const SpentTxOutTxInIndexSize = 4
The bytes of TxInIndex
const SpentTxOutTxIndexSize = 4
The bytes of TxIndex
const SpentTxoutAmountCoinIDSize = 2
The bytes of Amount's CoinId
const SpentTxoutFeesCoinIDSize = 2
The bytes of Fees field
const UtxoEntryAmountCoinIDSize = 2
Variables ¶
This section is empty.
Functions ¶
func DBPutSpendJournalEntry ¶
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 ¶
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 OutpointKeyNoPool ¶ added in v1.2.0
func OutpointKeyNoPool(outpoint types.TxOutPoint) []byte
func RecycleOutpointKey ¶
func RecycleOutpointKey(key *[]byte)
func SerializeUtxoEntry ¶
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(db model.DataBase, 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 DeserializeUtxoEntry ¶
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 (*UtxoEntry) IsCoinBase ¶
IsCoinBase returns whether or not the output was contained in a coinbase transaction.
func (*UtxoEntry) IsModified ¶
isModified returns whether or not the output has been modified since it was loaded.
func (*UtxoEntry) IsSpent ¶
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) SetBlockHash ¶
func (*UtxoEntry) SetPkScript ¶
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) 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 model.DataBase, 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.