database

package
v1.4.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

Database module defines the data DB struct which wraps specific DB interfaces for L1/L2 block headers, contract events, bridging schemas.

Index

Constants

This section is empty.

Variables

View Source
var (
	ETHTokenPair = TokenPair{LocalTokenAddress: predeploys.LegacyERC20ETHAddr, RemoteTokenAddress: predeploys.LegacyERC20ETHAddr}
)
View Source
var (
	SlowThresholdMilliseconds int64 = 500
)

Functions

This section is empty.

Types

type BlockHeader

type BlockHeader struct {
	Hash       common.Hash `gorm:"primaryKey;serializer:bytes"`
	ParentHash common.Hash `gorm:"serializer:bytes"`
	Number     *big.Int    `gorm:"serializer:u256"`
	Timestamp  uint64

	RLPHeader *RLPHeader `gorm:"serializer:rlp;column:rlp_bytes"`
}

func BlockHeaderFromHeader added in v1.1.4

func BlockHeaderFromHeader(header *types.Header) BlockHeader

func (BlockHeader) String added in v1.4.2

func (b BlockHeader) String() string

type BlocksDB

type BlocksDB interface {
	BlocksView

	StoreL1BlockHeaders([]L1BlockHeader) error
	StoreL2BlockHeaders([]L2BlockHeader) error
}

type BlocksView

type BlocksView interface {
	L1BlockHeader(common.Hash) (*L1BlockHeader, error)
	L1BlockHeaderWithFilter(BlockHeader) (*L1BlockHeader, error)
	L1BlockHeaderWithScope(func(db *gorm.DB) *gorm.DB) (*L1BlockHeader, error)
	L1LatestBlockHeader() (*L1BlockHeader, error)

	L2BlockHeader(common.Hash) (*L2BlockHeader, error)
	L2BlockHeaderWithFilter(BlockHeader) (*L2BlockHeader, error)
	L2BlockHeaderWithScope(func(db *gorm.DB) *gorm.DB) (*L2BlockHeader, error)
	L2LatestBlockHeader() (*L2BlockHeader, error)
}

type BridgeMessage added in v1.1.4

type BridgeMessage struct {
	MessageHash common.Hash `gorm:"primaryKey;serializer:bytes"`
	Nonce       *big.Int    `gorm:"serializer:u256"`

	SentMessageEventGUID    uuid.UUID
	RelayedMessageEventGUID *uuid.UUID

	Tx       Transaction `gorm:"embedded"`
	GasLimit *big.Int    `gorm:"serializer:u256"`
}

type BridgeMessagesDB added in v1.1.4

type BridgeMessagesDB interface {
	BridgeMessagesView

	StoreL1BridgeMessages([]L1BridgeMessage) error
	MarkRelayedL1BridgeMessage(common.Hash, uuid.UUID) error

	StoreL2BridgeMessages([]L2BridgeMessage) error
	MarkRelayedL2BridgeMessage(common.Hash, uuid.UUID) error

	StoreL2BridgeMessageV1MessageHashes([]L2BridgeMessageVersionedMessageHash) error
}

type BridgeMessagesView added in v1.1.4

type BridgeMessagesView interface {
	L1BridgeMessage(common.Hash) (*L1BridgeMessage, error)
	L1BridgeMessageWithFilter(BridgeMessage) (*L1BridgeMessage, error)

	L2BridgeMessage(common.Hash) (*L2BridgeMessage, error)
	L2BridgeMessageWithFilter(BridgeMessage) (*L2BridgeMessage, error)
}

type BridgeTransactionsDB added in v1.1.4

type BridgeTransactionsDB interface {
	BridgeTransactionsView

	StoreL1TransactionDeposits([]L1TransactionDeposit) error

	StoreL2TransactionWithdrawals([]L2TransactionWithdrawal) error
	MarkL2TransactionWithdrawalProvenEvent(common.Hash, uuid.UUID) error
	MarkL2TransactionWithdrawalFinalizedEvent(common.Hash, uuid.UUID, bool) error
}

type BridgeTransactionsView added in v1.1.4

type BridgeTransactionsView interface {
	L1TransactionDeposit(common.Hash) (*L1TransactionDeposit, error)
	L1LatestBlockHeader() (*L1BlockHeader, error)
	L1LatestFinalizedBlockHeader() (*L1BlockHeader, error)

	L2TransactionWithdrawal(common.Hash) (*L2TransactionWithdrawal, error)
	L2LatestBlockHeader() (*L2BlockHeader, error)
	L2LatestFinalizedBlockHeader() (*L2BlockHeader, error)
}

