database

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 9 Imported by: 0

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 ErrU256ContainsDecimal = errors.New("number contains fractional digits")
View Source
var ErrU256NotNull = errors.New("number cannot be null")
View Source
var ErrU256Overflow = errors.New("number exceeds u256")

Functions

This section is empty.

Types

type BlockHeader

type BlockHeader struct {
	Hash       common.Hash `gorm:"primaryKey;serializer:json"`
	ParentHash common.Hash `gorm:"serializer:json"`
	Number     U256
	Timestamp  uint64
}

type BlocksDB

type BlocksDB interface {
	BlocksView

	StoreL1BlockHeaders([]*L1BlockHeader) error
	StoreLegacyStateBatch(*LegacyStateBatch) error

	StoreL2BlockHeaders([]*L2BlockHeader) error
	MarkFinalizedL1RootForL2Block(common.Hash, common.Hash) error
}

type BlocksView

type BlocksView interface {
	FinalizedL1BlockHeight() (*big.Int, error)
	FinalizedL2BlockHeight() (*big.Int, error)
}

type BridgeDB

type BridgeDB interface {
	BridgeView

	StoreDeposits([]*Deposit) error
	StoreWithdrawals([]*Withdrawal) error
	MarkProvenWithdrawalEvent(string, string) error
	MarkFinalizedWithdrawalEvent(string, string) error
}

type BridgeView

type BridgeView interface {
	DepositsByAddress(address common.Address) ([]*DepositWithTransactionHash, error)
	WithdrawalsByAddress(address common.Address) ([]*WithdrawalWithTransactionHashes, error)
}

type ContractEvent

type ContractEvent struct {
	GUID            string      `gorm:"primaryKey"`
	BlockHash       common.Hash `gorm:"serializer:json"`
	TransactionHash common.Hash `gorm:"serializer:json"`

	EventSignature hexutil.Bytes `gorm:"serializer:json"`
	LogIndex       uint64
	Timestamp      uint64
}

type ContractEventsDB

type ContractEventsDB interface {
	ContractEventsView

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

type ContractEventsView

type ContractEventsView interface {
	L1ContractEventByGUID(string) (*L1ContractEvent, error)
	L2ContractEventByGUID(string) (*L2ContractEvent, error)
}

type DB

type DB struct {
	Blocks         BlocksDB
	ContractEvents ContractEventsDB
	Bridge         BridgeDB
	// contains filtered or unexported fields
}

func NewDB

func NewDB(dsn string) (*DB, error)

type Deposit

type Deposit struct {
	GUID                 string `gorm:"primaryKey"`
	InitiatedL1EventGUID string

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

type DepositWithTransactionHash

type DepositWithTransactionHash struct {
	Deposit           Deposit     `gorm:"embedded"`
	L1TransactionHash common.Hash `gorm:"serializer:json"`
}

type L1BlockHeader

type L1BlockHeader struct {
	BlockHeader
}

type L1ContractEvent

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

type L2BlockHeader

type L2BlockHeader struct {
	BlockHeader

	// Marked when the proposed output is finalized on L1.
	// All bedrock blocks will have `LegacyStateBatchIndex ^== NULL`
	L1BlockHash           *common.Hash `gorm:"serializer:json"`
	LegacyStateBatchIndex *uint64
}

type L2ContractEvent

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

type LegacyStateBatch

type LegacyStateBatch struct {
	// `default:0` is added since gorm would interepret 0 as NULL
	// violating the primary key constraint.
	Index uint64 `gorm:"primaryKey;default:0"`

	Root        common.Hash `gorm:"serializer:json"`
	Size        uint64
	PrevTotal   uint64
	L1BlockHash common.Hash `gorm:"serializer:json"`
}

type TokenPair

type TokenPair struct {
	L1TokenAddress common.Address `gorm:"serializer:json"`
	L2TokenAddress common.Address `gorm:"serializer:json"`
}

type Transaction

type Transaction struct {
	FromAddress common.Address `gorm:"serializer:json"`
	ToAddress   common.Address `gorm:"serializer:json"`
	Amount      U256
	Data        hexutil.Bytes `gorm:"serializer:json"`
	Timestamp   uint64
}

type U256

type U256 struct {
	Int *big.Int
}

U256 is a wrapper over big.Int that conforms to the database U256 numeric domain type

func (*U256) Scan

func (u256 *U256) Scan(src interface{}) error

Scan implements the database/sql Scanner interface.

func (U256) Value

func (u256 U256) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface.

type Withdrawal

type Withdrawal struct {
	GUID                 string `gorm:"primaryKey"`
	InitiatedL2EventGUID string

	WithdrawalHash       common.Hash `gorm:"serializer:json"`
	ProvenL1EventGUID    *string
	FinalizedL1EventGUID *string

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

type WithdrawalWithTransactionHashes

type WithdrawalWithTransactionHashes struct {
	Withdrawal        Withdrawal  `gorm:"embedded"`
	L2TransactionHash common.Hash `gorm:"serializer:json"`

	ProvenL1TransactionHash    *common.Hash `gorm:"serializer:json"`
	FinalizedL1TransactionHash *common.Hash `gorm:"serializer:json"`
}

Jump to

Keyboard shortcuts

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