Skip to content

Commit 4ee0250

Browse files
committed
feat: implement unified certificate persistence system
- Add SetCertificate method handling all Cardano certificate types - Switch interface from slot to ocommon.Point for consistency - Add comprehensive test suite with 19 test cases - Remove deprecated certificate setter methods - Include certificate mapping model and migration updates Signed-off-by: GitHub Copilot <[email protected]> Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 544d883 commit 4ee0250

31 files changed

+1058
-1105
lines changed

database/account.go

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package database
1616

1717
import (
1818
"github.com/blinklabs-io/dingo/database/models"
19-
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
2019
)
2120

2221
// GetAccount returns an account by staking key
@@ -37,138 +36,3 @@ func (d *Database) GetAccount(
3736
}
3837
return account, nil
3938
}
40-
41-
// SetDeregistration saves a deregistration certificate
42-
func (d *Database) SetDeregistration(
43-
cert *lcommon.DeregistrationCertificate,
44-
slot uint64,
45-
txn *Txn,
46-
) error {
47-
return d.metadata.SetDeregistration(
48-
cert,
49-
slot,
50-
txn.Metadata(),
51-
)
52-
}
53-
54-
// SetRegistration saves a registration certificate
55-
func (d *Database) SetRegistration(
56-
cert *lcommon.RegistrationCertificate,
57-
slot, deposit uint64,
58-
txn *Txn,
59-
) error {
60-
return d.metadata.SetRegistration(
61-
cert,
62-
slot,
63-
deposit,
64-
txn.Metadata(),
65-
)
66-
}
67-
68-
// SetStakeDelegation saves a stake delegation certificate
69-
func (d *Database) SetStakeDelegation(
70-
cert *lcommon.StakeDelegationCertificate,
71-
slot uint64,
72-
txn *Txn,
73-
) error {
74-
return d.metadata.SetStakeDelegation(
75-
cert,
76-
slot,
77-
txn.Metadata(),
78-
)
79-
}
80-
81-
// SetStakeDeregistration saves a stake deregistration certificate
82-
func (d *Database) SetStakeDeregistration(
83-
cert *lcommon.StakeDeregistrationCertificate,
84-
slot uint64,
85-
txn *Txn,
86-
) error {
87-
return d.metadata.SetStakeDeregistration(
88-
cert,
89-
slot,
90-
txn.Metadata(),
91-
)
92-
}
93-
94-
// SetStakeRegistration saves a stake registration certificate
95-
func (d *Database) SetStakeRegistration(
96-
cert *lcommon.StakeRegistrationCertificate,
97-
slot, deposit uint64,
98-
txn *Txn,
99-
) error {
100-
return d.metadata.SetStakeRegistration(
101-
cert,
102-
slot,
103-
deposit,
104-
txn.Metadata(),
105-
)
106-
}
107-
108-
// SetStakeRegistrationDelegation saves a stake registration delegation certificate
109-
func (d *Database) SetStakeRegistrationDelegation(
110-
cert *lcommon.StakeRegistrationDelegationCertificate,
111-
slot, deposit uint64,
112-
txn *Txn,
113-
) error {
114-
return d.metadata.SetStakeRegistrationDelegation(
115-
cert,
116-
slot,
117-
deposit,
118-
txn.Metadata(),
119-
)
120-
}
121-
122-
// SetStakeVoteDelegation saves a stake vote delegation certificate
123-
func (d *Database) SetStakeVoteDelegation(
124-
cert *lcommon.StakeVoteDelegationCertificate,
125-
slot uint64,
126-
txn *Txn,
127-
) error {
128-
return d.metadata.SetStakeVoteDelegation(
129-
cert,
130-
slot,
131-
txn.Metadata(),
132-
)
133-
}
134-
135-
// SetStakeVoteRegistrationDelegation saves a stake vote registration delegation certificate
136-
func (d *Database) SetStakeVoteRegistrationDelegation(
137-
cert *lcommon.StakeVoteRegistrationDelegationCertificate,
138-
slot, deposit uint64,
139-
txn *Txn,
140-
) error {
141-
return d.metadata.SetStakeVoteRegistrationDelegation(
142-
cert,
143-
slot,
144-
deposit,
145-
txn.Metadata(),
146-
)
147-
}
148-
149-
// SetVoteDelegation saves a vote delegation certificate
150-
func (d *Database) SetVoteDelegation(
151-
cert *lcommon.VoteDelegationCertificate,
152-
slot uint64,
153-
txn *Txn,
154-
) error {
155-
return d.metadata.SetVoteDelegation(
156-
cert,
157-
slot,
158-
txn.Metadata(),
159-
)
160-
}
161-
162-
// SetVoteRegistrationDelegation saves a vote registration delegation certificate
163-
func (d *Database) SetVoteRegistrationDelegation(
164-
cert *lcommon.VoteRegistrationDelegationCertificate,
165-
slot, deposit uint64,
166-
txn *Txn,
167-
) error {
168-
return d.metadata.SetVoteRegistrationDelegation(
169-
cert,
170-
slot,
171-
deposit,
172-
txn.Metadata(),
173-
)
174-
}

