Skip to content

Commit ac901ee

Browse files
authored
feat: track registration certificates and create account (#634)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 8dcd97c commit ac901ee

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

database/certs.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ func (d *Database) SetPoolRetirement(
5252
return d.metadata.SetPoolRetirement(cert, slot, txn.Metadata())
5353
}
5454

55+
// SetRegistration saves a registration certificate
56+
func (d *Database) SetRegistration(
57+
cert *lcommon.RegistrationCertificate,
58+
slot, deposit uint64,
59+
txn *Txn,
60+
) error {
61+
return d.metadata.SetRegistration(cert, slot, deposit, txn.Metadata())
62+
}
63+
5564
// SetStakeDelegation saves a stake delegation certificate
5665
func (d *Database) SetStakeDelegation(
5766
cert *lcommon.StakeDelegationCertificate,

database/plugin/metadata/sqlite/certs.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,37 @@ func (d *MetadataStoreSqlite) SetStakeRegistration(
295295
}
296296
return nil
297297
}
298+
299+
// SetRegistration saves a registration certificate
300+
func (d *MetadataStoreSqlite) SetRegistration(
301+
cert *lcommon.RegistrationCertificate,
302+
slot, deposit uint64,
303+
txn *gorm.DB,
304+
) error {
305+
tmpAccount := models.Account{
306+
StakingKey: cert.StakeCredential.Credential.Bytes(),
307+
AddedSlot: slot,
308+
DepositAmount: deposit,
309+
}
310+
tmpItem := models.Registration{
311+
StakingKey: cert.StakeCredential.Credential.Bytes(),
312+
AddedSlot: slot,
313+
DepositAmount: deposit,
314+
}
315+
if txn != nil {
316+
if accountResult := txn.Create(&tmpAccount); accountResult.Error != nil {
317+
return accountResult.Error
318+
}
319+
if result := txn.Create(&tmpItem); result.Error != nil {
320+
return result.Error
321+
}
322+
} else {
323+
if accountResult := d.DB().Create(&tmpAccount); accountResult.Error != nil {
324+
return accountResult.Error
325+
}
326+
if result := d.DB().Create(&tmpItem); result.Error != nil {
327+
return result.Error
328+
}
329+
}
330+
return nil
331+
}

database/plugin/metadata/store.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ type MetadataStore interface {
9292
uint64, // epoch
9393
*gorm.DB,
9494
) error
95+
SetRegistration(
96+
*lcommon.RegistrationCertificate,
97+
uint64, // slot
98+
uint64, // deposit
99+
*gorm.DB,
100+
) error
95101
SetStakeDelegation(
96102
*lcommon.StakeDelegationCertificate,
97103
uint64, // slot

ledger/certs.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -56,6 +56,16 @@ func (ls *LedgerState) processTransactionCertificates(
5656
if err != nil {
5757
return err
5858
}
59+
case *lcommon.RegistrationCertificate:
60+
err := ls.db.SetRegistration(
61+
cert,
62+
blockPoint.Slot,
63+
certDeposit,
64+
txn,
65+
)
66+
if err != nil {
67+
return err
68+
}
5969
case *lcommon.StakeDelegationCertificate:
6070
err := ls.db.SetStakeDelegation(
6171
cert,

ledger/eras/conway.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ func CertDepositConway(
132132
switch cert.(type) {
133133
case *lcommon.PoolRegistrationCertificate:
134134
return uint64(tmpPparams.PoolDeposit), nil
135+
case *lcommon.RegistrationCertificate:
136+
return uint64(tmpPparams.KeyDeposit), nil
135137
case *lcommon.StakeRegistrationCertificate:
136138
return uint64(tmpPparams.KeyDeposit), nil
137139
default:

0 commit comments

Comments
 (0)