dao

package
v0.0.0-...-943aac3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RedisMetadataKey      = "metadata"
	FillAlreadyBlockNum   = "fill_already_blockNum"
	FillFinalizedBlockNum = "fill_finalized_blockNum"

	MetadataBlockNum          = "blockNum"
	MetadataFinalizedBlockNum = "finalized_blockNum"
)

Variables

View Source
var (

	// MetadataBlockNum          = "MetadataBlockNum"
	// MetadataFinalizedBlockNum = "MetadataFinalizedBlockNum"
	MetadataImplName    = "MetadataImplName"
	MetadataSpecVersion = "MetadataSpecVersion"
)
View Source
var (
	DaemonAction = []string{"substrate"}
)
View Source
var SplitTableBlockNum = model.SplitTableBlockNum

Functions

func New

func New(ctx context.Context, mysqlDsn string) (*Dao, *DbStorage, error)

New new a dao and return.

Types

type Dao

type Dao struct {
	// contains filtered or unexported fields
}

dao

func (*Dao) AddIndex

func (d *Dao) AddIndex(blockNum int)

func (*Dao) BlockAsJson

func (d *Dao) BlockAsJson(c context.Context, block *model.ChainBlock) *model.ChainBlockJson

func (*Dao) BlocksReverseByNum

func (d *Dao) BlocksReverseByNum(blockNums []int) map[int]model.ChainBlock

func (*Dao) ByBlockHeight

func (d *Dao) ByBlockHeight(ctx context.Context, blockHeight int) ([]*EventDetail, error)

func (*Dao) ByID

func (d *Dao) ByID(ctx context.Context, eventID string) (*EventDetail, error)

func (*Dao) Close

func (d *Dao) Close()

Close close the resource.

func (*Dao) CreateBlock

func (d *Dao) CreateBlock(txn *GormDB, cb *model.ChainBlock) (err error)

CreateBlock, mysql db transaction Check if you need to create a new table(block, extrinsic, event, log ) after created

func (*Dao) CreateEvent

func (d *Dao) CreateEvent(txn *GormDB, event *model.ChainEvent) error

func (*Dao) CreateEventDetail

func (d *Dao) CreateEventDetail(txn *GormDB, eventDetail *EventDetail) error

func (*Dao) CreateExtrinsic

func (d *Dao) CreateExtrinsic(c context.Context, txn *GormDB, extrinsic *model.ChainExtrinsic) error

func (*Dao) CreateLog

func (d *Dao) CreateLog(txn *GormDB, ce *model.ChainLog) error

func (*Dao) CreateRuntimeVersion

func (d *Dao) CreateRuntimeVersion(name string, specVersion int) int64

func (*Dao) DbBegin

func (d *Dao) DbBegin() *GormDB

dao funcs

func (*Dao) DbCommit

func (d *Dao) DbCommit(c *GormDB)

func (*Dao) DbRollback

func (d *Dao) DbRollback(c *GormDB)

func (*Dao) DropEventNotFinalizedData

func (d *Dao) DropEventNotFinalizedData(blockNum int, finalized bool) bool

func (*Dao) DropExtrinsicNotFinalizedData

func (d *Dao) DropExtrinsicNotFinalizedData(c context.Context, blockNum int, finalized bool) bool

func (*Dao) DropLogsNotFinalizedData

func (d *Dao) DropLogsNotFinalizedData(blockNum int, finalized bool) bool

func (*Dao) ExtrinsicsAsJson

func (d *Dao) ExtrinsicsAsJson(e *model.ChainExtrinsic) *model.ChainExtrinsicJson

func (*Dao) GetBestBlockNum

func (d *Dao) GetBestBlockNum(c context.Context) (uint64, error)

func (*Dao) GetBlockByHash

func (d *Dao) GetBlockByHash(c context.Context, hash string) *model.ChainBlock

func (*Dao) GetBlockByNum

func (d *Dao) GetBlockByNum(blockNum int) *model.ChainBlock

func (*Dao) GetBlockList

func (d *Dao) GetBlockList(page, row int) []model.ChainBlock

func (*Dao) GetBlockNumArr

func (d *Dao) GetBlockNumArr(start, end int) []int

func (*Dao) GetEventByBlockNum

func (d *Dao) GetEventByBlockNum(blockNum int, where ...string) []model.ChainEventJson

func (*Dao) GetEventByIdx

func (d *Dao) GetEventByIdx(index string) *model.ChainEvent

func (*Dao) GetEventList

func (d *Dao) GetEventList(page, row int, order string, where ...string) ([]model.ChainEvent, int)

func (*Dao) GetEventsByIndex

func (d *Dao) GetEventsByIndex(extrinsicIndex string) []model.ChainEvent

