Skip to content

Commit b9ce455

Browse files
authored
Merge pull request #808 from onflow/peter/update-access-interface
Update access interface to align with latest changes
2 parents fdd2e42 + 3cf648e commit b9ce455

7 files changed

Lines changed: 1086 additions & 40 deletions

File tree

access/client.go

Lines changed: 191 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,57 +37,90 @@ type Client interface {
3737
// Ping is used to check if the access node is alive and healthy.
3838
Ping(ctx context.Context) error
3939

40-
// GetNetworkParameters gets the network parameters.
40+
// GetNetworkParameters returns the network parameters.
4141
GetNetworkParameters(ctx context.Context) (*flow.NetworkParameters, error)
4242

43-
// GetNodeVersionInfo gets the node information about the network.
43+
// GetNodeVersionInfo returns the node information about the network.
4444
GetNodeVersionInfo(ctx context.Context) (*flow.NodeVersionInfo, error)
4545

46-
// GetLatestBlockHeader gets the latest sealed or unsealed block header.
46+
// GetLatestBlockHeader returns the latest sealed or unsealed block header.
4747
GetLatestBlockHeader(ctx context.Context, isSealed bool) (*flow.BlockHeader, error)
4848

49-
// GetBlockHeaderByID gets a block header by ID.
49+
// GetBlockHeaderByID returns a block header by ID.
5050
GetBlockHeaderByID(ctx context.Context, blockID flow.Identifier) (*flow.BlockHeader, error)
5151

52-
// GetBlockHeaderByHeight gets a block header by height.
52+
// GetBlockHeaderByHeight returns a block header by height.
5353
GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.BlockHeader, error)
5454

55-
// GetLatestBlock gets the full payload of the latest sealed or unsealed block.
55+
// GetLatestBlock returns the full payload of the latest sealed or unsealed block.
5656
GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, error)
5757

58-
// GetBlockByID gets a full block by ID.
58+
// GetBlockByID returns a full block by ID.
5959
GetBlockByID(ctx context.Context, blockID flow.Identifier) (*flow.Block, error)
6060

61-
// GetBlockByHeight gets a full block by height.
61+
// GetBlockByHeight returns a full block by height.
6262
GetBlockByHeight(ctx context.Context, height uint64) (*flow.Block, error)
6363

64-
// GetCollection gets a collection by ID.
64+
// GetCollection returns a collection by ID.
6565
GetCollection(ctx context.Context, colID flow.Identifier) (*flow.Collection, error)
6666

67+
// GetCollectionByID returns a collection by ID.
68+
GetCollectionByID(ctx context.Context, id flow.Identifier) (*flow.Collection, error)
69+
70+
// GetFullCollectionByID returns a full collection including transaction bodies by ID.
71+
GetFullCollectionByID(ctx context.Context, id flow.Identifier) (*flow.FullCollection, error)
72+
6773
// SendTransaction submits a transaction to the network.
6874
SendTransaction(ctx context.Context, tx flow.Transaction) error
6975

70-
// GetTransaction gets a transaction by ID.
76+
// GetTransaction returns a transaction by ID.
7177
GetTransaction(ctx context.Context, txID flow.Identifier) (*flow.Transaction, error)
7278

73-
// GetTransactionsByBlockID gets all the transactions for a specified block.
79+
// GetTransactionsByBlockID returns all the transactions for a specified block.
7480
GetTransactionsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*flow.Transaction, error)
7581

76-
// GetTransactionResult gets the result of a transaction.
82+
// GetTransactionResult returns the result of a transaction.
7783
GetTransactionResult(ctx context.Context, txID flow.Identifier) (*flow.TransactionResult, error)
7884

79-
// GetTransactionResultsByBlockID gets all the transaction results for a specified block.
85+
// GetTransactionResultByIndex returns a transaction result by transaction index for the given block ID.
86+
GetTransactionResultByIndex(ctx context.Context, blockID flow.Identifier, index uint32) (*flow.TransactionResult, error)
87+
88+
// GetTransactionResultsByBlockID returns all the transaction results for a specified block.
8089
GetTransactionResultsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*flow.TransactionResult, error)
8190

