indexer

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrProcessNotFound is returned if the process is not found in the indexer database.
	ErrProcessNotFound = fmt.Errorf("process not found")
)
View Source
var ErrTransactionNotFound = fmt.Errorf("transaction not found")

ErrTransactionNotFound is returned if the transaction is not found.

View Source
var ErrVoteNotFound = fmt.Errorf("vote not found")

ErrVoteNotFound is returned if the vote is not found in the indexer database.

Functions

This section is empty.

Types

type ArchiveProcess added in v1.10.0

type ArchiveProcess struct {
	ChainID     string                `json:"chainId,omitempty"` // Legacy
	ProcessInfo *indexertypes.Process `json:"process"`
	Results     *results.Results      `json:"results"`
	StartDate   *time.Time            `json:"startDate,omitempty"` // Legacy
	EndDate     *time.Time            `json:"endDate,omitempty"`   // Legacy
}

ArchiveProcess is the struct used to store the process data in the archive.

type EventListener

type EventListener interface {
	OnComputeResults(results *results.Results, process *indexertypes.Process, height uint32)
}

EventListener is an interface used for executing custom functions during the events of the tally of a process.

type Indexer

type Indexer struct {
	App *vochain.BaseApplication
	// contains filtered or unexported fields
}

Indexer is the component which makes the accounting of the voting processes and keeps it indexed in a local database.

func NewIndexer

func NewIndexer(dataDir string, app *vochain.BaseApplication, countLiveResults bool) (*Indexer, error)

NewIndexer returns an instance of the Indexer using the local storage database in dataDir and integrated into the state vochain instance

func (*Indexer) AddEventListener

func (idx *Indexer) AddEventListener(l EventListener)

AddEventListener adds a new event listener, to receive method calls on block events as documented in EventListener.

func (*Indexer) AfterSyncBootstrap

func (idx *Indexer) AfterSyncBootstrap(inTest bool)

AfterSyncBootstrap is a blocking function that waits until the Vochain is synchronized and then execute a set of recovery actions. It mainly checks for those processes which are still open (live) and updates all temporary data (current voting weight and live results if unecrypted). This method might be called on a goroutine after initializing the Indexer. TO-DO: refactor and use blockHeight for reusing existing live results

func (*Indexer) Close

func (idx *Indexer) Close() error

func (*Indexer) Commit

func (idx *Indexer) Commit(height uint32) error

Commit is called by the APP when a block is confirmed and included into the chain

func (*Indexer) CountTokenTransfersByAccount added in v1.10.0

func (idx *Indexer) CountTokenTransfersByAccount(acc []byte) (uint64, error)

CountTokenTransfersByAccount returns the count all the token transfers made from a given account

func (*Indexer) CountTotalAccounts added in v1.10.0

func (idx *Indexer) CountTotalAccounts() (uint64, error)

CountTotalAccounts returns the total number of accounts indexed.

func (*Indexer) CountTotalEntities added in v1.9.0

func (idx *Indexer) CountTotalEntities() uint64

CountTotalEntities return the total number of entities indexed by the indexer

func (*Indexer) CountTotalProcesses added in v1.9.0

func (idx *Indexer) CountTotalProcesses() uint64

CountTotalProcesses returns the total number of processes indexed.

func (*Indexer) CountTotalTransactions added in v1.9.0

func (idx *Indexer) CountTotalTransactions() (uint64, error)

CountTotalTransactions returns the number of transactions indexed

func (*Indexer) CountTotalVotes added in v1.9.0

func (idx *Indexer) CountTotalVotes() (uint64, error)

CountTotalVotes returns the total number of envelopes.

func (*Indexer) EntityList

func (idx *Indexer) EntityList(max, from int, searchTerm string) []indexerdb.SearchEntitiesRow

EntityList returns the list of entities indexed by the indexer searchTerm is optional, if declared as zero-value will be ignored. Searches against the ID field.

func (*Indexer) GetEnvelope