type BridgeTransfer added in v1.1.4

type BridgeTransfer struct {
	CrossDomainMessageHash *common.Hash `gorm:"serializer:bytes"`

	Tx        Transaction `gorm:"embedded"`
	TokenPair TokenPair   `gorm:"embedded"`
}

type BridgeTransfersDB added in v1.1.4

type BridgeTransfersDB interface {
	BridgeTransfersView

	StoreL1BridgeDeposits([]L1BridgeDeposit) error
	StoreL2BridgeWithdrawals([]L2BridgeWithdrawal) error
}

type BridgeTransfersView added in v1.1.4

type BridgeTransfersView interface {
	L1BridgeDeposit(common.Hash) (*L1BridgeDeposit, error)
	L1BridgeDepositSum() (float64, error)
	L1BridgeDepositWithFilter(BridgeTransfer) (*L1BridgeDeposit, error)
	L1BridgeDepositsByAddress(common.Address, string, int) (*L1BridgeDepositsResponse, error)

	L2BridgeWithdrawal(common.Hash) (*L2BridgeWithdrawal, error)
	L2BridgeWithdrawalSum() (float64, error)
	L2BridgeWithdrawalWithFilter(BridgeTransfer) (*L2BridgeWithdrawal, error)
	L2BridgeWithdrawalsByAddress(common.Address, string, int) (*L2BridgeWithdrawalsResponse, error)
}

type Bytes added in v1.1.6

type Bytes []byte

func (Bytes) Bytes added in v1.1.6

func (b Bytes) Bytes() []byte

func (*Bytes) SetBytes added in v1.1.6

func (b *Bytes) SetBytes(bytes []byte)

type ContractEvent

type ContractEvent struct {
	GUID uuid.UUID `gorm:"primaryKey"`

	// Some useful derived fields
	BlockHash       common.Hash    `gorm:"serializer:bytes"`
	ContractAddress common.Address `gorm:"serializer:bytes"`
	TransactionHash common.Hash    `gorm:"serializer:bytes"`
	LogIndex        uint64

	EventSignature common.Hash `gorm:"serializer:bytes"`
	Timestamp      uint64

	// NOTE: NOT ALL THE DERIVED FIELDS ON `types.Log` ARE
	// AVAILABLE. FIELDS LISTED ABOVE ARE FILLED IN
	RLPLog *types.Log `gorm:"serializer:rlp;column:rlp_bytes"`
}

func ContractEventFromLog added in v1.1.4

func ContractEventFromLog(log *types.Log, timestamp uint64) ContractEvent

func (*ContractEvent) AfterFind added in v1.1.4

func (c *ContractEvent) AfterFind(tx *gorm.DB) error

type ContractEventsDB

type ContractEventsDB interface {
	ContractEventsView

	StoreL1ContractEvents([]L1ContractEvent) error
	StoreL2ContractEvents([]L2ContractEvent) error
}

type ContractEventsView

type ContractEventsView interface {
	L1ContractEvent(uuid.UUID) (*L1ContractEvent, error)
	L1ContractEventWithFilter(ContractEvent) (*L1ContractEvent, error)
	L1ContractEventsWithFilter(ContractEvent, *big.Int, *big.Int) ([]L1ContractEvent, error)
	L1LatestContractEventWithFilter(ContractEvent) (*L1ContractEvent, error)

	L2ContractEvent(uuid.UUID) (*L2ContractEvent, error)
	L2ContractEventWithFilter(ContractEvent) (*L2ContractEvent, error)
	L2ContractEventsWithFilter(ContractEvent, *big.Int, *big.Int) ([]L2ContractEvent, error)
	L2LatestContractEventWithFilter(ContractEvent) (*L2ContractEvent, error)

	ContractEventsWithFilter(ContractEvent, string, *big.Int, *big.Int) ([]ContractEvent, error)
}

type DB

type DB struct {
	Blocks             BlocksDB
	ContractEvents     ContractEventsDB
	BridgeTransfers    BridgeTransfersDB
	BridgeMessages     BridgeMessagesDB
	BridgeTransactions BridgeTransactionsDB
	// contains filtered or unexported fields
}

func NewDB

func NewDB(ctx context.Context, log log.Logger, dbConfig config.DBConfig) (*DB, error)

