dao

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SqlFix

func SqlFix(sql string, args ...string) string

SqlFix replaces the <binary> placeholder in a SQL string with the provided arguments.

Types

type DB

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

DB is a struct that embeds gorm.DB to provide additional database functionality.

func NewDB

func NewDB(opts ...DBOption) (*DB, error)

NewDB is a function that creates a new DB instance with the provided options.

func (*DB) AddUndoLog

func (d *DB) AddUndoLog(height uint32, sql string) error

AddUndoLog is a method that adds an undo log to the database. It takes two parameters: height of type uint32 and sql of type string. The height parameter represents the height of the undo log. The sql parameter represents the SQL statement of the undo log.

The method first calls the OldestSavepoint method to get the oldest savepoint. If an error occurs during this operation, it returns the error. If the ID of the oldest savepoint is 0, it returns nil.

The method then creates a new UndoLog struct with the provided height and SQL statement, and calls the Create method to add the undo log to the database. If an error occurs during this operation, it returns the error.

The method returns an error if any operation fails, or nil if the operations succeed.

func (*DB) BlockCount

func (d *DB) BlockCount() (count uint32, err error)

BlockCount retrieves the total number of blocks in the database. It returns the count as an uint32 and any error encountered.

func (*DB) BlockHash

func (d *DB) BlockHash(height ...uint32) (blockHash string, err error)

BlockHash retrieves the block hash for a given block height. If no height is provided, it retrieves the hash for the last block. It returns the block hash as a string and any error encountered.

func (*DB) BlockHeader

func (d *DB) BlockHeader() (height uint32, header *wire.BlockHeader, err error)

BlockHeader retrieves the block header for a given block height.

func (*DB) BlockHeight

func (d *DB) BlockHeight() (height uint32, err error)

BlockHeight retrieves the height of the last block in the database.

func (*DB) CreateInscription

func (d *DB) CreateInscription(ins *tables.Inscriptions) error

CreateInscription creates a new inscription in the database. It returns any error encountered.

func (*DB) DelSatRangesByOutpoint

func (d *DB) DelSatRangesByOutpoint(height uint32, outpoint string) (satRange tables.OutpointSatRange, err error)

DelSatRangesByOutpoint deletes the satoshi ranges for a given outpoint.

func (*DB) DeleteBlockInfoByHeight

func (d *DB) DeleteBlockInfoByHeight(height uint32) (info tables.BlockInfo, err error)

DeleteBlockInfoByHeight deletes a block info from the database by height.

func (*DB) DeleteBySatPoint

func (d *DB) DeleteBySatPoint(height uint32, satpoint *tables.SatPointToSequenceNum) error

DeleteBySatPoint deletes records by a given SatPoint. It takes a SatPoint as a parameter. It returns any error encountered during the operation.

func (*DB) DeleteInscriptionById

func (d *DB) DeleteInscriptionById(height uint32, inscriptionId *tables.InscriptionId) (sequenceNum int64, err error)

DeleteInscriptionById deletes an inscription by its outpoint. It returns the sequence number of the deleted inscription and any error encountered.

func (*DB) DeleteMockInscriptions

func (d *DB) DeleteMockInscriptions() error

func (*DB) DeleteMockProtocol

func (d *DB) DeleteMockProtocol() error

func (*DB) DeleteSavepoint

func (d *DB) DeleteSavepoint(id uint64) error

DeleteSavepoint is a method that deletes all savepoints from the database. It returns an error. The method creates a new SavePoint struct and uses its TableName method to get the name of the table. It then uses the Exec method of the DB struct to execute a SQL delete statement on the table. If an error occurs during the deletion, it returns the error.

func (*DB) DeleteUndoLog

func (d *DB) DeleteUndoLog() error

DeleteUndoLog is a method that deletes all undo logs from the database. It returns an error. The method creates a new UndoLog struct and uses its TableName method to get the name of the table. It then uses the Exec method of the DB struct to execute a SQL delete statement on the table. If an error occurs during the deletion, it returns the error.

func (*DB) DeleteValueByOutpoint

func (d *DB) DeleteValueByOutpoint(height uint32, outpoints ...string) (err error)

DeleteValueByOutpoint deletes the values associated with a list of outpoints. It returns any error encountered during the operation.

func (*DB) EmbedDB

func (d *DB) EmbedDB() bool

func (*DB) FindHoldersByTkId

func (d *DB) FindHoldersByTkId(tkid, protocol, operator string, page, pageSize int) (list []*FindHoldersByTkIdResp, err error)

FindHoldersByTkId finds the holders for a specific TkId and protocol. It returns a list of holders and any error encountered.