func (idx *Indexer) GetEnvelope(nullifier []byte) (*indexertypes.EnvelopePackage, error)

GetEnvelope retrieves an Envelope from the Blockchain block store identified by its nullifier. Returns the envelope and the signature (if any).

func (*Indexer) GetEnvelopes

func (idx *Indexer) GetEnvelopes(processId []byte, max, from int,
	searchTerm string) ([]*indexertypes.EnvelopeMetadata, error)

GetEnvelopes retrieves all envelope metadata for a ProcessId. Returns ErrVoteNotFound if the envelope reference is not found.

func (*Indexer) GetLastTransactions added in v1.8.0

func (idx *Indexer) GetLastTransactions(limit, offset int32) ([]*indexertypes.Transaction, error)

GetLastTransactions fetches a number of the latest indexed transactions. The first one returned is the newest, so they are in descending order.

func (*Indexer) GetListAccounts added in v1.10.0

func (idx *Indexer) GetListAccounts(offset, maxItems int32) ([]indexertypes.Account, error)

func (*Indexer) GetTokenFees added in v1.9.0

func (idx *Indexer) GetTokenFees(offset, maxItems int32) ([]*indexertypes.TokenFeeMeta, error)

GetTokenFees returns all the token transfers from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTokenFeesByFromAccount added in v1.9.0

func (idx *Indexer) GetTokenFeesByFromAccount(from []byte, offset, maxItems int32) ([]*indexertypes.TokenFeeMeta, error)

GetTokenFeesByFromAccount returns all the token transfers made from a given account from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTokenFeesByReference added in v1.9.0

func (idx *Indexer) GetTokenFeesByReference(reference string, offset, maxItems int32) ([]*indexertypes.TokenFeeMeta, error)

GetTokenFeesByReference returns all the token fees associated with a given reference from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTokenFeesByType added in v1.9.0

func (idx *Indexer) GetTokenFeesByType(txType string, offset, maxItems int32) ([]*indexertypes.TokenFeeMeta, error)

GetTokenFeesByType returns all the token fees associated with a given transaction type from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTokenTransfersByAccount added in v1.10.0

func (idx *Indexer) GetTokenTransfersByAccount(acc []byte, offset, maxItems int32) (indexertypes.TokenTransfersAccount, error)

GetTokenTransfersByAccount returns all the token transfers made to and from a given account from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTokenTransfersByFromAccount

func (idx *Indexer) GetTokenTransfersByFromAccount(from []byte, offset, maxItems int32) ([]*indexertypes.TokenTransferMeta, error)

GetTokenTransfersByFromAccount returns all the token transfers made from a given account from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTokenTransfersByToAccount added in v1.10.0

func (idx *Indexer) GetTokenTransfersByToAccount(to []byte, offset, maxItems int32) ([]*indexertypes.TokenTransferMeta, error)

GetTokenTransfersByToAccount returns all the token transfers made to a given account from the database, ordered by timestamp and paginated by maxItems and offset

func (*Indexer) GetTransaction added in v1.8.0

func (idx *Indexer) GetTransaction(id uint64) (*indexertypes.Transaction, error)

GetTransaction fetches the txReference for the given tx height

func (*Indexer) GetTxHashReference

func (idx *Indexer) GetTxHashReference(hash types.HexBytes) (*indexertypes.Transaction, error)

GetTxHashReference fetches the txReference for the given tx hash

func (*Indexer) GetTxReferenceByBlockHeightAndBlockIndex added in v1.8.0

func (idx *Indexer) GetTxReferenceByBlockHeightAndBlockIndex(blockHeight, blockIndex int64) (*indexertypes.Transaction, error)

GetTxReferenceByBlockHeightAndBlockIndex fetches the txReference for the given tx height and block tx index

func (*Indexer) ImportArchive added in v1.10.0

func (idx *Indexer) ImportArchive(archive []*ArchiveProcess) ([]*ArchiveProcess, error)

ImportArchive imports an archive list of processes into the indexer database. It checks if the process already exists in the database and if not, it creates it. Returns those processes that have been added to the database.

