pgstorage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 20 Imported by: 2

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 added in v0.4.0

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 added in v0.1.0

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) AddMonitoredTxsGroup added in v0.5.0

func (p *PostgresStorage) AddMonitoredTxsGroup(ctx context.Context, mTxGroup *ctmtypes.MonitoredTxGroupDBEntry, dbTx pgx.Tx) error

AddMonitoredTxsGroup

func (*PostgresStorage) AddRollupExitLeaves added in v0.4.0

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 added in v0.1.0

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 added in v0.4.0

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, originNetworkID, 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 added in v0.1.0

func (p *PostgresStorage) GetClaimTxsByStatus(ctx context.Context, statuses []ctmtypes.MonitoredTxStatus, rollupID uint, 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) GetExitRootByGER added in v0.5.0

func (p *PostgresStorage) GetExitRootByGER(ctx context.Context, ger common.Hash, dbTx pgx.Tx) (*etherman.GlobalExitRoot, error)

GetExitRootByGER gets the latest L1 synced global exit root.

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, networkID, destNetwork uint, 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) GetLatestMonitoredTxGroupID added in v0.5.0

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

GetLatestGroupID

func (*PostgresStorage) GetLatestRollupExitLeaves added in v0.4.0

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, networkID uint, dbTx pgx.Tx) (*etherman.GlobalExitRoot, error)

GetLatestTrustedExitRoot gets the latest trusted global exit root.

func (*PostgresStorage) GetMonitoredTxsGroups added in v0.5.0

func (p *PostgresStorage) GetMonitoredTxsGroups(ctx context.Context, groupIds []uint64, dbTx pgx.Tx) (map[uint64]ctmtypes.MonitoredTxGroupDBEntry, error)

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 added in v0.4.0

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) IsRollupExitRoot added in v0.4.0

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 added in v0.1.0

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 added in v0.1.0

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 added in v0.1.0

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

UpdateL1DepositsStatus updates the ready_for_claim status of L1 deposits.

func (*PostgresStorage) UpdateL2DepositsStatus added in v0.1.0

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.

func (*PostgresStorage) UpdateMonitoredTxsGroup added in v0.5.0

func (p *PostgresStorage) UpdateMonitoredTxsGroup(ctx context.Context, mTxGroup *ctmtypes.MonitoredTxGroupDBEntry, dbTx pgx.Tx) error

Jump to

Keyboard shortcuts

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