Skip to content

Commit a20dc99

Browse files
committed
refactor access structs into models/access
1 parent 0a7e228 commit a20dc99

38 files changed

+409
-278
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ generate-mocks: install-mock-generators
199199
mockery --name '.*' --dir="./consensus/hotstuff" --case=underscore --output="./consensus/hotstuff/mocks" --outpkg="mocks"
200200
mockery --name '.*' --dir="./engine/access/wrapper" --case=underscore --output="./engine/access/mock" --outpkg="mock"
201201
mockery --name 'API' --dir="./access" --case=underscore --output="./access/mock" --outpkg="mock"
202-
mockery --name 'Blocks' --dir="./access" --case=underscore --output="./access/mock" --outpkg="mock"
202+
mockery --name 'Blocks' --dir="./access/validator" --case=underscore --output="./access/validator/mock" --outpkg="mock"
203203
mockery --name 'API' --dir="./engine/protocol" --case=underscore --output="./engine/protocol/mock" --outpkg="mock"
204204
mockery --name '.*' --dir="./engine/access/state_stream" --case=underscore --output="./engine/access/state_stream/mock" --outpkg="mock"
205205
mockery --name 'BlockTracker' --dir="./engine/access/subscription" --case=underscore --output="./engine/access/subscription/mock" --outpkg="mock"

access/api.go

+17-101
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ package access
33
import (
44
"context"
55

6-
"github.com/onflow/flow/protobuf/go/flow/access"
76
"github.com/onflow/flow/protobuf/go/flow/entities"
87

98
"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"
1110
"github.com/onflow/flow-go/model/flow"
1211
)
1312

1413
// API provides all public-facing functionality of the Flow Access API.
1514
type API interface {
1615
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)
1918

2019
GetLatestBlockHeader(ctx context.Context, isSealed bool) (*flow.Header, flow.BlockStatus, error)
2120
GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.Header, flow.BlockStatus, error)
@@ -31,11 +30,11 @@ type API interface {
3130
SendTransaction(ctx context.Context, tx *flow.TransactionBody) error
3231
GetTransaction(ctx context.Context, id flow.Identifier) (*flow.TransactionBody, error)
3332
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)
3736
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)
3938

