dao

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDBName

func GetDBName(s interface{}) string

GetDBName get a db name by using the Suite struct in each test

Types

type BlockDao

type BlockDao struct {
	DB *gorm.DB
}

func NewBlockDao

func NewBlockDao(db *gorm.DB) *BlockDao

func (*BlockDao) DeleteBlocksBefore

func (d *BlockDao) DeleteBlocksBefore(unixTimestamp int64) error

func (*BlockDao) GetLatestBlock

func (d *BlockDao) GetLatestBlock() (*model.Block, error)

type DaoManager

type DaoManager struct {
	*BlockDao
	*EventDao
	*VoteDao
}

func NewDaoManager

func NewDaoManager(blockDao *BlockDao, eventDao *EventDao, voteDao *VoteDao) *DaoManager

type Database

type Database struct {
	Name string
	DB   *gorm.DB
	// contains filtered or unexported fields
}

Database is the struct for database docker

func RunDB

func RunDB(dbName string) (*Database, error)

RunDB run docker of db for unit test

func (*Database) ClearDB

func (d *Database) ClearDB() error

ClearDB drop the tables in database

func (*Database) InitDB

func (d *Database) InitDB() error

InitDB init database schema and data

func (*Database) InitData

func (d *Database) InitData() error

InitData init data for testing

func (*Database) StopDB

func (d *Database) StopDB() error

StopDB stop and remove the docker of db for unit test

type EventDao

type EventDao struct {
	DB *gorm.DB
}

func NewEventDao

func NewEventDao(db *gorm.DB) *EventDao

func (*EventDao) DeleteEventsBefore

func (d *EventDao) DeleteEventsBefore(unixTimestamp int64) error

func (*EventDao) GetEventByChallengeId

func (d *EventDao) GetEventByChallengeId(challengeId uint64) (*model.Event, error)

func (*EventDao) GetLatestEventByStatus

func (d *EventDao) GetLatestEventByStatus(status model.EventStatus) (*model.Event, error)

func (*EventDao) GetUnexpiredEventsByStatus

func (d *EventDao) GetUnexpiredEventsByStatus(currentHeight uint64, status model.EventStatus) ([]*model.Event, error)

func (*EventDao) GetUnexpiredEventsByVerifyResult

func (d *EventDao) GetUnexpiredEventsByVerifyResult(limit int, currentHeight uint64, verifyResult model.VerifyResult) ([]*model.Event, error)

func (*EventDao) IsEventExistsBetween

func (d *EventDao) IsEventExistsBetween(objectId, spOperatorAddress string, lowChallengeId, highChallengeId uint64) (bool, error)

func (*EventDao) SaveBlockAndEvents

func (d *EventDao) SaveBlockAndEvents(b *model.Block, events []*model.Event) error

func (*EventDao) UpdateEventStatusByChallengeId

func (d *EventDao) UpdateEventStatusByChallengeId(challengeId uint64, status model.EventStatus) error

func (*EventDao) UpdateEventStatusVerifyResultByChallengeId

func (d *EventDao) UpdateEventStatusVerifyResultByChallengeId(challengeId uint64, status model.EventStatus, result model.VerifyResult) error

type VoteDao

type VoteDao struct {
	DB *gorm.DB
}

func NewVoteDao

func NewVoteDao(db *gorm.DB) *VoteDao

func (*VoteDao) DeleteVotesBefore

func (d *VoteDao) DeleteVotesBefore(unixTimestamp int64) error

func (*VoteDao) GetVotesByEventHash

func (d *VoteDao) GetVotesByEventHash(eventHash string) ([]*model.Vote, error)

func (*VoteDao) IsVoteExists

func (d *VoteDao) IsVoteExists(eventHash string, pubKey string) (bool, error)

func (*VoteDao) SaveVote

func (d *VoteDao) SaveVote(vote *model.Vote) error

func (*VoteDao) SaveVoteAndUpdateEventStatus

func (d *VoteDao) SaveVoteAndUpdateEventStatus(vote *model.Vote, challengeId uint64) error

Jump to

Keyboard shortcuts

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