client

package
v0.0.0-...-cdf0fd8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: CC0-1.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateGrpcConnection

func CreateGrpcConnection(cfg types.Config) (*grpc.ClientConn, error)

CreateGrpcConnection creates a new gRPC client connection from the given configuration

func GetHeightRequestHeader

func GetHeightRequestHeader(height int64) grpc.CallOption

GetHeightRequestHeader returns the grpc.CallOption to query the state at a given height

func MustCreateGrpcConnection

func MustCreateGrpcConnection(cfg types.Config) *grpc.ClientConn

MustCreateGrpcConnection creates a new gRPC connection using the provided configuration and panics on error

Types

type Contracts

type Contracts struct {
	FungibleToken    string
	FlowToken        string
	FlowFee          string
	StakingTable     string
	LockedTokens     string
	NonFungibleToken string
	StakingProxy     string
	ChainID          string
}

func MainnetContracts

func MainnetContracts() Contracts

func TestnetContracts

func TestnetContracts() Contracts

type Proxy

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

Proxy implements a wrapper around both a Tendermint RPC client and a Cosmos Sdk REST client that allows for essential data queries.

func NewClientProxy

func NewClientProxy(cfg types.Config, encodingConfig *params.EncodingConfig) (*Proxy, error)

NewClientProxy allows to build a new Proxy instance

func (*Proxy) ElasticClient

func (cp *Proxy) ElasticClient() *elasticsearch.Client

func (*Proxy) GetGenesisHeight

func (cp *Proxy) GetGenesisHeight() uint64

GetGeneisisBlock parse the specific block as genesis block

func (*Proxy) LatestHeight

func (cp *Proxy) LatestHeight() (int64, error)

LatestHeight returns the latest block height on the active chain. An error is returned if the query fails.

func (Proxy) RestRequestGet

func (cp Proxy) RestRequestGet(endpoint string, values map[string]string) ([]byte, error)

QueryLCD queries the LCD at the given endpoint, and deserializes the result into the given pointer. If an error is raised, returns the error.

func (Proxy) RestRequestGetDecoded

func (cp Proxy) RestRequestGetDecoded(endpoint string, values map[string]string, ptr interface{}) error

func (*Proxy) Stop

func (cp *Proxy) Stop()

Txs queries for all the transactions in a block. Transactions are returned in the TransactionResult format which internally contains an array of Transactions. An error is returned if any query fails.

 func (cp *Proxy) Txs(block *flow.Block) (types.Txs, error) {

	var transactionIDs []flow.Identifier
	collections := cp.Collections(block)
	for _, collection := range collections {
		transactionIDs = append(transactionIDs, (collection.TransactionIds)...)
	}

	txResponses := make([]types.Tx, len(transactionIDs))
	for i, txID := range transactionIDs {
		transaction, err := cp.flowClient.GetTransaction(cp.ctx, txID)
		if err != nil {
			return nil, err
		}

		authoriser := make([]string, len(transaction.Authorizers))
		for i, auth := range transaction.Authorizers {
			authoriser[i] = auth.String()
		}

		payloadSignitures, err := json.Marshal(transaction.PayloadSignatures)
		if err != nil {
			return nil, err
		}

		envelopeSigniture, err := json.Marshal(transaction.EnvelopeSignatures)
		if err != nil {
			return nil, err
		}

		tx := types.NewTx(block.Height, txID.String(), transaction.Script, transaction.Arguments,
			transaction.ReferenceBlockID.String(), transaction.GasLimit, transaction.ProposalKey.Address.String(), transaction.Payer.String(),
			authoriser, payloadSignitures, envelopeSigniture)

		txResponses[i] = tx
	}
	return txResponses, nil
}
func (cp *Proxy) TransactionResult(transactionIds []flow.Identifier) ([]types.TransactionResult, error) {
	if len(transactionIds) == 0 {
		return nil, nil
	}

	txResults := make([]types.TransactionResult, len(transactionIds))
	for i, txid := range transactionIds {
		result, err := cp.flowClient.GetTransactionResult(cp.ctx, txid)
		if err != nil {
			return nil, err
		}
		errStr := ""
		if result.Error != nil {
			errStr = result.Error.Error()
		}
		txResults[i] = types.NewTransactionResult(txid.String(), result.Status.String(), errStr)
	}
	return txResults, nil
}
func (cp *Proxy) EventsInBlock(block *flow.Block) ([]types.Event, error) {
	txs, err := cp.Txs(block)
	if err != nil {
		return nil, err
	}
	var event []types.Event
	for _, tx := range txs {
		ev, err := cp.Events(tx.TransactionID, int(tx.Height))
		if err != nil {
			return []types.Event{}, err
		}
		event = append(event, ev...)
	}
	return event, nil
}
func (cp *Proxy) EventsInTransaction(tx types.Tx) ([]types.Event, error) {
	var event []types.Event

	ev, err := cp.Events(tx.TransactionID, int(tx.Height))
	if err != nil {
		return []types.Event{}, err
	}
	event = append(event, ev...)
	return event, nil
}

// Events get events from a transaction ID

func (cp *Proxy) Events(transactionID string, height int) ([]types.Event, error) {
	transactionResult, err := cp.flowClient.GetTransactionResult(cp.ctx, flow.HexToID(transactionID))
	if err != nil {
		return []types.Event{}, err
	}

	ev := make([]types.Event, len(transactionResult.Events))
	for i, event := range transactionResult.Events {
		ev[i] = types.NewEvent(height, event.Type, event.TransactionID.String(), event.TransactionIndex,
			event.EventIndex, event.Value)
	}
	return ev, nil
}

Stop defers the node stop execution to the RPC client.

Jump to

Keyboard shortcuts

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