@blinklabs/dingo 0.7.0 → 0.8.0

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.
Files changed (187) hide show
  1. package/.dingo/blob/000001.sst +0 -0
  2. package/.dingo/blob/000001.vlog +0 -0
  3. package/.dingo/blob/DISCARD +0 -0
  4. package/.dingo/blob/KEYREGISTRY +2 -0
  5. package/.dingo/blob/MANIFEST +0 -0
  6. package/.dingo/metadata.sqlite +0 -0
  7. package/.github/workflows/golangci-lint.yml +1 -1
  8. package/.github/workflows/publish.yml +1 -7
  9. package/README.md +2 -1
  10. package/{bin/dingo → dingo} +0 -0
  11. package/dingo.yaml.example +53 -0
  12. package/package.json +2 -2
  13. package/Dockerfile +0 -25
  14. package/Makefile +0 -53
  15. package/blockfetch.go +0 -144
  16. package/chain/chain.go +0 -504
  17. package/chain/chain_test.go +0 -468
  18. package/chain/errors.go +0 -80
  19. package/chain/event.go +0 -33
  20. package/chain/iter.go +0 -64
  21. package/chainsync/chainsync.go +0 -97
  22. package/chainsync.go +0 -223
  23. package/cmd/dingo/load.go +0 -52
  24. package/cmd/dingo/main.go +0 -118
  25. package/cmd/dingo/serve.go +0 -49
  26. package/config/cardano/node.go +0 -192
  27. package/config/cardano/node_test.go +0 -85
  28. package/config/cardano/preview/README.md +0 -4
  29. package/config/cardano/preview/alonzo-genesis.json +0 -196
  30. package/config/cardano/preview/byron-genesis.json +0 -117
  31. package/config/cardano/preview/config.json +0 -114
  32. package/config/cardano/preview/conway-genesis.json +0 -297
  33. package/config/cardano/preview/shelley-genesis.json +0 -68
  34. package/config.go +0 -245
  35. package/connmanager/connection_manager.go +0 -105
  36. package/connmanager/connection_manager_test.go +0 -185
  37. package/connmanager/event.go +0 -37
  38. package/connmanager/listener.go +0 -140
  39. package/connmanager/outbound.go +0 -93
  40. package/connmanager/socket.go +0 -55
  41. package/connmanager/unix.go +0 -78
  42. package/custom-p2p-topology.json +0 -24
  43. package/custom-p2p-topology.json.backup +0 -24
  44. package/custom-p2p-topology.json.mainnet +0 -37
  45. package/database/account.go +0 -180
  46. package/database/block.go +0 -362
  47. package/database/certs.go +0 -53
  48. package/database/commit_timestamp.go +0 -77
  49. package/database/database.go +0 -118
  50. package/database/database_test.go +0 -62
  51. package/database/drep.go +0 -47
  52. package/database/epoch.go +0 -121
  53. package/database/immutable/chunk.go +0 -182
  54. package/database/immutable/immutable.go +0 -350
  55. package/database/immutable/immutable_test.go +0 -59
  56. package/database/immutable/primary.go +0 -106
  57. package/database/immutable/secondary.go +0 -103
  58. package/database/immutable/testdata/08893.chunk +0 -0
  59. package/database/immutable/testdata/08893.primary +0 -0
  60. package/database/immutable/testdata/08893.secondary +0 -0
  61. package/database/immutable/testdata/08894.chunk +0 -0
  62. package/database/immutable/testdata/08894.primary +0 -0
  63. package/database/immutable/testdata/08894.secondary +0 -0
  64. package/database/immutable/testdata/README.md +0 -4
  65. package/database/plugin/blob/badger/commit_timestamp.go +0 -50
  66. package/database/plugin/blob/badger/database.go +0 -152
  67. package/database/plugin/blob/badger/logger.go +0 -63
  68. package/database/plugin/blob/badger/metrics.go +0 -98
  69. package/database/plugin/blob/blob.go +0 -19
  70. package/database/plugin/blob/store.go +0 -40
  71. package/database/plugin/log.go +0 -27
  72. package/database/plugin/metadata/metadata.go +0 -19
  73. package/database/plugin/metadata/sqlite/account.go +0 -313
  74. package/database/plugin/metadata/sqlite/certs.go +0 -58
  75. package/database/plugin/metadata/sqlite/commit_timestamp.go +0 -68
  76. package/database/plugin/metadata/sqlite/database.go +0 -218
  77. package/database/plugin/metadata/sqlite/drep.go +0 -140
  78. package/database/plugin/metadata/sqlite/epoch.go +0 -120
  79. package/database/plugin/metadata/sqlite/models/account.go +0 -118
  80. package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +0 -26
  81. package/database/plugin/metadata/sqlite/models/drep.go +0 -52
  82. package/database/plugin/metadata/sqlite/models/epoch.go +0 -31
  83. package/database/plugin/metadata/sqlite/models/models.go +0 -46
  84. package/database/plugin/metadata/sqlite/models/pool.go +0 -97
  85. package/database/plugin/metadata/sqlite/models/pparam_update.go +0 -27
  86. package/database/plugin/metadata/sqlite/models/pparams.go +0 -27
  87. package/database/plugin/metadata/sqlite/models/resign_committee_cold.go +0 -27
  88. package/database/plugin/metadata/sqlite/models/stake_vote_delegation.go +0 -27
  89. package/database/plugin/metadata/sqlite/models/tip.go +0 -26
  90. package/database/plugin/metadata/sqlite/models/update_drep.go +0 -27
  91. package/database/plugin/metadata/sqlite/models/utxo.go +0 -30
  92. package/database/plugin/metadata/sqlite/models/vote_delegation.go +0 -26
  93. package/database/plugin/metadata/sqlite/models/vote_registration_delegation.go +0 -15
  94. package/database/plugin/metadata/sqlite/pool.go +0 -240
  95. package/database/plugin/metadata/sqlite/pparams.go +0 -110
  96. package/database/plugin/metadata/sqlite/tip.go +0 -83
  97. package/database/plugin/metadata/sqlite/utxo.go +0 -292
  98. package/database/plugin/metadata/store.go +0 -198
  99. package/database/plugin/option.go +0 -190
  100. package/database/plugin/plugin.go +0 -20
  101. package/database/plugin/register.go +0 -118
  102. package/database/pparams.go +0 -145
  103. package/database/tip.go +0 -45
  104. package/database/txn.go +0 -147
  105. package/database/types/types.go +0 -74
  106. package/database/types/types_test.go +0 -83
  107. package/database/utxo.go +0 -263
  108. package/dist/artifacts.json +0 -1
  109. package/dist/checksums.txt +0 -22
  110. package/dist/config.yaml +0 -253
  111. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz +0 -0
  112. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz.sbom.json +0 -1
  113. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz +0 -0
  114. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz.sbom.json +0 -1
  115. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz +0 -0
  116. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz.sbom.json +0 -1
  117. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk +0 -0
  118. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk.sbom.json +0 -1
  119. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb +0 -0
  120. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb.sbom.json +0 -1
  121. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm +0 -0
  122. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm.sbom.json +0 -1
  123. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk +0 -0
  124. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk.sbom.json +0 -1
  125. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb +0 -0
  126. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb.sbom.json +0 -1
  127. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm +0 -0
  128. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm.sbom.json +0 -1
  129. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz +0 -0
  130. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz.sbom.json +0 -1
  131. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz +0 -0
  132. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz.sbom.json +0 -1
  133. package/dist/dingo_darwin_amd64_v1/dingo +0 -0
  134. package/dist/dingo_darwin_arm64_v8.0/dingo +0 -0
  135. package/dist/dingo_linux_amd64_v1/dingo +0 -0
  136. package/dist/dingo_linux_arm64_v8.0/dingo +0 -0
  137. package/dist/homebrew/dingo.rb +0 -51
  138. package/dist/metadata.json +0 -1
  139. package/event/event.go +0 -141
  140. package/event/event_test.go +0 -115
  141. package/event/metrics.go +0 -44
  142. package/go.mod +0 -98
  143. package/go.sum +0 -358
  144. package/internal/config/config.go +0 -145
  145. package/internal/config/config_test.go +0 -118
  146. package/internal/node/load.go +0 -149
  147. package/internal/node/node.go +0 -176
  148. package/internal/version/version.go +0 -33
  149. package/ledger/certs.go +0 -164
  150. package/ledger/chainsync.go +0 -504
  151. package/ledger/delta.go +0 -99
  152. package/ledger/eras/allegra.go +0 -154
  153. package/ledger/eras/alonzo.go +0 -156
  154. package/ledger/eras/babbage.go +0 -154
  155. package/ledger/eras/byron.go +0 -42
  156. package/ledger/eras/conway.go +0 -166
  157. package/ledger/eras/eras.go +0 -44
  158. package/ledger/eras/mary.go +0 -154
  159. package/ledger/eras/shelley.go +0 -164
  160. package/ledger/error.go +0 -19
  161. package/ledger/event.go +0 -50
  162. package/ledger/metrics.go +0 -53
  163. package/ledger/queries.go +0 -258
  164. package/ledger/slot.go +0 -127
  165. package/ledger/slot_test.go +0 -147
  166. package/ledger/state.go +0 -821
  167. package/ledger/view.go +0 -73
  168. package/localstatequery.go +0 -50
  169. package/localtxmonitor.go +0 -44
  170. package/localtxsubmission.go +0 -52
  171. package/mempool/consumer.go +0 -98
  172. package/mempool/mempool.go +0 -322
  173. package/node.go +0 -320
  174. package/peergov/event.go +0 -27
  175. package/peergov/peer.go +0 -67
  176. package/peergov/peergov.go +0 -290
  177. package/peersharing.go +0 -70
  178. package/preview-local-topology.json +0 -23
  179. package/topology/topology.go +0 -69
  180. package/topology/topology_test.go +0 -179
  181. package/tracing.go +0 -65
  182. package/txsubmission.go +0 -233
  183. package/utxorpc/query.go +0 -311
  184. package/utxorpc/submit.go +0 -395
  185. package/utxorpc/sync.go +0 -276
  186. package/utxorpc/utxorpc.go +0 -166
  187. package/utxorpc/watch.go +0 -310
