File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,19 @@ func (d *Database) SetAccount(
7070 )
7171}
7272
73+ // SetDeregistration saves a deregistration certificate
74+ func (d * Database ) SetDeregistration (
75+ cert * lcommon.DeregistrationCertificate ,
76+ slot uint64 ,
77+ txn * Txn ,
78+ ) error {
79+ return d .metadata .SetDeregistration (
80+ cert ,
81+ slot ,
82+ txn .Metadata (),
83+ )
84+ }
85+
7386// SetRegistration saves a registration certificate
7487func (d * Database ) SetRegistration (
7588 cert * lcommon.RegistrationCertificate ,
Original file line number Diff line number Diff line change @@ -66,6 +66,40 @@ func (d *MetadataStoreSqlite) SetAccount(
6666 return nil
6767}
6868
69+ // SetDeregistration saves a deregistration certificate
70+ func (d * MetadataStoreSqlite ) SetDeregistration (
71+ cert * lcommon.DeregistrationCertificate ,
72+ slot uint64 ,
73+ txn * gorm.DB ,
74+ ) error {
75+ stakeKey := cert .StakeCredential .Credential .Bytes ()
76+ tmpAccount , err := d .GetAccount (stakeKey , txn )
77+ if err != nil {
78+ return err
79+ }
80+ tmpItem := models.Deregistration {
81+ StakingKey : stakeKey ,
82+ AddedSlot : slot ,
83+ }
84+ tmpAccount .Active = false
85+ if txn != nil {
86+ if accountErr := txn .Save (& tmpAccount ); accountErr .Error != nil {
87+ return accountErr .Error
88+ }
89+ if result := txn .Create (& tmpItem ); result .Error != nil {
90+ return result .Error
91+ }
92+ } else {
93+ if accountErr := d .DB ().Save (& tmpAccount ); accountErr .Error != nil {
94+ return accountErr .Error
95+ }
96+ if result := d .DB ().Create (& tmpItem ); result .Error != nil {
97+ return result .Error
98+ }
99+ }
100+ return nil
101+ }
102+
69103// SetStakeRegistration saves a stake registration certificate and account
70104func (d * MetadataStoreSqlite ) SetStakeRegistration (
71105 cert * lcommon.StakeRegistrationCertificate ,
Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ type MetadataStore interface {
7070 bool , // active
7171 * gorm.DB ,
7272 ) error
73+ SetDeregistration (
74+ * lcommon.DeregistrationCertificate ,
75+ uint64 , // slot
76+ * gorm.DB ,
77+ ) error
7378 SetEpoch (
7479 uint64 , // slot
7580 uint64 , // epoch
Original file line number Diff line number Diff line change @@ -37,6 +37,15 @@ func (ls *LedgerState) processTransactionCertificates(
3737 return err
3838 }
3939 switch cert := tmpCert .(type ) {
40+ case * lcommon.DeregistrationCertificate :
41+ err := ls .db .SetDeregistration (
42+ cert ,
43+ blockPoint .Slot ,
44+ txn ,
45+ )
46+ if err != nil {
47+ return err
48+ }
4049 case * lcommon.PoolRegistrationCertificate :
4150 err := ls .db .SetPoolRegistration (
4251 cert ,
You can’t perform that action at this time.
0 commit comments