4039
GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)
4140
GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error)
@@ -80,6 +79,7 @@ type API interface {
8079
//
8180
// If invalid parameters will be supplied SubscribeBlocksFromStartBlockID will return a failed subscription.
8281
SubscribeBlocksFromStartBlockID(ctx context.Context, startBlockID flow.Identifier, blockStatus flow.BlockStatus) subscription.Subscription
82+
8383
// SubscribeBlocksFromStartHeight subscribes to the finalized or sealed blocks starting at the requested
8484
// start block height, up until the latest available block. Once the latest is
8585
// reached, the stream will remain open and responses are sent for each new
@@ -95,6 +95,7 @@ type API interface {
9595
//
9696
// If invalid parameters will be supplied SubscribeBlocksFromStartHeight will return a failed subscription.
9797
SubscribeBlocksFromStartHeight(ctx context.Context, startHeight uint64, blockStatus flow.BlockStatus) subscription.Subscription
98+
9899
// SubscribeBlocksFromLatest subscribes to the finalized or sealed blocks starting at the latest sealed block,
99100
// up until the latest available block. Once the latest is
100101
// reached, the stream will remain open and responses are sent for each new
@@ -127,6 +128,7 @@ type API interface {
127128
//
128129
// If invalid parameters will be supplied SubscribeBlockHeadersFromStartBlockID will return a failed subscription.
129130
SubscribeBlockHeadersFromStartBlockID(ctx context.Context, startBlockID flow.Identifier, blockStatus flow.BlockStatus) subscription.Subscription
131+
130132
// SubscribeBlockHeadersFromStartHeight streams finalized or sealed block headers starting at the requested
131133
// start block height, up until the latest available block header. Once the latest is
132134
// reached, the stream will remain open and responses are sent for each new
@@ -142,6 +144,7 @@ type API interface {
142144
//
143145
// If invalid parameters will be supplied SubscribeBlockHeadersFromStartHeight will return a failed subscription.
144146
SubscribeBlockHeadersFromStartHeight(ctx context.Context, startHeight uint64, blockStatus flow.BlockStatus) subscription.Subscription
147+
145148
// SubscribeBlockHeadersFromLatest streams finalized or sealed block headers starting at the latest sealed block,
146149
// up until the latest available block header. Once the latest is
147150
// reached, the stream will remain open and responses are sent for each new
@@ -174,6 +177,7 @@ type API interface {
174177
//
175178
// If invalid parameters will be supplied SubscribeBlockDigestsFromStartBlockID will return a failed subscription.
176179
SubscribeBlockDigestsFromStartBlockID(ctx context.Context, startBlockID flow.Identifier, blockStatus flow.BlockStatus) subscription.Subscription
180+
177181
// SubscribeBlockDigestsFromStartHeight streams finalized or sealed lightweight block starting at the requested
178182
// start block height, up until the latest available block. Once the latest is
179183
// reached, the stream will remain open and responses are sent for each new
@@ -189,6 +193,7 @@ type API interface {
189193
//
190194
// If invalid parameters will be supplied SubscribeBlockDigestsFromStartHeight will return a failed subscription.
191195
SubscribeBlockDigestsFromStartHeight(ctx context.Context, startHeight uint64, blockStatus flow.BlockStatus) subscription.Subscription
196+
192197
// SubscribeBlockDigestsFromLatest streams finalized or sealed lightweight block starting at the latest sealed block,
193198
// up until the latest available block. Once the latest is
194199
// reached, the stream will remain open and responses are sent for each new
@@ -203,6 +208,7 @@ type API interface {
203208
//
204209
// If invalid parameters will be supplied SubscribeBlockDigestsFromLatest will return a failed subscription.
205210
SubscribeBlockDigestsFromLatest(ctx context.Context, blockStatus flow.BlockStatus) subscription.Subscription
211+
206212
// SubscribeTransactionStatusesFromStartBlockID subscribes to transaction status updates for a given transaction ID.
207213
// Monitoring begins from the specified block ID. The subscription streams status updates until the transaction
208214
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
@@ -214,6 +220,7 @@ type API interface {
214220
// - startBlockID: The block ID from which to start monitoring.
215221
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
216222
SubscribeTransactionStatusesFromStartBlockID(ctx context.Context, txID flow.Identifier, startBlockID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
223+
217224
// SubscribeTransactionStatusesFromStartHeight subscribes to transaction status updates for a given transaction ID.
218225
// Monitoring begins from the specified block height. The subscription streams status updates until the transaction
219226
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
@@ -225,6 +232,7 @@ type API interface {
225232
// - startHeight: The block height from which to start monitoring.
226233
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
227234
SubscribeTransactionStatusesFromStartHeight(ctx context.Context, txID flow.Identifier, startHeight uint64, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
235+
228236
// SubscribeTransactionStatusesFromLatest subscribes to transaction status updates for a given transaction ID.
229237
// Monitoring begins from the latest block. The subscription streams status updates until the transaction
230238
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
@@ -235,6 +243,7 @@ type API interface {
235243
// - txID: The unique identifier of the transaction to monitor.
236244
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
237245
SubscribeTransactionStatusesFromLatest(ctx context.Context, txID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
246+
238247
// SendAndSubscribeTransactionStatuses sends a transaction to the network and subscribes to its status updates.
239248
// Monitoring begins from the reference block saved in the transaction itself and streams status updates until the transaction
240249
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). Once a final status is reached, the subscription
@@ -248,96 +257,3 @@ type API interface {
248257
// If the transaction cannot be sent, the subscription will fail and return a failed subscription.
249258
SendAndSubscribeTransactionStatuses(ctx context.Context, tx *flow.TransactionBody, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
250259
}
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-
}

access/legacy/convert/convert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
entitiesproto "github.com/onflow/flow/protobuf/go/flow/legacy/entities"
1111
"google.golang.org/protobuf/types/known/timestamppb"
1212

13-
"github.com/onflow/flow-go/access"
1413
"github.com/onflow/flow-go/engine/common/rpc/convert"
14+
accessmodel "github.com/onflow/flow-go/model/access"
1515
"github.com/onflow/flow-go/model/flow"
1616
)
1717

@@ -119,7 +119,7 @@ func TransactionToMessage(tb flow.TransactionBody) *entitiesproto.Transaction {
119119
}
120120
}
121121

122-
func TransactionResultToMessage(result access.TransactionResult) *accessproto.TransactionResultResponse {
122+
func TransactionResultToMessage(result accessmodel.TransactionResult) *accessproto.TransactionResultResponse {
123123
return &accessproto.TransactionResultResponse{
124124
Status: entitiesproto.TransactionStatus(result.Status),
125125
StatusCode: uint32(result.StatusCode),

0 commit comments

Comments
 (0)