pgstorage

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	String, _ = abi.NewType("string", "", nil)
	Uint8, _  = abi.NewType("uint8", "", nil)
)

nolint

Functions

func InitOrReset

func InitOrReset(cfg Config) error

InitOrReset will initializes the db running the migrations or will reset all the known data and rerun the migrations

func ResetDB

func ResetDB(cfg Config) error

ResetDB.

func RunMigrationsDown

func RunMigrationsDown(cfg Config) error

RunMigrationsDown migrate down.

func RunMigrationsUp

func RunMigrationsUp(cfg Config) error

RunMigrationsUp migrate up.

Types

type Config

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

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

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

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

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

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

Config struct

func NewConfigFromEnv

func NewConfigFromEnv() Config

NewConfigFromEnv creates config from standard postgres environment variables,

type PostgresStorage

type PostgresStorage struct {
	*pgxpool.Pool
}

PostgresStorage implements the Storage interface.

func NewPostgresStorage

func NewPostgresStorage(cfg Config) (*PostgresStorage, error)

NewPostgresStorage creates a new Storage DB

func (*PostgresStorage) AddBlock

func (p *PostgresStorage) AddBlock(ctx context.Context, block *etherman.Block, dbTx pgx.Tx) (uint64, error)

AddBlock adds a new block to the storage.

func (*PostgresStorage) AddClaim

func (p *PostgresStorage) AddClaim(ctx context.Context, claim *etherman.Claim, dbTx pgx.Tx) error

AddClaim adds new claim to the storage.

func (*PostgresStorage) AddClaimTx

func (p *PostgresStorage) AddClaimTx(ctx context.Context, mTx ctmtypes.MonitoredTx, dbTx pgx.Tx) error

AddClaimTx adds a claim monitored transaction to the storage.

func (*PostgresStorage) AddDeposit

func (p *PostgresStorage) AddDeposit(ctx context.Context, deposit *etherman.Deposit, dbTx pgx.Tx) (uint64, error)

AddDeposit adds new deposit to the storage.

func (*PostgresStorage) AddGlobalExitRoot

func (p *PostgresStorage) AddGlobalExitRoot(ctx context.Context, exitRoot *etherman.GlobalExitRoot, dbTx pgx.Tx) error

AddGlobalExitRoot adds a new ExitRoot to the db.

func (*PostgresStorage) AddRollupExitLeaves

func (p *PostgresStorage) AddRollupExitLeaves(ctx context.Context, rows [][]interface{}, dbTx pgx.Tx) error

AddRollupExitLeaves iinserts multiple entries into the db.

func (*PostgresStorage) AddTokenWrapped

func (p *PostgresStorage) AddTokenWrapped(ctx context.Context, tokenWrapped *etherman.TokenWrapped, dbTx pgx.Tx) error

AddTokenWrapped adds new wrapped token to the storage.

func (*PostgresStorage) AddTrustedGlobalExitRoot

func (p *PostgresStorage) AddTrustedGlobalExitRoot(ctx context.Context, trustedExitRoot *etherman.GlobalExitRoot, dbTx pgx.Tx) (bool, error)

AddTrustedGlobalExitRoot adds new global exit root which comes from the trusted sequencer.

func (*PostgresStorage) BeginDBTransaction

func (p *PostgresStorage) BeginDBTransaction(ctx context.Context) (pgx.Tx, error)

BeginDBTransaction starts a transaction block.

func (*PostgresStorage) BulkSet

func (p *PostgresStorage) BulkSet(ctx context.Context, rows [][]interface{}, dbTx pgx.Tx) error

BulkSet is similar to Set, but it inserts multiple key-value pairs into the db.

func (*PostgresStorage) CheckIfRootExists

func (p *PostgresStorage) CheckIfRootExists(ctx context.Context, root []byte, network uint8, dbTx pgx.Tx) (bool, error)

CheckIfRootExists checks that the root exists on the db.

func (*PostgresStorage) Commit

func (p *PostgresStorage) Commit(ctx context.Context, dbTx pgx.Tx) error

Commit commits a db transaction.

func (*PostgresStorage) Get

func (p *PostgresStorage) Get(ctx context.Context, key []byte, dbTx pgx.Tx) ([][]byte, error)

Get gets value of key from the merkle tree.

