Documentation
¶
Overview ¶
Package historydb is in charge of parsing the consuses blokchain, and providing apis for blockchain explorer.
Index ¶
- Variables
- func CreateBuckets(tx *dbutil.Tx) error
- func NewErrUxOutNotExist(uxID string) error
- type AddressIndexes
- type ErrHistoryDBCorrupted
- type ErrUxOutNotExist
- type HistoryDB
- func (hd *HistoryDB) Erase(tx *dbutil.Tx) error
- func (hd HistoryDB) ForEachTxn(tx *dbutil.Tx, f func(cipher.SHA256, *Transaction) error) error
- func (hd HistoryDB) GetAddrUxOuts(tx *dbutil.Tx, address cipher.Address) ([]*UxOut, error)
- func (hd HistoryDB) GetAddressTxns(tx *dbutil.Tx, address cipher.Address) ([]Transaction, error)
- func (hd HistoryDB) GetTransaction(tx *dbutil.Tx, hash cipher.SHA256) (*Transaction, error)
- func (hd *HistoryDB) GetUxOuts(tx *dbutil.Tx, uxIDs []cipher.SHA256) ([]*UxOut, error)
- func (hm HistoryDB) IsEmpty(tx *dbutil.Tx) (bool, error)
- func (hd *HistoryDB) NeedsReset(tx *dbutil.Tx) (bool, error)
- func (hd *HistoryDB) ParseBlock(tx *dbutil.Tx, b coin.Block) error
- func (hm HistoryDB) ParsedBlockSeq(tx *dbutil.Tx) (uint64, bool, error)
- func (hm HistoryDB) Reset(tx *dbutil.Tx) error
- func (hm HistoryDB) SetParsedBlockSeq(tx *dbutil.Tx, h uint64) error
- func (hd HistoryDB) Verify(tx *dbutil.Tx, b *coin.SignedBlock, indexesMap *IndexesMap) error
- type IndexesMap
- type Transaction
- type UxOut
- type UxOutJSON
- type UxOuts
- func (ux *UxOuts) Get(tx *dbutil.Tx, uxID cipher.SHA256) (*UxOut, error)
- func (ux *UxOuts) GetArray(tx *dbutil.Tx, uxIDs []cipher.SHA256) ([]*UxOut, error)
- func (ux *UxOuts) IsEmpty(tx *dbutil.Tx) (bool, error)
- func (ux *UxOuts) Reset(tx *dbutil.Tx) error
- func (ux *UxOuts) Set(tx *dbutil.Tx, out UxOut) error
Constants ¶
This section is empty.
Variables ¶
var AddressTxnsBkt = []byte("address_txns")
AddressTxnsBkt maps addresses to transaction hashes
var AddressUxBkt = []byte("address_in")
AddressUxBkt maps addresses to unspent outputs
var ( // HistoryMetaBkt holds history metadata HistoryMetaBkt = []byte("history_meta") )
var TransactionsBkt = []byte("transactions")
TransactionsBkt holds Transactions
var UxOutsBkt = []byte("uxouts")
UxOutsBkt holds unspent outputs
Functions ¶
func CreateBuckets ¶
CreateBuckets creates bolt.DB buckets used by the historydb
func NewErrUxOutNotExist ¶
NewErrUxOutNotExist creates ErrUxOutNotExist from a UxID
Types ¶
type AddressIndexes ¶
type AddressIndexes struct { TxnHashes map[cipher.SHA256]struct{} UxHashes map[cipher.SHA256]struct{} }
AddressIndexes represents the address indexes struct
type ErrHistoryDBCorrupted ¶
type ErrHistoryDBCorrupted struct {
// contains filtered or unexported fields
}
ErrHistoryDBCorrupted is returned when found the historydb is corrupted
func NewErrHistoryDBCorrupted ¶
func NewErrHistoryDBCorrupted(err error) ErrHistoryDBCorrupted
NewErrHistoryDBCorrupted is for user to be able to create ErrHistoryDBCorrupted instance outside of the package
type ErrUxOutNotExist ¶
type ErrUxOutNotExist struct {
UxID string
}
ErrUxOutNotExist is returned if an uxout is not found in historydb
func (ErrUxOutNotExist) Error ¶
func (e ErrUxOutNotExist) Error() string
type HistoryDB ¶
type HistoryDB struct {
// contains filtered or unexported fields
}
HistoryDB provides APIs for blockchain explorer
func (HistoryDB) ForEachTxn ¶
ForEachTxn traverses the transactions bucket
func (HistoryDB) GetAddrUxOuts ¶
GetAddrUxOuts get all uxout that the address affected.
func (HistoryDB) GetAddressTxns ¶
GetAddressTxns returns all the address related transactions
func (HistoryDB) GetTransaction ¶
GetTransaction get transaction by hash.
func (*HistoryDB) NeedsReset ¶
NeedsReset checks if need to reset the parsed block history, If we have a new added bucket, we need to reset to parse blockchain again to get the new bucket filled.
func (*HistoryDB) ParseBlock ¶
ParseBlock builds indexes out of the block data
func (HistoryDB) ParsedBlockSeq ¶
Height returns history parsed block seq
func (HistoryDB) SetParsedBlockSeq ¶
SetParsedHeight updates history parsed block seq
func (HistoryDB) Verify ¶
func (hd HistoryDB) Verify(tx *dbutil.Tx, b *coin.SignedBlock, indexesMap *IndexesMap) error
Verify checks if the historydb is corrupted
type IndexesMap ¶
type IndexesMap struct {
// contains filtered or unexported fields
}
IndexesMap is a goroutine safe address indexes map
func (*IndexesMap) Load ¶
func (im *IndexesMap) Load(address cipher.Address) (AddressIndexes, bool)
Load returns value of given key
func (*IndexesMap) Store ¶
func (im *IndexesMap) Store(address cipher.Address, indexes AddressIndexes)
Store saves address with indexes
type Transaction ¶
type Transaction struct { Tx coin.Transaction BlockSeq uint64 }
Transaction contains transaction info and the seq of block which executed this block.
type UxOut ¶
type UxOut struct { Out coin.UxOut SpentTxID cipher.SHA256 // id of tx which spent this output. SpentBlockSeq uint64 // block seq that spent the output. }
UxOut expend coin.UxOut struct
type UxOutJSON ¶
type UxOutJSON struct { Uxid string `json:"uxid"` Time uint64 `json:"time"` SrcBkSeq uint64 `json:"src_block_seq"` SrcTx string `json:"src_tx"` OwnerAddress string `json:"owner_address"` Coins uint64 `json:"coins"` Hours uint64 `json:"hours"` SpentBlockSeq uint64 `json:"spent_block_seq"` // block seq that spent the output. SpentTxID string `json:"spent_tx"` // id of tx which spent this output. }
UxOutJSON UxOut's json format
func NewUxOutJSON ¶
NewUxOutJSON generates UxOutJSON from UxOut
type UxOuts ¶
type UxOuts struct{}
UxOuts bucket stores outputs, UxOut hash as key and Output as value.
func (*UxOuts) GetArray ¶
GetArray returns UxOuts for a set of uxids, will return error if any of the uxids do not exist