db

package
v0.0.0-...-1fe6bf9 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package db provides a postgresql database client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenDB

func OpenDB(url string) *bun.DB

Types

type Database

type Database struct {
	DB *bun.DB
}

func New

func New(url string) (*Database, error)

func (*Database) CreateSchema

func (d *Database) CreateSchema(ctx context.Context) error

func (*Database) GetLatestVotesForNetwork

func (d *Database) GetLatestVotesForNetwork(
	ctx context.Context,
	network string,
) ([]VoteEvent, error)

func (*Database) GetNewRoundSteps

func (d *Database) GetNewRoundSteps(ctx context.Context, network string) (steps []NewRoundStepEvent, err error)

func (*Database) GetNewRounds

func (d *Database) GetNewRounds(ctx context.Context, network string) (rounds []NewRoundEvent, err error)

func (*Database) GetValidators

func (d *Database) GetValidators(ctx context.Context, network string) (validators Validators, err error)

func (*Database) GetVotes

func (d *Database) GetVotes(ctx context.Context, network string) (votes []VoteEvent, err error)

func (*Database) StoreNewRound

func (d *Database) StoreNewRound(
	ctx context.Context,
	network string,
	roundInfo common.ParsedNewRound,
) error

func (*Database) StoreNewRoundStep

func (d *Database) StoreNewRoundStep(
	ctx context.Context,
	network string,
	roundInfo common.ParsedNewRoundStep,
) error

func (*Database) StoreOrUpdateValidators

func (d *Database) StoreOrUpdateValidators(
	ctx context.Context,
	network string,
	data map[string]interface{},
) error

func (*Database) StoreVote

func (d *Database) StoreVote(
	ctx context.Context,
	network string,
	vote common.ParsedVote,
) error

type NewRoundEvent

type NewRoundEvent struct {
	bun.BaseModel `bun:"table:new_round_events"`

	ID      uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	Network string

	Height           int
	Round            int
	Step             string
	ValidatorAddress string
	ValidatorIndex   int
}

type NewRoundStepEvent

type NewRoundStepEvent struct {
	bun.BaseModel `bun:"table:new_round_step_events"`

	ID      uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	Network string

	Height int
	Round  int
	Step   string
}

type Validators

type Validators struct {
	bun.BaseModel `bun:"table:validators"`
	ID            uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	Network       string
	// map validator_address => last_vote_time
	Data map[string]interface{} `bun:"type:jsonb"`
}

type VoteEvent

type VoteEvent struct {
	bun.BaseModel      `bun:"table:vote_events"`
	ID                 uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()"`
	Network            string
	VoteType           string
	Height             int
	Round              int
	BlockID            string
	BlockTimestamp     time.Time
	ValidatorAddress   string
	ValidatorIndex     int
	ValidatorSignature []byte
}

Jump to

Keyboard shortcuts

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