ticket

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Separator separates prefixes
	Separator = ":"
	// TagTicket is the prefix for ticket data
	TagTicket = "tkt"
)

Variables

This section is empty.

Functions

func MakeHashKey

func MakeHashKey(hash []byte) []byte

MakeHashKey creates a key for storing a ticket.

func MakeKey

func MakeKey(hash []byte, height uint64, index int) []byte

MakeKey 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

func NewManager(db storagetypes.Tx, cfg *config.AppConfig, logic core.Logic) *Manager

NewManager returns an instance of Manager. Returns error if unable to initialize the store.

func (*Manager) CountActiveValidatorTickets

func (m *Manager) CountActiveValidatorTickets() (int, error)

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) Index

func (m *Manager) Index(tx types.BaseTx, blockHeight uint64, txIndex int) error

Index takes a tx and creates a ticket out of it

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) Remove

func (m *Manager) Remove(hash util.HexBytes) error

Remove deletes a ticket by its hash

func (*Manager) Stop

func (m *Manager) Stop() error

Stop stores the manager

func (*Manager) UpdateExpireBy

func (m *Manager) UpdateExpireBy(hash util.HexBytes, newExpireHeight uint64) error

UpdateExpireBy updates the expire height of a ticket

func (*Manager) ValueOfAllTickets

func (m *Manager) ValueOfAllTickets(maturityHeight uint64) (float64, error)

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

func (m *Manager) ValueOfTickets(
	pubKey util.Bytes32,
	maturityHeight uint64) (float64, error)

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 NewStore

func NewStore(db storagetypes.Tx) *Store

NewStore creates an instance of Store

func (*Store) Add

func (s *Store) Add(tickets ...*types2.Ticket) error

Register adds one or more tickets to the store

func (*Store) Count

func (s *Store) Count(predicate func(*types2.Ticket) bool) int

Count counts tickets for which the predicate returns true.

func (*Store) FromTail

func (s *Store) FromTail() *Store

FromTail returns a new instance of Store that will set iterators to start reading records from the bottom/tail

func (*Store) GetByHash

func (s *Store) GetByHash(hash util.HexBytes) *types2.Ticket

GetByHash queries a ticket by its hash

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

func (s *Store) QueryOne(predicate func(*types2.Ticket) bool) *types2.Ticket

QueryOne iterates over the tickets and returns the first ticket for which the predicate returns true.

func (*Store) RemoveByHash

func (s *Store) RemoveByHash(hash util.HexBytes) error

RemoveByHash deletes a ticket by its hash

func (*Store) UpdateOne

func (s *Store) UpdateOne(upd types2.Ticket, queryPredicate func(*types2.Ticket) bool)

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.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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