client

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var QueryNewBlockHeader = tmtypes.EventQueryNewBlockHeader

Functions

func NewHTTPConnection

func NewHTTPConnection(remote string) rpcclient.Client

NewHTTPConnection takes a URL and sends all requests to the remote node

func NewLocalConnection

func NewLocalConnection(node *nm.Node) rpcclient.Client

NewLocalConnection wraps an in-process node with a client, useful for tests

func QueryForHeader

func QueryForHeader() string

QueryForHeader is a subscription query for all new headers

func TestWithTendermint

func TestWithTendermint(app types.Application, cb func(*nm.Node), m Runner) int

TestWithTendermint provides adaptive startup capabilities and allows supplying a callback to initialize test resources dependent on tendermint node

Types

type Client

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

Client is a tendermint client wrapped to provide simple access to the basic data structures used in weave

Basic accessors are declared here. Higher-level API build around these basic accessors is defined on another level

func NewClient

func NewClient(conn rpcclient.Client) *Client

NewClient wraps a WeaveClient around an existing tendermint client connection.

func NewLocalClient

func NewLocalClient(node *nm.Node) *Client

NewLocalClient is simply a shorthand for a client with local connection

func (*Client) CommitTx

func (c *Client) CommitTx(ctx context.Context, tx weave.Tx) (*CommitResult, error)

CommitTx will block on both Check and Deliver, returning when it is in a block

func (*Client) CommitTxs

func (c *Client) CommitTxs(ctx context.Context, txs []weave.Tx) ([]*CommitResult, error)

CommitTxs will submit many transactions and wait until they are all included in blocks. Ideally, all in the same block.

If any tx fails in mempool or network, this returns an error TODO: improve error handling (maybe we need to use CommitResultOrError type?)

func (*Client) GetTxByID

func (c *Client) GetTxByID(ctx context.Context, id TransactionID) (*CommitResult, error)

GetTxByID will return 0 or 1 results (nil or result value)

func (*Client) Header

func (c *Client) Header(ctx context.Context, height int64) (*Header, error)

Header returns the block header at the given height. Returns an error if no header exists yet for that height

func (*Client) Query

func (c *Client) Query(query RequestQuery) ResponseQuery

Query is meant to mirror the abci query interface exactly, so we can wrap it with app.ABCIStore This will give us state from the application

TODO: provide other Query interface that accepts context for timeout??

func (*Client) SearchTx

func (c *Client) SearchTx(ctx context.Context, query TxQuery) ([]*CommitResult, error)

SearchTx will search for all committed transactions that match a query, returning them as one large array. It returns an error if the subscription request failed.

func (*Client) Status

func (c *Client) Status(ctx context.Context) (*Status, error)

Status returns current height and other (subjective) status info from this node

func (*Client) SubmitTx

func (c *Client) SubmitTx(ctx context.Context, tx weave.Tx) (TransactionID, error)

SubmitTx will submit the tx to the mempool and then return with success or error You will need to use WatchTx (easily parallelizable) to get the result. CommitTx and CommitTxs provide helpers for common use cases

func (*Client) SubscribeHeaders

func (c *Client) SubscribeHeaders(ctx context.Context, results chan<- Header, options ...Option) error

SubscribeHeaders will fills the channel with all new headers Stops when the context is cancelled

func (*Client) SubscribeTx

func (c *Client) SubscribeTx(ctx context.Context, query TxQuery, results chan<- CommitResult, options ...Option) error

SubscribeTx will subscribe to all transactions that match a query, writing them to the results channel as they arrive. It returns an error if the subscription request failed. Once subscriptions start, the continue until the context is closed (or network error)

func (*Client) SubscribeTxByID

func (c *Client) SubscribeTxByID(ctx context.Context, id TransactionID) (*CommitResult, error)

SubscribeTxByID will block until there is a result, then return it You must cancel the context to avoid blocking forever in some cases

func (*Client) WaitForHeight

func (c *Client) WaitForHeight(ctx context.Context, height int64) (*Header, error)

WaitForHeight subscribes to headers and returns as soon as a header arrives equal to or greater than the given height. If the requested height is in the past, it will still wait for the next block to arrive

func (*Client) WaitForNextBlock

func (c *Client) WaitForNextBlock(ctx context.Context) (*Header, error)

WaitForNextBlock will return the next block header to arrive (as subscription)

func (*Client) WatchTx

func (c *Client) WatchTx(ctx context.Context, id TransactionID) (*CommitResult, error)

WatchTx will block until this transaction makes it into a block It will return immediately if the id was included in a block prior to the query, to avoid timing issues You can use context.Context to pass in a timeout

func (*Client) WatchTxs

func (c *Client) WatchTxs(ctx context.Context, ids []TransactionID) ([]*CommitResult, error)

WatchTxs will watch a list of transactions in parallel

type CommitResult

type CommitResult struct {
	ID     TransactionID
	Height int64
	Result *weave.DeliverResult
	Err    error
}

CommitResult is returned from the block (DeliverTx) Result is only set on success codes, Err is set if it was a failure code

type GenesisDoc

type GenesisDoc = tmtypes.GenesisDoc

GenesisDoc is the full tendermint genesis file

type Header = tmtypes.Header

Header is a tendermint block header

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option represents an option supplied to subscription

type OptionCapacity

type OptionCapacity struct {
	Capacity int
}

OptionCapacity is used for setting channel outCapacity for subscriptions

type RequestQuery

type RequestQuery = abci.RequestQuery

RequestQuery is used for the query interface to mirror the abci query interface

type ResponseQuery

type ResponseQuery = abci.ResponseQuery

ResponseQuery is used for the query interface to mirror the abci query interface

type Runner

type Runner interface {
	Run() int
}

Runner is an interface that would allow us more flexibility in terms of types passed to the helper

type Status

type Status struct {
	Height     int64
	CatchingUp bool
}

Status is the current status of the node we connect to. Latest block height is a useful info

type TransactionID

type TransactionID = cmn.HexBytes

TransactionID is the hash used to identify the transaction

type TxQuery

type TxQuery = string

TxQuery is some query to find transactions

func QueryTxByID

func QueryTxByID(id TransactionID) TxQuery

QueryTxByID makes a subscription string based on the transaction id

Jump to

Keyboard shortcuts

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