Skip to content

Commit d567984

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 6540fb2 commit d567984

File tree

15 files changed

+513
-976
lines changed

15 files changed

+513
-976
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/certificates.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/certificates.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package models
16+
17+
// Certificates table to track Transaction.Certificates() results
18+
// This table mimics the shape of the Certificates() interface from ledger.Transaction
19+
// Individual certificates will continue to be stored in their own tables.
20+
type Certificates struct {
21+
ID uint `gorm:"primaryKey"`
22+
TransactionID uint `gorm:"index"`
23+
CertIndex uint `gorm:"column:cert_index"` // Index of the certificate in the transaction
24+
CertType uint // Type of certificate (matches lcommon.Certificate type)
25+
CertificateID uint `gorm:"index"` // FK to the appropriate certificate table (e.g., certs, registration, etc.)
26+
}
27+
28+
func (Certificates) TableName() string {
29+
return "certificates"
30+
}

database/models/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var MigrateModels = []any{
2121
&AuthCommitteeHot{},
2222
&BlockNonce{},
2323
&Certificate{},
24+
&Certificates{},
2425
&Datum{},
2526
&Deregistration{},
2627
&DeregistrationDrep{},

0 commit comments

Comments
 (0)