func (*Dao) GetExtrinsicList

func (d *Dao) GetExtrinsicList(c context.Context, page, row int, order string, queryWhere ...string) ([]model.ChainExtrinsic, int)

func (*Dao) GetExtrinsicsByBlockNum

func (d *Dao) GetExtrinsicsByBlockNum(blockNum int) []model.ChainExtrinsicJson

func (*Dao) GetExtrinsicsByHash

func (d *Dao) GetExtrinsicsByHash(c context.Context, hash string) *model.ChainExtrinsic

func (*Dao) GetExtrinsicsDetailByHash

func (d *Dao) GetExtrinsicsDetailByHash(c context.Context, hash string) *model.ExtrinsicDetail

func (*Dao) GetExtrinsicsDetailByIndex

func (d *Dao) GetExtrinsicsDetailByIndex(c context.Context, index string) *model.ExtrinsicDetail

func (*Dao) GetFillBestBlockNum

func (d *Dao) GetFillBestBlockNum(c context.Context) (int, error)

func (*Dao) GetFillFinalizedBlockNum

func (d *Dao) GetFillFinalizedBlockNum(c context.Context) (int, error)

func (*Dao) GetFinalizedBlockNum

func (d *Dao) GetFinalizedBlockNum(c context.Context) (uint64, error)

func (*Dao) GetLogByBlockNum

func (d *Dao) GetLogByBlockNum(blockNum int) []model.ChainLogJson

func (*Dao) GetLogsByIndex

func (d *Dao) GetLogsByIndex(index string) *model.ChainLogJson

func (*Dao) GetMetadata

func (d *Dao) GetMetadata(c context.Context) (map[string]string, error)

func (*Dao) GetNearBlock

func (d *Dao) GetNearBlock(blockNum int) *model.ChainBlock

func (*Dao) IncrMetadata

func (d *Dao) IncrMetadata(c context.Context, filed string, incrNum int) error

func (*Dao) InternalTables

func (d *Dao) InternalTables(blockNum int) (models []interface{})

func (*Dao) List

func (d *Dao) List(ctx context.Context) ([]*EventDetail, error)

func (*Dao) ListSapce

func (d *Dao) ListSapce() ([]models.Space, error)

func (*Dao) Migration

func (d *Dao) Migration(ctx context.Context)

func (*Dao) RuntimeVersionList

func (d *Dao) RuntimeVersionList() []model.RuntimeVersion

func (*Dao) RuntimeVersionRaw

func (d *Dao) RuntimeVersionRaw(spec int) *metadata.RuntimeRaw

func (*Dao) RuntimeVersionRecent

func (d *Dao) RuntimeVersionRecent() *model.RuntimeVersion

func (*Dao) SaveEventDetail

func (d *Dao) SaveEventDetail(ctx context.Context, eventDetail *EventDetail) error

func (*Dao) SaveFillAlreadyBlockNum

func (d *Dao) SaveFillAlreadyBlockNum(c context.Context, blockNum int) error

func (*Dao) SaveFillAlreadyFinalizedBlockNum

func (d *Dao) SaveFillAlreadyFinalizedBlockNum(ctx context.Context, blockNum int) error

func (*Dao) SaveSpace

func (d *Dao) SaveSpace(s *models.Space) error

func (*Dao) SetBlockFinalized

func (d *Dao) SetBlockFinalized(block *model.ChainBlock)

func (*Dao) SetMetadata

func (d *Dao) SetMetadata(c context.Context, metadata map[string]interface{}) error

func (*Dao) SetRuntimeData

func (d *Dao) SetRuntimeData(specVersion int, modules string, rawData string) int64

func (*Dao) UpdateEventAndExtrinsic

func (d *Dao) UpdateEventAndExtrinsic(txn *GormDB, block *model.ChainBlock, eventCount, extrinsicsCount, blockTimestamp int, validator string, codecError bool, finalized bool) error

type DbStorage

type DbStorage struct {
	Prefix string
	// contains filtered or unexported fields
}

func (*DbStorage) AddIndex

func (d *DbStorage) AddIndex(model interface{}, indexName string, columns ...string) error

func (*DbStorage) AddUniqueIndex

func (d *DbStorage) AddUniqueIndex(model interface{}, indexName string, columns ...string) error

func (*DbStorage) AutoMigration

func (d *DbStorage) AutoMigration(model interface{}) error

func (*DbStorage) Create

func (d *DbStorage) Create(record interface{}) error

func (*DbStorage) Delete

func (d *DbStorage) Delete(model interface{}, query interface{}) error

func (*DbStorage) FindBy

func (d *DbStorage) FindBy(record interface{}, query interface{}, option *storage.Option) (int, bool)

func (*DbStorage) GetPrefix

