Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 0 additions & 142 deletions database/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package database

import (
"github.com/blinklabs-io/dingo/database/models"
"github.com/blinklabs-io/dingo/database/types"
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
)

// GetAccount returns an account by staking key
Expand All @@ -38,143 +36,3 @@ func (d *Database) GetAccount(
}
return account, nil
}

// SetDeregistration saves a deregistration certificate
func (d *Database) SetDeregistration(
cert *lcommon.DeregistrationCertificate,
slot uint64,
txn *Txn,
) error {
return d.metadata.SetDeregistration(
cert,
slot,
txn.Metadata(),
)
}

// SetRegistration saves a registration certificate
func (d *Database) SetRegistration(
cert *lcommon.RegistrationCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetRegistration(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}

// SetStakeDelegation saves a stake delegation certificate
func (d *Database) SetStakeDelegation(
cert *lcommon.StakeDelegationCertificate,
slot uint64,
txn *Txn,
) error {
return d.metadata.SetStakeDelegation(
cert,
slot,
txn.Metadata(),
)
}

// SetStakeDeregistration saves a stake deregistration certificate
func (d *Database) SetStakeDeregistration(
cert *lcommon.StakeDeregistrationCertificate,
slot uint64,
txn *Txn,
) error {
return d.metadata.SetStakeDeregistration(
cert,
slot,
txn.Metadata(),
)
}

// SetStakeRegistration saves a stake registration certificate
func (d *Database) SetStakeRegistration(
cert *lcommon.StakeRegistrationCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetStakeRegistration(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}

// SetStakeRegistrationDelegation saves a stake registration delegation certificate
func (d *Database) SetStakeRegistrationDelegation(
cert *lcommon.StakeRegistrationDelegationCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetStakeRegistrationDelegation(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}

// SetStakeVoteDelegation saves a stake vote delegation certificate
func (d *Database) SetStakeVoteDelegation(
cert *lcommon.StakeVoteDelegationCertificate,
slot uint64,
txn *Txn,
) error {
return d.metadata.SetStakeVoteDelegation(
cert,
slot,
txn.Metadata(),
)
}

// SetStakeVoteRegistrationDelegation saves a stake vote registration delegation certificate
func (d *Database) SetStakeVoteRegistrationDelegation(
cert *lcommon.StakeVoteRegistrationDelegationCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetStakeVoteRegistrationDelegation(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}

// SetVoteDelegation saves a vote delegation certificate
func (d *Database) SetVoteDelegation(
cert *lcommon.VoteDelegationCertificate,
slot uint64,
txn *Txn,
) error {
return d.metadata.SetVoteDelegation(
cert,
slot,
txn.Metadata(),
)
}

// SetVoteRegistrationDelegation saves a vote registration delegation certificate
func (d *Database) SetVoteRegistrationDelegation(
cert *lcommon.VoteRegistrationDelegationCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetVoteRegistrationDelegation(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}
33 changes: 6 additions & 27 deletions database/certs.go → database/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,25 @@
package database

import (
"github.com/blinklabs-io/dingo/database/types"
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
)

// GetPoolRegistrations returns a list of pool registration certificates
// Certificate persistence is handled by SetTransaction.
// The ledger layer calculates deposits and calls SetTransaction
// to persist transactions and certificates together in a single operation.

// GetPoolRegistrations returns pool registration certificates for the given pool key hash
func (d *Database) GetPoolRegistrations(
poolKeyHash lcommon.PoolKeyHash,
txn *Txn,
) ([]lcommon.PoolRegistrationCertificate, error) {
return d.metadata.GetPoolRegistrations(poolKeyHash, txn.Metadata())
}

// GetStakeRegistrations returns a list of stake registration certificates
// GetStakeRegistrations returns stake registration certificates for the given staking key
func (d *Database) GetStakeRegistrations(
stakingKey []byte,
txn *Txn,
) ([]lcommon.StakeRegistrationCertificate, error) {
return d.metadata.GetStakeRegistrations(stakingKey, txn.Metadata())
}

// SetPoolRegistration saves a pool registration certificate
func (d *Database) SetPoolRegistration(
cert *lcommon.PoolRegistrationCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetPoolRegistration(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}

// SetPoolRetirement saves a pool retirement certificate
func (d *Database) SetPoolRetirement(
cert *lcommon.PoolRetirementCertificate,
slot uint64,
txn *Txn,
) error {
return d.metadata.SetPoolRetirement(cert, slot, txn.Metadata())
}
48 changes: 0 additions & 48 deletions database/drep.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,3 @@
// limitations under the License.

package database

import (
"github.com/blinklabs-io/dingo/database/types"
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
)

// SetRegistrationDrep saves a registration drep certificate
func (d *Database) SetRegistrationDrep(
cert *lcommon.RegistrationDrepCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetRegistrationDrep(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}

// SetDeregistrationDrep saves a deregistration drep certificate
func (d *Database) SetDeregistrationDrep(
cert *lcommon.DeregistrationDrepCertificate,
slot uint64,
deposit uint64,
txn *Txn,
) error {
return d.metadata.SetDeregistrationDrep(
cert,
slot,
types.Uint64(deposit),
txn.Metadata(),
)
}

// SetUpdateDrep saves an update drep certificate
func (d *Database) SetUpdateDrep(
cert *lcommon.UpdateDrepCertificate,
slot uint64,
txn *Txn,
) error {
return d.metadata.SetUpdateDrep(
cert,
slot,
txn.Metadata(),
)
}
10 changes: 5 additions & 5 deletions database/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
var ErrAccountNotFound = errors.New("account not found")

type Account struct {
StakingKey []byte `gorm:"uniqueIndex"`
StakingKey []byte `gorm:"index"`
Pool []byte `gorm:"index"`
Drep []byte `gorm:"index"`
ID uint `gorm:"primarykey"`
Expand Down Expand Up @@ -58,9 +58,9 @@ func (a *Account) String() (string, error) {
}

type Deregistration struct {
StakingKey []byte `gorm:"index"`
StakingKey []byte `gorm:"index;uniqueIndex:uniq_deregistration_cert"`
ID uint `gorm:"primarykey"`
CertificateID uint `gorm:"index"`
CertificateID uint `gorm:"uniqueIndex:uniq_deregistration_cert"`
AddedSlot uint64
Amount types.Uint64
}
Expand Down Expand Up @@ -105,8 +105,8 @@ func (StakeDeregistration) TableName() string {
}

type StakeRegistration struct {
StakingKey []byte `gorm:"index"`
CertificateID uint `gorm:"index"`
StakingKey []byte `gorm:"index;uniqueIndex:uniq_stake_registration_cert"`
CertificateID uint `gorm:"uniqueIndex:uniq_stake_registration_cert"`
ID uint `gorm:"primarykey"`
AddedSlot uint64
DepositAmount types.Uint64
Expand Down
4 changes: 2 additions & 2 deletions database/models/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
func TestAccount_String(t *testing.T) {
tests := []struct {
name string
wantErrMsg string
expectedHRP string
stakingKey []byte
wantErr bool
wantErrMsg string
validateAddr bool
expectedHRP string
}{
{
name: "valid staking key - 28 bytes",
Expand Down
3 changes: 2 additions & 1 deletion database/models/auth_committee_hot.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package models

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

Expand Down
40 changes: 40 additions & 0 deletions database/models/certificate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package models

// 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.
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"`
}

// TableName returns the database table name for the Certificate model.
func (Certificate) TableName() string {
return "certificates"
}

// Type returns the certificate type.
func (c Certificate) Type() uint {
return c.CertType
}
Loading
Loading