sqlite

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFromCmdlineOptions added in v0.18.0

func NewFromCmdlineOptions() plugin.Plugin

Types

type CommitTimestamp added in v0.4.0

type CommitTimestamp struct {
	ID        uint `gorm:"primarykey"`
	Timestamp int64
}

CommitTimestamp represents the sqlite table used to track the current commit timestamp

func (CommitTimestamp) TableName added in v0.4.0

func (CommitTimestamp) TableName() string

type MetadataStoreSqlite added in v0.4.0

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

MetadataStoreSqlite stores all data in sqlite. Data may not be persisted

func New

func New(
	dataDir string,
	logger *slog.Logger,
	promRegistry prometheus.Registerer,
) (*MetadataStoreSqlite, error)

New creates a new database

func NewWithOptions added in v0.18.0

func NewWithOptions(opts ...SqliteOptionFunc) (*MetadataStoreSqlite, error)

NewWithOptions creates a new database with options

func (*MetadataStoreSqlite) AddUtxos added in v0.8.0

func (d *MetadataStoreSqlite) AddUtxos(
	utxos []models.UtxoSlot,
	txn *gorm.DB,
) error

AddUtxos saves a batch of UTxOs

func (*MetadataStoreSqlite) AutoMigrate added in v0.4.0

func (d *MetadataStoreSqlite) AutoMigrate(dst ...any) error

AutoMigrate wraps the gorm AutoMigrate

func (*MetadataStoreSqlite) Close added in v0.4.0

func (d *MetadataStoreSqlite) Close() error

Close gets the database handle from our MetadataStore and closes it

func (*MetadataStoreSqlite) Create added in v0.4.0

func (d *MetadataStoreSqlite) Create(value any) *gorm.DB

Create creates a record

func (*MetadataStoreSqlite) DB added in v0.4.0

func (d *MetadataStoreSqlite) DB() *gorm.DB

DB returns the database handle

func (*MetadataStoreSqlite) DeleteBlockNoncesBeforeSlot added in v0.11.0

func (d *MetadataStoreSqlite) DeleteBlockNoncesBeforeSlot(
	slotNumber uint64,
	txn *gorm.DB,
) error

DeleteBlockNoncesBeforeSlot deletes block_nonce records with slot less than the specified value

func (*MetadataStoreSqlite) DeleteBlockNoncesBeforeSlotWithoutCheckpoints added in v0.11.0

func (d *MetadataStoreSqlite) DeleteBlockNoncesBeforeSlotWithoutCheckpoints(
	slotNumber uint64,
	txn *gorm.DB,
) error

DeleteBlockNoncesBeforeSlotWithoutCheckpoints deletes block_nonce records with slot < given value AND is_checkpoint = false

func (*MetadataStoreSqlite) DeleteUtxo added in v0.4.2

func (d *MetadataStoreSqlite) DeleteUtxo(
	utxo any,
	txn *gorm.DB,
) error

func (*MetadataStoreSqlite) DeleteUtxos added in v0.4.2

func (d *MetadataStoreSqlite) DeleteUtxos(
	utxos []any,
	txn *gorm.DB,
) error

func (*MetadataStoreSqlite) DeleteUtxosAfterSlot added in v0.4.4

func (d *MetadataStoreSqlite) DeleteUtxosAfterSlot(
	slot uint64,
	txn *gorm.DB,
) error

func (*MetadataStoreSqlite) First added in v0.4.0

func (d *MetadataStoreSqlite) First(args any) *gorm.DB

First returns the first DB entry

func (*MetadataStoreSqlite) GetAccount added in v0.6.0

func (d *MetadataStoreSqlite) GetAccount(
	stakeKey []byte,
	includeInactive bool,
	txn *gorm.DB,
) (*models.Account, error)

GetAccount gets an account

func (*MetadataStoreSqlite) GetAssetByPolicyAndName added in v0.18.0

func (d *MetadataStoreSqlite) GetAssetByPolicyAndName(
	policyId lcommon.Blake2b224,
	assetName []byte,
	txn *gorm.DB,
) (models.Asset, error)

GetAssetByPolicyAndName returns an asset by policy ID and asset name

func (*MetadataStoreSqlite) GetAssetsByPolicy added in v0.18.0

func (d *MetadataStoreSqlite) GetAssetsByPolicy(
	policyId lcommon.Blake2b224,
	txn *gorm.DB,
) ([]models.Asset, error)

GetAssetsByPolicy returns all assets for a given policy ID

func (*MetadataStoreSqlite) GetAssetsByUTxO added in v0.18.0

func (d *MetadataStoreSqlite) GetAssetsByUTxO(
	txId []byte,
	idx uint32,
	txn *gorm.DB,
) ([]models.Asset, error)

GetAssetsByUTxO returns all assets for a given UTxO using transaction ID and output index

func (*MetadataStoreSqlite) GetBlockNonce added in v0.11.0

func (d *MetadataStoreSqlite) GetBlockNonce(
	point ocommon.Point,
	txn *gorm.DB,
) ([]byte, error)

GetBlockNonce retrieves the block nonce for a specific block