func (*PostgresStorage) GetClaim

func (p *PostgresStorage) GetClaim(ctx context.Context, depositCount, networkID uint, dbTx pgx.Tx) (*etherman.Claim, error)

GetClaim gets a specific claim from the storage.

func (*PostgresStorage) GetClaimCount

func (p *PostgresStorage) GetClaimCount(ctx context.Context, destAddr string, dbTx pgx.Tx) (uint64, error)

GetClaimCount gets the claim count for the destination address.

func (*PostgresStorage) GetClaimTxsByStatus

func (p *PostgresStorage) GetClaimTxsByStatus(ctx context.Context, statuses []ctmtypes.MonitoredTxStatus, dbTx pgx.Tx) ([]ctmtypes.MonitoredTx, error)

GetClaimTxsByStatus gets the monitored transactions by status.

func (*PostgresStorage) GetClaims

func (p *PostgresStorage) GetClaims(ctx context.Context, destAddr string, limit uint, offset uint, dbTx pgx.Tx) ([]*etherman.Claim, error)

GetClaims gets the claim list which be smaller than index.

func (*PostgresStorage) GetDeposit

func (p *PostgresStorage) GetDeposit(ctx context.Context, depositCounterUser uint, networkID uint, dbTx pgx.Tx) (*etherman.Deposit, error)

GetDeposit gets a specific deposit from the storage.

func (*PostgresStorage) GetDepositCount

func (p *PostgresStorage) GetDepositCount(ctx context.Context, destAddr string, dbTx pgx.Tx) (uint64, error)

GetDepositCount gets the deposit count for the destination address.

func (*PostgresStorage) GetDepositCountByRoot

func (p *PostgresStorage) GetDepositCountByRoot(ctx context.Context, root []byte, network uint8, dbTx pgx.Tx) (uint, error)

GetDepositCountByRoot gets the deposit count by the root.

func (*PostgresStorage) GetDeposits

func (p *PostgresStorage) GetDeposits(ctx context.Context, destAddr string, limit uint, offset uint, dbTx pgx.Tx) ([]*etherman.Deposit, error)

GetDeposits gets the deposit list which be smaller than depositCount.

func (*PostgresStorage) GetLastBlock

func (p *PostgresStorage) GetLastBlock(ctx context.Context, networkID uint, dbTx pgx.Tx) (*etherman.Block, error)

GetLastBlock gets the last block.

func (*PostgresStorage) GetLastDepositCount

func (p *PostgresStorage) GetLastDepositCount(ctx context.Context, network uint, dbTx pgx.Tx) (uint, error)

GetLastDepositCount gets the last deposit count from the merkle tree.

func (*PostgresStorage) GetLatestExitRoot

func (p *PostgresStorage) GetLatestExitRoot(ctx context.Context, isRollup bool, dbTx pgx.Tx) (*etherman.GlobalExitRoot, error)

GetLatestExitRoot gets the latest global exit root.

func (*PostgresStorage) GetLatestL1SyncedExitRoot

func (p *PostgresStorage) GetLatestL1SyncedExitRoot(ctx context.Context, dbTx pgx.Tx) (*etherman.GlobalExitRoot, error)

GetLatestL1SyncedExitRoot gets the latest L1 synced global exit root.

func (*PostgresStorage) GetLatestRollupExitLeaves

func (p *PostgresStorage) GetLatestRollupExitLeaves(ctx context.Context, dbTx pgx.Tx) ([]etherman.RollupExitLeaf, error)

GetLatestRollupExitLeaves gets the latest leaves of the rollupExitTree

func (*PostgresStorage) GetLatestTrustedExitRoot

func (p *PostgresStorage) GetLatestTrustedExitRoot(ctx context.Context, dbTx pgx.Tx) (*etherman.GlobalExitRoot, error)

GetLatestTrustedExitRoot gets the latest trusted global exit root.

func (*PostgresStorage) GetNumberDeposits

func (p *PostgresStorage) GetNumberDeposits(ctx context.Context, networkID uint, blockNumber uint64, dbTx pgx.Tx) (uint64, error)

GetNumberDeposits gets the number of deposits.

func (*PostgresStorage) GetPreviousBlock

func (p *PostgresStorage) GetPreviousBlock(ctx context.Context, networkID uint, offset uint64, dbTx pgx.Tx) (*etherman.Block, error)

