store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: Apache-2.0 Imports: 12 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) CreateOrUpdate

func (s AccountsStore) CreateOrUpdate(acc *model.Account) error

CreateOrUpdate creates a new account or updates an existing one

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.

type BlockSearch

type BlockSearch struct {
	Creator string `form:"creator"`

	Order       string `form:"order"`
	OrderColumn string `form:"order_column"`
	Limit       int    `form:"limit"`
}

BlockSearch contains a block search params

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

func (s BlocksStore) CreateIfNotExists(block *model.Block) error

CreateIfNotExists creates the block if it does not exist

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

func (s BlocksStore) PickExisting(hashes []string) (result []string, err error)

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 FeeTransfersStore

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

func NewFeeTransfersStore

func NewFeeTransfersStore(db *gorm.DB) FeeTransfersStore

func (FeeTransfersStore) Create

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

Create creates a new record. Must pass a pointer.

func (FeeTransfersStore) DeleteByHeight

func (s FeeTransfersStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (FeeTransfersStore) FindByHeight

func (s FeeTransfersStore) FindByHeight(height uint64) (result []model.FeeTransfer, err error)

func (FeeTransfersStore) Import

func (s FeeTransfersStore) Import(records []model.FeeTransfer) error

func (FeeTransfersStore) Truncate

func (s FeeTransfersStore) Truncate() error

Truncate removes all records from the table

func (FeeTransfersStore) Update

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

Update updates the existing record. Must pass a pointer.

type HeightsStore

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

HeightsStore handles operations on heights

func NewHeightsStore

func NewHeightsStore(db *gorm.DB) HeightsStore

func (HeightsStore) Create

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

Create creates a new record. Must pass a pointer.

func (HeightsStore) DeleteByHeight

func (s HeightsStore) DeleteByHeight(height int64) error

DeleteByHeight removes all records associated with a height

func (HeightsStore) Last

func (s HeightsStore) Last() (*model.Height, error)

Last returns a last height record

func (HeightsStore) LastSuccessful

func (s HeightsStore) LastSuccessful() (*model.Height, error)

LastSuccessful returns the last successful height record

func (HeightsStore) StatusCounts

func (s HeightsStore) StatusCounts() ([]model.HeightStatusCount, error)

StatusCounts returns height sync statuses with counts

func (HeightsStore) Truncate

func (s HeightsStore) Truncate() error

Truncate removes all records from the table

func (HeightsStore) Update

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

Update updates the existing record. Must pass a pointer.

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

func (s JobsStore) ByHeight(height uint64) ([]model.Job, 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.Job) 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 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) Import

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

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

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

CreateTransactionsStats creates a new transaction stats record

func (StatsStore) CreateValidatorStats

func (s StatsStore) CreateValidatorStats(validator *model.Validator, 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) TransactionsStats

func (s StatsStore) TransactionsStats(period uint, interval string) ([]byte, error)

TransactionsStats returns transactions stats for a given timeframe

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 {
	Heights      HeightsStore
	Blocks       BlocksStore
	Accounts     AccountsStore
	Validators   ValidatorsStore
	Transactions TransactionsStore
	Jobs         JobsStore
	Snarkers     SnarkersStore
	FeeTransfers FeeTransfersStore
	Stats        StatsStore
	// 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"`
	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) ([]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) CreateIfNotExists

func (s TransactionsStore) CreateIfNotExists(t *model.Transaction) error

CreateIfNotExists creates the transaction if it does not exist

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

func (s TransactionsStore) Types() ([]byte, error)

Types returns the list of available transactions types

func (TransactionsStore) Update

func (s TransactionsStore) 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) CreateIfNotExists

func (s ValidatorsStore) CreateIfNotExists(validator *model.Validator) error

CreateIfNotExists creates the validator if it does not exist

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

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

FindByAccount returns a validator record associated with a key

func (ValidatorsStore) Import

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

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.

Jump to

Keyboard shortcuts

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