github.com/onflow/flow-go@v0.33.17/access/api.go (about) 1 package access 2 3 import ( 4 "context" 5 6 "github.com/onflow/flow/protobuf/go/flow/access" 7 "github.com/onflow/flow/protobuf/go/flow/entities" 8 9 "github.com/onflow/flow-go/engine/common/rpc/convert" 10 "github.com/onflow/flow-go/model/flow" 11 ) 12 13 // API provides all public-facing functionality of the Flow Access API. 14 type API interface { 15 Ping(ctx context.Context) error 16 GetNetworkParameters(ctx context.Context) NetworkParameters 17 GetNodeVersionInfo(ctx context.Context) (*NodeVersionInfo, error) 18 19 GetLatestBlockHeader(ctx context.Context, isSealed bool) (*flow.Header, flow.BlockStatus, error) 20 GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.Header, flow.BlockStatus, error) 21 GetBlockHeaderByID(ctx context.Context, id flow.Identifier) (*flow.Header, flow.BlockStatus, error) 22 23 GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, flow.BlockStatus, error) 24 GetBlockByHeight(ctx context.Context, height uint64) (*flow.Block, flow.BlockStatus, error) 25 GetBlockByID(ctx context.Context, id flow.Identifier) (*flow.Block, flow.BlockStatus, error) 26 27 GetCollectionByID(ctx context.Context, id flow.Identifier) (*flow.LightCollection, error) 28 29 SendTransaction(ctx context.Context, tx *flow.TransactionBody) error 30 GetTransaction(ctx context.Context, id flow.Identifier) (*flow.TransactionBody, error) 31 GetTransactionsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*flow.TransactionBody, error) 32 GetTransactionResult(ctx context.Context, id flow.Identifier, blockID flow.Identifier, collectionID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) (*TransactionResult, error) 33 GetTransactionResultByIndex(ctx context.Context, blockID flow.Identifier, index uint32, requiredEventEncodingVersion entities.EventEncodingVersion) (*TransactionResult, error) 34 GetTransactionResultsByBlockID(ctx context.Context, blockID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) ([]*TransactionResult, error) 35 GetSystemTransaction(ctx context.Context, blockID flow.Identifier) (*flow.TransactionBody, error) 36 GetSystemTransactionResult(ctx context.Context, blockID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) (*TransactionResult, error) 37 38 GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error) 39 GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error) 40 GetAccountAtBlockHeight(ctx context.Context, address flow.Address, height uint64) (*flow.Account, error) 41 42 ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments [][]byte) ([]byte, error) 43 ExecuteScriptAtBlockHeight(ctx context.Context, blockHeight uint64, script []byte, arguments [][]byte) ([]byte, error) 44 ExecuteScriptAtBlockID(ctx context.Context, blockID flow.Identifier, script []byte, arguments [][]byte) ([]byte, error) 45 46 GetEventsForHeightRange(ctx context.Context, eventType string, startHeight, endHeight uint64, requiredEventEncodingVersion entities.EventEncodingVersion) ([]flow.BlockEvents, error) 47 GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) ([]flow.BlockEvents, error) 48 49 GetLatestProtocolStateSnapshot(ctx context.Context) ([]byte, error) 50 GetProtocolStateSnapshotByBlockID(ctx context.Context, blockID flow.Identifier) ([]byte, error) 51 GetProtocolStateSnapshotByHeight(ctx context.Context, blockHeight uint64) ([]byte, error) 52 53 GetExecutionResultForBlockID(ctx context.Context, blockID flow.Identifier) (*flow.ExecutionResult, error) 54 GetExecutionResultByID(ctx context.Context, id flow.Identifier) (*flow.ExecutionResult, error) 55 } 56 57 // TODO: Combine this with flow.TransactionResult? 58 type TransactionResult struct { 59 Status flow.TransactionStatus 60 StatusCode uint 61 Events []flow.Event 62 ErrorMessage string 63 BlockID flow.Identifier 64 TransactionID flow.Identifier 65 CollectionID flow.Identifier 66 BlockHeight uint64 67 } 68 69 func TransactionResultToMessage(result *TransactionResult) *access.TransactionResultResponse { 70 return &access.TransactionResultResponse{ 71 Status: entities.TransactionStatus(result.Status), 72 StatusCode: uint32(result.StatusCode), 73 ErrorMessage: result.ErrorMessage, 74 Events: convert.EventsToMessages(result.Events), 75 BlockId: result.BlockID[:], 76 TransactionId: result.TransactionID[:], 77 CollectionId: result.CollectionID[:], 78 BlockHeight: result.BlockHeight, 79 } 80 } 81 82 func TransactionResultsToMessage(results []*TransactionResult) *access.TransactionResultsResponse { 83 messages := make([]*access.TransactionResultResponse, len(results)) 84 for i, result := range results { 85 messages[i] = TransactionResultToMessage(result) 86 } 87 88 return &access.TransactionResultsResponse{ 89 TransactionResults: messages, 90 } 91 } 92 93 func MessageToTransactionResult(message *access.TransactionResultResponse) *TransactionResult { 94 95 return &TransactionResult{ 96 Status: flow.TransactionStatus(message.Status), 97 StatusCode: uint(message.StatusCode), 98 ErrorMessage: message.ErrorMessage, 99 Events: convert.MessagesToEvents(message.Events), 100 BlockID: flow.HashToID(message.BlockId), 101 TransactionID: flow.HashToID(message.TransactionId), 102 CollectionID: flow.HashToID(message.CollectionId), 103 BlockHeight: message.BlockHeight, 104 } 105 } 106 107 // NetworkParameters contains the network-wide parameters for the Flow blockchain. 108 type NetworkParameters struct { 109 ChainID flow.ChainID 110 } 111 112 // NodeVersionInfo contains information about node, such as semver, commit, sporkID, protocolVersion, etc 113 type NodeVersionInfo struct { 114 Semver string 115 Commit string 116 SporkId flow.Identifier 117 ProtocolVersion uint64 118 SporkRootBlockHeight uint64 119 NodeRootBlockHeight uint64 120 }