client

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2020 License: Apache-2.0 Imports: 7 Imported by: 62

Documentation

Overview

Package client provides a Go client for the Flow Access gRPC API.

The Access API provides a set of methods that can be used to submit transactions and read state from Flow. This client is compatible with the Access API implemented by the Access Node role, as well as the mock Access API exposed by the Flow Emulator.

The full Access API specification is here: https://github.com/onflow/flow/blob/master/docs/access-api-spec.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockEvents

type BlockEvents struct {
	BlockID flow.Identifier
	Height  uint64
	Events  []flow.Event
}

BlockEvents are the events that occurred in a specific block.

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is a gRPC Client for the Flow Access API.

func New

func New(addr string, opts ...grpc.DialOption) (*Client, error)

New initializes a Flow client with the default gRPC provider.

An error will be returned if the host is unreachable.

func NewFromRPCClient

func NewFromRPCClient(rpcClient RPCClient) *Client

NewFromRPCClient initializes a Flow client using a pre-configured gRPC provider.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

func (*Client) ExecuteScriptAtBlockHeight

func (c *Client) ExecuteScriptAtBlockHeight(
	ctx context.Context,
	height uint64,
	script []byte,
	arguments []cadence.Value,
) (cadence.Value, error)

ExecuteScriptAtBlockHeight executes a ready-only Cadence script against the execution state at the given block height.

func (*Client) ExecuteScriptAtBlockID

func (c *Client) ExecuteScriptAtBlockID(
	ctx context.Context,
	blockID flow.Identifier,
	script []byte,
	arguments []cadence.Value,
) (cadence.Value, error)

ExecuteScriptAtBlockID executes a ready-only Cadence script against the execution state at the block with the given ID.

func (*Client) ExecuteScriptAtLatestBlock

func (c *Client) ExecuteScriptAtLatestBlock(
	ctx context.Context,
	script []byte,
	arguments []cadence.Value) (cadence.Value, error)

ExecuteScriptAtLatestBlock executes a read-only Cadence script against the latest sealed execution state.

func (*Client) GetAccount

func (c *Client) GetAccount(ctx context.Context, address flow.Address) (*flow.Account, error)

GetAccount gets an account by address.

func (*Client) GetBlockByHeight

func (c *Client) GetBlockByHeight(ctx context.Context, height uint64) (*flow.Block, error)

GetBlockByHeight gets a full block by height.

func (*Client) GetBlockByID

func (c *Client) GetBlockByID(ctx context.Context, blockID flow.Identifier) (*flow.Block, error)

GetBlockByID gets a full block by ID.

func (*Client) GetBlockHeaderByHeight

func (c *Client) GetBlockHeaderByHeight(ctx context.Context, height uint64) (*flow.BlockHeader, error)

GetBlockHeaderByHeight gets a block header by height.

func (*Client) GetBlockHeaderByID

func (c *Client) GetBlockHeaderByID(ctx context.Context, blockID flow.Identifier) (*flow.BlockHeader, error)

GetBlockHeaderByID gets a block header by ID.

func (*Client) GetCollection

func (c *Client) GetCollection(ctx context.Context, colID flow.Identifier) (*flow.Collection, error)

GetCollection gets a collection by ID.

func (*Client) GetEventsForBlockIDs

func (c *Client) GetEventsForBlockIDs(
	ctx context.Context,
	eventType string,
	blockIDs []flow.Identifier,
) ([]BlockEvents, error)

GetEventsForBlockIDs retrieves events with the given type from the specified block IDs.

func (*Client) GetEventsForHeightRange

func (c *Client) GetEventsForHeightRange(ctx context.Context, query EventRangeQuery) ([]BlockEvents, error)

GetEventsForHeightRange retrieves events for all sealed blocks between the start and end block heights (inclusive) with the given type.

func (*Client) GetLatestBlock

func (c *Client) GetLatestBlock(ctx context.Context, isSealed bool) (*flow.Block, error)

GetLatestBlock gets the full payload of the latest sealed or unsealed block.

func (*Client) GetLatestBlockHeader

func (c *Client) GetLatestBlockHeader(
	ctx context.Context,
	isSealed bool,
) (*flow.BlockHeader, error)

GetLatestBlockHeader gets the latest sealed or unsealed block header.

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, txID flow.Identifier) (*flow.Transaction, error)

GetTransaction gets a transaction by ID.

func (*Client) GetTransactionResult

func (c *Client) GetTransactionResult(ctx context.Context, txID flow.Identifier) (*flow.TransactionResult, error)

GetTransactionResult gets the result of a transaction.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping is used to check if the access node is alive and healthy.

func (*Client) SendTransaction

func (c *Client) SendTransaction(ctx context.Context, tx flow.Transaction) error

SendTransaction submits a transaction to the network.

type EventRangeQuery

type EventRangeQuery struct {
	// The event type to search for. If empty, no filtering by type is done.
	Type string
	// The block height to begin looking for events
	StartHeight uint64
	// The block height to end looking for events (inclusive)
	EndHeight uint64
}

EventRangeQuery defines a query for Flow events.

type RPCClient

type RPCClient interface {
	access.AccessAPIClient
}

An RPCClient is an RPC client for the Flow Access API.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL