Skip to content
Merged
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
13 changes: 13 additions & 0 deletions database/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ func (d *Database) SetStakeVoteRegistrationDelegation(
)
}

// 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,
Expand Down
39 changes: 39 additions & 0 deletions database/plugin/metadata/sqlite/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,45 @@ func (d *MetadataStoreSqlite) SetStakeVoteRegistrationDelegation(
return nil
}

// SetVoteDelegation saves a vote-only delegation certificate and updates the account.
func (d *MetadataStoreSqlite) SetVoteDelegation(
cert *lcommon.VoteDelegationCertificate,
slot uint64,
txn *gorm.DB,
) error {
stakeKey := cert.StakeCredential.Credential.Bytes()
tmpAccount, err := d.GetAccount(stakeKey, txn)
if err != nil {
return err
}

tmpItem := models.VoteDelegation{
StakingKey: stakeKey,
Drep: cert.Drep.Credential[:],
AddedSlot: slot,
}

tmpAccount.Drep = tmpItem.Drep

if txn != nil {
if accountErr := txn.Save(&tmpAccount); accountErr.Error != nil {
return accountErr.Error
}
if result := txn.Create(&tmpItem); result.Error != nil {
return result.Error
}
} else {
if accountErr := d.DB().Save(&tmpAccount); accountErr.Error != nil {
return accountErr.Error
}
if result := d.DB().Create(&tmpItem); result.Error != nil {
return result.Error
}
}

return nil
}

// SetVoteRegistrationDelegation saves a vote registration delegation certificate and account
func (d *MetadataStoreSqlite) SetVoteRegistrationDelegation(
cert *lcommon.VoteRegistrationDelegationCertificate,
Expand Down
11 changes: 11 additions & 0 deletions database/plugin/metadata/sqlite/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ func (StakeVoteRegistrationDelegation) TableName() string {
return "stake_vote_registration_delegation"
}

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

func (VoteDelegation) TableName() string {
return "vote_delegation"
}

type VoteRegistrationDelegation struct {
ID uint `gorm:"primarykey"`
StakingKey []byte `gorm:"index"`
Expand Down
26 changes: 0 additions & 26 deletions database/plugin/metadata/sqlite/models/vote_delegation.go

This file was deleted.

5 changes: 5 additions & 0 deletions database/plugin/metadata/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ type MetadataStore interface {
[]byte, // stake
*gorm.DB,
) error
SetVoteDelegation(
*lcommon.VoteDelegationCertificate,
uint64, // slot
*gorm.DB,
) error
SetVoteRegistrationDelegation(
*lcommon.VoteRegistrationDelegationCertificate,
uint64, // slot
Expand Down
9 changes: 9 additions & 0 deletions ledger/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ func (ls *LedgerState) processTransactionCertificates(
if err != nil {
return err
}
case *lcommon.VoteDelegationCertificate:
err := ls.db.SetVoteDelegation(
cert,
blockPoint.Slot,
txn,
)
if err != nil {
return err
}
case *lcommon.VoteRegistrationDelegationCertificate:
err := ls.db.SetVoteRegistrationDelegation(
cert,
Expand Down
Loading