func (*DB) FindInscriptionsByPage

func (d *DB) FindInscriptionsByPage(page, size int) (list []*tables.InscriptionId, err error)

FindInscriptionsByPage retrieves a page of inscription IDs. It returns a list of inscription IDs and any error encountered.

func (*DB) FindInscriptionsInBlock

func (d *DB) FindInscriptionsInBlock(height uint32) (list []*model.OutPoint, err error)

func (*DB) FindInscriptionsInBlockPage

func (d *DB) FindInscriptionsInBlockPage(height, page, size int) (list []*model.OutPoint, err error)

FindInscriptionsInBlockPage retrieves a page of inscription IDs in a block. It returns a list of inscription IDs and any error encountered.

func (*DB) FindMintHistoryByTkId

func (d *DB) FindMintHistoryByTkId(tkid, protocol, operator string, page, pageSize int) (list []*FindMintHistoryByTkIdResp, err error)

FindMintHistoryByTkId finds the mint history for a specific TkId and protocol. It returns a list of mint histories and any error encountered.

func (*DB) FindProtocol

func (d *DB) FindProtocol(protocol, ticker, operator string, tkid ...string) (list []*tables.Protocol, err error)

FindProtocol finds protocols based on the provided parameters. It returns a list of matching protocols and any error encountered.

func (*DB) FindTokenPageByTicker

func (d *DB) FindTokenPageByTicker(protocol, ticker, operator string, page, pageSize int) (list []*tables.Protocol, err error)

FindTokenPageByTicker retrieves a page of tokens by ticker for a specific protocol. It returns a list of tokens and any error encountered.

func (*DB) FindUndoLog

func (d *DB) FindUndoLog() (*sql.Rows, error)

FindUndoLog is a method that retrieves all undo logs from the database in descending order of their IDs. It returns a slice of pointers to UndoLog structs and an error. The method uses the Order method of the DB struct to order the undo logs by their IDs in descending order. It then uses the Find method of the DB struct to retrieve the undo logs and assigns them to undoLogs. If an error occurs during the retrieval, it returns the undoLogs and the error.

func (*DB) FirstInscriptionByOwner

func (d *DB) FirstInscriptionByOwner(owner string) (firts tables.Inscriptions, err error)

func (*DB) GetInscriptionById

func (d *DB) GetInscriptionById(inscriptionId *tables.InscriptionId) (ins tables.Inscriptions, err error)

GetInscriptionById retrieves an inscription by its outpoint. It returns the inscription and any error encountered.

func (*DB) GetInscriptionByInscriptionNum

func (d *DB) GetInscriptionByInscriptionNum(inscriptionNum int64) (ins tables.Inscriptions, err error)

GetInscriptionByInscriptionNum retrieves an inscription by its sequence number. It returns the inscription and any error encountered.

func (*DB) GetInscriptionByOutpoint

func (d *DB) GetInscriptionByOutpoint(outpoint *model.OutPoint) (list []*tables.InscriptionId, err error)

GetInscriptionByOutpoint retrieves an inscription by its outpoint.

func (*DB) GetInscriptionBySequenceNum

func (d *DB) GetInscriptionBySequenceNum(sequenceNum int64) (ins tables.Inscriptions, err error)

GetInscriptionBySequenceNum retrieves an inscription by its sequence number. It returns the inscription and any error encountered.

func (*DB) GetProtocolByInscriptionId

func (d *DB) GetProtocolByInscriptionId(inscriptionId *tables.InscriptionId) (p tables.Protocol, err error)

GetProtocolByInscriptionId retrieves a protocol by its outpoint. It returns the protocol and any error encountered.

func (*DB) GetSatPointBySat

func (d *DB) GetSatPointBySat(sat uint64) (res tables.SatSatPoint, err error)

GetSatPointBySat retrieves a SatSatPoint by a given SAT. It takes a SAT as a parameter. It returns a SatSatPoint and any error encountered.

func (*DB) GetStatisticCountByName

func (d *DB) GetStatisticCountByName(name tables.StatisticType) (count uint64, err error)

GetStatisticCountByName retrieves the count of a specific statistic by its name. It takes a name of type tables.StatisticType as a parameter. It returns the count of the statistic and any error encountered.

func (*DB) GetValueByOutpoint

func (d *DB) GetValueByOutpoint(outpoint string) (value int64, err error)

GetValueByOutpoint retrieves the value associated with a given outpoint. It returns the value as an int64 and any error encountered.

func (*DB) IncrementStatistic

func (d *DB) IncrementStatistic(height uint32, name tables.StatisticType, count uint64) error