func (d *DbStorage) GetPrefix() string

func (*DbStorage) RPCPool

func (d *DbStorage) RPCPool() *websocket.PoolConn

func (*DbStorage) SetPrefix

func (d *DbStorage) SetPrefix(prefix string)

func (*DbStorage) SpecialMetadata

func (d *DbStorage) SpecialMetadata(spec int) string

func (*DbStorage) Update

func (d *DbStorage) Update(model interface{}, query interface{}, attr map[string]interface{}) error

type EventDetail

type EventDetail struct {
	ID string `gorm:"column:id;type:varchar(256);primary_key"`
	// event id
	Name          string `gorm:"column:name;type:varchar(64);index"`
	BlockHeight   int    `gorm:"column:block_height;index"`
	PublicKey     string `gorm:"column:public_key;type:varchar(128);index"`
	ParentHash    string `gorm:"column:parent_hash;type:varchar(128)"`
	RewardAddress string `gorm:"column:reward_address;type:varchar(128);index"`
}

func (EventDetail) TableName

func (c EventDetail) TableName() string

type GormDB

type GormDB struct {
	*gorm.DB
	// contains filtered or unexported fields
}

db

type IDao

type IDao interface {
	Close()
	// Ping(ctx context.Context) (err error)
	// SetHeartBeatNow(context.Context, string) error
	// DaemonHeath(context.Context) map[string]bool
	DbBegin() *GormDB
	DbCommit(*GormDB)
	DbRollback(*GormDB)
	CreateBlock(*GormDB, *model.ChainBlock) (err error)
	UpdateEventAndExtrinsic(*GormDB, *model.ChainBlock, int, int, int, string, bool, bool) error
	GetNearBlock(int) *model.ChainBlock
	SetBlockFinalized(*model.ChainBlock)
	BlocksReverseByNum([]int) map[int]model.ChainBlock
	GetBlockByHash(context.Context, string) *model.ChainBlock
	GetBlockByNum(int) *model.ChainBlock
	SaveFillAlreadyBlockNum(context.Context, int) error
	SaveFillAlreadyFinalizedBlockNum(c context.Context, blockNum int) (err error)
	GetFillBestBlockNum(c context.Context) (num int, err error)
	GetBlockNumArr(start, end int) []int
	GetFillFinalizedBlockNum(c context.Context) (num int, err error)
	GetBlockList(page, row int) []model.ChainBlock
	BlockAsJson(c context.Context, block *model.ChainBlock) *model.ChainBlockJson
	CreateEvent(txn *GormDB, event *model.ChainEvent) error
	GetEventByBlockNum(blockNum int, where ...string) []model.ChainEventJson
	GetEventList(page, row int, order string, where ...string) ([]model.ChainEvent, int)
	GetEventsByIndex(extrinsicIndex string) []model.ChainEvent
	GetEventByIdx(index string) *model.ChainEvent
	CreateExtrinsic(c context.Context, txn *GormDB, extrinsic *model.ChainExtrinsic) error
	GetExtrinsicsByBlockNum(blockNum int) []model.ChainExtrinsicJson
	GetExtrinsicList(c context.Context, page, row int, order string, queryWhere ...string) ([]model.ChainExtrinsic, int)
	GetExtrinsicsByHash(c context.Context, hash string) *model.ChainExtrinsic
	GetExtrinsicsDetailByHash(c context.Context, hash string) *model.ExtrinsicDetail
	GetExtrinsicsDetailByIndex(c context.Context, index string) *model.ExtrinsicDetail
	ExtrinsicsAsJson(e *model.ChainExtrinsic) *model.ChainExtrinsicJson
	CreateLog(txn *GormDB, ce *model.ChainLog) error
	GetLogsByIndex(index string) *model.ChainLogJson
	GetLogByBlockNum(blockNum int) []model.ChainLogJson
	CreateEventDetail(txn *GormDB, eventDetail *EventDetail) error
	SetMetadata(c context.Context, metadata map[string]interface{}) (err error)
	IncrMetadata(c context.Context, filed string, incrNum int) (err error)
	GetMetadata(c context.Context) (ms map[string]string, err error)
	GetBestBlockNum(c context.Context) (uint64, error)
	GetFinalizedBlockNum(c context.Context) (uint64, error)
	CreateRuntimeVersion(name string, specVersion int) int64
	SetRuntimeData(specVersion int, modules string, rawData string) int64
	RuntimeVersionList() []model.RuntimeVersion
	RuntimeVersionRaw(spec int) *metadata.RuntimeRaw
	RuntimeVersionRecent() *model.RuntimeVersion

	SaveSpace(s *models.Space) error
	ListSapce() ([]models.Space, error)
}

Jump to

Keyboard shortcuts

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