func (*MetadataStoreSqlite) GetCommitTimestamp added in v0.4.0

func (d *MetadataStoreSqlite) GetCommitTimestamp() (int64, error)

func (*MetadataStoreSqlite) GetDatum added in v0.9.0

func (d *MetadataStoreSqlite) GetDatum(
	hash lcommon.Blake2b256,
	txn *gorm.DB,
) (*models.Datum, error)

GetDatum returns a datum by its hash

func (*MetadataStoreSqlite) GetDrep added in v0.7.0

func (d *MetadataStoreSqlite) GetDrep(
	cred []byte,
	includeInactive bool,
	txn *gorm.DB,
) (*models.Drep, error)

GetDrep gets a drep

func (*MetadataStoreSqlite) GetEpochs added in v0.6.0

func (d *MetadataStoreSqlite) GetEpochs(
	txn *gorm.DB,
) ([]models.Epoch, error)

GetEpochs returns the list of epochs

func (*MetadataStoreSqlite) GetEpochsByEra added in v0.4.3

func (d *MetadataStoreSqlite) GetEpochsByEra(
	eraId uint,
	txn *gorm.DB,
) ([]models.Epoch, error)

GetEpochsByEra returns the list of epochs by era

func (*MetadataStoreSqlite) GetPParamUpdates added in v0.4.2

func (d *MetadataStoreSqlite) GetPParamUpdates(
	epoch uint64,
	txn *gorm.DB,
) ([]models.PParamUpdate, error)

GetPParamUpdates returns a list of protocol parameter updates for a given epoch

func (*MetadataStoreSqlite) GetPParams added in v0.4.2

func (d *MetadataStoreSqlite) GetPParams(
	epoch uint64,
	txn *gorm.DB,
) ([]models.PParams, error)

GetPParams returns a list of protocol parameters for a given epoch. If there are no pparams for the specified epoch, it will return the most recent pparams before the specified epoch

func (*MetadataStoreSqlite) GetPool added in v0.6.0

func (d *MetadataStoreSqlite) GetPool(
	pkh lcommon.PoolKeyHash,
	includeInactive bool,
	txn *gorm.DB,
) (*models.Pool, error)

GetPool gets a pool

func (*MetadataStoreSqlite) GetPoolRegistrations added in v0.4.2

func (d *MetadataStoreSqlite) GetPoolRegistrations(
	pkh lcommon.PoolKeyHash,
	txn *gorm.DB,
) ([]lcommon.PoolRegistrationCertificate, error)

GetPoolRegistrations returns pool registration certificates

func (*MetadataStoreSqlite) GetScript added in v0.18.0

func (d *MetadataStoreSqlite) GetScript(
	hash lcommon.ScriptHash,
	txn *gorm.DB,
) (*models.Script, error)

GetScript returns the script content by its hash

func (*MetadataStoreSqlite) GetStakeRegistrations added in v0.4.2

func (d *MetadataStoreSqlite) GetStakeRegistrations(
	stakingKey []byte,
	txn *gorm.DB,
) ([]lcommon.StakeRegistrationCertificate, error)

GetStakeRegistrations returns stake registration certificates

func (*MetadataStoreSqlite) GetTip added in v0.4.2

func (d *MetadataStoreSqlite) GetTip(
	txn *gorm.DB,
) (ocommon.Tip, error)

GetTip returns the current metadata Tip as ocommon.Tip

func (*MetadataStoreSqlite) GetTransactionByHash added in v0.18.0

func (d *MetadataStoreSqlite) GetTransactionByHash(
	hash []byte,
	txn *gorm.DB,
) (*models.Transaction, error)

GetTransactionByHash returns a transaction by its hash

func (*MetadataStoreSqlite) GetUtxo added in v0.4.2

func (d *MetadataStoreSqlite) GetUtxo(
	txId []byte,
	idx uint32,
	txn *gorm.DB,
) (*models.Utxo, error)

GetUtxo returns a Utxo by reference

func (*MetadataStoreSqlite) GetUtxosAddedAfterSlot added in v0.4.3

func (d *MetadataStoreSqlite) GetUtxosAddedAfterSlot(
	slot uint64,
	txn *gorm.DB,
) ([]models.Utxo, error)

GetUtxosAddedAfterSlot returns a list of Utxos added after a given slot

func (*MetadataStoreSqlite) GetUtxosByAddress added in v0.4.2

func (d *MetadataStoreSqlite) GetUtxosByAddress(
	addr ledger.Address,
	txn *gorm.DB,
) ([]models.Utxo, error)

GetUtxosByAddress returns a list of Utxos

func (*MetadataStoreSqlite) GetUtxosDeletedBeforeSlot added in v0.4.3

func (d *MetadataStoreSqlite) GetUtxosDeletedBeforeSlot(
	slot uint64,
	limit int,
	txn *gorm.DB,
) ([]models.Utxo, error)

GetUtxosDeletedBeforeSlot returns a list of Utxos marked as deleted before a given slot

func (*MetadataStoreSqlite) Order added in v0.4.0