database/certs.go renamed to database/certificate.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,22 @@ import (
1818
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
1919
)
2020

21-
// GetPoolRegistrations returns a list of pool registration certificates
21+
// Certificate persistence is handled by SetTransaction.
22+
// The ledger layer calculates deposits and calls SetTransaction
23+
// to persist transactions and certificates together in a single operation.
24+
25+
// GetPoolRegistrations returns pool registration certificates for the given pool key hash
2226
func (d *Database) GetPoolRegistrations(
2327
poolKeyHash lcommon.PoolKeyHash,
2428
txn *Txn,
2529
) ([]lcommon.PoolRegistrationCertificate, error) {
2630
return d.metadata.GetPoolRegistrations(poolKeyHash, txn.Metadata())
2731
}
2832

29-
// GetStakeRegistrations returns a list of stake registration certificates
33+
// GetStakeRegistrations returns stake registration certificates for the given staking key
3034
func (d *Database) GetStakeRegistrations(
3135
stakingKey []byte,
3236
txn *Txn,
3337
) ([]lcommon.StakeRegistrationCertificate, error) {
3438
return d.metadata.GetStakeRegistrations(stakingKey, txn.Metadata())
3539
}
36-
37-
// SetPoolRegistration saves a pool registration certificate
38-
func (d *Database) SetPoolRegistration(
39-
cert *lcommon.PoolRegistrationCertificate,
40-
slot, deposit uint64, // slot
41-
txn *Txn,
42-
) error {
43-
return d.metadata.SetPoolRegistration(cert, slot, deposit, txn.Metadata())
44-
}
45-
46-
// SetPoolRetirement saves a pool retirement certificate
47-
func (d *Database) SetPoolRetirement(
48-
cert *lcommon.PoolRetirementCertificate,
49-
slot uint64,
50-
txn *Txn,
51-
) error {
52-
return d.metadata.SetPoolRetirement(cert, slot, txn.Metadata())
53-
}

database/drep.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,3 @@
1313
// limitations under the License.
1414

1515
package database
16-
17-
import (
18-
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
19-
)
20-
21-
// SetRegistrationDrep saves a registration drep certificate
22-
func (d *Database) SetRegistrationDrep(
23-
cert *lcommon.RegistrationDrepCertificate,
24-
slot, deposit uint64,
25-
txn *Txn,
26-
) error {
27-
return d.metadata.SetRegistrationDrep(
28-
cert,
29-
slot,
30-
deposit,
31-
txn.Metadata(),
32-
)
33-
}
34-
35-
// SetDeregistrationDrep saves a deregistration drep certificate
36-
func (d *Database) SetDeregistrationDrep(
37-
cert *lcommon.DeregistrationDrepCertificate,
38-
slot, deposit uint64,
39-
txn *Txn,
40-
) error {
41-
return d.metadata.SetDeregistrationDrep(
42-
cert,
43-
slot,
44-
deposit,
45-
txn.Metadata(),
46-
)
47-
}
48-
49-
// SetUpdateDrep saves an update drep certificate
50-
func (d *Database) SetUpdateDrep(
51-
cert *lcommon.UpdateDrepCertificate,
52-
slot uint64,
53-
txn *Txn,
54-
) error {
55-
return d.metadata.SetUpdateDrep(
56-
cert,
57-
slot,
58-
txn.Metadata(),
59-
)
60-
}

database/models/account.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"errors"
1919
"fmt"
2020

21+
"github.com/blinklabs-io/dingo/database/types"
2122
"github.com/btcsuite/btcd/btcutil/bech32"
2223
)
2324

@@ -57,7 +58,7 @@ func (a *Account) String() (string, error) {
5758
}
5859

