database

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockNotFound = errors.New("block not found")

Functions

func BlockBlobHeightKey added in v0.4.2

func BlockBlobHeightKey(blockNumber uint64) []byte

func BlockBlobKey added in v0.4.2

func BlockBlobKey(slot uint64, hash []byte) []byte

func BlockBlobKeyHashHex added in v0.4.2

func BlockBlobKeyHashHex(slot uint64, hashHex string) ([]byte, error)

func BlockBlobMetadataKey added in v0.4.2

func BlockBlobMetadataKey(baseKey []byte) []byte

func BlockCreateTxn added in v0.4.2

func BlockCreateTxn(txn *Txn, block Block) error

func BlockDeleteTxn added in v0.4.2

func BlockDeleteTxn(txn *Txn, block Block) error

func UtxoBlobKey added in v0.4.2

func UtxoBlobKey(txId []byte, outputIdx uint32) []byte

func UtxoDelete added in v0.4.2

func UtxoDelete(
	db Database,
	utxo Utxo,
) error

func UtxosDelete added in v0.4.2

func UtxosDelete(
	db Database,
	utxos []Utxo,
) error

Types

type BaseDatabase

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

func (*BaseDatabase) Blob

func (b *BaseDatabase) Blob() blob.BlobStore

Blob returns the underling blob store instance

func (*BaseDatabase) Close

func (b *BaseDatabase) Close() error

Close cleans up the database connections

func (*BaseDatabase) Metadata

func (b *BaseDatabase) Metadata() metadata.MetadataStore

Metadata returns the underlying metadata store instance

func (*BaseDatabase) Transaction

func (b *BaseDatabase) Transaction(readWrite bool) *Txn

Transaction starts a new database transaction and returns a handle to it

func (*BaseDatabase) UtxoByRef added in v0.4.2

func (d *BaseDatabase) UtxoByRef(
	txId []byte,
	outputIdx uint32,
	txn *Txn,
) (Utxo, error)

func (*BaseDatabase) UtxoDelete added in v0.4.2

func (d *BaseDatabase) UtxoDelete(
	utxo Utxo,
	txn *Txn,
) error

func (*BaseDatabase) UtxosByAddress added in v0.4.2

func (d *BaseDatabase) UtxosByAddress(
	addr ledger.Address,
	txn *Txn,
) ([]Utxo, error)

func (*BaseDatabase) UtxosDelete added in v0.4.2

func (d *BaseDatabase) UtxosDelete(
	utxos []Utxo,
	txn *Txn,
) error

type Block added in v0.4.2

type Block struct {
	Slot     uint64
	Number   uint64
	Hash     []byte
	Type     uint
	PrevHash []byte
	Nonce    []byte
	Cbor     []byte
}

func BlockBeforeSlot added in v0.4.2

func BlockBeforeSlot(db Database, slotNumber uint64) (Block, error)

func BlockBeforeSlotTxn added in v0.4.2

func BlockBeforeSlotTxn(txn *Txn, slotNumber uint64) (Block, error)

func BlockByNumber added in v0.4.2

func BlockByNumber(db Database, blockNumber uint64) (Block, error)

func BlockByNumberTxn added in v0.4.2

func BlockByNumberTxn(txn *Txn, blockNumber uint64) (Block, error)

func BlockByPoint added in v0.4.2

func BlockByPoint(db Database, point ocommon.Point) (Block, error)

func BlockByPointTxn added in v0.4.2

func BlockByPointTxn(txn *Txn, point ocommon.Point) (Block, error)

func BlocksAfterSlotTxn added in v0.4.2

func BlocksAfterSlotTxn(txn *Txn, slotNumber uint64) ([]Block, error)

func BlocksRecent added in v0.4.2

func BlocksRecent(db Database, count int) ([]Block, error)

func BlocksRecentTxn added in v0.4.2

func BlocksRecentTxn(txn *Txn, count int) ([]Block, error)

func (Block) Decode added in v0.4.2

func (b Block) Decode() (ledger.Block, error)

type BlockBlobMetadata added in v0.4.2

type BlockBlobMetadata struct {
	cbor.StructAsArray
	Type     uint
	Height   uint64
	PrevHash []byte
	Nonce    []byte
}

type CommitTimestampError

type CommitTimestampError struct {
	MetadataTimestamp int64
	BlobTimestamp     int64
}

func (CommitTimestampError) Error

func (e CommitTimestampError) Error() string

type Database

type Database interface {
	Close() error
	Metadata() metadata.MetadataStore
	Blob() blob.BlobStore
	Transaction(bool) *Txn
	// contains filtered or unexported methods
}

type InMemoryDatabase

type InMemoryDatabase struct {
	*BaseDatabase
}

InMemoryDatabase stores all data in memory. Data will not be persisted

func NewInMemory

func NewInMemory(logger *slog.Logger) (*InMemoryDatabase, error)

NewInMemory creates a new in-memory database

type PersistentDatabase

type PersistentDatabase struct {
	*BaseDatabase
	// contains filtered or unexported fields
}

PersistentDatabase stores its data on disk, providing persistence across restarts

func NewPersistent

func NewPersistent(
	dataDir string,
	logger *slog.Logger,
) (*PersistentDatabase, error)

NewPersistent creates a new persistent database instance using the provided data directory

type Rat

type Rat struct {
	*big.Rat
}

func (*Rat) Scan

func (r *Rat) Scan(val any) error

func (Rat) Value

func (r Rat) Value() (driver.Value, error)

type Txn

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

Txn is a wrapper around the transaction objects for the underlying DB engines

func NewTxn

func NewTxn(db Database, readWrite bool) *Txn

func (*Txn) Blob

func (t *Txn) Blob() *badger.Txn

func (*Txn) Commit

func (t *Txn) Commit() error

func (*Txn) DB added in v0.4.2

func (t *Txn) DB() Database

func (*Txn) Do

func (t *Txn) Do(fn func(*Txn) error) error

Do executes the specified function in the context of the transaction. Any errors returned will result in the transaction being rolled back

func (*Txn) Metadata

func (t *Txn) Metadata() *gorm.DB

func (*Txn) Rollback

func (t *Txn) Rollback() error

type Uint64

type Uint64 uint64

func (*Uint64) Scan

func (u *Uint64) Scan(val any) error

func (Uint64) Value

func (u Uint64) Value() (driver.Value, error)

type Utxo added in v0.4.2

type Utxo struct {
	ID          uint   `gorm:"primarykey"`
	TxId        []byte `gorm:"index:tx_id_output_idx"`
	OutputIdx   uint32 `gorm:"index:tx_id_output_idx"`
	AddedSlot   uint64 `gorm:"index"`
	DeletedSlot uint64 `gorm:"index"`
	PaymentKey  []byte `gorm:"index"`
	StakingKey  []byte `gorm:"index"`
	Cbor        []byte `gorm:"-"` // This is not represented in the metadata DB
}

func UtxoByRef added in v0.4.2

func UtxoByRef(
	db Database,
	txId []byte,
	outputIdx uint32,
) (Utxo, error)

func UtxosByAddress added in v0.4.2

func UtxosByAddress(
	db Database,
	addr ledger.Address,
) ([]Utxo, error)

func (*Utxo) Decode added in v0.4.2

func (u *Utxo) Decode() (ledger.TransactionOutput, error)

func (*Utxo) TableName added in v0.4.2

func (u *Utxo) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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