NewDB connects to the configured DB, and provides client-bindings to it. The initial connection may fail, or the dial may be cancelled with the provided context.

func (*DB) Close

func (db *DB) Close() error

func (*DB) ExecuteSQLMigration added in v1.1.6

func (db *DB) ExecuteSQLMigration(migrationsFolder string) error

func (*DB) Transaction

func (db *DB) Transaction(fn func(db *DB) error) error

Transaction executes all operations conducted with the supplied database in a single transaction. If the supplied function errors, the transaction is rolled back.

type L1BlockHeader

type L1BlockHeader struct {
	BlockHeader `gorm:"embedded"`
}

type L1BridgeDeposit added in v1.1.4

type L1BridgeDeposit struct {
	BridgeTransfer        `gorm:"embedded"`
	TransactionSourceHash common.Hash `gorm:"primaryKey;serializer:bytes"`
}

type L1BridgeDepositWithTransactionHashes added in v1.1.4

type L1BridgeDepositWithTransactionHashes struct {
	L1BridgeDeposit L1BridgeDeposit `gorm:"embedded"`

	L1BlockHash       common.Hash `gorm:"serializer:bytes"`
	L1TransactionHash common.Hash `gorm:"serializer:bytes"`
	L2TransactionHash common.Hash `gorm:"serializer:bytes"`
}

type L1BridgeDepositsResponse added in v1.1.6

type L1BridgeDepositsResponse struct {
	Deposits    []L1BridgeDepositWithTransactionHashes
	Cursor      string
	HasNextPage bool
}

type L1BridgeMessage added in v1.1.4

type L1BridgeMessage struct {
	BridgeMessage         `gorm:"embedded"`
	TransactionSourceHash common.Hash `gorm:"serializer:bytes"`
}

type L1ContractEvent

type L1ContractEvent struct {
	ContractEvent `gorm:"embedded"`
}

type L1TransactionDeposit added in v1.1.4

type L1TransactionDeposit struct {
	SourceHash           common.Hash `gorm:"serializer:bytes;primaryKey"`
	L2TransactionHash    common.Hash `gorm:"serializer:bytes"`
	InitiatedL1EventGUID uuid.UUID

	Tx       Transaction `gorm:"embedded"`
	GasLimit *big.Int    `gorm:"serializer:u256"`
}

type L2BlockHeader

type L2BlockHeader struct {
	BlockHeader `gorm:"embedded"`
}

type L2BridgeMessage added in v1.1.4

type L2BridgeMessage struct {
	BridgeMessage             `gorm:"embedded"`
	TransactionWithdrawalHash common.Hash `gorm:"serializer:bytes"`
}

type L2BridgeMessageVersionedMessageHash added in v1.4.2

type L2BridgeMessageVersionedMessageHash struct {
	MessageHash   common.Hash `gorm:"primaryKey;serializer:bytes"`
	V1MessageHash common.Hash `gorm:"serializer:bytes"`
}

type L2BridgeWithdrawal added in v1.1.4

type L2BridgeWithdrawal struct {
	BridgeTransfer            `gorm:"embedded"`
	TransactionWithdrawalHash common.Hash `gorm:"primaryKey;serializer:bytes"`
}

type L2BridgeWithdrawalWithTransactionHashes added in v1.1.4

type L2BridgeWithdrawalWithTransactionHashes struct {
	L2BridgeWithdrawal L2BridgeWithdrawal `gorm:"embedded"`
	L2TransactionHash  common.Hash        `gorm:"serializer:bytes"`
	L2BlockHash        common.Hash        `gorm:"serializer:bytes"`

	ProvenL1TransactionHash    common.Hash `gorm:"serializer:bytes"`
	FinalizedL1TransactionHash common.Hash `gorm:"serializer:bytes"`
}

type L2BridgeWithdrawalsResponse added in v1.1.6

type L2BridgeWithdrawalsResponse struct {
	Withdrawals []L2BridgeWithdrawalWithTransactionHashes
	Cursor      string
	HasNextPage bool
}

type L2ContractEvent

type L2ContractEvent struct {
	ContractEvent `gorm:"embedded"`
}

type L2TransactionWithdrawal added in v1.1.4

