historydb

package
v0.0.0-...-4a7a8e8 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package historydb is in charge of parsing the consuses blokchain, and providing apis for blockchain explorer.

Index

Constants

This section is empty.

Variables

View Source
var AddressTxnsBkt = []byte("address_txns")

AddressTxnsBkt maps addresses to transaction hashes

View Source
var AddressUxBkt = []byte("address_in")

AddressUxBkt maps addresses to unspent outputs

View Source
var (
	// HistoryMetaBkt holds history metadata
	HistoryMetaBkt = []byte("history_meta")
)
View Source
var TransactionsBkt = []byte("transactions")

TransactionsBkt holds Transactions

View Source
var UxOutsBkt = []byte("uxouts")

UxOutsBkt holds unspent outputs

Functions

func CreateBuckets

func CreateBuckets(tx *dbutil.Tx) error

CreateBuckets creates bolt.DB buckets used by the historydb

func NewErrUxOutNotExist

func NewErrUxOutNotExist(uxID string) error

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 New

func New() *HistoryDB

New create HistoryDB instance

func (*HistoryDB) Erase

func (hd *HistoryDB) Erase(tx *dbutil.Tx) error

Erase erases the entire HistoryDB

func (HistoryDB) ForEachTxn

func (hd HistoryDB) ForEachTxn(tx *dbutil.Tx, f func(cipher.SHA256, *Transaction) error) error

ForEachTxn traverses the transactions bucket

func (HistoryDB) GetAddrUxOuts

func (hd HistoryDB) GetAddrUxOuts(tx *dbutil.Tx, address cipher.Address) ([]*UxOut, error)

GetAddrUxOuts get all uxout that the address affected.

func (HistoryDB) GetAddressTxns

func (hd HistoryDB) GetAddressTxns(tx *dbutil.Tx, address cipher.Address) ([]Transaction, error)

GetAddressTxns returns all the address related transactions

func (HistoryDB) GetTransaction

func (hd HistoryDB) GetTransaction(tx *dbutil.Tx, hash cipher.SHA256) (*Transaction, error)

GetTransaction get transaction by hash.

func (*HistoryDB) GetUxOuts

func (hd *HistoryDB) GetUxOuts(tx *dbutil.Tx, uxIDs []cipher.SHA256) ([]*UxOut, error)

GetUxOuts get UxOut of specific uxIDs.

func (HistoryDB) IsEmpty

func (hm HistoryDB) IsEmpty(tx *dbutil.Tx) (bool, error)

IsEmpty checks if history meta bucket is empty

func (*HistoryDB) NeedsReset

func (hd *HistoryDB) NeedsReset(tx *dbutil.Tx) (bool, error)

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

func (hd *HistoryDB) ParseBlock(tx *dbutil.Tx, b coin.Block) error

ParseBlock builds indexes out of the block data

func (HistoryDB) ParsedBlockSeq

func (hm HistoryDB) ParsedBlockSeq(tx *dbutil.Tx) (uint64, bool, error)

Height returns history parsed block seq

func (HistoryDB) Reset

func (hm HistoryDB) Reset(tx *dbutil.Tx) error

Reset resets the bucket

func (HistoryDB) SetParsedBlockSeq

func (hm HistoryDB) SetParsedBlockSeq(tx *dbutil.Tx, h uint64) error

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 NewIndexesMap

func NewIndexesMap() *IndexesMap

NewIndexesMap creates a IndexesMap instance

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.

func (*Transaction) Hash

func (tx *Transaction) Hash() cipher.SHA256

Hash return the Tx hash.

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

func (UxOut) Hash

func (o UxOut) Hash() cipher.SHA256

Hash returns outhash

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

func NewUxOutJSON(out *UxOut) *UxOutJSON

NewUxOutJSON generates UxOutJSON from UxOut

type UxOuts

type UxOuts struct{}

UxOuts bucket stores outputs, UxOut hash as key and Output as value.

func (*UxOuts) Get

func (ux *UxOuts) Get(tx *dbutil.Tx, uxID cipher.SHA256) (*UxOut, error)

Get gets UxOut of given id

func (*UxOuts) GetArray

func (ux *UxOuts) GetArray(tx *dbutil.Tx, uxIDs []cipher.SHA256) ([]*UxOut, error)

GetArray returns UxOuts for a set of uxids, will return error if any of the uxids do not exist

func (*UxOuts) IsEmpty

func (ux *UxOuts) IsEmpty(tx *dbutil.Tx) (bool, error)

IsEmpty checks if the uxout bucekt is empty

func (*UxOuts) Reset

func (ux *UxOuts) Reset(tx *dbutil.Tx) error

Reset resets the bucket

func (*UxOuts) Set

func (ux *UxOuts) Set(tx *dbutil.Tx, out UxOut) error

Set sets out value

Jump to

Keyboard shortcuts

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