@blinklabs/dingo 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/{bin/dingo → dingo} +0 -0
- package/dingo.yaml.example +53 -0
- package/package.json +2 -2
- package/.github/CODEOWNERS +0 -5
- package/.github/assets/dingo-ate-my-blockchain.png +0 -0
- package/.github/assets/dingo-illustration.png +0 -0
- package/.github/assets/dingo-logo-with-text-horizontal.png +0 -0
- package/.github/assets/dingo-logo-with-text.png +0 -0
- package/.github/dependabot.yml +0 -19
- package/.github/dingo-20241210.png +0 -0
- package/.github/dingo.md +0 -56
- package/.github/workflows/ci-docker.yml +0 -36
- package/.github/workflows/conventional-commits.yml +0 -17
- package/.github/workflows/go-test.yml +0 -29
- package/.github/workflows/golangci-lint.yml +0 -23
- package/.github/workflows/publish.yml +0 -207
- package/Dockerfile +0 -25
- package/Makefile +0 -53
- package/blockfetch.go +0 -144
- package/chain/chain.go +0 -504
- package/chain/chain_test.go +0 -468
- package/chain/errors.go +0 -80
- package/chain/event.go +0 -33
- package/chain/iter.go +0 -64
- package/chainsync/chainsync.go +0 -97
- package/chainsync.go +0 -223
- package/cmd/dingo/load.go +0 -52
- package/cmd/dingo/main.go +0 -118
- package/cmd/dingo/serve.go +0 -49
- package/config/cardano/node.go +0 -192
- package/config/cardano/node_test.go +0 -85
- package/config/cardano/preview/README.md +0 -4
- package/config/cardano/preview/alonzo-genesis.json +0 -196
- package/config/cardano/preview/byron-genesis.json +0 -117
- package/config/cardano/preview/config.json +0 -114
- package/config/cardano/preview/conway-genesis.json +0 -297
- package/config/cardano/preview/shelley-genesis.json +0 -68
- package/config.go +0 -245
- package/connmanager/connection_manager.go +0 -105
- package/connmanager/connection_manager_test.go +0 -185
- package/connmanager/event.go +0 -37
- package/connmanager/listener.go +0 -140
- package/connmanager/outbound.go +0 -93
- package/connmanager/socket.go +0 -55
- package/connmanager/unix.go +0 -78
- package/custom-p2p-topology.json +0 -24
- package/custom-p2p-topology.json.backup +0 -24
- package/custom-p2p-topology.json.mainnet +0 -37
- package/database/account.go +0 -180
- package/database/block.go +0 -362
- package/database/certs.go +0 -53
- package/database/commit_timestamp.go +0 -77
- package/database/database.go +0 -118
- package/database/database_test.go +0 -62
- package/database/drep.go +0 -47
- package/database/epoch.go +0 -121
- package/database/immutable/chunk.go +0 -182
- package/database/immutable/immutable.go +0 -350
- package/database/immutable/immutable_test.go +0 -59
- package/database/immutable/primary.go +0 -106
- package/database/immutable/secondary.go +0 -103
- package/database/immutable/testdata/08893.chunk +0 -0
- package/database/immutable/testdata/08893.primary +0 -0
- package/database/immutable/testdata/08893.secondary +0 -0
- package/database/immutable/testdata/08894.chunk +0 -0
- package/database/immutable/testdata/08894.primary +0 -0
- package/database/immutable/testdata/08894.secondary +0 -0
- package/database/immutable/testdata/README.md +0 -4
- package/database/plugin/blob/badger/commit_timestamp.go +0 -50
- package/database/plugin/blob/badger/database.go +0 -152
- package/database/plugin/blob/badger/logger.go +0 -63
- package/database/plugin/blob/badger/metrics.go +0 -98
- package/database/plugin/blob/blob.go +0 -19
- package/database/plugin/blob/store.go +0 -40
- package/database/plugin/log.go +0 -27
- package/database/plugin/metadata/metadata.go +0 -19
- package/database/plugin/metadata/sqlite/account.go +0 -313
- package/database/plugin/metadata/sqlite/certs.go +0 -58
- package/database/plugin/metadata/sqlite/commit_timestamp.go +0 -68
- package/database/plugin/metadata/sqlite/database.go +0 -218
- package/database/plugin/metadata/sqlite/drep.go +0 -140
- package/database/plugin/metadata/sqlite/epoch.go +0 -120
- package/database/plugin/metadata/sqlite/models/account.go +0 -118
- package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +0 -26
- package/database/plugin/metadata/sqlite/models/drep.go +0 -52
- package/database/plugin/metadata/sqlite/models/epoch.go +0 -31
- package/database/plugin/metadata/sqlite/models/models.go +0 -46
- package/database/plugin/metadata/sqlite/models/pool.go +0 -97
- package/database/plugin/metadata/sqlite/models/pparam_update.go +0 -27
- package/database/plugin/metadata/sqlite/models/pparams.go +0 -27
- package/database/plugin/metadata/sqlite/models/resign_committee_cold.go +0 -27
- package/database/plugin/metadata/sqlite/models/stake_vote_delegation.go +0 -27
- package/database/plugin/metadata/sqlite/models/tip.go +0 -26
- package/database/plugin/metadata/sqlite/models/update_drep.go +0 -27
- package/database/plugin/metadata/sqlite/models/utxo.go +0 -30
- package/database/plugin/metadata/sqlite/models/vote_delegation.go +0 -26
- package/database/plugin/metadata/sqlite/models/vote_registration_delegation.go +0 -15
- package/database/plugin/metadata/sqlite/pool.go +0 -240
- package/database/plugin/metadata/sqlite/pparams.go +0 -110
- package/database/plugin/metadata/sqlite/tip.go +0 -83
- package/database/plugin/metadata/sqlite/utxo.go +0 -292
- package/database/plugin/metadata/store.go +0 -198
- package/database/plugin/option.go +0 -190
- package/database/plugin/plugin.go +0 -20
- package/database/plugin/register.go +0 -118
- package/database/pparams.go +0 -145
- package/database/tip.go +0 -45
- package/database/txn.go +0 -147
- package/database/types/types.go +0 -74
- package/database/types/types_test.go +0 -83
- package/database/utxo.go +0 -263
- package/dist/artifacts.json +0 -1
- package/dist/checksums.txt +0 -22
- package/dist/config.yaml +0 -253
- package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz +0 -0
- package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz.sbom.json +0 -1
- package/dist/dingo_darwin_amd64_v1/dingo +0 -0
- package/dist/dingo_darwin_arm64_v8.0/dingo +0 -0
- package/dist/dingo_linux_amd64_v1/dingo +0 -0
- package/dist/dingo_linux_arm64_v8.0/dingo +0 -0
- package/dist/homebrew/dingo.rb +0 -51
- package/dist/metadata.json +0 -1
- package/event/event.go +0 -141
- package/event/event_test.go +0 -115
- package/event/metrics.go +0 -44
- package/go.mod +0 -98
- package/go.sum +0 -358
- package/internal/config/config.go +0 -145
- package/internal/config/config_test.go +0 -118
- package/internal/node/load.go +0 -149
- package/internal/node/node.go +0 -176
- package/internal/version/version.go +0 -33
- package/ledger/certs.go +0 -164
- package/ledger/chainsync.go +0 -504
- package/ledger/delta.go +0 -99
- package/ledger/eras/allegra.go +0 -154
- package/ledger/eras/alonzo.go +0 -156
- package/ledger/eras/babbage.go +0 -154
- package/ledger/eras/byron.go +0 -42
- package/ledger/eras/conway.go +0 -166
- package/ledger/eras/eras.go +0 -44
- package/ledger/eras/mary.go +0 -154
- package/ledger/eras/shelley.go +0 -164
- package/ledger/error.go +0 -19
- package/ledger/event.go +0 -50
- package/ledger/metrics.go +0 -53
- package/ledger/queries.go +0 -258
- package/ledger/slot.go +0 -127
- package/ledger/slot_test.go +0 -147
- package/ledger/state.go +0 -821
- package/ledger/view.go +0 -73
- package/localstatequery.go +0 -50
- package/localtxmonitor.go +0 -44
- package/localtxsubmission.go +0 -52
- package/mempool/consumer.go +0 -98
- package/mempool/mempool.go +0 -322
- package/node.go +0 -320
- package/peergov/event.go +0 -27
- package/peergov/peer.go +0 -67
- package/peergov/peergov.go +0 -290
- package/peersharing.go +0 -70
- package/preview-local-topology.json +0 -23
- package/topology/topology.go +0 -69
- package/topology/topology_test.go +0 -179
- package/tracing.go +0 -65
- package/txsubmission.go +0 -233
- package/utxorpc/query.go +0 -311
- package/utxorpc/submit.go +0 -395
- package/utxorpc/sync.go +0 -276
- package/utxorpc/utxorpc.go +0 -166
- package/utxorpc/watch.go +0 -310
|
@@ -1,313 +0,0 @@
|
|
|
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 sqlite
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"github.com/blinklabs-io/dingo/database/plugin/metadata/sqlite/models"
|
|
19
|
-
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
|
|
20
|
-
"gorm.io/gorm"
|
|
21
|
-
"gorm.io/gorm/clause"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
// GetAccount gets an account
|
|
25
|
-
func (d *MetadataStoreSqlite) GetAccount(
|
|
26
|
-
stakeKey []byte,
|
|
27
|
-
txn *gorm.DB,
|
|
28
|
-
) (models.Account, error) {
|
|
29
|
-
ret := models.Account{}
|
|
30
|
-
tmpAccount := models.Account{}
|
|
31
|
-
if txn != nil {
|
|
32
|
-
if result := txn.First(&tmpAccount, "staking_key = ?", stakeKey); result.Error != nil {
|
|
33
|
-
return ret, result.Error
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
if result := d.DB().First(&tmpAccount, "staking_key = ?", stakeKey); result.Error != nil {
|
|
37
|
-
return ret, result.Error
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
ret = tmpAccount
|
|
41
|
-
return ret, nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// SetAccount saves an account
|
|
45
|
-
func (d *MetadataStoreSqlite) SetAccount(
|
|
46
|
-
stakeKey, pkh, drep []byte,
|
|
47
|
-
slot uint64,
|
|
48
|
-
active bool,
|
|
49
|
-
txn *gorm.DB,
|
|
50
|
-
) error {
|
|
51
|
-
tmpItem := models.Account{
|
|
52
|
-
StakingKey: stakeKey,
|
|
53
|
-
AddedSlot: slot,
|
|
54
|
-
Pool: pkh,
|
|
55
|
-
Drep: drep,
|
|
56
|
-
}
|
|
57
|
-
if txn != nil {
|
|
58
|
-
if result := txn.Clauses(clause.OnConflict{UpdateAll: true}).Create(&tmpItem); result.Error != nil {
|
|
59
|
-
return result.Error
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
if result := d.DB().Clauses(clause.OnConflict{UpdateAll: true}).Create(&tmpItem); result.Error != nil {
|
|
63
|
-
return result.Error
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return nil
|
|
67
|
-
}
|
|
68
|
-
|
|
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
|
-
|
|
103
|
-
// SetRegistration saves a registration certificate and account
|
|
104
|
-
func (d *MetadataStoreSqlite) SetRegistration(
|
|
105
|
-
cert *lcommon.RegistrationCertificate,
|
|
106
|
-
slot, deposit uint64,
|
|
107
|
-
txn *gorm.DB,
|
|
108
|
-
) error {
|
|
109
|
-
stakeKey := cert.StakeCredential.Credential.Bytes()
|
|
110
|
-
tmpItem := models.Registration{
|
|
111
|
-
StakingKey: stakeKey,
|
|
112
|
-
AddedSlot: slot,
|
|
113
|
-
DepositAmount: deposit,
|
|
114
|
-
}
|
|
115
|
-
if err := d.SetAccount(stakeKey, nil, nil, slot, true, txn); err != nil {
|
|
116
|
-
return err
|
|
117
|
-
}
|
|
118
|
-
if txn != nil {
|
|
119
|
-
if result := txn.Create(&tmpItem); result.Error != nil {
|
|
120
|
-
return result.Error
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
if result := d.DB().Create(&tmpItem); result.Error != nil {
|
|
124
|
-
return result.Error
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return nil
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// SetStakeDelegation saves a stake delegation certificate
|
|
131
|
-
func (d *MetadataStoreSqlite) SetStakeDelegation(
|
|
132
|
-
cert *lcommon.StakeDelegationCertificate,
|
|
133
|
-
slot uint64,
|
|
134
|
-
txn *gorm.DB,
|
|
135
|
-
) error {
|
|
136
|
-
stakeKey := cert.StakeCredential.Credential.Bytes()
|
|
137
|
-
tmpAccount, err := d.GetAccount(stakeKey, txn)
|
|
138
|
-
if err != nil {
|
|
139
|
-
return err
|
|
140
|
-
}
|
|
141
|
-
tmpItem := models.StakeDelegation{
|
|
142
|
-
StakingKey: stakeKey,
|
|
143
|
-
PoolKeyHash: cert.PoolKeyHash[:],
|
|
144
|
-
AddedSlot: slot,
|
|
145
|
-
}
|
|
146
|
-
tmpAccount.Pool = tmpItem.PoolKeyHash
|
|
147
|
-
if txn != nil {
|
|
148
|
-
if accountErr := txn.Save(&tmpAccount); accountErr.Error != nil {
|
|
149
|
-
return accountErr.Error
|
|
150
|
-
}
|
|
151
|
-
if result := txn.Create(&tmpItem); result.Error != nil {
|
|
152
|
-
return result.Error
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
if accountErr := d.DB().Save(&tmpAccount); accountErr.Error != nil {
|
|
156
|
-
return accountErr.Error
|
|
157
|
-
}
|
|
158
|
-
if result := d.DB().Create(&tmpItem); result.Error != nil {
|
|
159
|
-
return result.Error
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return nil
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// SetStakeDeregistration saves a stake deregistration certificate
|
|
166
|
-
func (d *MetadataStoreSqlite) SetStakeDeregistration(
|
|
167
|
-
cert *lcommon.StakeDeregistrationCertificate,
|
|
168
|
-
slot uint64,
|
|
169
|
-
txn *gorm.DB,
|
|
170
|
-
) error {
|
|
171
|
-
stakeKey := cert.StakeDeregistration.Credential.Bytes()
|
|
172
|
-
tmpAccount, err := d.GetAccount(stakeKey, txn)
|
|
173
|
-
if err != nil {
|
|
174
|
-
return err
|
|
175
|
-
}
|
|
176
|
-
tmpItem := models.StakeDeregistration{
|
|
177
|
-
StakingKey: stakeKey,
|
|
178
|
-
AddedSlot: slot,
|
|
179
|
-
}
|
|
180
|
-
tmpAccount.Active = false
|
|
181
|
-
if txn != nil {
|
|
182
|
-
if accountErr := txn.Save(&tmpAccount); accountErr.Error != nil {
|
|
183
|
-
return accountErr.Error
|
|
184
|
-
}
|
|
185
|
-
if result := txn.Create(&tmpItem); result.Error != nil {
|
|
186
|
-
return result.Error
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
if accountErr := d.DB().Save(&tmpAccount); accountErr.Error != nil {
|
|
190
|
-
return accountErr.Error
|
|
191
|
-
}
|
|
192
|
-
if result := d.DB().Create(&tmpItem); result.Error != nil {
|
|
193
|
-
return result.Error
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return nil
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// SetStakeRegistration saves a stake registration certificate and account
|
|
200
|
-
func (d *MetadataStoreSqlite) SetStakeRegistration(
|
|
201
|
-
cert *lcommon.StakeRegistrationCertificate,
|
|
202
|
-
slot, deposit uint64,
|
|
203
|
-
txn *gorm.DB,
|
|
204
|
-
) error {
|
|
205
|
-
stakeKey := cert.StakeRegistration.Credential.Bytes()
|
|
206
|
-
tmpItem := models.StakeRegistration{
|
|
207
|
-
StakingKey: stakeKey,
|
|
208
|
-
AddedSlot: slot,
|
|
209
|
-
DepositAmount: deposit,
|
|
210
|
-
}
|
|
211
|
-
if err := d.SetAccount(stakeKey, nil, nil, slot, true, txn); err != nil {
|
|
212
|
-
return err
|
|
213
|
-
}
|
|
214
|
-
if txn != nil {
|
|
215
|
-
if result := txn.Create(&tmpItem); result.Error != nil {
|
|
216
|
-
return result.Error
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
if result := d.DB().Create(&tmpItem); result.Error != nil {
|
|
220
|
-
return result.Error
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return nil
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// SetStakeRegistrationDelegation saves a stake registration delegation certificate and account
|
|
227
|
-
func (d *MetadataStoreSqlite) SetStakeRegistrationDelegation(
|
|
228
|
-
cert *lcommon.StakeRegistrationDelegationCertificate,
|
|
229
|
-
slot, deposit uint64,
|
|
230
|
-
txn *gorm.DB,
|
|
231
|
-
) error {
|
|
232
|
-
stakeKey := cert.StakeCredential.Credential.Bytes()
|
|
233
|
-
pkh := cert.PoolKeyHash[:]
|
|
234
|
-
tmpItem := models.StakeRegistrationDelegation{
|
|
235
|
-
StakingKey: stakeKey,
|
|
236
|
-
PoolKeyHash: pkh,
|
|
237
|
-
AddedSlot: slot,
|
|
238
|
-
DepositAmount: deposit,
|
|
239
|
-
}
|
|
240
|
-
if err := d.SetAccount(stakeKey, pkh, nil, slot, true, txn); err != nil {
|
|
241
|
-
return err
|
|
242
|
-
}
|
|
243
|
-
if txn != nil {
|
|
244
|
-
if result := txn.Create(&tmpItem); result.Error != nil {
|
|
245
|
-
return result.Error
|
|
246
|
-
}
|
|
247
|
-
} else {
|
|
248
|
-
if result := d.DB().Create(&tmpItem); result.Error != nil {
|
|
249
|
-
return result.Error
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return nil
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// SetStakeVoteRegistrationDelegation saves a stake vote registration delegation certificate and account
|
|
256
|
-
func (d *MetadataStoreSqlite) SetStakeVoteRegistrationDelegation(
|
|
257
|
-
cert *lcommon.StakeVoteRegistrationDelegationCertificate,
|
|
258
|
-
slot, deposit uint64,
|
|
259
|
-
txn *gorm.DB,
|
|
260
|
-
) error {
|
|
261
|
-
stakeKey := cert.StakeCredential.Credential.Bytes()
|
|
262
|
-
pkh := cert.PoolKeyHash[:]
|
|
263
|
-
drep := cert.Drep.Credential[:]
|
|
264
|
-
tmpItem := models.StakeVoteRegistrationDelegation{
|
|
265
|
-
StakingKey: stakeKey,
|
|
266
|
-
PoolKeyHash: pkh,
|
|
267
|
-
Drep: drep,
|
|
268
|
-
AddedSlot: slot,
|
|
269
|
-
DepositAmount: deposit,
|
|
270
|
-
}
|
|
271
|
-
if err := d.SetAccount(stakeKey, pkh, drep, slot, true, txn); err != nil {
|
|
272
|
-
return err
|
|
273
|
-
}
|
|
274
|
-
if txn != nil {
|
|
275
|
-
if result := txn.Create(&tmpItem); result.Error != nil {
|
|
276
|
-
return result.Error
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
if result := d.DB().Create(&tmpItem); result.Error != nil {
|
|
280
|
-
return result.Error
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return nil
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// SetVoteRegistrationDelegation saves a vote registration delegation certificate and account
|
|
287
|
-
func (d *MetadataStoreSqlite) SetVoteRegistrationDelegation(
|
|
288
|
-
cert *lcommon.VoteRegistrationDelegationCertificate,
|
|
289
|
-
slot, deposit uint64,
|
|
290
|
-
txn *gorm.DB,
|
|
291
|
-
) error {
|
|
292
|
-
stakeKey := cert.StakeCredential.Credential.Bytes()
|
|
293
|
-
drep := cert.Drep.Credential[:]
|
|
294
|
-
tmpItem := models.VoteRegistrationDelegation{
|
|
295
|
-
StakingKey: stakeKey,
|
|
296
|
-
Drep: drep,
|
|
297
|
-
AddedSlot: slot,
|
|
298
|
-
DepositAmount: deposit,
|
|
299
|
-
}
|
|
300
|
-
if err := d.SetAccount(stakeKey, nil, drep, slot, true, txn); err != nil {
|
|
301
|
-
return err
|
|
302
|
-
}
|
|
303
|
-
if txn != nil {
|
|
304
|
-
if result := txn.Create(&tmpItem); result.Error != nil {
|
|
305
|
-
return result.Error
|
|
306
|
-
}
|
|
307
|
-
} else {
|
|
308
|
-
if result := d.DB().Create(&tmpItem); result.Error != nil {
|
|
309
|
-
return result.Error
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return nil
|
|
313
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
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 sqlite
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"github.com/blinklabs-io/dingo/database/plugin/metadata/sqlite/models"
|
|
19
|
-
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
|
|
20
|
-
"gorm.io/gorm"
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
// GetStakeRegistrations returns stake registration certificates
|
|
24
|
-
func (d *MetadataStoreSqlite) GetStakeRegistrations(
|
|
25
|
-
stakingKey []byte,
|
|
26
|
-
txn *gorm.DB,
|
|
27
|
-
) ([]lcommon.StakeRegistrationCertificate, error) {
|
|
28
|
-
ret := []lcommon.StakeRegistrationCertificate{}
|
|
29
|
-
certs := []models.StakeRegistration{}
|
|
30
|
-
if txn != nil {
|
|
31
|
-
result := txn.Where("staking_key = ?", stakingKey).
|
|
32
|
-
Order("id DESC").
|
|
33
|
-
Find(&certs)
|
|
34
|
-
if result.Error != nil {
|
|
35
|
-
return ret, result.Error
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
result := d.DB().Where("staking_key = ?", stakingKey).
|
|
39
|
-
Order("id DESC").
|
|
40
|
-
Find(&certs)
|
|
41
|
-
if result.Error != nil {
|
|
42
|
-
return ret, result.Error
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
var tmpCert lcommon.StakeRegistrationCertificate
|
|
46
|
-
for _, cert := range certs {
|
|
47
|
-
tmpCert = lcommon.StakeRegistrationCertificate{
|
|
48
|
-
CertType: lcommon.CertificateTypeStakeRegistration,
|
|
49
|
-
StakeRegistration: lcommon.Credential{
|
|
50
|
-
// TODO: determine correct type
|
|
51
|
-
// CredType: lcommon.CredentialTypeAddrKeyHash,
|
|
52
|
-
Credential: lcommon.CredentialHash(cert.StakingKey),
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
ret = append(ret, tmpCert)
|
|
56
|
-
}
|
|
57
|
-
return ret, nil
|
|
58
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
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 sqlite
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"errors"
|
|
19
|
-
|
|
20
|
-
"gorm.io/gorm"
|
|
21
|
-
"gorm.io/gorm/clause"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const (
|
|
25
|
-
commitTimestampRowId = 1
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
// CommitTimestamp represents the sqlite table used to track the current commit timestamp
|
|
29
|
-
type CommitTimestamp struct {
|
|
30
|
-
ID uint `gorm:"primarykey"`
|
|
31
|
-
Timestamp int64
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
func (CommitTimestamp) TableName() string {
|
|
35
|
-
return "commit_timestamp"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
func (d *MetadataStoreSqlite) GetCommitTimestamp() (int64, error) {
|
|
39
|
-
// Get value from sqlite
|
|
40
|
-
var tmpCommitTimestamp CommitTimestamp
|
|
41
|
-
result := d.DB().First(&tmpCommitTimestamp)
|
|
42
|
-
if result.Error != nil {
|
|
43
|
-
// It's not an error if there's no records found
|
|
44
|
-
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
|
45
|
-
return 0, nil
|
|
46
|
-
}
|
|
47
|
-
return 0, result.Error
|
|
48
|
-
}
|
|
49
|
-
return tmpCommitTimestamp.Timestamp, nil
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
func (d *MetadataStoreSqlite) SetCommitTimestamp(
|
|
53
|
-
txn *gorm.DB,
|
|
54
|
-
timestamp int64,
|
|
55
|
-
) error {
|
|
56
|
-
tmpCommitTimestamp := CommitTimestamp{
|
|
57
|
-
ID: commitTimestampRowId,
|
|
58
|
-
Timestamp: timestamp,
|
|
59
|
-
}
|
|
60
|
-
result := txn.Clauses(clause.OnConflict{
|
|
61
|
-
Columns: []clause.Column{{Name: "id"}},
|
|
62
|
-
DoUpdates: clause.AssignmentColumns([]string{"timestamp"}),
|
|
63
|
-
}).Create(&tmpCommitTimestamp)
|
|
64
|
-
if result.Error != nil {
|
|
65
|
-
return result.Error
|
|
66
|
-
}
|
|
67
|
-
return nil
|
|
68
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
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 sqlite
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"errors"
|
|
19
|
-
"fmt"
|
|
20
|
-
"io"
|
|
21
|
-
"io/fs"
|
|
22
|
-
"log/slog"
|
|
23
|
-
"os"
|
|
24
|
-
"path/filepath"
|
|
25
|
-
"time"
|
|
26
|
-
|
|
27
|
-
"github.com/blinklabs-io/dingo/database/plugin"
|
|
28
|
-
"github.com/blinklabs-io/dingo/database/plugin/metadata/sqlite/models"
|
|
29
|
-
"github.com/glebarez/sqlite"
|
|
30
|
-
"gorm.io/gorm"
|
|
31
|
-
gormlogger "gorm.io/gorm/logger"
|
|
32
|
-
"gorm.io/plugin/opentelemetry/tracing"
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
// Register plugin
|
|
36
|
-
func init() {
|
|
37
|
-
plugin.Register(
|
|
38
|
-
plugin.PluginEntry{
|
|
39
|
-
Type: plugin.PluginTypeMetadata,
|
|
40
|
-
Name: "sqlite",
|
|
41
|
-
},
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// MetadataStoreSqlite stores all data in sqlite. Data may not be persisted
|
|
46
|
-
type MetadataStoreSqlite struct {
|
|
47
|
-
dataDir string
|
|
48
|
-
db *gorm.DB
|
|
49
|
-
logger *slog.Logger
|
|
50
|
-
timerVacuum *time.Timer
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// New creates a new database
|
|
54
|
-
func New(
|
|
55
|
-
dataDir string,
|
|
56
|
-
logger *slog.Logger,
|
|
57
|
-
) (*MetadataStoreSqlite, error) {
|
|
58
|
-
var metadataDb *gorm.DB
|
|
59
|
-
var err error
|
|
60
|
-
if dataDir == "" {
|
|
61
|
-
// No dataDir, use in-memory config
|
|
62
|
-
metadataDb, err = gorm.Open(
|
|
63
|
-
sqlite.Open("file::memory:?cache=shared"),
|
|
64
|
-
&gorm.Config{
|
|
65
|
-
Logger: gormlogger.Discard,
|
|
66
|
-
SkipDefaultTransaction: true,
|
|
67
|
-
},
|
|
68
|
-
)
|
|
69
|
-
if err != nil {
|
|
70
|
-
return nil, err
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
// Make sure that we can read data dir, and create if it doesn't exist
|
|
74
|
-
if _, err := os.Stat(dataDir); err != nil {
|
|
75
|
-
if !errors.Is(err, fs.ErrNotExist) {
|
|
76
|
-
return nil, fmt.Errorf("failed to read data dir: %w", err)
|
|
77
|
-
}
|
|
78
|
-
// Create data directory
|
|
79
|
-
if err := os.MkdirAll(dataDir, fs.ModePerm); err != nil {
|
|
80
|
-
return nil, fmt.Errorf("failed to create data dir: %w", err)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Open sqlite DB
|
|
84
|
-
metadataDbPath := filepath.Join(
|
|
85
|
-
dataDir,
|
|
86
|
-
"metadata.sqlite",
|
|
87
|
-
)
|
|
88
|
-
// WAL journal mode, disable sync on write, increase cache size to 50MB (from 2MB)
|
|
89
|
-
metadataConnOpts := "_pragma=journal_mode(WAL)&_pragma=sync(OFF)&_pragma=cache_size(-50000)"
|
|
90
|
-
metadataDb, err = gorm.Open(
|
|
91
|
-
sqlite.Open(
|
|
92
|
-
fmt.Sprintf("file:%s?%s", metadataDbPath, metadataConnOpts),
|
|
93
|
-
),
|
|
94
|
-
&gorm.Config{
|
|
95
|
-
Logger: gormlogger.Discard,
|
|
96
|
-
SkipDefaultTransaction: true,
|
|
97
|
-
},
|
|
98
|
-
)
|
|
99
|
-
if err != nil {
|
|
100
|
-
return nil, err
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
db := &MetadataStoreSqlite{
|
|
104
|
-
db: metadataDb,
|
|
105
|
-
dataDir: dataDir,
|
|
106
|
-
logger: logger,
|
|
107
|
-
}
|
|
108
|
-
if err := db.init(); err != nil {
|
|
109
|
-
// MetadataStoreSqlite is available for recovery, so return it with error
|
|
110
|
-
return db, err
|
|
111
|
-
}
|
|
112
|
-
// Create table schemas
|
|
113
|
-
db.logger.Debug(fmt.Sprintf("creating table: %#v", &CommitTimestamp{}))
|
|
114
|
-
if err := db.db.AutoMigrate(&CommitTimestamp{}); err != nil {
|
|
115
|
-
return db, err
|
|
116
|
-
}
|
|
117
|
-
for _, model := range models.MigrateModels {
|
|
118
|
-
db.logger.Debug(fmt.Sprintf("creating table: %#v", model))
|
|
119
|
-
if err := db.db.AutoMigrate(model); err != nil {
|
|
120
|
-
return db, err
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return db, nil
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
func (d *MetadataStoreSqlite) init() error {
|
|
127
|
-
if d.logger == nil {
|
|
128
|
-
// Create logger to throw away logs
|
|
129
|
-
// We do this so we don't have to add guards around every log operation
|
|
130
|
-
d.logger = slog.New(slog.NewJSONHandler(io.Discard, nil))
|
|
131
|
-
}
|
|
132
|
-
// Configure tracing for GORM
|
|
133
|
-
if err := d.db.Use(tracing.NewPlugin(tracing.WithoutMetrics())); err != nil {
|
|
134
|
-
return err
|
|
135
|
-
}
|
|
136
|
-
// Schedule daily database vacuum to free unused space
|
|
137
|
-
d.scheduleDailyVacuum()
|
|
138
|
-
return nil
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
func (d *MetadataStoreSqlite) runVacuum() error {
|
|
142
|
-
if d.dataDir == "" {
|
|
143
|
-
return nil
|
|
144
|
-
}
|
|
145
|
-
if result := d.DB().Raw("VACUUM"); result.Error != nil {
|
|
146
|
-
return result.Error
|
|
147
|
-
}
|
|
148
|
-
return nil
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
func (d *MetadataStoreSqlite) scheduleDailyVacuum() {
|
|
152
|
-
if d.timerVacuum != nil {
|
|
153
|
-
d.timerVacuum.Stop()
|
|
154
|
-
}
|
|
155
|
-
daily := time.Duration(24) * time.Hour
|
|
156
|
-
f := func() {
|
|
157
|
-
d.logger.Debug(
|
|
158
|
-
"running vacuum on sqlite metadata database",
|
|
159
|
-
)
|
|
160
|
-
// schedule next run
|
|
161
|
-
defer d.scheduleDailyVacuum()
|
|
162
|
-
if err := d.runVacuum(); err != nil {
|
|
163
|
-
d.logger.Error(
|
|
164
|
-
"failed to free unused space in metadata store",
|
|
165
|
-
"component", "database",
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
d.timerVacuum = time.AfterFunc(daily, f)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// AutoMigrate wraps the gorm AutoMigrate
|
|
173
|
-
func (d *MetadataStoreSqlite) AutoMigrate(dst ...interface{}) error {
|
|
174
|
-
return d.DB().AutoMigrate(dst...)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Close gets the database handle from our MetadataStore and closes it
|
|
178
|
-
func (d *MetadataStoreSqlite) Close() error {
|
|
179
|
-
// get DB handle from gorm.DB
|
|
180
|
-
db, err := d.DB().DB()
|
|
181
|
-
if err != nil {
|
|
182
|
-
return err
|
|
183
|
-
}
|
|
184
|
-
return db.Close()
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Create creates a record
|
|
188
|
-
func (d *MetadataStoreSqlite) Create(value interface{}) *gorm.DB {
|
|
189
|
-
return d.DB().Create(value)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// DB returns the database handle
|
|
193
|
-
func (d *MetadataStoreSqlite) DB() *gorm.DB {
|
|
194
|
-
return d.db
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// First returns the first DB entry
|
|
198
|
-
func (d *MetadataStoreSqlite) First(args interface{}) *gorm.DB {
|
|
199
|
-
return d.DB().First(args)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Order orders a DB query
|
|
203
|
-
func (d *MetadataStoreSqlite) Order(args interface{}) *gorm.DB {
|
|
204
|
-
return d.DB().Order(args)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Transaction creates a gorm transaction
|
|
208
|
-
func (d *MetadataStoreSqlite) Transaction() *gorm.DB {
|
|
209
|
-
return d.DB().Begin()
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Where constrains a DB query
|
|
213
|
-
func (d *MetadataStoreSqlite) Where(
|
|
214
|
-
query interface{},
|
|
215
|
-
args ...interface{},
|
|
216
|
-
) *gorm.DB {
|
|
217
|
-
return d.DB().Where(query, args...)
|
|
218
|
-
}
|