db

package
v0.0.0-...-146b0ff Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPostgresConfigPrefix = "postgres"

	DBPasswordModePlain = "plain"
	DBPasswordModeGCP   = "gcp-secret-manager"
)

Variables

This section is empty.

Functions

func BatchCreateCLBlocks

func BatchCreateCLBlocks(db *gorm.DB, indexer string, blocks []*CLBlock, height int64) error

func BatchCreateCLStakingEvents

func BatchCreateCLStakingEvents(db *gorm.DB, indexer string, events []*CLStakingEvent, height int64) error

func BatchCreateELBlocks

func BatchCreateELBlocks(db *gorm.DB, indexer string, blocks []*ELBlock, height int64) error

func BatchCreateELStakingEvents

func BatchCreateELStakingEvents(db *gorm.DB, indexer string, events []*ELStakingEvent, height int64) error

func BatchUpdateCLValidatorVotes

func BatchUpdateCLValidatorVotes(db *gorm.DB, indexer string, validatorVotes []*CLValidatorVote, height int64) error

func BatchUpsertCLTotalStakes

func BatchUpsertCLTotalStakes(db *gorm.DB, indexer string, stakes []*CLTotalStake, height int64) error

func BatchUpsertELRewards

func BatchUpsertELRewards(db *gorm.DB, indexer string, rewards []*ELReward, height int64) error

func GetCLValidatorsVotes

func GetCLValidatorsVotes(db *gorm.DB, validators ...string) (map[string]int64, error)

func GetIndexPointTime

func GetIndexPointTime(db *gorm.DB, indexer string) (time.Time, error)

func InsertCLTotalStake

func InsertCLTotalStake(db *gorm.DB, indexer string, stake *CLTotalStake) error

func NewPostgresClient

func NewPostgresClient(ctx context.Context, configFile string) (*gorm.DB, error)

func SetupIndexPoint

func SetupIndexPoint(db *gorm.DB, indexPoint *IndexPoint) error

func UpdateIndexPoint

func UpdateIndexPoint(db *gorm.DB, indexer string, blockHeight int64) error

Types

type CLBlock

type CLBlock struct {
	ID              uint64    `gorm:"primarykey"`
	Height          int64     `gorm:"not null;column:height;index:idx_cl_block_height,unique"`
	Hash            string    `gorm:"not null;column:hash;index:idx_cl_block_hash,unique"`
	ProposerAddress string    `gorm:"not null;column:proposer_address"`
	Time            time.Time `gorm:"not null;column:time"`
}

func GetCLBlocks

func GetCLBlocks(db *gorm.DB, heights []int64) ([]*CLBlock, error)

func GetLatestCLBlock

func GetLatestCLBlock(db *gorm.DB) (*CLBlock, error)

func (CLBlock) TableName

func (CLBlock) TableName() string

type CLStakingEvent

type CLStakingEvent struct {
	ID          uint64 `gorm:"primarykey"`
	ELTxHash    string `gorm:"not null;column:el_tx_hash;index:idx_cl_staking_event_el_tx_hash_event_type,priority:1"`
	EventType   string `gorm:"not null;column:event_type;index:idx_cl_staking_event_el_tx_hash_event_type,priority:2"`
	BlockHeight int64  `gorm:"not null;column:block_height;index:idx_cl_staking_event_block_height"`
	StatusOK    bool   `gorm:"not null;column:status_ok"`
	ErrorCode   string `gorm:"not null;column:error_code"`
	Amount      string `gorm:"not null;column:amount"`
}

func (CLStakingEvent) TableName

func (CLStakingEvent) TableName() string

type CLTotalStake

type CLTotalStake struct {
	ID uint64 `gorm:"primarykey"`

	UpdateAt         int64 `gorm:"not null;column:update_at;index:idx_cl_total_stake_update_at,unique"`
	TotalStakeAmount int64 `gorm:"not null;column:total_stake_amount"`
}

func GetCLTotalStakes

func GetCLTotalStakes(db *gorm.DB) ([]*CLTotalStake, error)

func GetCLTotalStakesAfter

func GetCLTotalStakesAfter(db *gorm.DB, timestamp int64) ([]*CLTotalStake, error)

func GetLatestCLTotalStake

func GetLatestCLTotalStake(db *gorm.DB) (*CLTotalStake, error)

func GetLatestCLTotalStakeBefore

func GetLatestCLTotalStakeBefore(db *gorm.DB, timestamp int64) (*CLTotalStake, error)

func (CLTotalStake) TableName

func (CLTotalStake) TableName() string

type CLValidatorVote

type CLValidatorVote struct {
	ID          uint64 `gorm:"primarykey"`
	Validator   string `gorm:"not null;column:validator;index:idx_cl_validator_vote_validator_block_height,priority:1,unique"` // To lower case
	BlockHeight int64  `gorm:"not null;column:block_height;index:idx_cl_validator_vote_validator_block_height,priority:2,unique"`
}

func (CLValidatorVote) TableName

func (CLValidatorVote) TableName() string