func (d *MetadataStoreSqlite) Order(args any) *gorm.DB

Order orders a DB query

func (*MetadataStoreSqlite) SetAccount added in v0.6.0

func (d *MetadataStoreSqlite) SetAccount(
	stakeKey, pkh, drep []byte,
	slot uint64,
	active bool,
	txn *gorm.DB,
) error

SetAccount saves an account

func (*MetadataStoreSqlite) SetBlockNonce added in v0.11.0

func (d *MetadataStoreSqlite) SetBlockNonce(
	blockHash []byte,
	slotNumber uint64,
	nonce []byte,
	isCheckpoint bool,
	txn *gorm.DB,
) error

SetBlockNonce inserts a block nonce into the block_nonce table

func (*MetadataStoreSqlite) SetCommitTimestamp added in v0.4.0

func (d *MetadataStoreSqlite) SetCommitTimestamp(
	txn *gorm.DB,
	timestamp int64,
) error

func (*MetadataStoreSqlite) SetDatum added in v0.9.0

func (d *MetadataStoreSqlite) SetDatum(
	hash lcommon.Blake2b256,
	rawDatum []byte,
	addedSlot uint64,
	txn *gorm.DB,
) error

SetDatum saves a datum into the database, or updates it if it already exists

func (*MetadataStoreSqlite) SetDrep added in v0.7.0

func (d *MetadataStoreSqlite) SetDrep(
	cred []byte,
	slot uint64,
	url string,
	hash []byte,
	active bool,
	txn *gorm.DB,
) error

SetDrep saves a drep

func (*MetadataStoreSqlite) SetEpoch added in v0.4.2

func (d *MetadataStoreSqlite) SetEpoch(
	slot, epoch uint64,
	nonce []byte,
	era, slotLength, lengthInSlots uint,
	txn *gorm.DB,
) error

SetEpoch saves an epoch

func (*MetadataStoreSqlite) SetPParamUpdate added in v0.4.2

func (d *MetadataStoreSqlite) SetPParamUpdate(
	genesis, update []byte,
	slot, epoch uint64,
	txn *gorm.DB,
) error

SetPParamUpdate saves a protocol parameter update

func (*MetadataStoreSqlite) SetPParams added in v0.4.2

func (d *MetadataStoreSqlite) SetPParams(
	params []byte,
	slot, epoch uint64,
	eraId uint,
	txn *gorm.DB,
) error

SetPParams saves protocol parameters

func (*MetadataStoreSqlite) SetTip added in v0.4.2

func (d *MetadataStoreSqlite) SetTip(
	tip ochainsync.Tip,
	txn *gorm.DB,
) error

SetTip saves a tip

func (*MetadataStoreSqlite) SetTransaction added in v0.18.0

func (d *MetadataStoreSqlite) SetTransaction(
	tx lcommon.Transaction,
	point ocommon.Point,
	idx uint32,
	certDeposits map[int]uint64,
	txn *gorm.DB,
) error

SetTransaction adds a new transaction to the database and processes all certificates

func (*MetadataStoreSqlite) SetUtxoDeletedAtSlot added in v0.4.4

func (d *MetadataStoreSqlite) SetUtxoDeletedAtSlot(
	utxoId ledger.TransactionInput,
	slot uint64,
	txn *gorm.DB,
) error

SetUtxoDeletedAtSlot marks a UTxO as deleted at a given slot

func (*MetadataStoreSqlite) SetUtxosNotDeletedAfterSlot added in v0.4.3

func (d *MetadataStoreSqlite) SetUtxosNotDeletedAfterSlot(
	slot uint64,
	txn *gorm.DB,
) error

SetUtxosNotDeletedAfterSlot marks a list of Utxos as not deleted after a given slot

func (*MetadataStoreSqlite) Start added in v0.18.0

func (d *MetadataStoreSqlite) Start() error

Start implements the plugin.Plugin interface

func (*MetadataStoreSqlite) Stop added in v0.18.0

func (d *MetadataStoreSqlite) Stop() error

Stop implements the plugin.Plugin interface

func (*MetadataStoreSqlite) Transaction added in v0.4.0

func (d *MetadataStoreSqlite) Transaction() *gorm.DB

Transaction creates a gorm transaction

func (*MetadataStoreSqlite) Where added in v0.4.0

func (d *MetadataStoreSqlite) Where(
	query any,
	args ...any,
) *gorm.DB

Where constrains a DB query

type SqliteOptionFunc added in v0.18.0

type SqliteOptionFunc func(*MetadataStoreSqlite)

func WithDataDir added in v0.18.0

func WithDataDir(dataDir string) SqliteOptionFunc

WithDataDir specifies the data directory to use for storage

func WithLogger added in v0.18.0

func WithLogger(logger *slog.Logger) SqliteOptionFunc

WithLogger specifies the logger object to use for logging messages

func WithPromRegistry added in v0.18.0

func WithPromRegistry(
	registry prometheus.Registerer,
) SqliteOptionFunc

WithPromRegistry specifies the prometheus registry to use for metrics

Jump to

Keyboard shortcuts

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