@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.
Files changed (192) hide show
  1. package/README.md +2 -1
  2. package/{bin/dingo → dingo} +0 -0
  3. package/dingo.yaml.example +53 -0
  4. package/package.json +2 -2
  5. package/.github/CODEOWNERS +0 -5
  6. package/.github/assets/dingo-ate-my-blockchain.png +0 -0
  7. package/.github/assets/dingo-illustration.png +0 -0
  8. package/.github/assets/dingo-logo-with-text-horizontal.png +0 -0
  9. package/.github/assets/dingo-logo-with-text.png +0 -0
  10. package/.github/dependabot.yml +0 -19
  11. package/.github/dingo-20241210.png +0 -0
  12. package/.github/dingo.md +0 -56
  13. package/.github/workflows/ci-docker.yml +0 -36
  14. package/.github/workflows/conventional-commits.yml +0 -17
  15. package/.github/workflows/go-test.yml +0 -29
  16. package/.github/workflows/golangci-lint.yml +0 -23
  17. package/.github/workflows/publish.yml +0 -207
  18. package/Dockerfile +0 -25
  19. package/Makefile +0 -53
  20. package/blockfetch.go +0 -144
  21. package/chain/chain.go +0 -504
  22. package/chain/chain_test.go +0 -468
  23. package/chain/errors.go +0 -80
  24. package/chain/event.go +0 -33
  25. package/chain/iter.go +0 -64
  26. package/chainsync/chainsync.go +0 -97
  27. package/chainsync.go +0 -223
  28. package/cmd/dingo/load.go +0 -52
  29. package/cmd/dingo/main.go +0 -118
  30. package/cmd/dingo/serve.go +0 -49
  31. package/config/cardano/node.go +0 -192
  32. package/config/cardano/node_test.go +0 -85
  33. package/config/cardano/preview/README.md +0 -4
  34. package/config/cardano/preview/alonzo-genesis.json +0 -196
  35. package/config/cardano/preview/byron-genesis.json +0 -117
  36. package/config/cardano/preview/config.json +0 -114
  37. package/config/cardano/preview/conway-genesis.json +0 -297
  38. package/config/cardano/preview/shelley-genesis.json +0 -68
  39. package/config.go +0 -245
  40. package/connmanager/connection_manager.go +0 -105
  41. package/connmanager/connection_manager_test.go +0 -185
  42. package/connmanager/event.go +0 -37
  43. package/connmanager/listener.go +0 -140
  44. package/connmanager/outbound.go +0 -93
  45. package/connmanager/socket.go +0 -55
  46. package/connmanager/unix.go +0 -78
  47. package/custom-p2p-topology.json +0 -24
  48. package/custom-p2p-topology.json.backup +0 -24
  49. package/custom-p2p-topology.json.mainnet +0 -37
  50. package/database/account.go +0 -180
  51. package/database/block.go +0 -362
  52. package/database/certs.go +0 -53
  53. package/database/commit_timestamp.go +0 -77
  54. package/database/database.go +0 -118
  55. package/database/database_test.go +0 -62
  56. package/database/drep.go +0 -47
  57. package/database/epoch.go +0 -121
  58. package/database/immutable/chunk.go +0 -182
  59. package/database/immutable/immutable.go +0 -350
  60. package/database/immutable/immutable_test.go +0 -59
  61. package/database/immutable/primary.go +0 -106
  62. package/database/immutable/secondary.go +0 -103
  63. package/database/immutable/testdata/08893.chunk +0 -0
  64. package/database/immutable/testdata/08893.primary +0 -0
  65. package/database/immutable/testdata/08893.secondary +0 -0
  66. package/database/immutable/testdata/08894.chunk +0 -0
  67. package/database/immutable/testdata/08894.primary +0 -0
  68. package/database/immutable/testdata/08894.secondary +0 -0
  69. package/database/immutable/testdata/README.md +0 -4
  70. package/database/plugin/blob/badger/commit_timestamp.go +0 -50
  71. package/database/plugin/blob/badger/database.go +0 -152
  72. package/database/plugin/blob/badger/logger.go +0 -63
  73. package/database/plugin/blob/badger/metrics.go +0 -98
  74. package/database/plugin/blob/blob.go +0 -19
  75. package/database/plugin/blob/store.go +0 -40
  76. package/database/plugin/log.go +0 -27
  77. package/database/plugin/metadata/metadata.go +0 -19
  78. package/database/plugin/metadata/sqlite/account.go +0 -313
  79. package/database/plugin/metadata/sqlite/certs.go +0 -58
  80. package/database/plugin/metadata/sqlite/commit_timestamp.go +0 -68
  81. package/database/plugin/metadata/sqlite/database.go +0 -218
  82. package/database/plugin/metadata/sqlite/drep.go +0 -140
  83. package/database/plugin/metadata/sqlite/epoch.go +0 -120
  84. package/database/plugin/metadata/sqlite/models/account.go +0 -118
  85. package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +0 -26
  86. package/database/plugin/metadata/sqlite/models/drep.go +0 -52
  87. package/database/plugin/metadata/sqlite/models/epoch.go +0 -31
  88. package/database/plugin/metadata/sqlite/models/models.go +0 -46
  89. package/database/plugin/metadata/sqlite/models/pool.go +0 -97
  90. package/database/plugin/metadata/sqlite/models/pparam_update.go +0 -27
  91. package/database/plugin/metadata/sqlite/models/pparams.go +0 -27
  92. package/database/plugin/metadata/sqlite/models/resign_committee_cold.go +0 -27
  93. package/database/plugin/metadata/sqlite/models/stake_vote_delegation.go +0 -27
  94. package/database/plugin/metadata/sqlite/models/tip.go +0 -26
  95. package/database/plugin/metadata/sqlite/models/update_drep.go +0 -27
  96. package/database/plugin/metadata/sqlite/models/utxo.go +0 -30
  97. package/database/plugin/metadata/sqlite/models/vote_delegation.go +0 -26
  98. package/database/plugin/metadata/sqlite/models/vote_registration_delegation.go +0 -15
  99. package/database/plugin/metadata/sqlite/pool.go +0 -240
  100. package/database/plugin/metadata/sqlite/pparams.go +0 -110
  101. package/database/plugin/metadata/sqlite/tip.go +0 -83
  102. package/database/plugin/metadata/sqlite/utxo.go +0 -292
  103. package/database/plugin/metadata/store.go +0 -198
  104. package/database/plugin/option.go +0 -190
  105. package/database/plugin/plugin.go +0 -20
  106. package/database/plugin/register.go +0 -118
  107. package/database/pparams.go +0 -145
  108. package/database/tip.go +0 -45
  109. package/database/txn.go +0 -147
  110. package/database/types/types.go +0 -74
  111. package/database/types/types_test.go +0 -83
  112. package/database/utxo.go +0 -263
  113. package/dist/artifacts.json +0 -1
  114. package/dist/checksums.txt +0 -22
  115. package/dist/config.yaml +0 -253
  116. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz +0 -0
  117. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz.sbom.json +0 -1
  118. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz +0 -0
  119. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz.sbom.json +0 -1
  120. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz +0 -0
  121. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz.sbom.json +0 -1
  122. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk +0 -0
  123. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk.sbom.json +0 -1
  124. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb +0 -0
  125. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb.sbom.json +0 -1
  126. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm +0 -0
  127. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm.sbom.json +0 -1
  128. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk +0 -0
  129. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk.sbom.json +0 -1
  130. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb +0 -0
  131. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb.sbom.json +0 -1
  132. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm +0 -0
  133. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm.sbom.json +0 -1
  134. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz +0 -0
  135. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz.sbom.json +0 -1
  136. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz +0 -0
  137. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz.sbom.json +0 -1
  138. package/dist/dingo_darwin_amd64_v1/dingo +0 -0
  139. package/dist/dingo_darwin_arm64_v8.0/dingo +0 -0
  140. package/dist/dingo_linux_amd64_v1/dingo +0 -0
  141. package/dist/dingo_linux_arm64_v8.0/dingo +0 -0
  142. package/dist/homebrew/dingo.rb +0 -51
  143. package/dist/metadata.json +0 -1
  144. package/event/event.go +0 -141
  145. package/event/event_test.go +0 -115
  146. package/event/metrics.go +0 -44
  147. package/go.mod +0 -98
  148. package/go.sum +0 -358
  149. package/internal/config/config.go +0 -145
  150. package/internal/config/config_test.go +0 -118
  151. package/internal/node/load.go +0 -149
  152. package/internal/node/node.go +0 -176
  153. package/internal/version/version.go +0 -33
  154. package/ledger/certs.go +0 -164
  155. package/ledger/chainsync.go +0 -504
  156. package/ledger/delta.go +0 -99
  157. package/ledger/eras/allegra.go +0 -154
  158. package/ledger/eras/alonzo.go +0 -156
  159. package/ledger/eras/babbage.go +0 -154
  160. package/ledger/eras/byron.go +0 -42
  161. package/ledger/eras/conway.go +0 -166
  162. package/ledger/eras/eras.go +0 -44
  163. package/ledger/eras/mary.go +0 -154
  164. package/ledger/eras/shelley.go +0 -164
  165. package/ledger/error.go +0 -19
  166. package/ledger/event.go +0 -50
  167. package/ledger/metrics.go +0 -53
  168. package/ledger/queries.go +0 -258
  169. package/ledger/slot.go +0 -127
  170. package/ledger/slot_test.go +0 -147
  171. package/ledger/state.go +0 -821
  172. package/ledger/view.go +0 -73
  173. package/localstatequery.go +0 -50
  174. package/localtxmonitor.go +0 -44
  175. package/localtxsubmission.go +0 -52
  176. package/mempool/consumer.go +0 -98
  177. package/mempool/mempool.go +0 -322
  178. package/node.go +0 -320
  179. package/peergov/event.go +0 -27
  180. package/peergov/peer.go +0 -67
  181. package/peergov/peergov.go +0 -290
  182. package/peersharing.go +0 -70
  183. package/preview-local-topology.json +0 -23
  184. package/topology/topology.go +0 -69
  185. package/topology/topology_test.go +0 -179
  186. package/tracing.go +0 -65
  187. package/txsubmission.go +0 -233
  188. package/utxorpc/query.go +0 -311
  189. package/utxorpc/submit.go +0 -395
  190. package/utxorpc/sync.go +0 -276
  191. package/utxorpc/utxorpc.go +0 -166
  192. 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
- }