IncrementStatistic increments the count of a specific statistic by a given amount. It takes a name of type tables.StatisticType and a count of type uint32 as parameters. If the statistic does not exist, it creates a new one with the given name and count. If the statistic exists, it increments its count by the given amount. It returns any error encountered during the operation.

func (*DB) InscriptionsByOutpoint

func (d *DB) InscriptionsByOutpoint(outpoint string) (res []*Inscription, err error)

InscriptionsByOutpoint retrieves inscriptions by a given outpoint. It takes an outpoint as a parameter. It returns a list of inscriptions and any error encountered.

func (*DB) InscriptionsNum

func (d *DB) InscriptionsNum() (total int64, err error)

func (*DB) InscriptionsStoredData

func (d *DB) InscriptionsStoredData() (total uint64, err error)

func (*DB) InscriptionsTotalFees

func (d *DB) InscriptionsTotalFees() (total uint64, err error)

func (*DB) ListSavepoint

func (d *DB) ListSavepoint() (list []*tables.SavePoint, err error)

ListSavepoint is a method that retrieves a list of all savepoints from the database. It returns a slice of pointers to SavePoint structs and an error. The method uses the Find method of the DB struct to retrieve the savepoints and assigns them to the list. If an error occurs during the retrieval, it checks if the error is a ErrRecordNotFound error from the gorm package. If it is, it assigns nil to the error, effectively ignoring the error. The method then returns the list of savepoints and the error.

func (*DB) NextSequenceNumber

func (d *DB) NextSequenceNumber() (num int64, err error)

NextSequenceNumber retrieves the next sequence number for inscriptions. It returns the next sequence number as an uint64 and any error encountered.

func (*DB) OldestSavepoint

func (d *DB) OldestSavepoint() (savepoint *tables.SavePoint, err error)

OldestSavepoint is a method that retrieves the oldest savepoint from the database. It returns a pointer to a SavePoint struct and an error. The method uses the First method of the DB struct to retrieve the oldest savepoint and assigns it to savepoint. If an error occurs during the retrieval, it returns the savepoint and the error.

func (*DB) OutpointToSatRanges

func (d *DB) OutpointToSatRanges(outpoint string) (satRange tables.OutpointSatRange, err error)

OutpointToSatRanges returns the satoshi ranges for a given outpoint.

func (*DB) SatToSatPoint

func (d *DB) SatToSatPoint(height uint32, satSatPoint *tables.SatSatPoint) error

SatToSatPoint saves a SAT (Satisfiability) to a sequence number in the database.

func (*DB) SaveBlockInfo

func (d *DB) SaveBlockInfo(block *tables.BlockInfo) error

SaveBlockInfo saves a block info to the database. If a block with the same height already exists, it updates the existing record. It returns any error encountered.

func (*DB) SaveProtocol

func (d *DB) SaveProtocol(height uint32, protocol *tables.Protocol) error

SaveProtocol saves a protocol to the database. It returns any error encountered during the operation.

func (*DB) SaveSatToSequenceNumber

func (d *DB) SaveSatToSequenceNumber(height uint32, sat uint64, sequenceNum int64) error

SaveSatToSequenceNumber saves a SAT (Satisfiability) to a sequence number in the database. It takes a SAT and a sequence number as parameters, both of type uint64. It returns any error encountered during the operation.

func (*DB) SearchInscriptions

func (d *DB) SearchInscriptions(params *FindProtocolsParams) (list []*tables.Inscriptions, total int64, err error)

func (*DB) SetOutpointToSatRange

func (d *DB) SetOutpointToSatRange(height uint32, satRanges ...*tables.OutpointSatRange) (err error)

SetOutpointToSatRange sets the satoshi range for a set of outpoints. It takes a map where the keys are outpoints and the values are the corresponding satoshi ranges. It returns any error encountered during the operation.

func (*DB) SetOutpointToValue

func (d *DB) SetOutpointToValue(height uint32, values map[string]int64) (err error)

SetOutpointToValue sets the values for a set of outpoints. It takes a map where the keys are outpoints and the values are the corresponding values. It returns any error encountered during the operation.

func (*DB) SetSatPointToSequenceNum

func (d *DB) SetSatPointToSequenceNum(height uint32, satPoint *tables.SatPointToSequenceNum) error

SetSatPointToSequenceNum sets a SatPoint to a sequence number in the database. It takes a SatPoint and a sequence number as parameters. It returns any error encountered during the operation.

func (*DB) SetStatistic

func (d *DB) SetStatistic(height uint32, name tables.StatisticType, count uint64) error