91+
// GetSystemTransaction returns the system transaction for the given block ID.
92+
GetSystemTransaction(ctx context.Context, blockID flow.Identifier) (*flow.Transaction, error)
93+
94+
// GetSystemTransactionResult returns the transaction result of the system transaction for the given block ID.
95+
GetSystemTransactionResult(ctx context.Context, blockID flow.Identifier) (*flow.TransactionResult, error)
96+
8297
// GetAccount is an alias for GetAccountAtLatestBlock.
8398
GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)
8499

85-
// GetAccountAtLatestBlock gets an account by address at the latest sealed block.
100+
// GetAccountAtLatestBlock returns an account by address at the latest sealed block.
86101
GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error)
87102

88-
// GetAccountAtBlockHeight gets an account by address at the given block height
103+
// GetAccountAtBlockHeight returns an account by address at the given block height
89104
GetAccountAtBlockHeight(ctx context.Context, address flow.Address, blockHeight uint64) (*flow.Account, error)
90105

106+
// GetAccountBalanceAtLatestBlock returns the balance of an account at the latest sealed block.
107+
GetAccountBalanceAtLatestBlock(ctx context.Context, address flow.Address) (uint64, error)
108+
109+
// GetAccountBalanceAtBlockHeight returns the balance of an account at the given block height.
110+
GetAccountBalanceAtBlockHeight(ctx context.Context, address flow.Address, blockHeight uint64) (uint64, error)
111+
112+
// GetAccountKeyAtLatestBlock returns the account key with the provided index at the latest sealed block.
113+
GetAccountKeyAtLatestBlock(ctx context.Context, address flow.Address, keyIndex uint32) (*flow.AccountKey, error)
114+
115+
// GetAccountKeyAtBlockHeight returns the account key with the provided index at the given block height.
116+
GetAccountKeyAtBlockHeight(ctx context.Context, address flow.Address, keyIndex uint32, height uint64) (*flow.AccountKey, error)
117+
118+
// GetAccountKeysAtLatestBlock returns all account keys at the latest sealed block.
119+
GetAccountKeysAtLatestBlock(ctx context.Context, address flow.Address) ([]*flow.AccountKey, error)
120+
121+
// GetAccountKeysAtBlockHeight returns all account keys at the given block height.
122+
GetAccountKeysAtBlockHeight(ctx context.Context, address flow.Address, height uint64) ([]*flow.AccountKey, error)
123+
91124
// ExecuteScriptAtLatestBlock executes a read-only Cadence script against the latest sealed execution state.
92125
ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments []cadence.Value) (cadence.Value, error)
93126

@@ -97,34 +130,167 @@ type Client interface {
97130
// ExecuteScriptAtBlockHeight executes a ready-only Cadence script against the execution state at the given block height.
98131
ExecuteScriptAtBlockHeight(ctx context.Context, height uint64, script []byte, arguments []cadence.Value) (cadence.Value, error)
99132

100-
// GetEventsForHeightRange retrieves events for all sealed blocks between the start and end block heights (inclusive) with the given type.
133+
// GetEventsForHeightRange returns events for all sealed blocks between the start and end block heights (inclusive) with the given type.
101134
GetEventsForHeightRange(ctx context.Context, eventType string, startHeight uint64, endHeight uint64) ([]flow.BlockEvents, error)
102135

103-
// GetEventsForBlockIDs retrieves events with the given type from the specified block IDs.
136+
// GetEventsForBlockIDs returns events with the given type from the specified block IDs.
104137
GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier) ([]flow.BlockEvents, error)
105138

106-
// GetLatestProtocolStateSnapshot retrieves the latest snapshot of the protocol
107-
// state in serialized form. This is used to generate a root snapshot file
108-
// used by Flow nodes to bootstrap their local protocol state database.
139+
// GetLatestProtocolStateSnapshot returns the protocol state snapshot in serialized form at latest sealed block.
140+
// This is used to generate a root snapshot file used by Flow nodes to bootstrap their local protocol state database.
109141
GetLatestProtocolStateSnapshot(ctx context.Context) ([]byte, error)
110142

