@@ -16,97 +16,10 @@ package sqlite
16
16
17
17
import (
18
18
"github.com/blinklabs-io/dingo/database/plugin/metadata/sqlite/models"
19
- "github.com/blinklabs-io/dingo/database/types"
20
- "github.com/blinklabs-io/gouroboros/cbor"
21
19
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
22
20
"gorm.io/gorm"
23
21
)
24
22
25
- // GetPoolRegistrations returns pool registration certificates
26
- func (d * MetadataStoreSqlite ) GetPoolRegistrations (
27
- pkh lcommon.PoolKeyHash ,
28
- txn * gorm.DB ,
29
- ) ([]lcommon.PoolRegistrationCertificate , error ) {
30
- ret := []lcommon.PoolRegistrationCertificate {}
31
- certs := []models.PoolRegistration {}
32
- if txn != nil {
33
- result := txn .Where ("pool_key_hash = ?" , lcommon .Blake2b224 (pkh ).Bytes ()).
34
- Order ("id DESC" ).
35
- Find (& certs )
36
- if result .Error != nil {
37
- return ret , result .Error
38
- }
39
- } else {
40
- result := d .DB ().Where ("pool_key_hash = ?" , lcommon .Blake2b224 (pkh ).Bytes ()).
41
- Order ("id DESC" ).
42
- Find (& certs )
43
- if result .Error != nil {
44
- return ret , result .Error
45
- }
46
- }
47
- var addrKeyHash lcommon.AddrKeyHash
48
- var tmpCert lcommon.PoolRegistrationCertificate
49
- var tmpMargin cbor.Rat
50
- var tmpRelay lcommon.PoolRelay
51
- for _ , cert := range certs {
52
- tmpMargin = cbor.Rat {Rat : cert .Margin .Rat }
53
- tmpCert = lcommon.PoolRegistrationCertificate {
54
- CertType : lcommon .CertificateTypePoolRegistration ,
55
- Operator : lcommon .PoolKeyHash (
56
- lcommon .NewBlake2b224 (cert .PoolKeyHash ),
57
- ),
58
- VrfKeyHash : lcommon .VrfKeyHash (
59
- lcommon .NewBlake2b256 (cert .VrfKeyHash ),
60
- ),
61
- Pledge : uint64 (cert .Pledge ),
62
- Cost : uint64 (cert .Cost ),
63
- Margin : tmpMargin ,
64
- RewardAccount : lcommon .AddrKeyHash (
65
- lcommon .NewBlake2b224 (cert .RewardAccount ),
66
- ),
67
- }
68
- for _ , owner := range cert .Owners {
69
- addrKeyHash = lcommon .AddrKeyHash (
70
- lcommon .NewBlake2b224 (owner .KeyHash ),
71
- )
72
- tmpCert .PoolOwners = append (tmpCert .PoolOwners , addrKeyHash )
73
- }
74
- for _ , relay := range cert .Relays {
75
- tmpRelay = lcommon.PoolRelay {}
76
- // Determine type
77
- if relay .Port != 0 {
78
- port := uint32 (relay .Port ) // #nosec G115
79
- tmpRelay .Port = & port
80
- if relay .Hostname != "" {
81
- hostname := relay .Hostname
82
- tmpRelay .Type = lcommon .PoolRelayTypeSingleHostName
83
- tmpRelay .Hostname = & hostname
84
- } else {
85
- tmpRelay .Type = lcommon .PoolRelayTypeSingleHostAddress
86
- tmpRelay .Ipv4 = relay .Ipv4
87
- tmpRelay .Ipv6 = relay .Ipv6
88
- }
89
- } else {
90
- hostname := relay .Hostname
91
- tmpRelay .Type = lcommon .PoolRelayTypeMultiHostName
92
- tmpRelay .Hostname = & hostname
93
- }
94
- tmpCert .Relays = append (tmpCert .Relays , tmpRelay )
95
- }
96
- if cert .MetadataUrl != "" {
97
- poolMetadata := & lcommon.PoolMetadata {
98
- Url : cert .MetadataUrl ,
99
- Hash : lcommon .PoolMetadataHash (
100
- lcommon .NewBlake2b256 (cert .MetadataHash ),
101
- ),
102
- }
103
- tmpCert .PoolMetadata = poolMetadata
104
- }
105
- ret = append (ret , tmpCert )
106
- }
107
- return ret , nil
108
- }
109
-
110
23
// GetStakeRegistrations returns stake registration certificates
111
24
func (d * MetadataStoreSqlite ) GetStakeRegistrations (
112
25
stakingKey []byte ,
@@ -144,80 +57,6 @@ func (d *MetadataStoreSqlite) GetStakeRegistrations(
144
57
return ret , nil
145
58
}
146
59
147
- // SetPoolRegistration saves a pool registration certificate
148
- func (d * MetadataStoreSqlite ) SetPoolRegistration (
149
- cert * lcommon.PoolRegistrationCertificate ,
150
- slot , deposit uint64 ,
151
- txn * gorm.DB ,
152
- ) error {
153
- tmpItem := models.PoolRegistration {
154
- PoolKeyHash : cert .Operator [:],
155
- VrfKeyHash : cert .VrfKeyHash [:],
156
- Pledge : types .Uint64 (cert .Pledge ),
157
- Cost : types .Uint64 (cert .Cost ),
158
- Margin : & types.Rat {Rat : cert .Margin .Rat },
159
- AddedSlot : slot ,
160
- DepositAmount : deposit ,
161
- }
162
- if cert .PoolMetadata != nil {
163
- tmpItem .MetadataUrl = cert .PoolMetadata .Url
164
- tmpItem .MetadataHash = cert .PoolMetadata .Hash [:]
165
- }
166
- for _ , owner := range cert .PoolOwners {
167
- tmpItem .Owners = append (
168
- tmpItem .Owners ,
169
- models.PoolRegistrationOwner {KeyHash : owner [:]},
170
- )
171
- }
172
- var tmpRelay models.PoolRegistrationRelay
173
- for _ , relay := range cert .Relays {
174
- tmpRelay = models.PoolRegistrationRelay {
175
- Ipv4 : relay .Ipv4 ,
176
- Ipv6 : relay .Ipv6 ,
177
- }
178
- if relay .Port != nil {
179
- tmpRelay .Port = uint (* relay .Port )
180
- }
181
- if relay .Hostname != nil {
182
- tmpRelay .Hostname = * relay .Hostname
183
- }
184
- tmpItem .Relays = append (tmpItem .Relays , tmpRelay )
185
- }
186
- if txn != nil {
187
- if result := txn .Create (& tmpItem ); result .Error != nil {
188
- return result .Error
189
- }
190
- } else {
191
- if result := d .DB ().Create (& tmpItem ); result .Error != nil {
192
- return result .Error
193
- }
194
- }
195
- return nil
196
- }
197
-
198
- // SetPoolRetirement saves a pool retirement certificate
199
- func (d * MetadataStoreSqlite ) SetPoolRetirement (
200
- cert * lcommon.PoolRetirementCertificate ,
201
- slot uint64 ,
202
- txn * gorm.DB ,
203
- ) error {
204
- tmpItem := models.PoolRetirement {
205
- PoolKeyHash : cert .PoolKeyHash [:],
206
- Epoch : cert .Epoch ,
207
- AddedSlot : slot ,
208
- }
209
- if txn != nil {
210
- if result := txn .Create (& tmpItem ); result .Error != nil {
211
- return result .Error
212
- }
213
- } else {
214
- if result := d .DB ().Create (& tmpItem ); result .Error != nil {
215
- return result .Error
216
- }
217
- }
218
- return nil
219
- }
220
-
221
60
// SetStakeDelegation saves a stake delegation certificate
222
61
func (d * MetadataStoreSqlite ) SetStakeDelegation (
223
62
cert * lcommon.StakeDelegationCertificate ,
0 commit comments