Skip to content

Commit 8dcd97c

Browse files
authored
feat(database): account tracking on credential registration (#623)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 48c8d92 commit 8dcd97c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

database/plugin/metadata/sqlite/certs.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,27 @@ func (d *MetadataStoreSqlite) SetStakeRegistration(
268268
slot, deposit uint64,
269269
txn *gorm.DB,
270270
) error {
271+
tmpAccount := models.Account{
272+
StakingKey: cert.StakeRegistration.Credential.Bytes(),
273+
AddedSlot: slot,
274+
DepositAmount: deposit,
275+
}
271276
tmpItem := models.StakeRegistration{
272277
StakingKey: cert.StakeRegistration.Credential.Bytes(),
273278
AddedSlot: slot,
274279
DepositAmount: deposit,
275280
}
276281
if txn != nil {
282+
if accountResult := txn.Create(&tmpAccount); accountResult.Error != nil {
283+
return accountResult.Error
284+
}
277285
if result := txn.Create(&tmpItem); result.Error != nil {
278286
return result.Error
279287
}
280288
} else {
289+
if accountResult := d.DB().Create(&tmpAccount); accountResult.Error != nil {
290+
return accountResult.Error
291+
}
281292
if result := d.DB().Create(&tmpItem); result.Error != nil {
282293
return result.Error
283294
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
type Account struct {
18+
ID uint `gorm:"primarykey"`
19+
StakingKey []byte `gorm:"index,unique"`
20+
DepositAmount uint64
21+
AddedSlot uint64
22+
Pool []byte `gorm:"index"`
23+
Drep []byte `gorm:"index"`
24+
}
25+
26+
func (a *Account) TableName() string {
27+
return "account"
28+
}

database/plugin/metadata/sqlite/models/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package models
1616

1717
// MigrateModels contains a list of model objects that should have DB migrations applied
1818
var MigrateModels = []any{
19+
&Account{},
1920
&AuthCommitteeHot{},
2021
&Deregistration{},
2122
&Drep{},

0 commit comments

Comments
 (0)