type L2TransactionWithdrawal struct {
	WithdrawalHash       common.Hash `gorm:"serializer:bytes;primaryKey"`
	Nonce                *big.Int    `gorm:"serializer:u256"`
	InitiatedL2EventGUID uuid.UUID

	ProvenL1EventGUID    *uuid.UUID
	FinalizedL1EventGUID *uuid.UUID
	Succeeded            *bool

	Tx       Transaction `gorm:"embedded"`
	GasLimit *big.Int    `gorm:"serializer:u256"`
}

type Logger added in v1.2.0

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

func (Logger) Error added in v1.2.0

func (l Logger) Error(ctx context.Context, msg string, data ...interface{})

func (Logger) Info added in v1.2.0

func (l Logger) Info(ctx context.Context, msg string, data ...interface{})

func (Logger) LogMode added in v1.2.0

func (l Logger) LogMode(lvl logger.LogLevel) logger.Interface

func (Logger) Trace added in v1.2.0

func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (Logger) Warn added in v1.2.0

func (l Logger) Warn(ctx context.Context, msg string, data ...interface{})

type MockBlocksDB added in v1.1.6

type MockBlocksDB struct {
	MockBlocksView
}

func (*MockBlocksDB) StoreL1BlockHeaders added in v1.1.6

func (m *MockBlocksDB) StoreL1BlockHeaders(headers []L1BlockHeader) error

func (*MockBlocksDB) StoreL2BlockHeaders added in v1.1.6

func (m *MockBlocksDB) StoreL2BlockHeaders(headers []L2BlockHeader) error

type MockBlocksView added in v1.1.6

type MockBlocksView struct {
	mock.Mock
}

func (*MockBlocksView) L1BlockHeader added in v1.1.6

func (m *MockBlocksView) L1BlockHeader(common.Hash) (*L1BlockHeader, error)

func (*MockBlocksView) L1BlockHeaderWithFilter added in v1.1.6

func (m *MockBlocksView) L1BlockHeaderWithFilter(BlockHeader) (*L1BlockHeader, error)

func (*MockBlocksView) L1BlockHeaderWithScope added in v1.4.2

func (m *MockBlocksView) L1BlockHeaderWithScope(func(*gorm.DB) *gorm.DB) (*L1BlockHeader, error)

func (*MockBlocksView) L1LatestBlockHeader added in v1.1.6

func (m *MockBlocksView) L1LatestBlockHeader() (*L1BlockHeader, error)

func (*MockBlocksView) L2BlockHeader added in v1.1.6

func (m *MockBlocksView) L2BlockHeader(common.Hash) (*L2BlockHeader, error)

func (*MockBlocksView) L2BlockHeaderWithFilter added in v1.1.6

func (m *MockBlocksView) L2BlockHeaderWithFilter(BlockHeader) (*L2BlockHeader, error)

func (*MockBlocksView) L2BlockHeaderWithScope added in v1.4.2

func (m *MockBlocksView) L2BlockHeaderWithScope(func(*gorm.DB) *gorm.DB) (*L2BlockHeader, error)

func (*MockBlocksView) L2LatestBlockHeader added in v1.1.6

func (m *MockBlocksView) L2LatestBlockHeader() (*L2BlockHeader, error)

type MockDB added in v1.1.6

type MockDB struct {
	MockBlocks *MockBlocksDB
	DB         *DB
}

MockDB is a mock database that can be used for testing

func NewMockDB added in v1.1.6

func NewMockDB() *MockDB

type RLPHeader added in v1.1.4

type RLPHeader types.Header

func (*RLPHeader) DecodeRLP added in v1.1.4

func (h *RLPHeader) DecodeRLP(s *rlp.Stream) error

func (*RLPHeader) EncodeRLP added in v1.1.4

func (h *RLPHeader) EncodeRLP(w io.Writer) error

func (*RLPHeader) Hash added in v1.1.4

func (h *RLPHeader) Hash() common.Hash

func (*RLPHeader) Header added in v1.1.4

func (h *RLPHeader) Header() *types.Header

type TokenPair

type TokenPair struct {
	LocalTokenAddress  common.Address `gorm:"serializer:bytes"`
	RemoteTokenAddress common.Address `gorm:"serializer:bytes"`
}

type Transaction

type Transaction struct {
	FromAddress common.Address `gorm:"serializer:bytes"`
	ToAddress   common.Address `gorm:"serializer:bytes"`
	Amount      *big.Int       `gorm:"serializer:u256"`
	Data        Bytes          `gorm:"serializer:bytes"`
	Timestamp   uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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