111-
// GetExecutionResultForBlockID gets the execution results at the block ID.
143+
// GetProtocolStateSnapshotByBlockID returns the protocol state snapshot in serialized form at the given block ID.
144+
// This is used to generate a root snapshot file used by Flow nodes to bootstrap their local protocol state database.
145+
GetProtocolStateSnapshotByBlockID(ctx context.Context, blockID flow.Identifier) ([]byte, error)
146+
147+
// GetProtocolStateSnapshotByHeight returns the protocol state snapshot in serialized form at the given block height.
148+
// This is used to generate a root snapshot file used by Flow nodes to bootstrap their local protocol state database.
149+
GetProtocolStateSnapshotByHeight(ctx context.Context, blockHeight uint64) ([]byte, error)
150+
151+
// GetExecutionResultByID returns the execution result by ID.
152+
GetExecutionResultByID(ctx context.Context, id flow.Identifier) (*flow.ExecutionResult, error)
153+
154+
// GetExecutionResultForBlockID returns the execution results at the block ID.
112155
GetExecutionResultForBlockID(ctx context.Context, blockID flow.Identifier) (*flow.ExecutionResult, error)
113156

114157
// GetExecutionDataByBlockID returns execution data for a specific block ID.
115158
GetExecutionDataByBlockID(ctx context.Context, blockID flow.Identifier) (*flow.ExecutionData, error)
116159

117160
// SubscribeExecutionDataByBlockID subscribes to execution data updates starting at the given block ID.
118-
SubscribeExecutionDataByBlockID(ctx context.Context, startBlockID flow.Identifier) (<-chan *flow.ExecutionDataStreamResponse, <-chan error, error)
161+
SubscribeExecutionDataByBlockID(
162+
ctx context.Context,
163+
startBlockID flow.Identifier,
164+
) (<-chan *flow.ExecutionDataStreamResponse, <-chan error, error)
119165

120166
// SubscribeExecutionDataByBlockHeight subscribes to execution data updates starting at the given block height.
121-
SubscribeExecutionDataByBlockHeight(ctx context.Context, startHeight uint64) (<-chan *flow.ExecutionDataStreamResponse, <-chan error, error)
167+
SubscribeExecutionDataByBlockHeight(
168+
ctx context.Context,
169+
startHeight uint64,
170+
) (<-chan *flow.ExecutionDataStreamResponse, <-chan error, error)
122171

123172
// SubscribeEventsByBlockID subscribes to events starting at the given block ID.
124-
SubscribeEventsByBlockID(ctx context.Context, startBlockID flow.Identifier, filter flow.EventFilter, opts ...SubscribeOption) (<-chan flow.BlockEvents, <-chan error, error)
173+
SubscribeEventsByBlockID(
174+
ctx context.Context,
175+
startBlockID flow.Identifier,
176+
filter flow.EventFilter,
177+
opts ...SubscribeOption,
178+
) (<-chan flow.BlockEvents, <-chan error, error)
125179

