@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
package/utxorpc/sync.go
DELETED
|
@@ -1,276 +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 utxorpc
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"context"
|
|
19
|
-
"errors"
|
|
20
|
-
"fmt"
|
|
21
|
-
|
|
22
|
-
"connectrpc.com/connect"
|
|
23
|
-
"github.com/blinklabs-io/gouroboros/ledger"
|
|
24
|
-
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
|
|
25
|
-
sync "github.com/utxorpc/go-codegen/utxorpc/v1alpha/sync"
|
|
26
|
-
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/sync/syncconnect"
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
// syncServiceServer implements the SyncService API
|
|
30
|
-
type syncServiceServer struct {
|
|
31
|
-
syncconnect.UnimplementedSyncServiceHandler
|
|
32
|
-
utxorpc *Utxorpc
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// FetchBlock
|
|
36
|
-
func (s *syncServiceServer) FetchBlock(
|
|
37
|
-
ctx context.Context,
|
|
38
|
-
req *connect.Request[sync.FetchBlockRequest],
|
|
39
|
-
) (*connect.Response[sync.FetchBlockResponse], error) {
|
|
40
|
-
ref := req.Msg.GetRef() // []*BlockRef
|
|
41
|
-
fieldMask := req.Msg.GetFieldMask()
|
|
42
|
-
|
|
43
|
-
s.utxorpc.config.Logger.Info(
|
|
44
|
-
fmt.Sprintf(
|
|
45
|
-
"Got a FetchBlock request with ref %v and fieldMask %v",
|
|
46
|
-
ref,
|
|
47
|
-
fieldMask,
|
|
48
|
-
),
|
|
49
|
-
)
|
|
50
|
-
resp := &sync.FetchBlockResponse{}
|
|
51
|
-
|
|
52
|
-
// Get our points
|
|
53
|
-
var points []ocommon.Point
|
|
54
|
-
if len(ref) > 0 {
|
|
55
|
-
for _, blockRef := range ref {
|
|
56
|
-
blockIdx := blockRef.GetIndex()
|
|
57
|
-
blockHash := blockRef.GetHash()
|
|
58
|
-
slot := blockIdx
|
|
59
|
-
point := ocommon.NewPoint(slot, blockHash)
|
|
60
|
-
points = append(points, point)
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
point := s.utxorpc.config.LedgerState.Tip().Point
|
|
64
|
-
points = append(points, point)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
for _, point := range points {
|
|
68
|
-
block, err := s.utxorpc.config.LedgerState.GetBlock(point)
|
|
69
|
-
if err != nil {
|
|
70
|
-
return nil, err
|
|
71
|
-
}
|
|
72
|
-
if block == nil {
|
|
73
|
-
return nil, errors.New("block returned nil")
|
|
74
|
-
}
|
|
75
|
-
var acb sync.AnyChainBlock
|
|
76
|
-
ret, err := block.Decode()
|
|
77
|
-
if err != nil {
|
|
78
|
-
return nil, err
|
|
79
|
-
}
|
|
80
|
-
acbc := sync.AnyChainBlock_Cardano{
|
|
81
|
-
Cardano: ret.Utxorpc(),
|
|
82
|
-
}
|
|
83
|
-
acb.Chain = &acbc
|
|
84
|
-
resp.Block = append(resp.Block, &acb)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return connect.NewResponse(resp), nil
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// DumpHistory
|
|
91
|
-
func (s *syncServiceServer) DumpHistory(
|
|
92
|
-
ctx context.Context,
|
|
93
|
-
req *connect.Request[sync.DumpHistoryRequest],
|
|
94
|
-
) (*connect.Response[sync.DumpHistoryResponse], error) {
|
|
95
|
-
startToken := req.Msg.GetStartToken() // *BlockRef
|
|
96
|
-
maxItems := req.Msg.GetMaxItems() // uint32
|
|
97
|
-
fieldMask := req.Msg.GetFieldMask()
|
|
98
|
-
|
|
99
|
-
s.utxorpc.config.Logger.Info(
|
|
100
|
-
fmt.Sprintf(
|
|
101
|
-
"Got a DumpHistory request with token %v and maxItems %d and fieldMask %v",
|
|
102
|
-
startToken,
|
|
103
|
-
maxItems,
|
|
104
|
-
fieldMask,
|
|
105
|
-
),
|
|
106
|
-
)
|
|
107
|
-
resp := &sync.DumpHistoryResponse{}
|
|
108
|
-
|
|
109
|
-
// Get our points
|
|
110
|
-
var points []ocommon.Point
|
|
111
|
-
if maxItems > 0 {
|
|
112
|
-
tmpPoints, err := s.utxorpc.config.LedgerState.RecentChainPoints(
|
|
113
|
-
int(maxItems),
|
|
114
|
-
)
|
|
115
|
-
if err != nil {
|
|
116
|
-
return nil, err
|
|
117
|
-
}
|
|
118
|
-
points = tmpPoints
|
|
119
|
-
} else {
|
|
120
|
-
point := s.utxorpc.config.LedgerState.Tip().Point
|
|
121
|
-
points = append(points, point)
|
|
122
|
-
}
|
|
123
|
-
// TODO: make this work (#401)
|
|
124
|
-
// if startToken != nil {
|
|
125
|
-
// blockIdx := startToken.GetIndex()
|
|
126
|
-
// blockHash := startToken.GetHash()
|
|
127
|
-
// slot := uint64(blockIdx)
|
|
128
|
-
// point = ocommon.NewPoint(slot, blockHash)
|
|
129
|
-
// }
|
|
130
|
-
|
|
131
|
-
for _, point := range points {
|
|
132
|
-
block, err := s.utxorpc.config.LedgerState.GetBlock(point)
|
|
133
|
-
if err != nil {
|
|
134
|
-
return nil, err
|
|
135
|
-
}
|
|
136
|
-
if block == nil {
|
|
137
|
-
return nil, errors.New("block returned nil")
|
|
138
|
-
}
|
|
139
|
-
var acb sync.AnyChainBlock
|
|
140
|
-
ret, err := block.Decode()
|
|
141
|
-
if err != nil {
|
|
142
|
-
return nil, err
|
|
143
|
-
}
|
|
144
|
-
acbc := sync.AnyChainBlock_Cardano{
|
|
145
|
-
Cardano: ret.Utxorpc(),
|
|
146
|
-
}
|
|
147
|
-
acb.Chain = &acbc
|
|
148
|
-
resp.Block = append(resp.Block, &acb)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return connect.NewResponse(resp), nil
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// FollowTip
|
|
155
|
-
func (s *syncServiceServer) FollowTip(
|
|
156
|
-
ctx context.Context,
|
|
157
|
-
req *connect.Request[sync.FollowTipRequest],
|
|
158
|
-
stream *connect.ServerStream[sync.FollowTipResponse],
|
|
159
|
-
) error {
|
|
160
|
-
intersect := req.Msg.GetIntersect() // []*BlockRef
|
|
161
|
-
|
|
162
|
-
s.utxorpc.config.Logger.Info(
|
|
163
|
-
fmt.Sprintf(
|
|
164
|
-
"Got a FollowTip request with intersect %v",
|
|
165
|
-
intersect,
|
|
166
|
-
),
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
// Get our points
|
|
170
|
-
var points []ocommon.Point
|
|
171
|
-
if len(intersect) > 0 {
|
|
172
|
-
for _, blockRef := range intersect {
|
|
173
|
-
blockIdx := blockRef.GetIndex()
|
|
174
|
-
blockHash := blockRef.GetHash()
|
|
175
|
-
slot := blockIdx
|
|
176
|
-
point := ocommon.NewPoint(slot, blockHash)
|
|
177
|
-
points = append(points, point)
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
point := s.utxorpc.config.LedgerState.Tip().Point
|
|
181
|
-
points = append(points, point)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Get our starting point matching our chain
|
|
185
|
-
point, err := s.utxorpc.config.LedgerState.GetIntersectPoint(points)
|
|
186
|
-
if err != nil {
|
|
187
|
-
s.utxorpc.config.Logger.Error(
|
|
188
|
-
"failed to get points",
|
|
189
|
-
"error", err,
|
|
190
|
-
)
|
|
191
|
-
return err
|
|
192
|
-
}
|
|
193
|
-
if point == nil {
|
|
194
|
-
s.utxorpc.config.Logger.Error(
|
|
195
|
-
"nil point returned",
|
|
196
|
-
)
|
|
197
|
-
return errors.New("nil point returned")
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Create our chain iterator
|
|
201
|
-
chainIter, err := s.utxorpc.config.LedgerState.GetChainFromPoint(
|
|
202
|
-
*point,
|
|
203
|
-
false,
|
|
204
|
-
)
|
|
205
|
-
if err != nil {
|
|
206
|
-
s.utxorpc.config.Logger.Error(
|
|
207
|
-
"failed to get chain iterator",
|
|
208
|
-
"error", err,
|
|
209
|
-
)
|
|
210
|
-
return err
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
for {
|
|
214
|
-
// Check for available block
|
|
215
|
-
next, err := chainIter.Next(true)
|
|
216
|
-
if err != nil {
|
|
217
|
-
s.utxorpc.config.Logger.Error(
|
|
218
|
-
"failed to iterate chain",
|
|
219
|
-
"error", err,
|
|
220
|
-
)
|
|
221
|
-
return err
|
|
222
|
-
}
|
|
223
|
-
if next != nil {
|
|
224
|
-
// Send block response
|
|
225
|
-
blockBytes := next.Block.Cbor[:]
|
|
226
|
-
blockType, err := ledger.DetermineBlockType(blockBytes)
|
|
227
|
-
if err != nil {
|
|
228
|
-
s.utxorpc.config.Logger.Error(
|
|
229
|
-
"failed to get block type",
|
|
230
|
-
"error", err,
|
|
231
|
-
)
|
|
232
|
-
return err
|
|
233
|
-
}
|
|
234
|
-
block, err := ledger.NewBlockFromCbor(blockType, blockBytes)
|
|
235
|
-
if err != nil {
|
|
236
|
-
s.utxorpc.config.Logger.Error(
|
|
237
|
-
"failed to get block",
|
|
238
|
-
"error", err,
|
|
239
|
-
)
|
|
240
|
-
return err
|
|
241
|
-
}
|
|
242
|
-
var acb sync.AnyChainBlock
|
|
243
|
-
acbc := sync.AnyChainBlock_Cardano{
|
|
244
|
-
Cardano: block.Utxorpc(),
|
|
245
|
-
}
|
|
246
|
-
acb.Chain = &acbc
|
|
247
|
-
resp := &sync.FollowTipResponse{
|
|
248
|
-
Action: &sync.FollowTipResponse_Apply{
|
|
249
|
-
Apply: &acb,
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
err = stream.Send(resp)
|
|
253
|
-
if err != nil {
|
|
254
|
-
s.utxorpc.config.Logger.Error(
|
|
255
|
-
"failed to send message to client",
|
|
256
|
-
"error", err,
|
|
257
|
-
)
|
|
258
|
-
return err
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// ReadTip
|
|
265
|
-
func (s *syncServiceServer) ReadTip(
|
|
266
|
-
ctx context.Context,
|
|
267
|
-
req *connect.Request[sync.ReadTipRequest],
|
|
268
|
-
) (*connect.Response[sync.ReadTipResponse], error) {
|
|
269
|
-
s.utxorpc.config.Logger.Info("Got a ReadTip request")
|
|
270
|
-
resp := &sync.ReadTipResponse{}
|
|
271
|
-
|
|
272
|
-
point := s.utxorpc.config.LedgerState.Tip().Point
|
|
273
|
-
resp.Tip = &sync.BlockRef{Index: point.Slot, Hash: point.Hash}
|
|
274
|
-
|
|
275
|
-
return connect.NewResponse(resp), nil
|
|
276
|
-
}
|
package/utxorpc/utxorpc.go
DELETED
|
@@ -1,166 +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 utxorpc
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"fmt"
|
|
19
|
-
"io"
|
|
20
|
-
"log/slog"
|
|
21
|
-
"net/http"
|
|
22
|
-
"time"
|
|
23
|
-
|
|
24
|
-
"connectrpc.com/connect"
|
|
25
|
-
"connectrpc.com/grpchealth"
|
|
26
|
-
"connectrpc.com/grpcreflect"
|
|
27
|
-
"github.com/blinklabs-io/dingo/event"
|
|
28
|
-
"github.com/blinklabs-io/dingo/ledger"
|
|
29
|
-
"github.com/blinklabs-io/dingo/mempool"
|
|
30
|
-
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/query/queryconnect"
|
|
31
|
-
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/submit/submitconnect"
|
|
32
|
-
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/sync/syncconnect"
|
|
33
|
-
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/watch/watchconnect"
|
|
34
|
-
"golang.org/x/net/http2"
|
|
35
|
-
"golang.org/x/net/http2/h2c"
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
type Utxorpc struct {
|
|
39
|
-
config UtxorpcConfig
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type UtxorpcConfig struct {
|
|
43
|
-
Logger *slog.Logger
|
|
44
|
-
EventBus *event.EventBus
|
|
45
|
-
LedgerState *ledger.LedgerState
|
|
46
|
-
Mempool *mempool.Mempool
|
|
47
|
-
Host string
|
|
48
|
-
Port uint
|
|
49
|
-
TlsCertFilePath string
|
|
50
|
-
TlsKeyFilePath string
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
func NewUtxorpc(cfg UtxorpcConfig) *Utxorpc {
|
|
54
|
-
if cfg.Logger == nil {
|
|
55
|
-
cfg.Logger = slog.New(slog.NewJSONHandler(io.Discard, nil))
|
|
56
|
-
}
|
|
57
|
-
cfg.Logger = cfg.Logger.With("component", "utxorpc")
|
|
58
|
-
if cfg.Host == "" {
|
|
59
|
-
cfg.Host = "0.0.0.0"
|
|
60
|
-
}
|
|
61
|
-
if cfg.Port == 0 {
|
|
62
|
-
cfg.Port = 9090
|
|
63
|
-
}
|
|
64
|
-
return &Utxorpc{
|
|
65
|
-
config: cfg,
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
func (u *Utxorpc) Start() error {
|
|
70
|
-
mux := http.NewServeMux()
|
|
71
|
-
compress1KB := connect.WithCompressMinBytes(1024)
|
|
72
|
-
queryPath, queryHandler := queryconnect.NewQueryServiceHandler(
|
|
73
|
-
&queryServiceServer{utxorpc: u},
|
|
74
|
-
compress1KB,
|
|
75
|
-
)
|
|
76
|
-
submitPath, submitHandler := submitconnect.NewSubmitServiceHandler(
|
|
77
|
-
&submitServiceServer{utxorpc: u},
|
|
78
|
-
compress1KB,
|
|
79
|
-
)
|
|
80
|
-
syncPath, syncHandler := syncconnect.NewSyncServiceHandler(
|
|
81
|
-
&syncServiceServer{utxorpc: u},
|
|
82
|
-
compress1KB,
|
|
83
|
-
)
|
|
84
|
-
watchPath, watchHandler := watchconnect.NewWatchServiceHandler(
|
|
85
|
-
&watchServiceServer{utxorpc: u},
|
|
86
|
-
compress1KB,
|
|
87
|
-
)
|
|
88
|
-
mux.Handle(queryPath, queryHandler)
|
|
89
|
-
mux.Handle(submitPath, submitHandler)
|
|
90
|
-
mux.Handle(syncPath, syncHandler)
|
|
91
|
-
mux.Handle(watchPath, watchHandler)
|
|
92
|
-
mux.Handle(
|
|
93
|
-
grpchealth.NewHandler(
|
|
94
|
-
grpchealth.NewStaticChecker(
|
|
95
|
-
queryconnect.QueryServiceName,
|
|
96
|
-
submitconnect.SubmitServiceName,
|
|
97
|
-
syncconnect.SyncServiceName,
|
|
98
|
-
watchconnect.WatchServiceName,
|
|
99
|
-
),
|
|
100
|
-
compress1KB,
|
|
101
|
-
),
|
|
102
|
-
)
|
|
103
|
-
mux.Handle(
|
|
104
|
-
grpcreflect.NewHandlerV1(
|
|
105
|
-
grpcreflect.NewStaticReflector(
|
|
106
|
-
queryconnect.QueryServiceName,
|
|
107
|
-
submitconnect.SubmitServiceName,
|
|
108
|
-
syncconnect.SyncServiceName,
|
|
109
|
-
watchconnect.WatchServiceName,
|
|
110
|
-
),
|
|
111
|
-
compress1KB,
|
|
112
|
-
),
|
|
113
|
-
)
|
|
114
|
-
mux.Handle(
|
|
115
|
-
grpcreflect.NewHandlerV1Alpha(
|
|
116
|
-
grpcreflect.NewStaticReflector(
|
|
117
|
-
queryconnect.QueryServiceName,
|
|
118
|
-
submitconnect.SubmitServiceName,
|
|
119
|
-
syncconnect.SyncServiceName,
|
|
120
|
-
watchconnect.WatchServiceName,
|
|
121
|
-
),
|
|
122
|
-
compress1KB,
|
|
123
|
-
),
|
|
124
|
-
)
|
|
125
|
-
if u.config.TlsCertFilePath != "" && u.config.TlsKeyFilePath != "" {
|
|
126
|
-
u.config.Logger.Info(
|
|
127
|
-
fmt.Sprintf(
|
|
128
|
-
"starting gRPC TLS listener on %s:%d",
|
|
129
|
-
u.config.Host,
|
|
130
|
-
u.config.Port,
|
|
131
|
-
),
|
|
132
|
-
)
|
|
133
|
-
utxorpc := &http.Server{
|
|
134
|
-
Addr: fmt.Sprintf(
|
|
135
|
-
"%s:%d",
|
|
136
|
-
u.config.Host,
|
|
137
|
-
u.config.Port,
|
|
138
|
-
),
|
|
139
|
-
Handler: mux,
|
|
140
|
-
ReadHeaderTimeout: 60 * time.Second,
|
|
141
|
-
}
|
|
142
|
-
return utxorpc.ListenAndServeTLS(
|
|
143
|
-
u.config.TlsCertFilePath,
|
|
144
|
-
u.config.TlsKeyFilePath,
|
|
145
|
-
)
|
|
146
|
-
} else {
|
|
147
|
-
u.config.Logger.Info(
|
|
148
|
-
fmt.Sprintf(
|
|
149
|
-
"starting gRPC listener on %s:%d",
|
|
150
|
-
u.config.Host,
|
|
151
|
-
u.config.Port,
|
|
152
|
-
),
|
|
153
|
-
)
|
|
154
|
-
utxorpc := &http.Server{
|
|
155
|
-
Addr: fmt.Sprintf(
|
|
156
|
-
"%s:%d",
|
|
157
|
-
u.config.Host,
|
|
158
|
-
u.config.Port,
|
|
159
|
-
),
|
|
160
|
-
// Use h2c so we can serve HTTP/2 without TLS
|
|
161
|
-
Handler: h2c.NewHandler(mux, &http2.Server{}),
|
|
162
|
-
ReadHeaderTimeout: 60 * time.Second,
|
|
163
|
-
}
|
|
164
|
-
return utxorpc.ListenAndServe()
|
|
165
|
-
}
|
|
166
|
-
}
|