Documentation ¶
Index ¶
- Constants
- func MakeHashKey(hash []byte) []byte
- func MakeKey(hash []byte, height uint64, index int) []byte
- type Manager
- func (m *Manager) CountActiveValidatorTickets() (int, error)
- func (m *Manager) GetByHash(hash util.HexBytes) *tickettypes.Ticket
- func (m *Manager) GetByProposer(ticketType types.TxCode, proposerPubKey util.Bytes32, queryOpt ...interface{}) ([]*tickettypes.Ticket, error)
- func (m *Manager) GetNonDelegatedTickets(pubKey util.Bytes32, ticketType types.TxCode) ([]*tickettypes.Ticket, error)
- func (m *Manager) GetTopHosts(limit int) (tickettypes.SelectedTickets, error)
- func (m *Manager) GetTopValidators(limit int) (tickettypes.SelectedTickets, error)
- func (m *Manager) GetUnExpiredTickets(pubKey util.Bytes32, maturityHeight uint64) ([]*tickettypes.Ticket, error)
- func (m *Manager) Index(tx types.BaseTx, blockHeight uint64, txIndex int) error
- func (m *Manager) Query(qf func(t *tickettypes.Ticket) bool, queryOpt ...interface{}) []*tickettypes.Ticket
- func (m *Manager) QueryOne(qf func(t *tickettypes.Ticket) bool) *tickettypes.Ticket
- func (m *Manager) Remove(hash util.HexBytes) error
- func (m *Manager) Stop() error
- func (m *Manager) UpdateExpireBy(hash util.HexBytes, newExpireHeight uint64) error
- func (m *Manager) ValueOfAllTickets(maturityHeight uint64) (float64, error)
- func (m *Manager) ValueOfDelegatedTickets(pubKey util.Bytes32, maturityHeight uint64) (float64, error)
- func (m *Manager) ValueOfNonDelegatedTickets(pubKey util.Bytes32, maturityHeight uint64) (float64, error)
- func (m *Manager) ValueOfTickets(pubKey util.Bytes32, maturityHeight uint64) (float64, error)
- type Store
- func (s *Store) Add(tickets ...*types2.Ticket) error
- func (s *Store) Count(predicate func(*types2.Ticket) bool) int
- func (s *Store) FromTail() *Store
- func (s *Store) GetByHash(hash util.HexBytes) *types2.Ticket
- func (s *Store) Query(predicate func(*types2.Ticket) bool, queryOpt ...interface{}) []*types2.Ticket
- func (s *Store) QueryOne(predicate func(*types2.Ticket) bool) *types2.Ticket
- func (s *Store) RemoveByHash(hash util.HexBytes) error
- func (s *Store) UpdateOne(upd types2.Ticket, queryPredicate func(*types2.Ticket) bool)
- type TicketStore
Constants ¶
const ( // Separator separates prefixes Separator = ":" // TagTicket is the prefix for ticket data TagTicket = "tkt" )
Variables ¶
This section is empty.
Functions ¶
func MakeHashKey ¶
MakeHashKey creates a key for storing a ticket.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager implements types.TicketManager. It provides ticket management functionalities.
func NewManager ¶
NewManager returns an instance of Manager. Returns error if unable to initialize the store.
func (*Manager) CountActiveValidatorTickets ¶
CountActiveValidatorTickets returns the number of matured and unexpired tickets.
func (*Manager) GetByHash ¶
func (m *Manager) GetByHash(hash util.HexBytes) *tickettypes.Ticket
GetByHash get a ticket by hash
func (*Manager) GetByProposer ¶
func (m *Manager) GetByProposer( ticketType types.TxCode, proposerPubKey util.Bytes32, queryOpt ...interface{}) ([]*tickettypes.Ticket, error)
GetByProposer finds tickets belonging to the given proposer public key.
func (*Manager) GetNonDelegatedTickets ¶
func (m *Manager) GetNonDelegatedTickets( pubKey util.Bytes32, ticketType types.TxCode) ([]*tickettypes.Ticket, error)
GetNonDelegatedTickets returns all non-delegated, unexpired tickets belonging to the given public key.
pubKey: The public key of the proposer ticketType: Filter the search to a specific ticket type
func (*Manager) GetTopHosts ¶
func (m *Manager) GetTopHosts(limit int) (tickettypes.SelectedTickets, error)
GetTopHosts gets host tickets with the most total delegated value.
func (*Manager) GetTopValidators ¶
func (m *Manager) GetTopValidators(limit int) (tickettypes.SelectedTickets, error)
GetTopValidators gets validator tickets with the most total delegated value.
func (*Manager) GetUnExpiredTickets ¶
func (m *Manager) GetUnExpiredTickets(pubKey util.Bytes32, maturityHeight uint64) ([]*tickettypes.Ticket, error)
GetUnExpiredTickets finds unexpired tickets that have the given proposer public key as the proposer or the delegator; If maturityHeight is non-zero, then only tickets that reached maturity before or on the given height are selected. Otherwise, the current chain height is used.
func (*Manager) Query ¶
func (m *Manager) Query(qf func(t *tickettypes.Ticket) bool, queryOpt ...interface{}) []*tickettypes.Ticket
Query finds and returns tickets that match the given query
func (*Manager) QueryOne ¶
func (m *Manager) QueryOne(qf func(t *tickettypes.Ticket) bool) *tickettypes.Ticket
QueryOne finds and returns a ticket that match the given query
func (*Manager) UpdateExpireBy ¶
UpdateExpireBy updates the expire height of a ticket
func (*Manager) ValueOfAllTickets ¶
ValueOfAllTickets returns the sum of value of all unexpired tickets; Includes both validator and host tickets.
maturityHeight: if set to non-zero, only tickets that reached maturity before or on the given height are selected. Otherwise, the current chain height is used.
func (*Manager) ValueOfDelegatedTickets ¶
func (m *Manager) ValueOfDelegatedTickets( pubKey util.Bytes32, maturityHeight uint64) (float64, error)
ValueOfDelegatedTickets returns the sum of value of all delegated, unexpired tickets which has the given public key as the proposer; Includes both validator and host tickets.
pubKey: The public key of the proposer maturityHeight: if set to non-zero, only tickets that reached maturity before or on the given height are selected. Otherwise, the current chain height is used.
func (*Manager) ValueOfNonDelegatedTickets ¶
func (m *Manager) ValueOfNonDelegatedTickets( pubKey util.Bytes32, maturityHeight uint64) (float64, error)
ValueOfNonDelegatedTickets returns the sum of value of all non-delegated, unexpired tickets which has the given public key as the proposer; Includes both validator and host tickets.
pubKey: The public key of the proposer maturityHeight: if set to non-zero, only tickets that reached maturity before or on the given height are selected. Otherwise, the current chain height is used.
func (*Manager) ValueOfTickets ¶
ValueOfTickets returns the sum of value of all unexpired tickets where the given public key is the proposer or delegator; Includes both validator and host tickets.
pubKey: The public key of the proposer maturityHeight: if set to non-zero, only tickets that reached maturity before or on the given height are selected. Otherwise, the current chain height is used.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements TicketStore
func (*Store) FromTail ¶
FromTail returns a new instance of Store that will set iterators to start reading records from the bottom/tail
func (*Store) Query ¶
func (s *Store) Query(predicate func(*types2.Ticket) bool, queryOpt ...interface{}) []*types2.Ticket
Query iterates over the tickets and returns all tickets for which the predicate returns true.
func (*Store) QueryOne ¶
QueryOne iterates over the tickets and returns the first ticket for which the predicate returns true.
func (*Store) RemoveByHash ¶
RemoveByHash deletes a ticket by its hash
type TicketStore ¶
type TicketStore interface { // Register adds one or more tickets to the store Add(tickets ...*types2.Ticket) error // GetByHash queries a ticket by its hash GetByHash(hash util.HexBytes) *types2.Ticket // RemoveByHash deletes a ticket by its hash RemoveByHash(hash util.HexBytes) error // QueryOne iterates over the tickets and returns the first ticket // for which the predicate returns true. QueryOne(predicate func(*types2.Ticket) bool) *types2.Ticket // Query iterates over the tickets and returns all tickets // for which the predicate returns true. Query(predicate func(*types2.Ticket) bool, queryOpt ...interface{}) []*types2.Ticket // Count counts tickets for which the predicate returns true. Count(predicate func(*types2.Ticket) bool) int // UpdateOne update a ticket for which the query predicate returns true. // NOTE: If the fields that make up the key of the ticket is updated, a new record // with different key composition will be created. UpdateOne(upd types2.Ticket, queryPredicate func(*types2.Ticket) bool) }
TicketStore describes the functions of a ticket store