126180
// SubscribeEventsByBlockHeight subscribes to events starting at the given block height.
127-
SubscribeEventsByBlockHeight(ctx context.Context, startHeight uint64, filter flow.EventFilter, opts ...SubscribeOption) (<-chan flow.BlockEvents, <-chan error, error)
181+
SubscribeEventsByBlockHeight(
182+
ctx context.Context,
183+
startHeight uint64,
184+
filter flow.EventFilter,
185+
opts ...SubscribeOption,
186+
) (<-chan flow.BlockEvents, <-chan error, error)
187+
188+
// SubscribeBlockDigestsFromStartBlockID subscribes to block digests with the given status
189+
// starting at the given block ID.
190+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
191+
SubscribeBlockDigestsFromStartBlockID(
192+
ctx context.Context,
193+
startBlockID flow.Identifier,
194+
blockStatus flow.BlockStatus,
195+
) (<-chan *flow.BlockDigest, <-chan error, error)
196+
197+
// SubscribeBlockDigestsFromStartHeight subscribes to block digests with the given status
198+
// starting at the given block height.
199+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
200+
SubscribeBlockDigestsFromStartHeight(
201+
ctx context.Context,
202+
startHeight uint64,
203+
blockStatus flow.BlockStatus,
204+
) (<-chan *flow.BlockDigest, <-chan error, error)
205+
206+
// SubscribeBlockDigestsFromLatest subscribes to block digests with the given status
207+
// starting at the latest block.
208+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
209+
SubscribeBlockDigestsFromLatest(
210+
ctx context.Context,
211+
blockStatus flow.BlockStatus,
212+
) (<-chan *flow.BlockDigest, <-chan error, error)
213+
214+
// SubscribeBlocksFromStartBlockID subscribes to blocks with the given status starting at the
215+
// given block ID.
216+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
217+
SubscribeBlocksFromStartBlockID(
218+
ctx context.Context,
219+
startBlockID flow.Identifier,
220+
blockStatus flow.BlockStatus,
221+
) (<-chan *flow.Block, <-chan error, error)
222+
223+
// SubscribeBlocksFromStartHeight subscribes to blocks with the given status starting at the
224+
// given block height.
225+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
226+
SubscribeBlocksFromStartHeight(
227+
ctx context.Context,
228+
startHeight uint64,
229+
blockStatus flow.BlockStatus,
230+
) (<-chan *flow.Block, <-chan error, error)
231+
232+
// SubscribeBlocksFromLatest subscribes to blocks with the given status starting at the latest block.
233+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
234+
SubscribeBlocksFromLatest(
235+
ctx context.Context,
236+
blockStatus flow.BlockStatus,
237+
) (<-chan *flow.Block, <-chan error, error)
238+
239+
// SubscribeBlockHeadersFromStartBlockID subscribes to block headers with the given status starting
240+
// at the given block ID.
241+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
242+
SubscribeBlockHeadersFromStartBlockID(
243+
ctx context.Context,
244+
startBlockID flow.Identifier,
245+
blockStatus flow.BlockStatus,
246+
) (<-chan *flow.BlockHeader, <-chan error, error)
247+
248+
// SubscribeBlockHeadersFromStartHeight subscribes to block headers with the given status starting
249+
// at the given block height.
250+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
251+
SubscribeBlockHeadersFromStartHeight(
252+
ctx context.Context,
253+
startHeight uint64,
254+
blockStatus flow.BlockStatus,
255+
) (<-chan *flow.BlockHeader, <-chan error, error)
256+
257+
// SubscribeBlockHeadersFromLatest subscribes to block headers with the given status starting
258+
// at the latest block.
259+
// The status may be either flow.BlockStatusFinalized or flow.BlockStatusSealed
260+
SubscribeBlockHeadersFromLatest(
261+
ctx context.Context,
262+
blockStatus flow.BlockStatus,
263+
) (<-chan *flow.BlockHeader, <-chan error, error)
264+
265+
// SubscribeAccountStatusesFromStartHeight subscribes to account status events starting at the
266+
// given block height.
267+
SubscribeAccountStatusesFromStartHeight(
268+
ctx context.Context,
269+
startBlockHeight uint64,
270+
filter flow.AccountStatusFilter,
271+
) (<-chan *flow.AccountStatus, <-chan error, error)
272+
273+
// SubscribeAccountStatusesFromStartBlockID subscribes to account status events starting at the
274+
// given block ID.
275+
SubscribeAccountStatusesFromStartBlockID(
276+
ctx context.Context,
277+
startBlockID flow.Identifier,
278+
filter flow.AccountStatusFilter,
279+
) (<-chan *flow.AccountStatus, <-chan error, error)
280+
281+
// SubscribeAccountStatusesFromLatestBlock subscribes to account status events starting at the
282+
// latest block.
283+
SubscribeAccountStatusesFromLatestBlock(
284+
ctx context.Context,
285+
filter flow.AccountStatusFilter,
286+
) (<-chan *flow.AccountStatus, <-chan error, error)
287+
288+
// SendAndSubscribeTransactionStatuses submits a transaction to the network and subscribes to the
289+
// transaction status updates.
290+
SendAndSubscribeTransactionStatuses(
291+
ctx context.Context,
292+
tx flow.Transaction,
293+
) (<-chan *flow.TransactionResult, <-chan error, error)
128294