GetPreviousBlock gets the offset previous L1 block respect to latest.

func (*PostgresStorage) GetRollupExitLeavesByRoot

func (p *PostgresStorage) GetRollupExitLeavesByRoot(ctx context.Context, root common.Hash, dbTx pgx.Tx) ([]etherman.RollupExitLeaf, error)

GetRollupExitLeavesByRoot gets the leaves of the rollupExitTree given a root

func (*PostgresStorage) GetRoot

func (p *PostgresStorage) GetRoot(ctx context.Context, depositCnt uint, network uint, dbTx pgx.Tx) ([]byte, error)

GetRoot gets root by the deposit count from the merkle tree.

func (*PostgresStorage) GetTokenMetadata

func (p *PostgresStorage) GetTokenMetadata(ctx context.Context, networkID, destNet uint, originalTokenAddr common.Address, dbTx pgx.Tx) ([]byte, error)

GetTokenMetadata gets the metadata of the dedicated token.

func (*PostgresStorage) GetTokenWrapped

func (p *PostgresStorage) GetTokenWrapped(ctx context.Context, originalNetwork uint, originalTokenAddress common.Address, dbTx pgx.Tx) (*etherman.TokenWrapped, error)

GetTokenWrapped gets a specific wrapped token.

func (*PostgresStorage) IsLxLyActivated

func (p *PostgresStorage) IsLxLyActivated(ctx context.Context, dbTx pgx.Tx) (bool, error)

IsLxLyActivated checks in db if LxLy is activated

func (*PostgresStorage) IsRollupExitRoot

func (p *PostgresStorage) IsRollupExitRoot(ctx context.Context, root common.Hash, dbTx pgx.Tx) (bool, error)

IsRollupExitRoot checks if db contains the root

func (*PostgresStorage) Reset

func (p *PostgresStorage) Reset(ctx context.Context, blockNumber uint64, networkID uint, dbTx pgx.Tx) error

Reset resets the state to a block for the given DB tx.

func (*PostgresStorage) Rollback

func (p *PostgresStorage) Rollback(ctx context.Context, dbTx pgx.Tx) error

Rollback rollbacks a db transaction.

func (*PostgresStorage) Set

func (p *PostgresStorage) Set(ctx context.Context, key []byte, value [][]byte, depositID uint64, dbTx pgx.Tx) error

Set inserts a key-value pair into the db. If record with such a key already exists its assumed that the value is correct, because it's a reverse hash table, and the key is a hash of the value

func (*PostgresStorage) SetRoot

func (p *PostgresStorage) SetRoot(ctx context.Context, root []byte, depositID uint64, network uint, dbTx pgx.Tx) error

SetRoot store the root with deposit count to the storage.

func (*PostgresStorage) UpdateBlocksForTesting

func (p *PostgresStorage) UpdateBlocksForTesting(ctx context.Context, networkID uint, blockNum uint64, dbTx pgx.Tx) error

UpdateBlocksForTesting updates the hash of blocks.

func (*PostgresStorage) UpdateClaimTx

func (p *PostgresStorage) UpdateClaimTx(ctx context.Context, mTx ctmtypes.MonitoredTx, dbTx pgx.Tx) error

UpdateClaimTx updates a claim monitored transaction in the storage.

func (*PostgresStorage) UpdateDepositsStatusForTesting

func (p *PostgresStorage) UpdateDepositsStatusForTesting(ctx context.Context, dbTx pgx.Tx) error

UpdateDepositsStatusForTesting updates the ready_for_claim status of all deposits for testing.

func (*PostgresStorage) UpdateL1DepositsStatus

func (p *PostgresStorage) UpdateL1DepositsStatus(ctx context.Context, exitRoot []byte, dbTx pgx.Tx) ([]*etherman.Deposit, error)

UpdateL1DepositsStatus updates the ready_for_claim status of L1 deposits.

func (*PostgresStorage) UpdateL2DepositsStatus

func (p *PostgresStorage) UpdateL2DepositsStatus(ctx context.Context, exitRoot []byte, rollupID, networkID uint, dbTx pgx.Tx) error

UpdateL2DepositsStatus updates the ready_for_claim status of L2 deposits.

Jump to

Keyboard shortcuts

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