5960
type Deregistration struct {
60-
StakingKey []byte `gorm:"index"`
61+
StakingKey []byte `gorm:"unique"`
6162
ID uint `gorm:"primarykey"`
6263
CertificateID uint `gorm:"index"`
6364
AddedSlot uint64
@@ -69,19 +70,19 @@ func (Deregistration) TableName() string {
6970
}
7071

7172
type Registration struct {
72-
StakingKey []byte `gorm:"index"`
73+
StakingKey []byte `gorm:"unique"`
7374
ID uint `gorm:"primarykey"`
7475
CertificateID uint `gorm:"index"`
7576
AddedSlot uint64
76-
DepositAmount uint64
77+
DepositAmount types.Uint64
7778
}
7879

7980
func (Registration) TableName() string {
8081
return "registration"
8182
}
8283

8384
type StakeDelegation struct {
84-
StakingKey []byte `gorm:"index"`
85+
StakingKey []byte `gorm:"unique"`
8586
PoolKeyHash []byte `gorm:"index"`
8687
CertificateID uint `gorm:"index"`
8788
ID uint `gorm:"primarykey"`
@@ -93,7 +94,7 @@ func (StakeDelegation) TableName() string {
9394
}
9495

9596
type StakeDeregistration struct {
96-
StakingKey []byte `gorm:"index"`
97+
StakingKey []byte `gorm:"unique"`
9798
CertificateID uint `gorm:"index"`
9899
ID uint `gorm:"primarykey"`
99100
AddedSlot uint64
@@ -104,32 +105,32 @@ func (StakeDeregistration) TableName() string {
104105
}
105106

106107
type StakeRegistration struct {
107-
StakingKey []byte `gorm:"index"`
108+
StakingKey []byte `gorm:"unique"`
108109
CertificateID uint `gorm:"index"`
109110
ID uint `gorm:"primarykey"`
110111
AddedSlot uint64
111-
DepositAmount uint64
112+
DepositAmount types.Uint64
112113
}
113114

114115
func (StakeRegistration) TableName() string {
115116
return "stake_registration"
116117
}
117118

118119
type StakeRegistrationDelegation struct {
119-
StakingKey []byte `gorm:"index"`
120+
StakingKey []byte `gorm:"unique"`
120121
PoolKeyHash []byte `gorm:"index"`
121122
CertificateID uint `gorm:"index"`
122123
ID uint `gorm:"primarykey"`
123124
AddedSlot uint64
124-
DepositAmount uint64
125+
DepositAmount types.Uint64
125126
}
126127

127128
func (StakeRegistrationDelegation) TableName() string {
128129
return "stake_registration_delegation"
129130
}
130131

131132
type StakeVoteDelegation struct {
132-
StakingKey []byte `gorm:"index"`
133+
StakingKey []byte `gorm:"unique"`
133134
PoolKeyHash []byte `gorm:"index"`
134135
Drep []byte `gorm:"index"`
135136
CertificateID uint `gorm:"index"`
@@ -142,21 +143,21 @@ func (StakeVoteDelegation) TableName() string {
142143
}
143144

144145
type StakeVoteRegistrationDelegation struct {
145-
StakingKey []byte `gorm:"index"`
146+
StakingKey []byte `gorm:"unique"`
146147
PoolKeyHash []byte `gorm:"index"`
147148
Drep []byte `gorm:"index"`
148149
CertificateID uint `gorm:"index"`
149150
ID uint `gorm:"primarykey"`
150151
AddedSlot uint64
151-
DepositAmount uint64
152+
DepositAmount types.Uint64
152153
}
153154

154155
func (StakeVoteRegistrationDelegation) TableName() string {
155156
return "stake_vote_registration_delegation"
156157
}
157158

158159
type VoteDelegation struct {
159-
StakingKey []byte `gorm:"index"`
160+
StakingKey []byte `gorm:"unique"`
160161
Drep []byte `gorm:"index"`
161162
CertificateID uint `gorm:"index"`
162163
ID uint `gorm:"primarykey"`
@@ -168,12 +169,12 @@ func (VoteDelegation) TableName() string {
168169
}
169170

170171
type VoteRegistrationDelegation struct {
171-
StakingKey []byte `gorm:"index"`
172+
StakingKey []byte `gorm:"unique"`
172173
Drep []byte `gorm:"index"`
173174
CertificateID uint `gorm:"index"`
174175
ID uint `gorm:"primarykey"`
175176
AddedSlot uint64
176-
DepositAmount uint64
177+
DepositAmount types.Uint64
177178
}
178179

179180
func (VoteRegistrationDelegation) TableName() string {

database/models/account_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
func TestAccount_String(t *testing.T) {
2727
tests := []struct {
2828
name string
29+
wantErrMsg string
30+
expectedHRP string
2931
stakingKey []byte
3032
wantErr bool
31-
wantErrMsg string
3233
validateAddr bool
33-
expectedHRP string
3434
}{
3535
{
3636
name: "valid staking key - 28 bytes",

database/models/auth_committee_hot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package models
1616

1717
type AuthCommitteeHot struct {
18-
ColdCredential []byte `gorm:"index"`
18+
ColdCredential []byte `gorm:"unique"`
1919
HostCredential []byte `gorm:"index"`
2020
ID uint `gorm:"primarykey"`
2121
AddedSlot uint64

0 commit comments

Comments
 (0)