client

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: GPL-3.0 Imports: 18 Imported by: 4

README

BandChain Go Client Module

This module is a part of the BandChain Go Client SDK, a Go library for interacting with the BandChain blockchain. It provides a set of tools to easily communicate with BandChain to query data and send transactions.

Installation

To start using the BandChain Go Client SDK, install the library and its dependencies using the following command:

go get github.com/bandprotocol/go-band-sdk/client

Features

The client module provides the following functionalities:

  • Get account details
  • Retrieve transaction details
  • Get result of a request
  • Get signature of a request
  • Get block result
  • Query request failure reason
  • Get balance of an account
  • Send a request

Usage

Here is an example of how to use the client to retrieve data from BandChain:

package main

import (
	"fmt"

	"github.com/bandprotocol/go-band-sdk/client"
	"github.com/bandprotocol/go-band-sdk/utils/logger"
	"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

func main() {
	// Initialize a new keyring
	kr := keyring.NewInMemory()

	// Define the RPC endpoints
	endpoints := []string{"https://rpc.laozi-testnet6.bandchain.org:443"}

	// Create a new RPC client
	rpcClient, err := client.NewRPC(
		logger.NewLogrus("info"),
		endpoints,
		"band-laozi-testnet6",
		"30s",
		"0.0025uband",
		kr,
	)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Use the RPC client to get account details
	account, err := rpcClient.GetAccount(kr.GetAddress())
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Account details:", account)
}

In this example, we initialize a new client and use it to query the failure reason of a request with ID 1234.

Documentation

For more detailed information about the BandChain Go Client SDK and its modules, please refer to the official documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestID

func GetRequestID(events []sdk.StringEvent) (uint64, error)

func NewClientCtx

func NewClientCtx(chainID string) client.Context

Types

type Client

type Client interface {
	GetAccount(account sdk.AccAddress) (client.Account, error)
	GetTx(txHash string) (*sdk.TxResponse, error)
	GetResult(id uint64) (*oracletypes.Result, error)
	GetSignature(id uint64) ([]byte, error)
	GetBlockResult(height int64) (*ctypes.ResultBlockResults, error)
	QueryRequestFailureReason(id uint64) (string, error)
	GetBalance(account sdk.AccAddress) (uint64, error)
	SendRequest(msg *oracletypes.MsgRequestData, gasPrice float64, key keyring.Info) (*sdk.TxResponse, error)
}

type RPC

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

RPC implements Clients by using multiple RPC nodes

func NewRPC

func NewRPC(
	logger logging.Logger,
	endpoints []string,
	chainID string,
	timeout string,
	gasPrice string,
	keyring keyring.Keyring,
) (*RPC, error)

NewRPC creates new RPC client

func (RPC) GetAccount

func (c RPC) GetAccount(account sdk.AccAddress) (client.Account, error)

GetAccount find max account sequence from multiple clients

func (RPC) GetBalance

func (c RPC) GetBalance(_ sdk.AccAddress) (uint64, error)

func (RPC) GetBlockResult

func (c RPC) GetBlockResult(height int64) (*ctypes.ResultBlockResults, error)

func (RPC) GetResult

func (c RPC) GetResult(id uint64) (*oracletypes.Result, error)

GetResult find result from multiple clients

func (RPC) GetSignature

func (c RPC) GetSignature(_ uint64) ([]byte, error)

func (RPC) GetTx

func (c RPC) GetTx(txHash string) (*sdk.TxResponse, error)

func (RPC) QueryRequestFailureReason

func (c RPC) QueryRequestFailureReason(id uint64) (string, error)

func (RPC) SendRequest

func (c RPC) SendRequest(msg *oracletypes.MsgRequestData, gasPrice float64, key keyring.Info) (*sdk.TxResponse, error)

Directories

Path Synopsis
Package client is a generated GoMock package.
Package client is a generated GoMock package.

Jump to

Keyboard shortcuts

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