129295
// Close stops the client connection to the access node.
130296
Close() error

access/grpc/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (c *Client) SubscribeBlockHeadersFromStartHeight(
391391
return c.grpc.SubscribeBlockHeadersFromStartHeight(ctx, startHeight, blockStatus)
392392
}
393393

394-
func (c *Client) SubscribeBlocksHeadersFromLatest(
394+
func (c *Client) SubscribeBlockHeadersFromLatest(
395395
ctx context.Context,
396396
blockStatus flow.BlockStatus,
397397
) (<-chan *flow.BlockHeader, <-chan error, error) {

access/grpc/grpc.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,14 @@ func (c *BaseClient) GetAccountKeyAtLatestBlock(
657657
ctx context.Context,
658658
address flow.Address,
659659
keyIndex uint32,
660+
opts ...grpc.CallOption,
660661
) (*flow.AccountKey, error) {
661662
request := &access.GetAccountKeyAtLatestBlockRequest{
662663
Address: address.Bytes(),
663664
Index: keyIndex,
664665
}
665666

666-
response, err := c.rpcClient.GetAccountKeyAtLatestBlock(ctx, request)
667+
response, err := c.rpcClient.GetAccountKeyAtLatestBlock(ctx, request, opts...)
667668
if err != nil {
668669
return nil, newRPCError(err)
669670
}
@@ -681,14 +682,15 @@ func (c *BaseClient) GetAccountKeyAtBlockHeight(
681682
address flow.Address,
682683
keyIndex uint32,
683684
height uint64,
685+
opts ...grpc.CallOption,
684686
) (*flow.AccountKey, error) {
685687
request := &access.GetAccountKeyAtBlockHeightRequest{
686688
Address: address.Bytes(),
687689
Index: keyIndex,
688690
BlockHeight: height,
689691
}
690692

691-
response, err := c.rpcClient.GetAccountKeyAtBlockHeight(ctx, request)
693+
response, err := c.rpcClient.GetAccountKeyAtBlockHeight(ctx, request, opts...)
692694
if err != nil {
693695
return nil, newRPCError(err)
694696
}
@@ -704,12 +706,13 @@ func (c *BaseClient) GetAccountKeyAtBlockHeight(
704706
func (c *BaseClient) GetAccountKeysAtLatestBlock(
705707
ctx context.Context,
706708
address flow.Address,
709+
opts ...grpc.CallOption,
707710
) ([]*flow.AccountKey, error) {
708711
request := &access.GetAccountKeysAtLatestBlockRequest{
709712
Address: address.Bytes(),
710713
}
711714

712-
response, err := c.rpcClient.GetAccountKeysAtLatestBlock(ctx, request)
715+
response, err := c.rpcClient.GetAccountKeysAtLatestBlock(ctx, request, opts...)
713716
if err != nil {
714717
return nil, newRPCError(err)
715718
}
@@ -726,13 +729,14 @@ func (c *BaseClient) GetAccountKeysAtBlockHeight(
726729
ctx context.Context,
727730
address flow.Address,
728731
height uint64,
732+
opts ...grpc.CallOption,
729733
) ([]*flow.AccountKey, error) {
730734
request := &access.GetAccountKeysAtBlockHeightRequest{
731735
Address: address.Bytes(),
732736
BlockHeight: height,
733737
}
734738

735-
response, err := c.rpcClient.GetAccountKeysAtBlockHeight(ctx, request)
739+
response, err := c.rpcClient.GetAccountKeysAtBlockHeight(ctx, request, opts...)
736740
if err != nil {
737741
return nil, newRPCError(err)
738742
}

0 commit comments

Comments
 (0)