store

package
v0.19.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	BucketHour = "h"
	BucketDay  = "d"
)

Variables

View Source
var (
	ErrNotFound = errors.New("record not found")
)

Functions

This section is empty.

Types

type AccountsStore

type AccountsStore struct {
	// contains filtered or unexported fields
}

AccountsStore handles operations on accounts

func NewAccountsStore

func NewAccountsStore(db *gorm.DB) AccountsStore

func (AccountsStore) All

func (s AccountsStore) All() ([]model.Account, error)

All returns all accounts

func (AccountsStore) AllByDelegator

func (s AccountsStore) AllByDelegator(account string) ([]model.Account, error)

AllByDelegator returns all accounts delegated to another account

func (AccountsStore) ByHeight

func (s AccountsStore) ByHeight(height int64) ([]model.Account, error)

ByHeight returns all accounts that were created at a given height

func (AccountsStore) Count

func (s AccountsStore) Count() (int, error)

func (AccountsStore) Create

func (s AccountsStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (AccountsStore) DeleteByHeight

func (s AccountsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (AccountsStore) FindBy

func (s AccountsStore) FindBy(key string, value interface{}) (*model.Account, error)

FindBy returns an account for a matching attribute

func (AccountsStore) FindByID

func (s AccountsStore) FindByID(id int64) (*model.Account, error)

FindByID returns an account for the ID

func (AccountsStore) FindByPublicKey

func (s AccountsStore) FindByPublicKey(key string) (*model.Account, error)

FindByPublicKey returns an account for the public key

func (AccountsStore) Import

func (s AccountsStore) Import(records []model.Account) error

func (AccountsStore) Truncate

func (s AccountsStore) Truncate() error

Truncate removes all records from the table

func (AccountsStore) Update

func (s AccountsStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

func (AccountsStore) UpdateStaking

func (s AccountsStore) UpdateStaking() error

type BlockSearch

type BlockSearch struct {
	Creator   string `form:"creator"`
	Canonical string `form:"canonical"`
	MinHeight uint   `form:"min_height"`
	MaxHeight uint   `form:"max_height"`
	Sort      string `form:"sort"`
	Order     string `form:"order"`
	Limit     uint   `form:"limit"`
}

BlockSearch contains a block search params

func (*BlockSearch) Validate

func (search *BlockSearch) Validate() error

Validate performs validation on search parameters

type BlocksStore

type BlocksStore struct {
	// contains filtered or unexported fields
}

BlocksStore handles operations on blocks

func NewBlocksStore

func NewBlocksStore(db *gorm.DB) BlocksStore

func (BlocksStore) AvgTimes

func (s BlocksStore) AvgTimes(limit int64) ([]byte, error)

AvgTimes returns recent blocks averages

func (BlocksStore) Create

func (s BlocksStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (BlocksStore) DeleteByHeight

func (s BlocksStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (BlocksStore) FindBy

func (s BlocksStore) FindBy(key string, value interface{}) (*model.Block, error)

FindBy returns a block for a matching attribute

func (BlocksStore) FindByHash

func (s BlocksStore) FindByHash(hash string) (*model.Block, error)

FindByHash returns a block with the matching hash

func (BlocksStore) FindByHeight

func (s BlocksStore) FindByHeight(height uint64) (*model.Block, error)

FindByHeight returns a canonical block with the matching height

func (BlocksStore) FindByID

func (s BlocksStore) FindByID(id int64) (*model.Block, error)

FindByID returns a block with matching ID

func (BlocksStore) FindLastCalculatedBlockReward added in v0.11.0

func (s BlocksStore) FindLastCalculatedBlockReward(from, to uint64) (*model.Block, error)

FindLastCalculatedBlockReward returns the last calculated block reward

func (BlocksStore) FindNonCalculatedBlockRewards added in v0.11.0

func (s BlocksStore) FindNonCalculatedBlockRewards(from, to uint64) ([]model.Block, error)

FindNonCalculatedBlockRewards returns the non calculated blocks for rewards

func (BlocksStore) FindUnsafeBlocks added in v0.9.3

func (s BlocksStore) FindUnsafeBlocks(startingHeight uint64) ([]model.Block, error)

FindUnsafeBlocks returns the last indexed unsafe blocks that may be orphaned

func (BlocksStore) FirstBlockOfEpoch added in v0.11.0

func (s BlocksStore) FirstBlockOfEpoch(epoch string) (*model.Block, error)

FirstBlockOfEpoch returns the first block of epoch

func (BlocksStore) LastBlock added in v0.9.3

func (s BlocksStore) LastBlock() (*model.Block, error)

LastBlock returns the last block

func (BlocksStore) MarkBlockCanonical added in v0.9.3

func (s BlocksStore) MarkBlockCanonical(hash string) error

MarkBlockCanonical updates canonical at a height

func (BlocksStore) MarkBlocksOrphan added in v0.9.3

func (s BlocksStore) MarkBlocksOrphan(height uint64) error

MarkBlocksOrphan updates all blocks as non canonical at a height

func (BlocksStore) Recent

func (s BlocksStore) Recent() (*model.Block, error)

Recent returns the most recent block

func (BlocksStore) Search

func (s BlocksStore) Search(search *BlockSearch) ([]model.Block, error)

Search returns blocks that match search filters

func (BlocksStore) Stats

func (s BlocksStore) Stats(period uint, interval string) ([]byte, error)

Stats returns block stats for a given interval

func (BlocksStore) Truncate

func (s BlocksStore) Truncate() error

Truncate removes all records from the table

func (BlocksStore) Update

func (s BlocksStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type FindDelegationsParams

type FindDelegationsParams struct {
	LedgerID  *int
	PublicKey string
	Delegate  string
}

type JobsStore

type JobsStore struct {
	// contains filtered or unexported fields
}

JobsStore handles operations on jobs

func NewJobsStore

func NewJobsStore(db *gorm.DB) JobsStore

func (JobsStore) ByHash added in v0.9.3

func (s JobsStore) ByHash(hash string) ([]model.SnarkJob, error)

ByHash returns all jobs for a given block hash

func (JobsStore) ByHeight

func (s JobsStore) ByHeight(height uint64) ([]model.SnarkJob, error)

ByHeight returns all jobs for a given height

func (JobsStore) Create

func (s JobsStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (JobsStore) DeleteByHeight

func (s JobsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (JobsStore) Import

func (s JobsStore) Import(jobs []model.SnarkJob) error

func (JobsStore) Truncate

func (s JobsStore) Truncate() error

Truncate removes all records from the table

func (JobsStore) Update

func (s JobsStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type RewardStore added in v0.11.0

type RewardStore struct {
	// contains filtered or unexported fields
}

RewardStore handles operations on rewards

func NewRewardStore added in v0.11.0

func NewRewardStore(db *gorm.DB) RewardStore

func (RewardStore) Create added in v0.11.0

func (s RewardStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (RewardStore) DeleteByDelegator added in v0.17.0

func (s RewardStore) DeleteByDelegator(account string) error

DeleteByDelegator removes all block rewards records for given delegator address

func (RewardStore) DeleteByHeight added in v0.11.0

func (s RewardStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (RewardStore) DeleteByValidator added in v0.17.0

func (s RewardStore) DeleteByValidator(account string) error

DeleteByValidator removes all block rewards records for a given validator address

func (*RewardStore) FetchRewardsByInterval added in v0.11.0

func (s *RewardStore) FetchRewardsByInterval(
	ownerAccount string,
	delegate string,
	from time.Time,
	to time.Time,
	timeInterval model.TimeInterval,
	rewardOwnerType model.RewardOwnerType,
	includeEpoch bool,
) ([]model.RewardsSummary, error)

FetchRewardsByInterval fetches rewards by interval

func (RewardStore) Import added in v0.11.0

func (s RewardStore) Import(records []model.BlockReward) error

Import creates new rewards

func (RewardStore) Truncate added in v0.11.0

func (s RewardStore) Truncate() error

Truncate removes all records from the table

func (RewardStore) Update added in v0.11.0

func (s RewardStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type SnarkersStore

type SnarkersStore struct {
	// contains filtered or unexported fields
}

func NewSnarkersStore

func NewSnarkersStore(db *gorm.DB) SnarkersStore

func (SnarkersStore) All

func (s SnarkersStore) All() ([]model.Snarker, error)

func (SnarkersStore) Create

func (s SnarkersStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (SnarkersStore) DeleteByHeight

func (s SnarkersStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (SnarkersStore) FindSnarker added in v0.9.3

func (s SnarkersStore) FindSnarker(account string) (*model.Snarker, error)

FindSnarker returns snarker for a given account

func (SnarkersStore) Import

func (s SnarkersStore) Import(records []model.Snarker) error

func (SnarkersStore) SnarkerInfoFromCanonicalBlocks added in v0.9.3

func (s SnarkersStore) SnarkerInfoFromCanonicalBlocks(account string, start, end uint64) ([]byte, error)

SnarkerInfoFromCanonicalBlocks returns snarker info from canonical blocks

func (SnarkersStore) Truncate

func (s SnarkersStore) Truncate() error

Truncate removes all records from the table

func (SnarkersStore) Update

func (s SnarkersStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type StakingStore

type StakingStore struct {
	// contains filtered or unexported fields
}

StakingStore handles operations on staking data

func NewStakingStore

func NewStakingStore(db *gorm.DB) StakingStore

func (StakingStore) AllLedgers added in v0.7.0

func (s StakingStore) AllLedgers() ([]model.Ledger, error)

AllLedgers returns all existing ledgers

func (StakingStore) Create

func (s StakingStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (StakingStore) CreateLedger

func (s StakingStore) CreateLedger(ledger *model.Ledger) error

CreateLedger creates a new ledger record

func (StakingStore) CreateLedgerEntries

func (s StakingStore) CreateLedgerEntries(records []model.LedgerEntry) error

CreateLedgerEntries create a batch of ledger entries

func (StakingStore) DelegateLedgerRecords added in v0.11.0

func (s StakingStore) DelegateLedgerRecords(ledgerID int, delegate string) ([]model.LedgerEntry, error)

DelegateLedgerRecords returns delegations' ledger info

func (StakingStore) DeleteByHeight

func (s StakingStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (StakingStore) FindDelegations

func (s StakingStore) FindDelegations(params FindDelegationsParams) ([]model.Delegation, error)

FindDelegations returns delegations for a given ledger ID

func (StakingStore) FindLedger

func (s StakingStore) FindLedger(epoch int) (*model.Ledger, error)

FindLedger returns the most recent ledger of an epoch

func (StakingStore) LastLedger

func (s StakingStore) LastLedger() (*model.Ledger, error)

LastLedger returns the most recent ledger record

func (StakingStore) LedgerRecords

func (s StakingStore) LedgerRecords(ledgerID int) ([]model.LedgerEntry, error)

LedgerRecords returns all ledger records from current epoch

func (StakingStore) Truncate

func (s StakingStore) Truncate() error

Truncate removes all records from the table

func (StakingStore) Update

func (s StakingStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type StatsStore

type StatsStore struct {
	// contains filtered or unexported fields
}

func NewStatsStore

func NewStatsStore(db *gorm.DB) StatsStore

func (StatsStore) Create

func (s StatsStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (StatsStore) CreateChainStats

func (s StatsStore) CreateChainStats(bucket string, ts time.Time) error

CreateChainStats creates a new chain stats record

func (StatsStore) CreateValidatorStats

func (s StatsStore) CreateValidatorStats(validatorPublicKey string, bucket string, ts time.Time) error

CreateValidatorStats creates a new validator stats record

func (StatsStore) DeleteByHeight

func (s StatsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (StatsStore) FindValidatorsForDefaultStats added in v0.9.3

func (s StatsStore) FindValidatorsForDefaultStats(bucket string, ts time.Time) ([]model.Validator, error)

FindValidatorsForDefaultStats returns validator for default values

func (StatsStore) SnarkerJobFeesBreakdown added in v0.18.0

func (s StatsStore) SnarkerJobFeesBreakdown(account string) ([]model.SnarkerJobFee, error)

func (StatsStore) SnarkerJobsStats added in v0.18.0

func (s StatsStore) SnarkerJobsStats(bucket string, limit uint) ([]model.SnarkerJobsStat, error)

func (StatsStore) SnarkerStats added in v0.18.0

func (s StatsStore) SnarkerStats(account string) (model.SnarkerStat, error)

func (StatsStore) SnarkerTimeStats added in v0.18.0

func (s StatsStore) SnarkerTimeStats(account string) ([]model.SnarkerTimeStat, error)

func (StatsStore) Truncate

func (s StatsStore) Truncate() error

Truncate removes all records from the table

func (StatsStore) Update

func (s StatsStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

func (StatsStore) ValidatorStats

func (s StatsStore) ValidatorStats(validator *model.Validator, period uint, interval string) ([]model.ValidatorStat, error)

ValidatorStats returns validator stats for a given timeframe

type Store

type Store struct {
	Blocks           BlocksStore
	Accounts         AccountsStore
	Validators       ValidatorsStore
	ValidatorsEpochs ValidatorsEpochsStore
	Transactions     TransactionsStore
	Jobs             JobsStore
	Snarkers         SnarkersStore
	Stats            StatsStore
	Staking          StakingStore
	Rewards          RewardStore
	// contains filtered or unexported fields
}

Store handles all database operations

func New

func New(connStr string) (*Store, error)

New returns a new store from the connection string

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection

func (*Store) Conn

func (s *Store) Conn() *sql.DB

Conn returns an underlying database connection

func (*Store) SetDebugMode

func (s *Store) SetDebugMode(enabled bool)

SetDebugMode enabled detailed query logging

func (*Store) Test

func (s *Store) Test() error

Test checks the connection status

type TransactionSearch

type TransactionSearch struct {
	AfterID   uint   `form:"after_id"`
	BeforeID  uint   `form:"before_id"`
	Height    uint64 `form:"height"`
	Type      string `form:"type"`
	BlockHash string `form:"block_hash"`
	Account   string `form:"account"`
	Sender    string `form:"sender"`
	Receiver  string `form:"receiver"`
	Memo      string `form:"memo"`
	StartTime string `form:"start_time"`
	EndTime   string `form:"end_time"`
	Status    string `form:"status"`
	Canonical *bool  `form:"canonical"`
	Limit     uint   `form:"limit"`
	// contains filtered or unexported fields
}

TransactionSearch contains transaction search params

func (*TransactionSearch) Validate

func (s *TransactionSearch) Validate() error

Validate returns an error if search form is invalid

type TransactionsStore

type TransactionsStore struct {
	// contains filtered or unexported fields
}

TransactionsStore handles operations on transactions

func NewTransactionsStore

func NewTransactionsStore(db *gorm.DB) TransactionsStore

func (TransactionsStore) ByAccount

func (s TransactionsStore) ByAccount(account string) ([]model.Transaction, error)

ByAccount returns a list of transactions sent or received by the account

func (TransactionsStore) ByHeight

func (s TransactionsStore) ByHeight(height uint64, limit uint) ([]model.Transaction, error)

ByHeight returns transactions for a given height

func (TransactionsStore) Create

func (s TransactionsStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (TransactionsStore) DeleteByHeight

func (s TransactionsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (TransactionsStore) FindBy

func (s TransactionsStore) FindBy(key string, value interface{}) (*model.Transaction, error)

FindBy returns transactions by a given key and value

func (TransactionsStore) FindByHash

func (s TransactionsStore) FindByHash(hash string) (*model.Transaction, error)

FindByHash returns a transaction for a given hash

func (TransactionsStore) FindByID

func (s TransactionsStore) FindByID(id int64) (*model.Transaction, error)

FindByID returns a transaction for a given ID

func (TransactionsStore) Import

func (s TransactionsStore) Import(records []model.Transaction) error

func (TransactionsStore) MarkTransactionsCanonical added in v0.9.3

func (s TransactionsStore) MarkTransactionsCanonical(blockHash string) error

MarkTransactionsCanonical updates transactions canonical for given block hash

func (TransactionsStore) MarkTransactionsOrphan added in v0.9.3

func (s TransactionsStore) MarkTransactionsOrphan(height uint64) error

MarkTransactionsOrphan updates all transactions as non canonical at a height

func (TransactionsStore) Search

Search returns a list of transactions that matches the filters

func (TransactionsStore) Truncate

func (s TransactionsStore) Truncate() error

Truncate removes all records from the table

func (TransactionsStore) Update

func (s TransactionsStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type ValidatorsEpochsStore added in v0.11.0

type ValidatorsEpochsStore struct {
	// contains filtered or unexported fields
}

ValidatorsEpochsStore handles operations on validator epochs

func NewValidatorsEpochsStore added in v0.11.0

func NewValidatorsEpochsStore(db *gorm.DB) ValidatorsEpochsStore

func (ValidatorsEpochsStore) Create added in v0.11.0

func (s ValidatorsEpochsStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (ValidatorsEpochsStore) DeleteByHeight added in v0.11.0

func (s ValidatorsEpochsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (*ValidatorsEpochsStore) GetLastValidatorEpoch added in v0.12.0

func (s *ValidatorsEpochsStore) GetLastValidatorEpoch(address string) (*model.ValidatorEpoch, error)

GetLastValidatorEpoch returns the most recent validator epoch record

func (*ValidatorsEpochsStore) GetValidatorEpochs added in v0.11.0

func (s *ValidatorsEpochsStore) GetValidatorEpochs(epoch string, accountAddress string) ([]model.ValidatorEpoch, error)

GetValidatorEpochs fetches validator epochs

func (ValidatorsEpochsStore) Import added in v0.11.0

func (s ValidatorsEpochsStore) Import(records []model.ValidatorEpoch) error

Import creates or updates validator records in bulk

func (ValidatorsEpochsStore) Truncate added in v0.11.0

func (s ValidatorsEpochsStore) Truncate() error

Truncate removes all records from the table

func (ValidatorsEpochsStore) Update added in v0.11.0

func (s ValidatorsEpochsStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

type ValidatorsStore

type ValidatorsStore struct {
	// contains filtered or unexported fields
}

ValidatorsStore handles operations on validators

func NewValidatorsStore

func NewValidatorsStore(db *gorm.DB) ValidatorsStore

func (ValidatorsStore) Create

func (s ValidatorsStore) Create(record interface{}) error

Create creates a new record. Must pass a pointer.

func (ValidatorsStore) DeleteByHeight

func (s ValidatorsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (ValidatorsStore) FindAll

func (s ValidatorsStore) FindAll() (result []model.Validator, err error)

FindAll returns all available validators

func (ValidatorsStore) FindByPublicKey

func (s ValidatorsStore) FindByPublicKey(key string) (*model.Validator, error)

FindByPublicKey returns a validator record associated with a key

func (ValidatorsStore) Import

func (s ValidatorsStore) Import(records []model.Validator) error

Import creates or updates validator records in bulk

func (ValidatorsStore) Index

func (s ValidatorsStore) Index() ([]byte, error)

func (ValidatorsStore) Truncate

func (s ValidatorsStore) Truncate() error

Truncate removes all records from the table

func (ValidatorsStore) Update

func (s ValidatorsStore) Update(record interface{}) error

Update updates the existing record. Must pass a pointer.

func (ValidatorsStore) UpdateFee added in v0.14.0

func (s ValidatorsStore) UpdateFee(key string, value float64) error

UpdateFee updates the validator fee

func (ValidatorsStore) UpdateIdentity

func (s ValidatorsStore) UpdateIdentity(key string, name string) error

UpdateIdentity updates the identity name of the validator

func (ValidatorsStore) UpdateStaking

func (s ValidatorsStore) UpdateStaking() error

Jump to

Keyboard shortcuts

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