SetStatistic sets the count of a specific statistic to a given amount.

func (*DB) SumAddressNum

func (d *DB) SumAddressNum(protocol, ticker, operator string, tkid ...string) (total uint64, err error)

SumAddressNum counts the number of distinct addresses for a specific protocol. It returns the total count and any error encountered.

func (*DB) SumMintAmountByAddress

func (d *DB) SumMintAmountByAddress(address, protocol string, page, pageSize int) (list []*tables.ProtocolAmount, err error)

SumMintAmountByAddress sums the amount for a specific address and protocol. It returns a list of protocol amounts and any error encountered.

func (*DB) SumProtocolAmount

func (d *DB) SumProtocolAmount(protocol, ticker, operator string, tkid ...string) (total uint64, err error)

SumProtocolAmount counts the total amount for a specific protocol. It returns the total amount and any error encountered.

func (*DB) Transaction

func (d *DB) Transaction(fn func(tx *DB) error) error

Transaction is a method on DB that executes a function within a database transaction.

type DBOption

type DBOption func(*DBOptions)

DBOption is a function type that modifies DBOptions.

func WithAddr

func WithAddr(addr string) DBOption

WithAddr returns a DBOption that sets the address of the database.

func WithAutoMigrateTables

func WithAutoMigrateTables(tables ...interface{}) DBOption

WithAutoMigrateTables returns a DBOption that sets the tables to be auto migrated in the database.

func WithDBName

func WithDBName(dbName string) DBOption

WithDBName returns a DBOption that sets the name of the database.

func WithDataDir

func WithDataDir(dir string) DBOption

WithDataDir returns a DBOption that sets the data directory of the database.

func WithEmbedDB

func WithEmbedDB(embed bool) DBOption

WithEmbedDB returns a DBOption that sets whether to use an embedded database or not.

func WithPassword

func WithPassword(password string) DBOption

WithPassword returns a DBOption that sets the password of the database.

func WithServerPort

func WithServerPort(port string) DBOption

WithServerPort returns a DBOption that sets the server port of the database.

func WithStatusPort

func WithStatusPort(port string) DBOption

WithStatusPort returns a DBOption that sets the status port of the database.

func WithUser

func WithUser(user string) DBOption

WithUser returns a DBOption that sets the user of the database.

type DBOptions

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

DBOptions is a struct that holds the configuration options for the database.

type FindHoldersByTkIdResp

type FindHoldersByTkIdResp struct {
	Amount  uint64 `gorm:"column:amount" json:"amount"`   // The amount held by the holder
	Address string `gorm:"column:address" json:"address"` // The address of the holder
}

FindHoldersByTkIdResp is a struct that represents the response for finding holders by TkId.

type FindMintHistoryByTkIdResp

type FindMintHistoryByTkIdResp struct {
	tables.InscriptionId `gorm:"embedded" json:"inscription_id"`
	Amount               uint64 `gorm:"column:amount" json:"amount"` // The amount of the mint
	To                   string `gorm:"column:to" json:"to_address"` // The address to which the mint was made
	Miner                string `gorm:"column:miner" json:"miner"`   // The miner of the mint
}

FindMintHistoryByTkIdResp is a struct that represents the response for finding mint history by TkId.

type FindProtocolsParams

type FindProtocolsParams struct {
	Page            int
	Limit           int
	Owner           string
	Ticker          string
	Order           string
	MediaTypes      []string
	ContentTypes    []string
	Charms          []string
	InscriptionType string
}

type GormLogger

type GormLogger struct {
	btclog.Logger
}

GormLogger is a struct that embeds btclog.Logger to provide additional logging functionality.

func (*GormLogger) Error

func (g *GormLogger) Error(ctx context.Context, msg string, data ...interface{})

Error is a method on GormLogger that logs an error message.

func (*GormLogger) Info

func (g *GormLogger) Info(ctx context.Context, msg string, data ...interface{})

Info is a method on GormLogger that logs an informational message.

func (*GormLogger) LogMode

func (g *GormLogger) LogMode(level logger.LogLevel) logger.Interface

LogMode is a method on GormLogger that sets the log level.

func (*GormLogger) Print

func (g *GormLogger) Print(data ...interface{})

func (*GormLogger) Trace

func (g *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace is a method on GormLogger that logs a trace message.

func (*GormLogger) Warn

func (g *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

Warn is a method on GormLogger that logs a warning message.

type Inscription

type Inscription struct {
	*tables.Inscriptions
	*tables.SatPointToSequenceNum
}

Inscription is a struct that embeds tables.Inscriptions and util.SatPoint.

Jump to

Keyboard shortcuts

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