-
Notifications
You must be signed in to change notification settings - Fork 175
/
api.go
74 lines (58 loc) · 3.02 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package access
import (
"context"
"github.com/onflow/flow/protobuf/go/flow/access"
"github.com/onflow/flow/protobuf/go/flow/entities"
"github.com/onflow/flow-go/engine/common/rpc/convert"
"github.com/onflow/flow-go/model/flow"
)
// API provides all public-facing functionality of the Flow Access API.
type API interface {
Ping(ctx context.Context) error
GetNetworkParameters(ctx context.Context) NetworkParameters
GetLatestBlockHeader(ctx context.Context, isSealed bool) (*flow.Header, error)
GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.Header, error)
GetBlockHeaderByID(ctx context.Context, id flow.Identifier) (*flow.Header, error)
GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, error)
GetBlockByHeight(ctx context.Context, height uint64) (*flow.Block, error)
GetBlockByID(ctx context.Context, id flow.Identifier) (*flow.Block, error)
GetCollectionByID(ctx context.Context, id flow.Identifier) (*flow.LightCollection, error)
SendTransaction(ctx context.Context, tx *flow.TransactionBody) error
GetTransaction(ctx context.Context, id flow.Identifier) (*flow.TransactionBody, error)
GetTransactionResult(ctx context.Context, id flow.Identifier) (*TransactionResult, error)
GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)
GetAccountAtLatestBlock(ctx context.Context, address flow.Address) (*flow.Account, error)
GetAccountAtBlockHeight(ctx context.Context, address flow.Address, height uint64) (*flow.Account, error)
ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments [][]byte) ([]byte, error)
ExecuteScriptAtBlockHeight(ctx context.Context, blockHeight uint64, script []byte, arguments [][]byte) ([]byte, error)
ExecuteScriptAtBlockID(ctx context.Context, blockID flow.Identifier, script []byte, arguments [][]byte) ([]byte, error)
GetEventsForHeightRange(ctx context.Context, eventType string, startHeight, endHeight uint64) ([]flow.BlockEvents, error)
GetEventsForBlockIDs(ctx context.Context, eventType string, blockIDs []flow.Identifier) ([]flow.BlockEvents, error)
}
// TODO: Combine this with flow.TransactionResult?
type TransactionResult struct {
Status flow.TransactionStatus
StatusCode uint
Events []flow.Event
ErrorMessage string
}
func TransactionResultToMessage(result *TransactionResult) *access.TransactionResultResponse {
return &access.TransactionResultResponse{
Status: entities.TransactionStatus(result.Status),
StatusCode: uint32(result.StatusCode),
ErrorMessage: result.ErrorMessage,
Events: convert.EventsToMessages(result.Events),
}
}
func MessageToTransactionResult(message *access.TransactionResultResponse) *TransactionResult {
return &TransactionResult{
Status: flow.TransactionStatus(message.Status),
StatusCode: uint(message.StatusCode),
ErrorMessage: message.ErrorMessage,
Events: convert.MessagesToEvents(message.Events),
}
}
// NetworkParameters contains the network-wide parameters for the Flow blockchain.
type NetworkParameters struct {
ChainID flow.ChainID
}