github.com/koko1123/flow-go-1@v0.29.6/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/koko1123/flow-go-1/engine/common/rpc/convert" 10 "github.com/koko1123/flow-go-1/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 18 GetLatestBlockHeader(ctx context.Context, isSealed bool) (*flow.Header, flow.BlockStatus, error) 19 GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.Header, flow.BlockStatus, error) 20 GetBlockHeaderByID(ctx context.Context, id flow.Identifier) (*flow.Header, flow.BlockStatus, error) 21 22 GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, flow.BlockStatus, error) 23 GetBlockByHeight(ctx context.Context, height uint64) (*flow.Block, flow.BlockStatus, error) 24 GetBlockByID(ctx context.Context, id flow.Identifier) (*flow.Block, flow.BlockStatus, error) 25 26 GetCollectionByID(ctx context.Context, id flow.Identifier) (*flow.LightCollection, error) 27 28 SendTransaction(ctx context.Context, tx *flow.TransactionBody) error 29 GetTransaction(ctx context.Context, id flow.Identifier) (*flow.TransactionBody, error) 30 GetTransactionsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*flow.TransactionBody, error) 31 GetTransactionResult(ctx context.Context, id flow.Identifier) (*TransactionResult, error) 32 GetTransactionResultByIndex(ctx context.Context, blockID flow.Identifier, index uint32) (*TransactionResult, error) 33 GetTransactionResultsByBlockID(ctx context.Context, blockID flow.Identifier) ([]*TransactionResult, error) 34 35 GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error) 36 GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error) 37 GetAccountAtBlockHeight(ctx context.Context, address flow.Address, height uint64) (*flow.Account, error) 38 39 ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments [][]byte) ([]byte, error) 40 ExecuteScriptAtBlockHeight(ctx context.Context, blockHeight uint64, script []byte, arguments [][]byte) ([]byte, error) 41 ExecuteScriptAtBlockID(ctx context.Context, blockID flow.Identifier, script []byte, arguments [][]byte) ([]byte, error) 42 43 GetEventsForHeightRange(ctx context.Context, eventType string, startHeight, endHeight uint64) ([]flow.BlockEvents, error) 44 GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier) ([]flow.BlockEvents, error) 45 46 GetLatestProtocolStateSnapshot(ctx context.Context) ([]byte, error) 47 48 GetExecutionResultForBlockID(ctx context.Context, blockID flow.Identifier) (*flow.ExecutionResult, error) 49 GetExecutionResultByID(ctx context.Context, id flow.Identifier) (*flow.ExecutionResult, error) 50 } 51 52 // TODO: Combine this with flow.TransactionResult? 53 type TransactionResult struct { 54 Status flow.TransactionStatus 55 StatusCode uint 56 Events []flow.Event 57 ErrorMessage string 58 BlockID flow.Identifier 59 TransactionID flow.Identifier 60 CollectionID flow.Identifier 61 BlockHeight uint64 62 } 63 64 func TransactionResultToMessage(result *TransactionResult) *access.TransactionResultResponse { 65 return &access.TransactionResultResponse{ 66 Status: entities.TransactionStatus(result.Status), 67 StatusCode: uint32(result.StatusCode), 68 ErrorMessage: result.ErrorMessage, 69 Events: convert.EventsToMessages(result.Events), 70 BlockId: result.BlockID[:], 71 TransactionId: result.TransactionID[:], 72 CollectionId: result.CollectionID[:], 73 BlockHeight: uint64(result.BlockHeight), 74 } 75 } 76 77 func TransactionResultsToMessage(results []*TransactionResult) *access.TransactionResultsResponse { 78 messages := make([]*access.TransactionResultResponse, len(results)) 79 for i, result := range results { 80 messages[i] = TransactionResultToMessage(result) 81 } 82 83 return &access.TransactionResultsResponse{ 84 TransactionResults: messages, 85 } 86 } 87 88 func MessageToTransactionResult(message *access.TransactionResultResponse) *TransactionResult { 89 90 return &TransactionResult{ 91 Status: flow.TransactionStatus(message.Status), 92 StatusCode: uint(message.StatusCode), 93 ErrorMessage: message.ErrorMessage, 94 Events: convert.MessagesToEvents(message.Events), 95 BlockID: flow.HashToID(message.BlockId), 96 TransactionID: flow.HashToID(message.TransactionId), 97 CollectionID: flow.HashToID(message.CollectionId), 98 BlockHeight: message.BlockHeight, 99 } 100 } 101 102 // NetworkParameters contains the network-wide parameters for the Flow blockchain. 103 type NetworkParameters struct { 104 ChainID flow.ChainID 105 }