database

package
v0.0.0-...-6d3733d Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: ISC Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func Connect

func Connect(connectionString string) (*Database, error)

Connect connects to the database mentioned in the config variable.

func New

func New(pgDatabase *pg.DB) *Database

func (*Database) BlockCountAtDAAScore

func (db *Database) BlockCountAtDAAScore(databaseTransaction *pg.Tx, blockDAAScore uint64) (uint32, error)

BlockCountAtDAAScore returns the number of blocks having a DAA Score of `blockDAAScore`

func (*Database) BlockHeight

func (db *Database) BlockHeight(databaseTransaction *pg.Tx, blockID uint64) (uint64, error)

func (*Database) BlockHeightByHash

func (db *Database) BlockHeightByHash(databaseTransaction *pg.Tx, blockHash *externalapi.DomainHash) (uint64, error)

blockBaseByHash returns the height of a block idendified by `blockHash`. Returns an error if `blockHash` does not exist in the database

func (*Database) BlockHeightGroupIndex

func (db *Database) BlockHeightGroupIndex(databaseTransaction *pg.Tx, blockID uint64) (uint32, error)

func (*Database) BlockIDByDAAScore

func (db *Database) BlockIDByDAAScore(databaseTransaction *pg.Tx, blockDAAScore uint64) (uint64, error)

BlockIDByDAAScore returns the block ID of one block having the closest DAA score to `blockDAAScore`

func (*Database) BlockIDByHash

func (db *Database) BlockIDByHash(databaseTransaction *pg.Tx, blockHash *externalapi.DomainHash) (uint64, error)

blockBaseByHash returns the id of a block idendified by `blockHash`. Returns an error if `blockHash` does not exist in the database

func (*Database) BlockIDsAndHeightsByHashes

func (db *Database) BlockIDsAndHeightsByHashes(databaseTransaction *pg.Tx, blockHashes []*externalapi.DomainHash) ([]uint64, []uint64, error)

BlockIDsAndHeightsByHashes returns two arrays, one of ids and one of heights for `blockHashes` hashes

func (*Database) BlockIDsByHashes

func (db *Database) BlockIDsByHashes(databaseTransaction *pg.Tx, blockHashes []*externalapi.DomainHash) ([]uint64, error)

BlockIDsByHashes returns an arrays of ids for `blockHashes` hashes. Returns an error if any hash in `blockHash` does not exist in the database

func (*Database) Clear

func (db *Database) Clear(databaseTransaction *pg.Tx) error

func (*Database) Close

func (db *Database) Close()

func (*Database) DoesBlockExist

func (db *Database) DoesBlockExist(databaseTransaction *pg.Tx, blockHash *externalapi.DomainHash) (bool, error)

func (*Database) FindLatestStoredBlockIndex

func (db *Database) FindLatestStoredBlockIndex(databaseTransaction *pg.Tx, blockHashes []*externalapi.DomainHash) (int, error)

FindLatestStoredBlockIndex returns the index in a DAG ordered block hash array `blockHashes` of the latest block hash that is stored in the database

func (*Database) GetAppConfig

func (db *Database) GetAppConfig(databaseTransaction *pg.Tx) (*model.AppConfig, error)

GetAppConfig returns the stored app config. Returns an error if no app config does exist in the database.

func (*Database) GetBlock

func (db *Database) GetBlock(databaseTransaction *pg.Tx, id uint64) (*model.Block, error)

GetBlock returns a block identified by `id`. Returns an error if the block `id` does not exist

func (*Database) HashesToBlockIDs

func (db *Database) HashesToBlockIDs(databaseTransaction *pg.Tx, blockHashes []*externalapi.DomainHash) ([]uint64, []*externalapi.DomainHash)

HashesToBlockIDs returns an arrays of ids for `blockHashes` hashes and all the hashes having no matching ID.

func (*Database) HeightGroupSize

func (db *Database) HeightGroupSize(databaseTransaction *pg.Tx, height uint64) (uint32, error)

func (*Database) HighestBlockHeight

func (db *Database) HighestBlockHeight(databaseTransaction *pg.Tx, blockIDs []uint64) (uint64, error)

func (*Database) HighestBlockInVirtualSelectedParentChain

func (db *Database) HighestBlockInVirtualSelectedParentChain(databaseTransaction *pg.Tx) (*model.Block, error)

func (*Database) InsertBlock

func (db *Database) InsertBlock(databaseTransaction *pg.Tx, blockHash *externalapi.DomainHash, block *model.Block) error

func (*Database) InsertEdge

func (db *Database) InsertEdge(databaseTransaction *pg.Tx, edge *model.Edge) error

func (*Database) InsertOrUpdateHeightGroup

func (db *Database) InsertOrUpdateHeightGroup(databaseTransaction *pg.Tx, heightGroup *model.HeightGroup) error

func (*Database) LoadCache

func (db *Database) LoadCache(databaseTransaction *pg.Tx, minHeight uint64) error

Load block infos into the memory cache for all blocks having a height geater or equal to minHeight

func (*Database) RunInTransaction

func (db *Database) RunInTransaction(transactionFunction func(*pg.Tx) error) error

func (*Database) StoreAppConfig

func (db *Database) StoreAppConfig(databaseTransaction *pg.Tx, appConfig *model.AppConfig) error

StoreAppConfig stores an AppConfig in the database. ID is forced to true, this is the only accepted value by the database. Consequently, the database stores at most one AppConfig row.

func (*Database) UpdateBlockColors

func (db *Database) UpdateBlockColors(databaseTransaction *pg.Tx, blockIDsToColors map[uint64]string) error

func (*Database) UpdateBlockDAAScores

func (db *Database) UpdateBlockDAAScores(databaseTransaction *pg.Tx, blockIDsToDAAScores map[uint64]uint64) error

UpdateBlockDAAScores updates DAA Scores of block ids

func (*Database) UpdateBlockIsInVirtualSelectedParentChain

func (db *Database) UpdateBlockIsInVirtualSelectedParentChain(
	databaseTransaction *pg.Tx, blockIDsToIsInVirtualSelectedParentChain map[uint64]bool) error

func (*Database) UpdateBlockMergeSet

func (db *Database) UpdateBlockMergeSet(
	databaseTransaction *pg.Tx, blockID uint64, mergeSetRedIDs []uint64, mergeSetBlueIDs []uint64) error

func (*Database) UpdateBlockSelectedParent

func (db *Database) UpdateBlockSelectedParent(databaseTransaction *pg.Tx, blockID uint64, selectedParentID uint64) error

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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