Documentation ¶
Index ¶
- Constants
- Variables
- func BuildProcessResult(results *results.Results, entityID []byte) *models.ProcessResult
- func GetFriendlyResults(votes [][]*types.BigInt) [][]string
- type EventListener
- type Indexer
- func (idx *Indexer) AddEventListener(l EventListener)
- func (idx *Indexer) AfterSyncBootstrap()
- func (idx *Indexer) Close() error
- func (idx *Indexer) Commit(height uint32) error
- func (s *Indexer) ComputeResult(processID []byte) error
- func (s *Indexer) EntityCount() uint64
- func (s *Indexer) EntityList(max, from int, searchTerm string) []types.HexBytes
- func (s *Indexer) EntityProcessCount(entityId []byte) (uint32, error)
- func (s *Indexer) GetEnvelope(nullifier []byte) (*indexertypes.EnvelopePackage, error)
- func (s *Indexer) GetEnvelopeHeight(processID []byte) (uint64, error)
- func (s *Indexer) GetEnvelopeReference(nullifier []byte) (*indexertypes.VoteReference, error)
- func (s *Indexer) GetEnvelopes(processId []byte, max, from int, searchTerm string) ([]*indexertypes.EnvelopeMetadata, error)
- func (s *Indexer) GetLastTxReferences(limit, offset int32) ([]*indexertypes.TxReference, error)
- func (s *Indexer) GetResults(processID []byte) (*results.Results, error)
- func (s *Indexer) GetResultsWeight(processID []byte) (*big.Int, error)
- func (idx *Indexer) GetTokenTransfersByFromAccount(from []byte, offset, maxItems int32) ([]*indexertypes.TokenTransferMeta, error)
- func (s *Indexer) GetTxHashReference(hash types.HexBytes) (*indexertypes.TxReference, error)
- func (s *Indexer) GetTxReference(height uint64) (*indexertypes.TxReference, error)
- func (idx *Indexer) OnCancel(pid []byte, txIndex int32)
- func (s *Indexer) OnNewTx(tx *vochaintx.VochainTx, blockHeight uint32, txIndex int32)
- func (idx *Indexer) OnProcess(pid, eid []byte, censusRoot, censusURI string, txIndex int32)
- func (idx *Indexer) OnProcessKeys(pid []byte, pub string, txIndex int32)
- func (idx *Indexer) OnProcessResults(pid []byte, presults *models.ProcessResult, txIndex int32)
- func (idx *Indexer) OnProcessStatusChange(pid []byte, status models.ProcessStatus, txIndex int32)
- func (idx *Indexer) OnProcessesStart(pids [][]byte)
- func (idx *Indexer) OnRevealKeys(pid []byte, priv string, txIndex int32)
- func (idx *Indexer) OnSetAccount(addr []byte, account *state.Account)
- func (idx *Indexer) OnTransferTokens(tx *vochaintx.TokenTransfer)
- func (idx *Indexer) OnVote(v *state.Vote, txIndex int32)
- func (s *Indexer) ProcessCount(entityID []byte) uint64
- func (s *Indexer) ProcessInfo(pid []byte) (*indexertypes.Process, error)
- func (s *Indexer) ProcessList(entityID []byte, from, max int, searchTerm string, namespace uint32, ...) ([][]byte, error)
- func (idx *Indexer) Rollback()
- func (s *Indexer) TransactionCount() (uint64, error)
- func (idx *Indexer) WaitIdle()
- func (s *Indexer) WalkEnvelopes(processId []byte, async bool, callback func(*models.StateDBVote)) error
- type VoteWithIndex
Constants ¶
const ( // MaxEnvelopeListSize is the maximum number of envelopes a process can store. // 8.3M seems enough for now MaxEnvelopeListSize = 32 << 18 )
Variables ¶
var ErrNoResultsYet = fmt.Errorf("no results yet")
ErrNoResultsYet is an error returned to indicate the process exist but it does not have yet reuslts.
var (
ErrProcessNotFound = fmt.Errorf("process not found")
)
var ( // ErrTransactionNotFound is returned if the transaction is not found. ErrTransactionNotFound = fmt.Errorf("transaction not found") )
var ErrVoteNotFound = fmt.Errorf("vote not found")
ErrVoteNotFound is returned if the vote is not found in the indexer database.
Functions ¶
func BuildProcessResult ¶
func BuildProcessResult(results *results.Results, entityID []byte) *models.ProcessResult
BuildProcessResult takes the indexer Results type and builds the protobuf type ProcessResult. EntityId should be provided as addition field to include in ProcessResult.
func GetFriendlyResults ¶
GetFriendlyResults translates votes into a matrix of strings
Types ¶
type EventListener ¶
type EventListener interface { OnComputeResults(results *results.Results, process *indexertypes.Process, height uint32) OnOracleResults(oracleResults *models.ProcessResult, pid []byte, 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(dbPath string, app *vochain.BaseApplication, countLiveResults bool) (*Indexer, error)
NewIndexer returns an instance of the Indexer using the local storage database of dbPath 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()
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) Commit ¶
Commit is called by the APP when a block is confirmed and included into the chain
func (*Indexer) ComputeResult ¶
ComputeResult process a finished voting, compute the results and saves it in the Storage. Once this function is called, any future live vote event for the processId will be discarted.
func (*Indexer) EntityCount ¶
EntityCount return the number of entities indexed by the indexer
func (*Indexer) EntityList ¶
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) EntityProcessCount ¶
EntityProcessCount returns the number of processes that an entity holds
func (*Indexer) GetEnvelope ¶
func (s *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) GetEnvelopeHeight ¶
GetEnvelopeHeight returns the number of envelopes for a processId. If processId is empty, returns the total number of envelopes.
func (*Indexer) GetEnvelopeReference ¶
func (s *Indexer) GetEnvelopeReference(nullifier []byte) (*indexertypes.VoteReference, error)
GetEnvelopeReference gets the reference for an AddVote transaction. This reference can then be used to fetch the vote transaction directly from the BlockStore.
func (*Indexer) GetEnvelopes ¶
func (s *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) GetLastTxReferences ¶
func (s *Indexer) GetLastTxReferences(limit, offset int32) ([]*indexertypes.TxReference, error)
GetLastTxReferences fetches a number of the latest indexed transactions. The first one returned is the newest, so they are in descending order.
func (*Indexer) GetResults ¶
GetResults returns the current result for a processId
func (*Indexer) GetResultsWeight ¶
GetResultsWeight returns the current weight of cast votes for a processId.
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) GetTxHashReference ¶
func (s *Indexer) GetTxHashReference(hash types.HexBytes) (*indexertypes.TxReference, error)
GetTxHashReference fetches the txReference for the given tx hash
func (*Indexer) GetTxReference ¶
func (s *Indexer) GetTxReference(height uint64) (*indexertypes.TxReference, error)
GetTxReference fetches the txReference for the given tx height
func (*Indexer) OnProcessKeys ¶
OnProcessKeys does nothing
func (*Indexer) OnProcessResults ¶
func (idx *Indexer) OnProcessResults(pid []byte, presults *models.ProcessResult, txIndex int32)
OnProcessResults verifies the results for a process and appends it to the updateProcessPool
func (*Indexer) OnProcessStatusChange ¶
func (idx *Indexer) OnProcessStatusChange(pid []byte, status models.ProcessStatus, txIndex int32)
OnProcessStatusChange adds the process to the updateProcessPool and, if ended, the resultsPool
func (*Indexer) OnProcessesStart ¶
OnProcessesStart adds the processes to the updateProcessPool. This is required to update potential changes when a process is started, such as the rolling census.
func (*Indexer) OnRevealKeys ¶
OnRevealKeys checks if all keys have been revealed and in such case add the process to the results queue
func (*Indexer) OnSetAccount ¶
NOT USED but required for implementing the vochain.EventListener interface
func (*Indexer) OnTransferTokens ¶
func (idx *Indexer) OnTransferTokens(tx *vochaintx.TokenTransfer)
func (*Indexer) OnVote ¶
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) ProcessCount ¶
ProcessCount returns the number of processes of a given entityID indexed. If entityID is zero-value, returns the total number of processes of all entities.
func (*Indexer) ProcessInfo ¶
func (s *Indexer) ProcessInfo(pid []byte) (*indexertypes.Process, error)
ProcessInfo returns the available information regarding an election process id
func (*Indexer) ProcessList ¶
func (s *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) TransactionCount ¶
TransactionCount returns the number of transactions indexed
func (*Indexer) WaitIdle ¶
func (idx *Indexer) WaitIdle()
WaitIdle waits until there are no live asynchronous goroutines, such as those started by the Commit method.
Note that this method is racy by nature if the indexer keeps committing more blocks, as it simply waits for any goroutines already started to stop.
func (*Indexer) WalkEnvelopes ¶
func (s *Indexer) WalkEnvelopes(processId []byte, async bool, callback func(*models.StateDBVote)) error
WalkEnvelopes executes callback for each envelopes of the ProcessId. The callback function is executed async (in a goroutine) if async=true. The method will return once all goroutines have finished the work.
type VoteWithIndex ¶
type VoteWithIndex struct {
// contains filtered or unexported fields
}
VoteWithIndex holds a Vote and a txIndex. Model for the VotePool.