@@ -3,19 +3,18 @@ package access
3
3
import (
4
4
"context"
5
5
6
- "github.com/onflow/flow/protobuf/go/flow/access"
7
6
"github.com/onflow/flow/protobuf/go/flow/entities"
8
7
9
8
"github.com/onflow/flow-go/engine/access/subscription"
10
- "github.com/onflow/flow-go/engine/common/rpc/convert "
9
+ accessmodel "github.com/onflow/flow-go/model/access "
11
10
"github.com/onflow/flow-go/model/flow"
12
11
)
13
12
14
13
// API provides all public-facing functionality of the Flow Access API.
15
14
type API interface {
16
15
Ping (ctx context.Context ) error
17
- GetNetworkParameters (ctx context.Context ) NetworkParameters
18
- GetNodeVersionInfo (ctx context.Context ) (* NodeVersionInfo , error )
16
+ GetNetworkParameters (ctx context.Context ) accessmodel. NetworkParameters
17
+ GetNodeVersionInfo (ctx context.Context ) (* accessmodel. NodeVersionInfo , error )
19
18
20
19
GetLatestBlockHeader (ctx context.Context , isSealed bool ) (* flow.Header , flow.BlockStatus , error )
21
20
GetBlockHeaderByHeight (ctx context.Context , height uint64 ) (* flow.Header , flow.BlockStatus , error )
@@ -31,11 +30,11 @@ type API interface {
31
30
SendTransaction (ctx context.Context , tx * flow.TransactionBody ) error
32
31
GetTransaction (ctx context.Context , id flow.Identifier ) (* flow.TransactionBody , error )
33
32
GetTransactionsByBlockID (ctx context.Context , blockID flow.Identifier ) ([]* flow.TransactionBody , error )
34
- GetTransactionResult (ctx context.Context , id flow.Identifier , blockID flow.Identifier , collectionID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) (* TransactionResult , error )
35
- GetTransactionResultByIndex (ctx context.Context , blockID flow.Identifier , index uint32 , requiredEventEncodingVersion entities.EventEncodingVersion ) (* TransactionResult , error )
36
- GetTransactionResultsByBlockID (ctx context.Context , blockID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) ([]* TransactionResult , error )
33
+ GetTransactionResult (ctx context.Context , id flow.Identifier , blockID flow.Identifier , collectionID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) (* accessmodel. TransactionResult , error )
34
+ GetTransactionResultByIndex (ctx context.Context , blockID flow.Identifier , index uint32 , requiredEventEncodingVersion entities.EventEncodingVersion ) (* accessmodel. TransactionResult , error )
35
+ GetTransactionResultsByBlockID (ctx context.Context , blockID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) ([]* accessmodel. TransactionResult , error )
37
36
GetSystemTransaction (ctx context.Context , blockID flow.Identifier ) (* flow.TransactionBody , error )
38
- GetSystemTransactionResult (ctx context.Context , blockID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) (* TransactionResult , error )
37
+ GetSystemTransactionResult (ctx context.Context , blockID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) (* accessmodel. TransactionResult , error )
39
38
40
39
GetAccount (ctx context.Context , address flow.Address ) (* flow.Account , error )
41
40
GetAccountAtLatestBlock (ctx context.Context , address flow.Address ) (* flow.Account , error )
@@ -80,6 +79,7 @@ type API interface {
80
79
//
81
80
// If invalid parameters will be supplied SubscribeBlocksFromStartBlockID will return a failed subscription.
82
81
SubscribeBlocksFromStartBlockID (ctx context.Context , startBlockID flow.Identifier , blockStatus flow.BlockStatus ) subscription.Subscription
82
+
83
83
// SubscribeBlocksFromStartHeight subscribes to the finalized or sealed blocks starting at the requested
84
84
// start block height, up until the latest available block. Once the latest is
85
85
// reached, the stream will remain open and responses are sent for each new
@@ -95,6 +95,7 @@ type API interface {
95
95
//
96
96
// If invalid parameters will be supplied SubscribeBlocksFromStartHeight will return a failed subscription.
97
97
SubscribeBlocksFromStartHeight (ctx context.Context , startHeight uint64 , blockStatus flow.BlockStatus ) subscription.Subscription
98
+
98
99
// SubscribeBlocksFromLatest subscribes to the finalized or sealed blocks starting at the latest sealed block,
99
100
// up until the latest available block. Once the latest is
100
101
// reached, the stream will remain open and responses are sent for each new
@@ -127,6 +128,7 @@ type API interface {
127
128
//
128
129
// If invalid parameters will be supplied SubscribeBlockHeadersFromStartBlockID will return a failed subscription.
129
130
SubscribeBlockHeadersFromStartBlockID (ctx context.Context , startBlockID flow.Identifier , blockStatus flow.BlockStatus ) subscription.Subscription
131
+
130
132
// SubscribeBlockHeadersFromStartHeight streams finalized or sealed block headers starting at the requested
131
133
// start block height, up until the latest available block header. Once the latest is
132
134
// reached, the stream will remain open and responses are sent for each new
@@ -142,6 +144,7 @@ type API interface {
142
144
//
143
145
// If invalid parameters will be supplied SubscribeBlockHeadersFromStartHeight will return a failed subscription.
144
146
SubscribeBlockHeadersFromStartHeight (ctx context.Context , startHeight uint64 , blockStatus flow.BlockStatus ) subscription.Subscription
147
+
145
148
// SubscribeBlockHeadersFromLatest streams finalized or sealed block headers starting at the latest sealed block,
146
149
// up until the latest available block header. Once the latest is
147
150
// reached, the stream will remain open and responses are sent for each new
@@ -174,6 +177,7 @@ type API interface {
174
177
//
175
178
// If invalid parameters will be supplied SubscribeBlockDigestsFromStartBlockID will return a failed subscription.
176
179
SubscribeBlockDigestsFromStartBlockID (ctx context.Context , startBlockID flow.Identifier , blockStatus flow.BlockStatus ) subscription.Subscription
180
+
177
181
// SubscribeBlockDigestsFromStartHeight streams finalized or sealed lightweight block starting at the requested
178
182
// start block height, up until the latest available block. Once the latest is
179
183
// reached, the stream will remain open and responses are sent for each new
@@ -189,6 +193,7 @@ type API interface {
189
193
//
190
194
// If invalid parameters will be supplied SubscribeBlockDigestsFromStartHeight will return a failed subscription.
191
195
SubscribeBlockDigestsFromStartHeight (ctx context.Context , startHeight uint64 , blockStatus flow.BlockStatus ) subscription.Subscription
196
+
192
197
// SubscribeBlockDigestsFromLatest streams finalized or sealed lightweight block starting at the latest sealed block,
193
198
// up until the latest available block. Once the latest is
194
199
// reached, the stream will remain open and responses are sent for each new
@@ -203,6 +208,7 @@ type API interface {
203
208
//
204
209
// If invalid parameters will be supplied SubscribeBlockDigestsFromLatest will return a failed subscription.
205
210
SubscribeBlockDigestsFromLatest (ctx context.Context , blockStatus flow.BlockStatus ) subscription.Subscription
211
+
206
212
// SubscribeTransactionStatusesFromStartBlockID subscribes to transaction status updates for a given transaction ID.
207
213
// Monitoring begins from the specified block ID. The subscription streams status updates until the transaction
208
214
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
@@ -214,6 +220,7 @@ type API interface {
214
220
// - startBlockID: The block ID from which to start monitoring.
215
221
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
216
222
SubscribeTransactionStatusesFromStartBlockID (ctx context.Context , txID flow.Identifier , startBlockID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) subscription.Subscription
223
+
217
224
// SubscribeTransactionStatusesFromStartHeight subscribes to transaction status updates for a given transaction ID.
218
225
// Monitoring begins from the specified block height. The subscription streams status updates until the transaction
219
226
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
@@ -225,6 +232,7 @@ type API interface {
225
232
// - startHeight: The block height from which to start monitoring.
226
233
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
227
234
SubscribeTransactionStatusesFromStartHeight (ctx context.Context , txID flow.Identifier , startHeight uint64 , requiredEventEncodingVersion entities.EventEncodingVersion ) subscription.Subscription
235
+
228
236
// SubscribeTransactionStatusesFromLatest subscribes to transaction status updates for a given transaction ID.
229
237
// Monitoring begins from the latest block. The subscription streams status updates until the transaction
230
238
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
@@ -235,6 +243,7 @@ type API interface {
235
243
// - txID: The unique identifier of the transaction to monitor.
236
244
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
237
245
SubscribeTransactionStatusesFromLatest (ctx context.Context , txID flow.Identifier , requiredEventEncodingVersion entities.EventEncodingVersion ) subscription.Subscription
246
+
238
247
// SendAndSubscribeTransactionStatuses sends a transaction to the network and subscribes to its status updates.
239
248
// Monitoring begins from the reference block saved in the transaction itself and streams status updates until the transaction
240
249
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). Once a final status is reached, the subscription
@@ -248,96 +257,3 @@ type API interface {
248
257
// If the transaction cannot be sent, the subscription will fail and return a failed subscription.
249
258
SendAndSubscribeTransactionStatuses (ctx context.Context , tx * flow.TransactionBody , requiredEventEncodingVersion entities.EventEncodingVersion ) subscription.Subscription
250
259
}
251
-
252
- // TODO: Combine this with flow.TransactionResult?
253
- type TransactionResult struct {
254
- Status flow.TransactionStatus
255
- StatusCode uint
256
- Events []flow.Event
257
- ErrorMessage string
258
- BlockID flow.Identifier
259
- TransactionID flow.Identifier
260
- CollectionID flow.Identifier
261
- BlockHeight uint64
262
- }
263
-
264
- func TransactionResultToMessage (result * TransactionResult ) * access.TransactionResultResponse {
265
- return & access.TransactionResultResponse {
266
- Status : entities .TransactionStatus (result .Status ),
267
- StatusCode : uint32 (result .StatusCode ),
268
- ErrorMessage : result .ErrorMessage ,
269
- Events : convert .EventsToMessages (result .Events ),
270
- BlockId : result .BlockID [:],
271
- TransactionId : result .TransactionID [:],
272
- CollectionId : result .CollectionID [:],
273
- BlockHeight : result .BlockHeight ,
274
- }
275
- }
276
-
277
- func TransactionResultsToMessage (results []* TransactionResult ) * access.TransactionResultsResponse {
278
- messages := make ([]* access.TransactionResultResponse , len (results ))
279
- for i , result := range results {
280
- messages [i ] = TransactionResultToMessage (result )
281
- }
282
-
283
- return & access.TransactionResultsResponse {
284
- TransactionResults : messages ,
285
- }
286
- }
287
-
288
- func MessageToTransactionResult (message * access.TransactionResultResponse ) * TransactionResult {
289
-
290
- return & TransactionResult {
291
- Status : flow .TransactionStatus (message .Status ),
292
- StatusCode : uint (message .StatusCode ),
293
- ErrorMessage : message .ErrorMessage ,
294
- Events : convert .MessagesToEvents (message .Events ),
295
- BlockID : flow .HashToID (message .BlockId ),
296
- TransactionID : flow .HashToID (message .TransactionId ),
297
- CollectionID : flow .HashToID (message .CollectionId ),
298
- BlockHeight : message .BlockHeight ,
299
- }
300
- }
301
-
302
- // NetworkParameters contains the network-wide parameters for the Flow blockchain.
303
- type NetworkParameters struct {
304
- ChainID flow.ChainID
305
- }
306
-
307
- // CompatibleRange contains the first and the last height that the version supports.
308
- type CompatibleRange struct {
309
- // The first block that the version supports.
310
- StartHeight uint64
311
- // The last block that the version supports.
312
- EndHeight uint64
313
- }
314
-
315
- // NodeVersionInfo contains information about node, such as semver, commit, sporkID, protocolVersion, etc
316
- type NodeVersionInfo struct {
317
- Semver string
318
- Commit string
319
- SporkId flow.Identifier
320
- // ProtocolVersion is the deprecated protocol version number.
321
- // Deprecated: Previously this referred to the major software version as of the most recent spork.
322
- // Replaced by protocol_state_version.
323
- ProtocolVersion uint64
324
- // ProtocolStateVersion is the Protocol State version as of the latest finalized block.
325
- // This tracks the schema version of the Protocol State and is used to coordinate breaking changes in the Protocol.
326
- // Version numbers are monotonically increasing.
327
- ProtocolStateVersion uint64
328
- SporkRootBlockHeight uint64
329
- NodeRootBlockHeight uint64
330
- CompatibleRange * CompatibleRange
331
- }
332
-
333
- // CompatibleRangeToMessage converts a flow.CompatibleRange to a protobuf message
334
- func CompatibleRangeToMessage (c * CompatibleRange ) * entities.CompatibleRange {
335
- if c != nil {
336
- return & entities.CompatibleRange {
337
- StartHeight : c .StartHeight ,
338
- EndHeight : c .EndHeight ,
339
- }
340
- }
341
-
342
- return nil
343
- }
0 commit comments