db

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrStateNotSynchronized indicates the state database may be empty
	ErrStateNotSynchronized = errors.New("state not synchronized")
)

Functions

func NewSQLDB

func NewSQLDB(cfg Config) (*pgxpool.Pool, error)

NewSQLDB creates a new SQL DB

func RunMigrationsDown

func RunMigrationsDown(pg *pgxpool.Pool) error

RunMigrationsDown runs migrate-down for the given config.

func RunMigrationsUp

func RunMigrationsUp(pg *pgxpool.Pool) error

RunMigrationsUp runs migrate-up for the given config.

Types

type Config

type Config struct {
	// Database name
	Name string `mapstructure:"Name"`

	// Database User name
	User string `mapstructure:"User"`

	// Database Password of the user
	Password string `mapstructure:"Password"`

	// Host address of database
	Host string `mapstructure:"Host"`

	// Port Number of database
	Port string `mapstructure:"Port"`

	// EnableLog
	EnableLog bool `mapstructure:"EnableLog"`

	// MaxConns is the maximum number of connections in the pool.
	MaxConns int `mapstructure:"MaxConns"`
}

Config provide fields to configure the pool

type DB

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

DB is the database layer of the data node

func New

func New(pg *pgxpool.Pool) *DB

New instantiates a DB

func (*DB) BeginStateTransaction

func (db *DB) BeginStateTransaction(ctx context.Context) (pgx.Tx, error)

BeginStateTransaction begins a DB transaction. The caller is responsible for committing or rolling back the transaction

func (*DB) Exists

func (db *DB) Exists(ctx context.Context, key common.Hash) bool

Exists checks if a key exists in offchain data table

func (*DB) GetLastProcessedBlock

func (db *DB) GetLastProcessedBlock(ctx context.Context) (uint64, error)

GetLastProcessedBlock returns the latest block successfully processed by the synchronizer

func (*DB) GetOffChainData

func (db *DB) GetOffChainData(ctx context.Context, key common.Hash, dbTx pgx.Tx) (rpc.ArgBytes, error)

GetOffChainData returns the value identified by the key

func (*DB) ResetLastProcessedBlock

func (db *DB) ResetLastProcessedBlock(ctx context.Context, block uint64) (uint64, error)

ResetLastProcessedBlock removes all sync_info for blocks greater than `block`

func (*DB) StoreLastProcessedBlock

func (db *DB) StoreLastProcessedBlock(ctx context.Context, block uint64, dbTx pgx.Tx) error

StoreLastProcessedBlock stores a record of a block processed by the synchronizer

func (*DB) StoreOffChainData

func (db *DB) StoreOffChainData(ctx context.Context, od []offchaindata.OffChainData, dbTx pgx.Tx) error

StoreOffChainData stores and array of key values in the Db

Jump to

Keyboard shortcuts

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