models

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: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyWitnessTypeVkey represents a Vkey witness
	KeyWitnessTypeVkey uint8 = 0
	// KeyWitnessTypeBootstrap represents a Bootstrap witness
	KeyWitnessTypeBootstrap uint8 = 1
)

Variables

View Source
var ErrAccountNotFound = errors.New("account not found")
View Source
var ErrBlockNotFound = errors.New("block not found")
View Source
var ErrDrepNotFound = errors.New("drep not found")
View Source
var ErrPoolNotFound = errors.New("pool not found")

MigrateModels contains a list of model objects that should have DB migrations applied

Functions

This section is empty.

Types

type Account

type Account struct {
	StakingKey    []byte `gorm:"uniqueIndex"`
	Pool          []byte `gorm:"index"`
	Drep          []byte `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
	CertificateID uint `gorm:"index"`
	Active        bool `gorm:"default:true"`
}

func (*Account) String

func (a *Account) String() (string, error)

String returns the bech32-encoded representation of the Account's StakingKey with the "stake" human-readable part. Returns an error if the StakingKey is empty or if encoding fails.

func (*Account) TableName

func (a *Account) TableName() string

type Asset

type Asset struct {
	Name        []byte       `gorm:"index"`
	NameHex     []byte       `gorm:"index"`
	PolicyId    []byte       `gorm:"index"`
	Fingerprint []byte       `gorm:"index"`
	ID          uint         `gorm:"primaryKey"`
	UtxoID      uint         `gorm:"index"`
	Amount      types.Uint64 `gorm:"index"`
}

func ConvertMultiAssetToModels

func ConvertMultiAssetToModels(
	multiAsset *lcommon.MultiAsset[lcommon.MultiAssetTypeOutput],
) []Asset

ConvertMultiAssetToModels converts a MultiAsset structure into a slice of Asset models. Each asset is populated with its name, hex-encoded name, policy ID, fingerprint, and amount. Returns an empty slice if multiAsset is nil or contains no assets.

func (Asset) TableName

func (Asset) TableName() string

type AuthCommitteeHot

type AuthCommitteeHot struct {
	ColdCredential []byte `gorm:"index"`
	HostCredential []byte `gorm:"index"`
	ID             uint   `gorm:"primarykey"`
	CertificateID  uint   `gorm:"index"`
	AddedSlot      uint64
}

func (AuthCommitteeHot) TableName

func (AuthCommitteeHot) TableName() string

type Block

type Block struct {
	Hash     []byte `gorm:"index:hash_slot"`
	PrevHash []byte
	Cbor     []byte
	ID       uint64 `gorm:"primaryKey"`
	Slot     uint64 `gorm:"index:hash_slot"`
	Number   uint64
	Type     uint
}

func (Block) Decode

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

func (Block) TableName

func (Block) TableName() string

TableName overrides default table name

type BlockNonce

type BlockNonce struct {
	Hash         []byte `gorm:"index:hash_slot"`
	Nonce        []byte
	ID           uint   `gorm:"primarykey"`
	Slot         uint64 `gorm:"index:hash_slot"`
	IsCheckpoint bool
}

func (BlockNonce) TableName

func (BlockNonce) TableName() string

TableName overrides default table name

type Certificate

type Certificate struct {
	BlockHash     []byte `gorm:"index"`
	ID            uint   `gorm:"primaryKey"`
	TransactionID uint   `gorm:"index;uniqueIndex:uniq_tx_cert;constraint:OnDelete:CASCADE"`
	CertificateID uint   `gorm:"index"` // Polymorphic FK to certificate table based on CertType. Not DB-enforced.
	Slot          uint64 `gorm:"index"`
	CertIndex     uint   `gorm:"column:cert_index;uniqueIndex:uniq_tx_cert"`
	CertType      uint   `gorm:"index"`
}

Certificate maps transaction certificates to their specialized table records. Provides unified indexing across all certificate types without requiring joins.

All certificate types now have dedicated specialized models. The CertificateID field references the ID of the specific certificate record based on CertType.

func (Certificate) TableName

func (Certificate) TableName() string

func (Certificate) Type

func (c Certificate) Type() uint

type Datum

type Datum struct {
	Hash      []byte `gorm:"index;not null;unique"`
	RawDatum  []byte `gorm:"not null"`
	ID        uint   `gorm:"primarykey"`
	AddedSlot uint64 `gorm:"not null"`
}

func (Datum) TableName

func (Datum) TableName() string

type Deregistration

type Deregistration struct {
	StakingKey    []byte `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	CertificateID uint   `gorm:"index"`
	AddedSlot     uint64
	Amount        types.Uint64
}

func (Deregistration) TableName

func (Deregistration) TableName() string

type DeregistrationDrep

type DeregistrationDrep struct {
	DrepCredential []byte `gorm:"index"`
	CertificateID  uint   `gorm:"index"`
	ID             uint   `gorm:"primarykey"`
	AddedSlot      uint64
	DepositAmount  types.Uint64
}

func (DeregistrationDrep) TableName

func (DeregistrationDrep) TableName() string

type Drep

type Drep struct {
	AnchorUrl     string
	Credential    []byte `gorm:"uniqueIndex"`
	AnchorHash    []byte
	CertificateID uint `gorm:"index"`
	ID            uint `gorm:"primarykey"`
	AddedSlot     uint64
	Active        bool `gorm:"default:true"`
}

func (*Drep) TableName

func (d *Drep) TableName() string

type Epoch

type Epoch struct {
	Nonce []byte
	ID    uint `gorm:"primarykey"`
	// NOTE: we would normally use this as the primary key, but GORM doesn't
	// like a primary key value of 0
	EpochId       uint64 `gorm:"uniqueIndex"`
	StartSlot     uint64
	EraId         uint
	SlotLength    uint
	LengthInSlots uint
}

func (Epoch) TableName

func (Epoch) TableName() string

type KeyWitness

type KeyWitness struct {
	ID            uint   `gorm:"primaryKey"`
	TransactionID uint   `gorm:"index"`
	Type          uint8  `gorm:"index"` // See KeyWitnessType* constants
	Vkey          []byte // Vkey witness key
	Signature     []byte // Witness signature
	PublicKey     []byte // For Bootstrap witness
	ChainCode     []byte // For Bootstrap witness
	Attributes    []byte // For Bootstrap witness
}

KeyWitness represents a key witness entry (Vkey or Bootstrap) Type: KeyWitnessTypeVkey = VkeyWitness, KeyWitnessTypeBootstrap = BootstrapWitness

func (KeyWitness) TableName

func (KeyWitness) TableName() string

type MoveInstantaneousRewards

type MoveInstantaneousRewards struct {
	Pot           uint `gorm:"index"`
	CertificateID uint `gorm:"index"`
	ID            uint `gorm:"primarykey"`
	AddedSlot     uint64
}

func (MoveInstantaneousRewards) TableName

func (MoveInstantaneousRewards) TableName() string

type MoveInstantaneousRewardsReward

type MoveInstantaneousRewardsReward struct {
	Credential []byte
	Amount     types.Uint64
	ID         uint `gorm:"primarykey"`
	MIRID      uint `gorm:"index;constraint:OnDelete:CASCADE"`
}

func (MoveInstantaneousRewardsReward) TableName

type PParamUpdate

type PParamUpdate struct {
	GenesisHash []byte
	Cbor        []byte
	ID          uint `gorm:"primarykey"`
	AddedSlot   uint64
	Epoch       uint64
}

func (PParamUpdate) TableName

func (PParamUpdate) TableName() string

type PParams

type PParams struct {
	Cbor      []byte
	ID        uint `gorm:"primarykey"`
	AddedSlot uint64
	Epoch     uint64
	EraId     uint
}

func (PParams) TableName

func (PParams) TableName() string

type PlutusData

type PlutusData struct {
	ID            uint `gorm:"primaryKey"`
	TransactionID uint `gorm:"index"`
	Data          []byte
	Transaction   *Transaction
}

PlutusData represents a Plutus data value in the witness set

func (PlutusData) TableName

func (PlutusData) TableName() string

type Pool

type Pool struct {
	Margin        *types.Rat
	PoolKeyHash   []byte `gorm:"uniqueIndex"`
	VrfKeyHash    []byte
	RewardAccount []byte
	Owners        []PoolRegistrationOwner
	Relays        []PoolRegistrationRelay
	Registration  []PoolRegistration
	Retirement    []PoolRetirement
	ID            uint `gorm:"primarykey"`
	Pledge        types.Uint64
	Cost          types.Uint64
}

func (*Pool) TableName

func (p *Pool) TableName() string

type PoolRegistration

type PoolRegistration struct {
	Margin        *types.Rat
	MetadataUrl   string
	VrfKeyHash    []byte
	PoolKeyHash   []byte `gorm:"index"`
	RewardAccount []byte
	MetadataHash  []byte
	Owners        []PoolRegistrationOwner
	Relays        []PoolRegistrationRelay
	Pledge        types.Uint64
	Cost          types.Uint64
	CertificateID uint `gorm:"index"`
	ID            uint `gorm:"primarykey"`
	PoolID        uint `gorm:"index"`
	AddedSlot     uint64
	DepositAmount types.Uint64
}

func (PoolRegistration) TableName

func (PoolRegistration) TableName() string

type PoolRegistrationOwner

type PoolRegistrationOwner struct {
	KeyHash            []byte
	ID                 uint `gorm:"primarykey"`
	PoolRegistrationID uint `gorm:"index"`
	PoolID             uint `gorm:"index"`
}

func (PoolRegistrationOwner) TableName

func (PoolRegistrationOwner) TableName() string

type PoolRegistrationRelay

type PoolRegistrationRelay struct {
	Ipv4               *net.IP
	Ipv6               *net.IP
	Hostname           string
	ID                 uint `gorm:"primarykey"`
	PoolRegistrationID uint `gorm:"index"`
	PoolID             uint `gorm:"index"`
	Port               uint
}

func (PoolRegistrationRelay) TableName

func (PoolRegistrationRelay) TableName() string

type PoolRetirement

type PoolRetirement struct {
	PoolKeyHash   []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	PoolID        uint   `gorm:"index"`
	Epoch         uint64
	AddedSlot     uint64
}

func (PoolRetirement) TableName

func (PoolRetirement) TableName() string

type Redeemer

type Redeemer struct {
	ID            uint   `gorm:"primaryKey"`
	TransactionID uint   `gorm:"index"`
	Tag           uint8  `gorm:"index"` // Redeemer tag
	Index         uint32 `gorm:"index"`
	Data          []byte // Plutus data
	ExUnitsMemory uint64
	ExUnitsCPU    uint64
}

Redeemer represents a redeemer in the witness set

func (Redeemer) TableName

func (Redeemer) TableName() string

type Registration

type Registration struct {
	StakingKey    []byte `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	CertificateID uint   `gorm:"index"`
	AddedSlot     uint64
	DepositAmount types.Uint64
}

func (Registration) TableName

func (Registration) TableName() string

type RegistrationDrep

type RegistrationDrep struct {
	AnchorUrl      string
	DrepCredential []byte `gorm:"index"`
	AnchorHash     []byte
	CertificateID  uint `gorm:"index"`
	ID             uint `gorm:"primarykey"`
	AddedSlot      uint64
	DepositAmount  types.Uint64
}

func (RegistrationDrep) TableName

func (RegistrationDrep) TableName() string

type ResignCommitteeCold

type ResignCommitteeCold struct {
	AnchorUrl      string
	ColdCredential []byte `gorm:"index"`
	AnchorHash     []byte
	ID             uint `gorm:"primarykey"`
	CertificateID  uint `gorm:"index"`
	AddedSlot      uint64
}

func (ResignCommitteeCold) TableName

func (ResignCommitteeCold) TableName() string

type Script

type Script struct {
	ID          uint   `gorm:"primaryKey"`
	Hash        []byte `gorm:"index;unique"` // Script hash
	Type        uint8  `gorm:"index"`        // Script type
	Content     []byte // Script content
	CreatedSlot uint64 // Slot when this script was first seen
}

Script represents the content of a script, indexed by its hash This avoids storing duplicate script data when the same script appears in multiple transactions

func (Script) TableName

func (Script) TableName() string

type StakeDelegation

type StakeDelegation struct {
	StakingKey    []byte `gorm:"index"`
	PoolKeyHash   []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
}

func (StakeDelegation) TableName

func (StakeDelegation) TableName() string

type StakeDeregistration

type StakeDeregistration struct {
	StakingKey    []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
}

func (StakeDeregistration) TableName

func (StakeDeregistration) TableName() string

type StakeRegistration

type StakeRegistration struct {
	StakingKey    []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
	DepositAmount types.Uint64
}

func (StakeRegistration) TableName

func (StakeRegistration) TableName() string

type StakeRegistrationDelegation

type StakeRegistrationDelegation struct {
	StakingKey    []byte `gorm:"index"`
	PoolKeyHash   []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
	DepositAmount types.Uint64
}

func (StakeRegistrationDelegation) TableName

func (StakeRegistrationDelegation) TableName() string

type StakeVoteDelegation

type StakeVoteDelegation struct {
	StakingKey    []byte `gorm:"index"`
	PoolKeyHash   []byte `gorm:"index"`
	Drep          []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
}

func (StakeVoteDelegation) TableName

func (StakeVoteDelegation) TableName() string

type StakeVoteRegistrationDelegation

type StakeVoteRegistrationDelegation struct {
	StakingKey    []byte `gorm:"index"`
	PoolKeyHash   []byte `gorm:"index"`
	Drep          []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
	DepositAmount types.Uint64
}

func (StakeVoteRegistrationDelegation) TableName

type Tip

type Tip struct {
	Hash        []byte
	ID          uint `gorm:"primarykey"`
	Slot        uint64
	BlockNumber uint64
}

func (Tip) TableName

func (Tip) TableName() string

type Transaction

type Transaction struct {
	Hash             []byte           `gorm:"uniqueIndex"`
	BlockHash        []byte           `gorm:"index"`
	Inputs           []Utxo           `gorm:"foreignKey:SpentAtTxId;references:Hash"`
	Outputs          []Utxo           `gorm:"foreignKey:TransactionID;references:ID"`
	ReferenceInputs  []Utxo           `gorm:"foreignKey:ReferencedByTxId;references:Hash"`
	Collateral       []Utxo           `gorm:"foreignKey:CollateralByTxId;references:Hash"`
	CollateralReturn *Utxo            `gorm:"foreignKey:TransactionID;references:ID"`
	KeyWitnesses     []KeyWitness     `gorm:"foreignKey:TransactionID;references:ID"`
	WitnessScripts   []WitnessScripts `gorm:"foreignKey:TransactionID;references:ID"`
	Redeemers        []Redeemer       `gorm:"foreignKey:TransactionID;references:ID"`
	PlutusData       []PlutusData     `gorm:"foreignKey:TransactionID;references:ID"`
	ID               uint             `gorm:"primaryKey"`
	Type             int
	BlockIndex       uint32
	Metadata         []byte
	Fee              types.Uint64
	TTL              types.Uint64
	Valid            bool
}

Transaction represents a transaction record

func (Transaction) TableName

func (Transaction) TableName() string

type UpdateDrep

type UpdateDrep struct {
	AnchorUrl     string
	Credential    []byte `gorm:"index"`
	AnchorHash    []byte
	CertificateID uint `gorm:"index"`
	ID            uint `gorm:"primarykey"`
	AddedSlot     uint64
}

func (UpdateDrep) TableName

func (UpdateDrep) TableName() string

type Utxo

type Utxo struct {
	TransactionID    *uint  `gorm:"index"`
	TxId             []byte `gorm:"uniqueIndex:tx_id_output_idx"`
	PaymentKey       []byte `gorm:"index"`
	StakingKey       []byte `gorm:"index"`
	Assets           []Asset
	Cbor             []byte       `gorm:"-"` // This is here for convenience but not represented in the metadata DB
	SpentAtTxId      []byte       `gorm:"index"`
	ReferencedByTxId []byte       `gorm:"index"`
	CollateralByTxId []byte       `gorm:"index"`
	ID               uint         `gorm:"primarykey"`
	AddedSlot        uint64       `gorm:"index"`
	DeletedSlot      uint64       `gorm:"index"`
	Amount           types.Uint64 `gorm:"index"`
	OutputIdx        uint32       `gorm:"uniqueIndex:tx_id_output_idx"`
}

Utxo represents an unspent transaction output

func UtxoLedgerToModel

func UtxoLedgerToModel(
	utxo ledger.Utxo,
	slot uint64,
) Utxo

func (*Utxo) Decode

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

func (*Utxo) TableName

func (u *Utxo) TableName() string

type UtxoSlot

type UtxoSlot struct {
	Utxo ledger.Utxo
	Slot uint64
}

UtxoSlot allows providing a slot number with a ledger.Utxo object

type VoteDelegation

type VoteDelegation struct {
	StakingKey    []byte `gorm:"index"`
	Drep          []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
}

func (VoteDelegation) TableName

func (VoteDelegation) TableName() string

type VoteRegistrationDelegation

type VoteRegistrationDelegation struct {
	StakingKey    []byte `gorm:"index"`
	Drep          []byte `gorm:"index"`
	CertificateID uint   `gorm:"index"`
	ID            uint   `gorm:"primarykey"`
	AddedSlot     uint64
	DepositAmount types.Uint64
}

func (VoteRegistrationDelegation) TableName

func (VoteRegistrationDelegation) TableName() string

type WitnessScripts

type WitnessScripts struct {
	ID            uint   `gorm:"primaryKey"`
	TransactionID uint   `gorm:"index"`
	Type          uint8  `gorm:"index"` // Script type
	ScriptHash    []byte `gorm:"index"` // Hash of the script
}

WitnessScripts represents a reference to a script in the witness set Type corresponds to ScriptRefType constants from gouroboros/ledger/common: 0=NativeScript (ScriptRefTypeNativeScript) 1=PlutusV1 (ScriptRefTypePlutusV1) 2=PlutusV2 (ScriptRefTypePlutusV2) 3=PlutusV3 (ScriptRefTypePlutusV3)

To avoid storing duplicate script data for the same script used in multiple transactions, we store only the script hash here. The actual script content is stored separately in Script table, indexed by hash.

func (WitnessScripts) TableName

func (WitnessScripts) TableName() string

Jump to

Keyboard shortcuts

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