func (*Indexer) OnBeginBlock added in v1.9.0

func (idx *Indexer) OnBeginBlock(bb state.BeginBlock)

func (*Indexer) OnCancel

func (idx *Indexer) OnCancel(pid []byte, _ int32)

OnCancel indexer stores the processID and entityID

func (*Indexer) OnCensusUpdate added in v1.9.0

func (idx *Indexer) OnCensusUpdate(pid, _ []byte, _ string)

OnCensusUpdate adds the process to blockUpdateProcs in order to update the census. This function call is triggered by the SET_PROCESS_CENSUS tx.

func (*Indexer) OnNewTx

func (idx *Indexer) OnNewTx(tx *vochaintx.Tx, blockHeight uint32, txIndex int32)

func (*Indexer) OnProcess

func (idx *Indexer) OnProcess(pid, _ []byte, _, _ string, _ int32)

OnProcess indexer stores the processID

func (*Indexer) OnProcessKeys

func (idx *Indexer) OnProcessKeys(pid []byte, _ string, _ int32)

OnProcessKeys does nothing

func (*Indexer) OnProcessResults

func (idx *Indexer) OnProcessResults(pid []byte, _ *models.ProcessResult, _ int32)

OnProcessResults verifies the results for a process and appends it to blockUpdateProcs

func (*Indexer) OnProcessStatusChange

func (idx *Indexer) OnProcessStatusChange(pid []byte, _ models.ProcessStatus, _ int32)

OnProcessStatusChange adds the process to blockUpdateProcs and, if ended, the resultsPool

func (*Indexer) OnProcessesStart

func (idx *Indexer) OnProcessesStart(pids [][]byte)

OnProcessesStart adds the processes to blockUpdateProcs. This is required to update potential changes when a process is started, such as the census root.

func (*Indexer) OnRevealKeys

func (idx *Indexer) OnRevealKeys(pid []byte, _ string, _ int32)

OnRevealKeys checks if all keys have been revealed and in such case add the process to the results queue

func (*Indexer) OnSetAccount

func (idx *Indexer) OnSetAccount(accountAddress []byte, account *state.Account)

func (*Indexer) OnSpendTokens added in v1.9.0

func (idx *Indexer) OnSpendTokens(address []byte, txType models.TxType, cost uint64, reference string)

OnSpendTokens indexes a token spending event.

func (*Indexer) OnTransferTokens

func (idx *Indexer) OnTransferTokens(tx *vochaintx.TokenTransfer)

func (*Indexer) OnVote

func (idx *Indexer) OnVote(vote *state.Vote, txIndex int32)

OnVote indexer stores the votes if the processId is live results (on going) and the blockchain is not synchronizing. voterID is the identifier of the voter, the most common case is an ethereum address but can be any kind of id expressed as bytes.

func (*Indexer) ProcessInfo

func (idx *Indexer) ProcessInfo(pid []byte) (*indexertypes.Process, error)

ProcessInfo returns the available information regarding an election process id

func (*Indexer) ProcessList

func (idx *Indexer) ProcessList(entityID []byte, from, max int, searchTerm string, namespace uint32,
	srcNetworkId int32, status string, withResults bool) ([][]byte, error)

ProcessList returns a list of process identifiers (PIDs) registered in the Vochain. EntityID, searchTerm, namespace, status, and withResults are optional filters, if declared as zero-values will be ignored. SearchTerm is a partial or full PID. Status is one of READY, CANCELED, ENDED, PAUSED, RESULTS

func (*Indexer) Rollback

func (idx *Indexer) Rollback()

Rollback removes the non committed pending operations

func (*Indexer) StartArchiveRetrieval added in v1.10.0

func (idx *Indexer) StartArchiveRetrieval(storage *downloader.Downloader, archiveURL string)

StartArchiveRetrieval starts the archive retrieval process. It is a blocking function that runs continuously. Retrieves the archive directory from the storage and imports the processes into the indexer database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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