database

package
v0.0.0-...-eb934a0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 10 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
	StoreL2BlockHeaders([]*L2BlockHeader) error

	StoreLegacyStateBatches([]*LegacyStateBatch) error
	StoreOutputProposals([]*OutputProposal) error
}

type BlocksView

type BlocksView interface {
	LatestL1BlockHeader() (*L1BlockHeader, error)
	LatestCheckpointedOutput() (*OutputProposal, error)

	LatestL2BlockHeader() (*L2BlockHeader, 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            uuid.UUID   `gorm:"primaryKey"`
	BlockHash       common.Hash `gorm:"serializer:json"`
	TransactionHash common.Hash `gorm:"serializer:json"`

	EventSignature common.Hash `gorm:"serializer:json"`
	LogIndex       uint64
	Timestamp      uint64
}

type ContractEventsDB

type ContractEventsDB interface {
	ContractEventsView

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

type ContractEventsView

type ContractEventsView interface {
}

type DB

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

func NewDB

func NewDB(dsn string) (*DB, 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 Deposit

type Deposit struct {
	GUID                 uuid.UUID `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
}

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
	L1ContractEventGUID uuid.UUID
}

type OutputProposal

type OutputProposal struct {
	OutputRoot          common.Hash `gorm:"primaryKey;serializer:json"`
	L2BlockNumber       U256
	L1ContractEventGUID uuid.UUID
}

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                 uuid.UUID `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