db

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StreamTypeSequencer represents a Sequencer stream
	StreamTypeSequencer datastreamer.StreamType = 1
	// EntryTypeL2BlockStart represents a L2 block start
	EntryTypeL2BlockStart datastreamer.EntryType = 1
	// EntryTypeL2Tx represents a L2 transaction
	EntryTypeL2Tx datastreamer.EntryType = 2
	// EntryTypeL2BlockEnd represents a L2 block end
	EntryTypeL2BlockEnd datastreamer.EntryType = 3
)

Variables

This section is empty.

Functions

func NewSQLDB

func NewSQLDB(cfg Config) (*pgxpool.Pool, error)

NewSQLDB creates a new SQL DB

Types

type Config

type Config struct {
	// Database name
	Name string `mapstructure:"Name"`
	// Database User name
	User string `mapstructure:"User"`
	// Database Password of the user
	Password string `mapstructure:"Password"`
	// Host address of database
	Host string `mapstructure:"Host"`
	// Port Number of database
	Port string `mapstructure:"Port"`
	// EnableLog
	EnableLog bool `mapstructure:"EnableLog"`
	// MaxConns is the maximum number of connections in the pool.
	MaxConns int `mapstructure:"MaxConns"`
}

Config is the configuration for the database

type L2Block

type L2Block struct {
	BatchNumber    uint64         // 8 bytes
	L2BlockNumber  uint64         // 8 bytes
	Timestamp      int64          // 8 bytes
	GlobalExitRoot common.Hash    // 32 bytes
	Coinbase       common.Address // 20 bytes
	ForkID         uint16         // 2 bytes
	BlockHash      common.Hash    // 32 bytes
	StateRoot      common.Hash    // 32 bytes
}

L2Block is a full l2 block

type L2BlockEnd added in v0.0.7

type L2BlockEnd struct {
	L2BlockNumber uint64      // 8 bytes
	BlockHash     common.Hash // 32 bytes
	StateRoot     common.Hash // 32 bytes
}

L2BlockEnd represents a L2 block end

func (L2BlockEnd) Encode added in v0.0.7

func (b L2BlockEnd) Encode() []byte

Encode returns the encoded EndL2Block as a byte slice

type L2BlockStart added in v0.0.7

type L2BlockStart struct {
	BatchNumber    uint64         // 8 bytes
	L2BlockNumber  uint64         // 8 bytes
	Timestamp      int64          // 8 bytes
	GlobalExitRoot common.Hash    // 32 bytes
	Coinbase       common.Address // 20 bytes
	ForkID         uint16         // 2 bytes
}

L2BlockStart represents a L2 block start

func (L2BlockStart) Encode added in v0.0.7

func (b L2BlockStart) Encode() []byte

Encode returns the encoded StartL2Block as a byte slice

type L2Transaction

type L2Transaction struct {
	EffectiveGasPricePercentage uint8  // 1 byte
	IsValid                     uint8  // 1 byte
	EncodedLength               uint32 // 4 bytes
	Encoded                     []byte
}

L2Transaction represents a L2 transaction

func (L2Transaction) Encode

func (l L2Transaction) Encode() []byte

Encode returns the encoded L2Transaction as a byte slice

type StateDB

type StateDB struct {
	*pgxpool.Pool
}

StateDB implements the StateDB interface

func NewStateDB

func NewStateDB(db *pgxpool.Pool) *StateDB

NewStateDB creates a new StateDB

func (*StateDB) GetGenesisBlock added in v0.0.7

func (db *StateDB) GetGenesisBlock(ctx context.Context) (*L2Block, error)

GetGenesisBlock returns the genesis block

func (*StateDB) GetL2Blocks

func (db *StateDB) GetL2Blocks(ctx context.Context, limit, offset uint64) ([]*L2Block, error)

GetL2Blocks returns the L2 blocks

func (*StateDB) GetL2Transactions

func (db *StateDB) GetL2Transactions(ctx context.Context, minL2Block, maxL2Block uint64) ([]*L2Transaction, error)

GetL2Transactions returns the L2 transactions

Jump to

Keyboard shortcuts

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