store

package
v1.1.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrConflict is returned when an operation cannot be completed
	// because of database constraints.
	ErrConflict = errors.Register(2000, "conflict")
	// ErrLimit is returned when allowed database query limit is exceeded
	ErrLimit = errors.Register(2001, "limit")
)

Functions

func EnsureDB

func EnsureDB(t *testing.T) (testdb *sql.DB, cleanup func())

ensureDB connects to a Postgres instance creates a database and returns a connection to it. If the connection to Postres cannot be established, the test is skipped.

Each database is initialized with the schema.

Unless an option is provided, defaults are used:

  • Database name: test_database_<creation time in unix ns>
  • Host: localhost
  • Port: 5432
  • SSLMode: disable
  • User: postgres

Function connects to the 'postgres' database first to create a new database.

func EnsureSchema

func EnsureSchema(pg *sql.DB) error

Types

type QueryError

type QueryError struct {
	Query string
	Args  []interface{}
	Err   error
}

func (*QueryError) Error

func (e *QueryError) Error() string

type Store

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

func NewStore

func NewStore(db *sql.DB) *Store

NewStore returns a store that provides an access to our database.

func (*Store) InsertAccount added in v1.1.3

func (s *Store) InsertAccount(ctx context.Context, a *account.RegisterAccountMsg) error

func (*Store) InsertBlock

func (s *Store) InsertBlock(ctx context.Context, b models.Block) error

func (*Store) InsertValidator

func (s *Store) InsertValidator(ctx context.Context, publicKey, address []byte) (int64, error)

InsertValidator adds a validator information into the database. It returns the newly created validator ID on success. This method returns ErrConflict if the validator cannot be inserted due to conflicting data.

func (*Store) LastNBlock

func (s *Store) LastNBlock(ctx context.Context, limit, after int) ([]*models.Block, error)

LoadLastNBlock returns the last blocks with given count. ErrNotFound is returned if no blocks exist. ErrLimit is returned if allowed limit is exceeded Note that it doesn't load the validators by default

func (*Store) LatestBlock

func (s *Store) LatestBlock(ctx context.Context) (*models.Block, error)

LatestBlock returns the block with the greatest high value. This method returns ErrNotFound if no block exist. Note that it doesn't load the validators by default

func (*Store) LoadAccount added in v1.1.3

func (s *Store) LoadAccount(ctx context.Context, name, domain string) (*models.Account, error)

func (*Store) LoadAccountTargets added in v1.1.3

func (s *Store) LoadAccountTargets(ctx context.Context, name, domain string) ([]models.AccountTarget, error)

func (*Store) LoadBlock

func (s *Store) LoadBlock(ctx context.Context, blockHeight int64) (*models.Block, error)

LoadBlock returns the block with the given block height from the database. This method returns ErrNotFound if no block exist. Note that it doesn't load the validators by default

TODO: de-duplicate LatestBlock() code

func (*Store) LoadBlockByHash

func (s *Store) LoadBlockByHash(ctx context.Context, blockHash string) (*models.Block, error)

func (*Store) LoadBlockByHeight

func (s *Store) LoadBlockByHeight(ctx context.Context, blockHeight string) (*models.Block, error)

func (*Store) LoadLatestNTx

func (s *Store) LoadLatestNTx(ctx context.Context, n int) ([]*models.Transaction, error)

LoadLatestNTx

func (*Store) LoadTx

func (s *Store) LoadTx(ctx context.Context, txHash string) (*models.Transaction, error)

LoadTx

func (*Store) LoadTxsByMemo

func (s *Store) LoadTxsByMemo(ctx context.Context, memo string) ([]models.Transaction, error)

LoadTxsByMemo

func (*Store) LoadTxsByParams

func (s *Store) LoadTxsByParams(ctx context.Context, source, dest, memo string) ([]models.Transaction, error)

func (*Store) LoadTxsInBlock

func (s *Store) LoadTxsInBlock(ctx context.Context, blockHeight int64) ([]models.Transaction, error)

LoadTxsInBlock

func (*Store) ReplaceAccountTargets added in v1.1.3

func (s *Store) ReplaceAccountTargets(ctx context.Context, a *account.ReplaceAccountTargetsMsg) error

func (*Store) ValidatorAddressID

func (s *Store) ValidatorAddressID(ctx context.Context, address []byte) (int64, error)

ValidatorAddressID returns an ID of a validator with given address. It returns ErrNotFound if no such address is present in the database.

Jump to

Keyboard shortcuts

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