@@ -1,24 +0,0 @@
1
- {
2
- "bootstrapPeers": [
3
- {
4
- "address": "backbone.cardano.iog.io",
5
- "port": 3001
6
- }
7
- ],
8
- "localRoots": [
9
- {
10
- "accessPoints": [],
11
- "advertise": false,
12
- "trustable": false,
13
- "valency": 1
14
- }
15
- ],
16
- "publicRoots": [
17
- {
18
- "accessPoints": [
19
- ],
20
- "advertise": false
21
- }
22
- ],
23
- "useLedgerAfterSlot": 128908821
24
- }
@@ -1,24 +0,0 @@
1
- {
2
- "bootstrapPeers": [
3
- {
4
- "address": "backbone.cardano.iog.io",
5
- "port": 3001
6
- }
7
- ],
8
- "localRoots": [
9
- {
10
- "accessPoints": [],
11
- "advertise": false,
12
- "trustable": false,
13
- "valency": 1
14
- }
15
- ],
16
- "publicRoots": [
17
- {
18
- "accessPoints": [
19
- ],
20
- "advertise": false
21
- }
22
- ],
23
- "useLedgerAfterSlot": 128908821
24
- }
@@ -1,37 +0,0 @@
1
- {
2
- "bootstrapPeers": [
3
- {
4
- "address": "backbone.cardano.iog.io",
5
- "port": 3001
6
- },
7
- {
8
- "address": "backbone.mainnet.emurgornd.com",
9
- "port": 3001
10
- },
11
- {
12
- "address": "backbone.mainnet.cardanofoundation.org",
13
- "port": 3001
14
- }
15
- ],
16
- "localRoots": [
17
- {
18
- "accessPoints": [
19
- {
20
- "address": "otg-relay-1.adamantium.online",
21
- "port": 6001
22
- }
23
- ],
24
- "advertise": false,
25
- "trustable": false,
26
- "valency": 1
27
- }
28
- ],
29
- "publicRoots": [
30
- {
31
- "accessPoints": [
32
- ],
33
- "advertise": false
34
- }
35
- ],
36
- "useLedgerAfterSlot": 128908821
37
- }
@@ -1,180 +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 database
16
-
17
- import (
18
- lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
19
- )
20
-
21
- type Account struct {
22
- ID uint `gorm:"primarykey"`
23
- StakingKey []byte `gorm:"index,unique"`
24
- Pool []byte `gorm:"index"`
25
- Drep []byte `gorm:"index"`
26
- AddedSlot uint64
27
- Active bool
28
- }
29
-
30
- func (a *Account) TableName() string {
31
- return "account"
32
- }
33
-
34
- // GetAccount returns an account by staking key
35
- func (d *Database) GetAccount(
36
- stakeKey []byte,
37
- txn *Txn,
38
- ) (Account, error) {
39
- tmpAccount := Account{}
40
- if txn == nil {
41
- txn = d.Transaction(false)
42
- defer txn.Commit() //nolint:errcheck
43
- }
44
- account, err := d.metadata.GetAccount(stakeKey, txn.Metadata())
45
- if err != nil {
46
- return tmpAccount, err
47
- }
48
- tmpAccount = Account(account)
49
- return tmpAccount, nil
50
- }
51
-
52
- // SetAccount saves an account
53
- func (d *Database) SetAccount(
54
- stakeKey, pkh, drep []byte,
55
- slot uint64,
56
- active bool,
57
- txn *Txn,
58
- ) error {
59
- if txn == nil {
60
- txn = d.Transaction(false)
61
- defer txn.Commit() //nolint:errcheck
62
- }
63
- return d.metadata.SetAccount(
64
- stakeKey,
65
- pkh,
66
- drep,
67
- slot,
68
- active,
69
- txn.Metadata(),
70
- )
71
- }
72
-
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
-
86
- // SetRegistration saves a registration certificate
87
- func (d *Database) SetRegistration(
88
- cert *lcommon.RegistrationCertificate,
89
- slot, deposit uint64,
90
- txn *Txn,
91
- ) error {
92
- return d.metadata.SetRegistration(
93
- cert,
94
- slot,
95
- deposit,
96
- txn.Metadata(),
97
- )
98
- }
99
-
100
- // SetStakeDelegation saves a stake delegation certificate
101
- func (d *Database) SetStakeDelegation(
102
- cert *lcommon.StakeDelegationCertificate,
103
- slot uint64,
104
- txn *Txn,
105
- ) error {
106
- return d.metadata.SetStakeDelegation(
107
- cert,
108
- slot,
109
- txn.Metadata(),
110
- )
111
- }
112
-
113
- // SetStakeDeregistration saves a stake deregistration certificate
114
- func (d *Database) SetStakeDeregistration(
115
- cert *lcommon.StakeDeregistrationCertificate,
116
- slot uint64,
117
- txn *Txn,
118
- ) error {
119
- return d.metadata.SetStakeDeregistration(
120
- cert,
121
- slot,
122
- txn.Metadata(),
123
- )
124
- }
125
-
126
- // SetStakeRegistration saves a stake registration certificate
127
- func (d *Database) SetStakeRegistration(
128
- cert *lcommon.StakeRegistrationCertificate,
129
- slot, deposit uint64,
130
- txn *Txn,
131
- ) error {
132
- return d.metadata.SetStakeRegistration(
133
- cert,
134
- slot,
135
- deposit,
136
- txn.Metadata(),
137
- )
138
- }
139
-
140
- // SetStakeRegistrationDelegation saves a stake registration delegation certificate
141
- func (d *Database) SetStakeRegistrationDelegation(
142
- cert *lcommon.StakeRegistrationDelegationCertificate,
143
- slot, deposit uint64,
144
- txn *Txn,
145
- ) error {
146
- return d.metadata.SetStakeRegistrationDelegation(
147
- cert,
148
- slot,
149
- deposit,
150
- txn.Metadata(),
151
- )
152
- }
153
-
154
- // SetStakeVoteRegistrationDelegation saves a stake vote registration delegation certificate
155
- func (d *Database) SetStakeVoteRegistrationDelegation(
156
- cert *lcommon.StakeVoteRegistrationDelegationCertificate,
157
- slot, deposit uint64,
158
- txn *Txn,
159
- ) error {
160
- return d.metadata.SetStakeVoteRegistrationDelegation(
161
- cert,
162
- slot,
163
- deposit,
164
- txn.Metadata(),
165
- )
166
- }
167
-
168
- // SetVoteRegistrationDelegation saves a vote registration delegation certificate
169
- func (d *Database) SetVoteRegistrationDelegation(
170
- cert *lcommon.VoteRegistrationDelegationCertificate,
171
- slot, deposit uint64,
172
- txn *Txn,
173
- ) error {
174
- return d.metadata.SetVoteRegistrationDelegation(
175
- cert,
176
- slot,
177
- deposit,
178
- txn.Metadata(),
179
- )
180
- }
package/database/block.go DELETED
@@ -1,362 +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 database
16
-
17
- import (
18
- "encoding/hex"
19
- "errors"
20
- "math/big"
21
- "slices"
22
- "strings"
23
-
24
- "github.com/blinklabs-io/gouroboros/cbor"
25
- "github.com/blinklabs-io/gouroboros/ledger"
26
- ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
27
- "github.com/dgraph-io/badger/v4"
28
- )
29
-
30
- const (
31
- BlockInitialIndex uint64 = 1
32
-
33
- blockBlobKeyPrefix = "bp"
34
- blockBlobIndexKeyPrefix = "bi"
35
- blockBlobMetadataKeySuffix = "_metadata"
36
- )
37
-
38
- var ErrBlockNotFound = errors.New("block not found")
39
-
40
- type Block struct {
41
- ID uint64
42
- Slot uint64
43
- Number uint64
44
- Hash []byte
45
- Type uint
46
- PrevHash []byte
47
- Nonce []byte
48
- Cbor []byte
49
- }
50
-
51
- func (b Block) Decode() (ledger.Block, error) {
52
- return ledger.NewBlockFromCbor(b.Type, b.Cbor)
53
- }
54
-
55
- func (d *Database) BlockCreate(block Block, txn *Txn) error {
56
- if txn == nil {
57
- txn = d.BlobTxn(true)
58
- defer txn.Commit() //nolint:errcheck
59
- }
60
- // Block content by point
61
- key := BlockBlobKey(block.Slot, block.Hash)
62
- if err := txn.Blob().Set(key, block.Cbor); err != nil {
63
- return err
64
- }
65
- // Set index if not provided
66
- if block.ID == 0 {
67
- recentBlocks, err := BlocksRecentTxn(txn, 1)
68
- if err != nil {
69
- return err
70
- }
71
- if len(recentBlocks) > 0 {
72
- block.ID = recentBlocks[0].ID + 1
73
- } else {
74
- block.ID = BlockInitialIndex
75
- }
76
- }
77
- // Block index to point key
78
- indexKey := BlockBlobIndexKey(block.ID)
79
- if err := txn.Blob().Set(indexKey, key); err != nil {
80
- return err
81
- }
82
- // Block metadata by point
83
- metadataKey := BlockBlobMetadataKey(key)
84
- tmpMetadata := BlockBlobMetadata{
85
- ID: block.ID,
86
- Type: block.Type,
87
- Height: block.Number,
88
- PrevHash: block.PrevHash,
89
- Nonce: block.Nonce,
90
- }
91
- tmpMetadataBytes, err := cbor.Encode(tmpMetadata)
92
- if err != nil {
93
- return err
94
- }
95
- if err := txn.Blob().Set(metadataKey, tmpMetadataBytes); err != nil {
96
- return err
97
- }
98
- return nil
99
- }
100
-
101
- func BlockDeleteTxn(txn *Txn, block Block) error {
102
- // Remove from blob store
103
- key := BlockBlobKey(block.Slot, block.Hash)
104
- if err := txn.Blob().Delete(key); err != nil {
105
- return err
106
- }
107
- indexKey := BlockBlobIndexKey(block.ID)
108
- if err := txn.Blob().Delete(indexKey); err != nil {
109
- return err
110
- }
111
- metadataKey := BlockBlobMetadataKey(key)
112
- if err := txn.Blob().Delete(metadataKey); err != nil {
113
- return err
114
- }
115
- return nil
116
- }
117
-
118
- func BlockByPoint(db *Database, point ocommon.Point) (Block, error) {
119
- var ret Block
120
- txn := db.Transaction(false)
121
- err := txn.Do(func(txn *Txn) error {
122
- var err error
123
- ret, err = BlockByPointTxn(txn, point)
124
- return err
125
- })
126
- return ret, err
127
- }
128
-
129
- func blockByKey(txn *Txn, blockKey []byte) (Block, error) {
130
- point := blockBlobKeyToPoint(blockKey)
131
- ret := Block{
132
- Slot: point.Slot,
133
- Hash: point.Hash,
134
- }
135
- item, err := txn.Blob().Get(blockKey)
136
- if err != nil {
137
- if errors.Is(err, badger.ErrKeyNotFound) {
138
- return ret, ErrBlockNotFound
139
- }
140
- return ret, err
141
- }
142
- ret.Cbor, err = item.ValueCopy(nil)
143
- if err != nil {
144
- return ret, err
145
- }
146
- metadataKey := BlockBlobMetadataKey(blockKey)
147
- item, err = txn.Blob().Get(metadataKey)
148
- if err != nil {
149
- return ret, err
150
- }
151
- metadataBytes, err := item.ValueCopy(nil)
152
- if err != nil {
153
- return ret, err
154
- }
155
- var tmpMetadata BlockBlobMetadata
156
- if _, err := cbor.Decode(metadataBytes, &tmpMetadata); err != nil {
157
- return ret, err
158
- }
159
- ret.ID = tmpMetadata.ID
160
- ret.Type = tmpMetadata.Type
161
- ret.Number = tmpMetadata.Height
162
- ret.PrevHash = tmpMetadata.PrevHash
163
- ret.Nonce = tmpMetadata.Nonce
164
- return ret, nil
165
- }
166
-
167
- func BlockByPointTxn(txn *Txn, point ocommon.Point) (Block, error) {
168
- key := BlockBlobKey(point.Slot, point.Hash)
169
- return blockByKey(txn, key)
170
- }
171
-
172
- func (d *Database) BlockByIndex(blockIndex uint64, txn *Txn) (Block, error) {
173
- if txn == nil {
174
- txn = d.BlobTxn(false)
175
- defer txn.Commit() //nolint:errcheck
176
- }
177
- indexKey := BlockBlobIndexKey(blockIndex)
178
- item, err := txn.Blob().Get(indexKey)
179
- if err != nil {
180
- if errors.Is(err, badger.ErrKeyNotFound) {
181
- return Block{}, ErrBlockNotFound
182
- }
183
- return Block{}, err
184
- }
185
- blockKey, err := item.ValueCopy(nil)
186
- if err != nil {
187
- return Block{}, err
188
- }
189
- return blockByKey(txn, blockKey)
190
- }
191
-
192
- func BlocksRecent(db *Database, count int) ([]Block, error) {
193
- var ret []Block
194
- txn := db.Transaction(false)
195
- err := txn.Do(func(txn *Txn) error {
196
- var err error
197
- ret, err = BlocksRecentTxn(txn, count)
198
- return err
199
- })
200
- return ret, err
201
- }
202
-
203
- func BlocksRecentTxn(txn *Txn, count int) ([]Block, error) {
204
- ret := make([]Block, 0, count)
205
- iterOpts := badger.IteratorOptions{
206
- Reverse: true,
207
- }
208
- it := txn.Blob().NewIterator(iterOpts)
209
- defer it.Close()
210
- var foundCount int
211
- // Generate our seek key
212
- // We use our block index key prefix and append 0xFF to get a key that should be
213
- // after any legitimate key. This should leave our most recent block as the next
214
- // item when doing reverse iteration
215
- tmpPrefix := append([]byte(blockBlobIndexKeyPrefix), 0xff)
216
- var blockKey []byte
217
- var err error
218
- var tmpBlock Block
219
- for it.Seek(tmpPrefix); it.ValidForPrefix([]byte(blockBlobIndexKeyPrefix)); it.Next() {
220
- item := it.Item()
221
- blockKey, err = item.ValueCopy(nil)
222
- if err != nil {
223
- return ret, err
224
- }
225
- tmpBlock, err = blockByKey(txn, blockKey)
226
- if err != nil {
227
- return ret, err
228
- }
229
- ret = append(ret, tmpBlock)
230
- foundCount++
231
- if foundCount >= count {
232
- break
233
- }
234
- }
235
- return ret, nil
236
- }
237
-
238
- func BlockBeforeSlot(db *Database, slotNumber uint64) (Block, error) {
239
- var ret Block
240
- txn := db.Transaction(false)
241
- err := txn.Do(func(txn *Txn) error {
242
- var err error
243
- ret, err = BlockBeforeSlotTxn(txn, slotNumber)
244
- return err
245
- })
246
- return ret, err
247
- }
248
-
249
- func BlockBeforeSlotTxn(txn *Txn, slotNumber uint64) (Block, error) {
250
- iterOpts := badger.IteratorOptions{
251
- Reverse: true,
252
- }
253
- it := txn.Blob().NewIterator(iterOpts)
254
- defer it.Close()
255
- keyPrefix := slices.Concat(
256
- []byte(blockBlobKeyPrefix),
257
- blockBlobKeyUint64ToBytes(slotNumber),
258
- )
259
- for it.Seek(keyPrefix); it.Valid(); it.Next() {
260
- // Skip if we get a key matching the input slot number
261
- if it.ValidForPrefix(keyPrefix) {
262
- continue
263
- }
264
- // Check for end of block keys
265
- if !it.ValidForPrefix([]byte(blockBlobKeyPrefix)) {
266
- return Block{}, ErrBlockNotFound
267
- }
268
- item := it.Item()
269
- k := item.Key()
270
- // Skip the metadata key
271
- if strings.HasSuffix(string(k), blockBlobMetadataKeySuffix) {
272
- continue
273
- }
274
- return blockByKey(txn, k)
275
- }
276
- return Block{}, ErrBlockNotFound
277
- }
278
-
279
- func BlocksAfterSlotTxn(txn *Txn, slotNumber uint64) ([]Block, error) {
280
- var ret []Block
281
- iterOpts := badger.IteratorOptions{}
282
- it := txn.Blob().NewIterator(iterOpts)
283
- defer it.Close()
284
- keyPrefix := slices.Concat(
285
- []byte(blockBlobKeyPrefix),
286
- blockBlobKeyUint64ToBytes(slotNumber),
287
- )
288
- var err error
289
- var k []byte
290
- var tmpBlock Block
291
- for it.Seek(keyPrefix); it.ValidForPrefix([]byte(blockBlobKeyPrefix)); it.Next() {
292
- // Skip the start slot
293
- if it.ValidForPrefix(keyPrefix) {
294
- continue
295
- }
296
- item := it.Item()
297
- k = item.Key()
298
- // Skip the metadata key
299
- if strings.HasSuffix(string(k), blockBlobMetadataKeySuffix) {
300
- continue
301
- }
302
- tmpBlock, err = blockByKey(txn, k)
303
- if err != nil {
304
- return []Block{}, err
305
- }
306
- ret = append(ret, tmpBlock)
307
- }
308
- return ret, nil
309
- }
310
-
311
- func blockBlobKeyUint64ToBytes(input uint64) []byte {
312
- ret := make([]byte, 8)
313
- new(big.Int).SetUint64(input).FillBytes(ret)
314
- return ret
315
- }
316
-
317
- func blockBlobKeyToPoint(key []byte) ocommon.Point {
318
- slotBytes := make([]byte, 8)
319
- copy(slotBytes, key[2:2+8])
320
- hash := make([]byte, 32)
321
- copy(hash, key[10:10+32])
322
- slot := new(big.Int).SetBytes(slotBytes).Uint64()
323
- return ocommon.NewPoint(slot, hash)
324
- }
325
-
326
- func BlockBlobKey(slot uint64, hash []byte) []byte {
327
- key := []byte(blockBlobKeyPrefix)
328
- // Convert slot to bytes
329
- slotBytes := blockBlobKeyUint64ToBytes(slot)
330
- key = append(key, slotBytes...)
331
- key = append(key, hash...)
332
- return key
333
- }
334
-
335
- func BlockBlobIndexKey(blockNumber uint64) []byte {
336
- key := []byte(blockBlobIndexKeyPrefix)
337
- // Convert block number to bytes
338
- blockNumberBytes := blockBlobKeyUint64ToBytes(blockNumber)
339
- key = append(key, blockNumberBytes...)
340
- return key
341
- }
342
-
343
- func BlockBlobMetadataKey(baseKey []byte) []byte {
344
- return slices.Concat(baseKey, []byte(blockBlobMetadataKeySuffix))
345
- }
346
-
347
- func BlockBlobKeyHashHex(slot uint64, hashHex string) ([]byte, error) {
348
- hashBytes, err := hex.DecodeString(hashHex)
349
- if err != nil {
350
- return nil, err
351
- }
352
- return BlockBlobKey(slot, hashBytes), nil
353
- }
354
-
355
- type BlockBlobMetadata struct {
356
- cbor.StructAsArray
357
- ID uint64
358
- Type uint
359
- Height uint64
360
- PrevHash []byte
361
- Nonce []byte
362
- }
package/database/certs.go DELETED
@@ -1,53 +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 database
16
-
17
- import (
18
- lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
19
- )
20
-
21
- // GetPoolRegistrations returns a list of pool registration certificates
22
- func (d *Database) GetPoolRegistrations(
23
- poolKeyHash lcommon.PoolKeyHash,
24
- txn *Txn,
25
- ) ([]lcommon.PoolRegistrationCertificate, error) {
26
- return d.metadata.GetPoolRegistrations(poolKeyHash, txn.Metadata())
27
- }
28
-
29
- // GetStakeRegistrations returns a list of stake registration certificates
30
- func (d *Database) GetStakeRegistrations(
31
- stakingKey []byte,
32
- txn *Txn,
33
- ) ([]lcommon.StakeRegistrationCertificate, error) {
34
- return d.metadata.GetStakeRegistrations(stakingKey, txn.Metadata())
35
- }
36
-
37
- // SetPoolRegistration saves a pool registration certificate
38
- func (d *Database) SetPoolRegistration(
39
- cert *lcommon.PoolRegistrationCertificate,
40
- slot, deposit uint64, // slot
41
- txn *Txn,
42
- ) error {
43
- return d.metadata.SetPoolRegistration(cert, slot, deposit, txn.Metadata())
44
- }
45
-
46
- // SetPoolRetirement saves a pool retirement certificate
47
- func (d *Database) SetPoolRetirement(
48
- cert *lcommon.PoolRetirementCertificate,
49
- slot uint64,
50
- txn *Txn,
51
- ) error {
52
- return d.metadata.SetPoolRetirement(cert, slot, txn.Metadata())
53
- }