type ELBlock

type ELBlock struct {
	ID       uint64    `gorm:"primarykey"`
	Height   int64     `gorm:"not null;column:height;index:idx_el_block_height,unique"`
	Hash     string    `gorm:"not null;column:hash;index:idx_el_block_hash,unique"`
	GasUsed  uint64    `gorm:"not null"`
	GasLimit uint64    `gorm:"not null"`
	Time     time.Time `gorm:"not null;column:time"`
}

func GetLatestELBlock

func GetLatestELBlock(db *gorm.DB, n int) ([]*ELBlock, error)

func (ELBlock) TableName

func (ELBlock) TableName() string

type ELReward

type ELReward struct {
	ID               uint64 `gorm:"primarykey"`
	Address          string `gorm:"not null;column:address;index:idx_el_reward_address,unique"` // To lower case
	Amount           string `gorm:"not null;column:amount;type:numeric"`
	LastUpdateHeight int64  `gorm:"not null;column:last_update_height"`
}

func GetELRewards

func GetELRewards(db *gorm.DB, evmAddr string) (*ELReward, error)

func (ELReward) TableName

func (ELReward) TableName() string

type ELStakingEvent

type ELStakingEvent struct {
	ID                  uint64 `gorm:"primarykey"`
	TxHash              string `gorm:"not null;column:tx_hash;index:idx_el_staking_event_tx_hash_event_type,priority:1"`
	EventType           string `gorm:"not null;column:event_type;index:idx_el_staking_event_tx_hash_event_type,priority:2"`
	Address             string `gorm:"not null;column:address;index:idx_el_staking_event_address_block_height,priority:1"` // To lower case
	BlockHeight         int64  `gorm:"not null;column:block_height;index:idx_el_staking_event_address_block_height,priority:2"`
	SrcValidatorAddress string `gorm:"not null;column:src_validator_address"`
	DstValidatorAddress string `gorm:"not null;column:dst_validator_address"`
	DstAddress          string `gorm:"not null;column:dst_address"` // RewardAddrss | WithdrawAddress | OperatorAddress
}

func (ELStakingEvent) TableName

func (ELStakingEvent) TableName() string

type IndexPoint

type IndexPoint struct {
	ID          uint64 `gorm:"primarykey"`
	Indexer     string `gorm:"not null;column:indexer;index:idx_index_point_indexer,unique"`
	BlockHeight int64  `gorm:"not null;column:block_height"`
}

func GetIndexPoint

func GetIndexPoint(db *gorm.DB, indexer string) (*IndexPoint, error)

func (IndexPoint) TableName

func (IndexPoint) TableName() string

type MetricsPlugin

type MetricsPlugin struct{}

func (*MetricsPlugin) Initialize

func (p *MetricsPlugin) Initialize(db *gorm.DB) (err error)

func (*MetricsPlugin) Name

func (p *MetricsPlugin) Name() string

type Operation

type Operation struct {
	TxHash              string `gorm:"column:tx_hash" json:"tx_hash"`
	BlockHeight         int64  `gorm:"column:block_height" json:"block_height"`
	EventType           string `gorm:"column:event_type" json:"event_type"`
	Address             string `gorm:"column:address" json:"address"`
	SrcValidatorAddress string `gorm:"column:src_validator_address" json:"src_validator_address"`
	DstValidatorAddress string `gorm:"column:dst_validator_address" json:"dst_validator_address"`
	DstAddress          string `gorm:"column:dst_address" json:"dst_address"`

	StatusOK  bool   `gorm:"column:status_ok" json:"status_ok"`
	ErrorCode string `gorm:"column:error_code" json:"error_code"`
	Amount    string `gorm:"column:amount;type:numeric" json:"amount"`
}

func GetOperations

func GetOperations(db *gorm.DB, evmAddr string, page, perPage int) ([]*Operation, int64, error)

type PostgresConfig

type PostgresConfig struct {
	DBUsername        string        `yaml:"db-username" envconfig:"DB_USERNAME"`
	DBPasswordMode    string        `yaml:"db-password-mode" envconfig:"DB_PASSWORD_MODE"`
	DBPassword        string        `yaml:"db-password" envconfig:"DB_PASSWORD"`
	DBHost            string        `yaml:"db-host" envconfig:"DB_HOST"`
	DBPort            int           `yaml:"db-port" envconfig:"DB_PORT"`
	DBName            string        `yaml:"db-name" envconfig:"DB_NAME"`
	DBMaxConns        int           `yaml:"db-max-conns" envconfig:"DB_MAX_CONNS"`
	DBMinConns        int           `yaml:"db-min-conns" envconfig:"DB_MIN_CONNS"`
	DBMaxConnLifetime time.Duration `yaml:"db-max-conn-lifetime" envconfig:"DB_MAX_CONN_LIFETIME"`
	DBMaxConnIdleTime time.Duration `yaml:"db-max-conn-idle-time" envconfig:"DB_MAX_CONN_IDLE_TIME"`
}

Jump to

Keyboard shortcuts

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