client

package
v0.0.0-...-efdc0dc Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: AGPL-3.0 Imports: 19 Imported by: 0

README

Chain Client

This chain client will be used for integration testing for multiple chains. There will be configuration files for each chain under test_data/client, our chain client will read data from that folder and return a new client for each chain as required.

Reason behind usage of v0.16.1 version of starport client.
- As demeris backend supports v0.42 version of cosmos sdk, it was required to downgrade the usage of chain client to the v0.16.1 as its supports v0.42 version of [sdk](https://github.com/tendermint/starport/blob/v0.16.1/starport/pkg/spn/spn.go) .

- we have faced import issues while using v0.19.1 [starport client](https://github.com/tendermint/starport/blob/v0.19.1/starport/pkg/cosmosclient/cosmosclient.go) as its supports v0.44 version of sdk.

* we have duplicated most of the code of starport client since its context was not global and we are not able to use it in our code.
When we have to upgrade our chain client
- If demeris backend upgrades to v0.44+ version of cosmos sdk, we can updrade our chain client to use latest version of starport. With that most of the duplicated code can be removed and we can directly use starport client methods.
- This is an [example](https://github.com/emerishq/demeris-backend/blob/prathyusha/chain_client_v44/chain_client/create_client.go) to upgrade our chain client to use latest version of starport client i.e., v0.19.1.
How to use chain client
- In the first step we have to configure chains information under test_data/client/dev or staging.
- This is how config file looks like .
{
    "chain_name":"akash",  ## Give your chain name, for this you can also refer config files under ci/env/chains, env: dev/staging
    "rpc": "https://akash-emeris.app.alpha.starport.cloud:443",  ## RPC of your node
    "key":"akash_test", ## Key name of your account.
    "mnemonic":"Some drink shoot suffer cradle art melt lake crane food cat mask champion force dilemma lizard merit color portion hammer pig portion mix spin",  ##  Mnemonic of the account which you wants to import, if you are testing for staging then you need not to pass mnemonic from here. You can export through env variables. ex : export CHAINNAME_MNEMONIC="seed goes here" (export AKASH_MNEMONIC="seed of your account")
    "keyring_service_name":"akash" ### keyring service name
}

- After configuring chains you can call the method [GetClient](https://github.com/emerishq/demeris-backend/blob/prathyusha/chainclient/chainclient/import_accounts.go#L24) by passing required params. This method will return a chainclient for that particular chain details you passed to it. This method also imports mnemonic in the keyring and returns the context of it, which you can use to get information about account.
- After getting client you can query the account balances and account information by providing required params.You can find the methods [here](https://github.com/emerishq/demeris-backend/blob/prathyusha/chainclient/chainclient/create_client.go).
- To make a transaction you can call the [broadCastTx](https://github.com/emerishq/demeris-backend/blob/prathyusha/chainclient/chainclient/broadcast_tx.go) method passing params to it.

Documentation

Index

Constants

View Source
const (
	StagingEnvKey      = "staging"
	AkashMnemonicKey   = "AKASH_MNEMONIC"
	CosmosMnemonicKey  = "COSMOS_MNEMONIC"
	TerraMnemonicKey   = "TERRA_MNEMONIC"
	OsmosisMnemonicKey = "OSMOSIS_MNEMONIC"
)
View Source
const (
	KeyringBackendTest = "test"
)

Variables

This section is empty.

Functions

func GetMnemonic

func GetMnemonic(chName string) string

GetMnemonic returns the mnemonic of particular chain for staging accounts

func LoadSingleChainInfo

func LoadSingleChainInfo(env string, chainName string) (cns.Chain, error)

Types

type ChainClient

type ChainClient struct {
	Address            string `json:"address"`
	AddressPrefix      string `json:"account_address_prefix"`
	RPC                string `json:"rpc"`
	Key                string `json:"key"`
	Mnemonic           string `json:"mnemonic"`
	KeyringServiceName string `json:"keyring_service_name"`
	HDPath             string `json:"hd_path"`
	Enabled            bool   `json:"enabled"`
	ChainName          string `json:"chain_name"`
	Denom              string `json:"denom"`
	// contains filtered or unexported fields
}

ChainClient is client to interact with SPN.

func CreateChainClient

func CreateChainClient(nodeAddress, keyringServiceName, chainID, homePath string) (*ChainClient, error)

func GetClient

func GetClient(env string, chainName string, cc ChainClient, dir string) (c *ChainClient, err error)

GetClient is to create client and imports mnemonic and returns created chain client

func (*ChainClient) AccountCreate

func (c *ChainClient) AccountCreate(accountName, mnemonic, hdPath string) (spn.Account, error)

AccountCreate creates an account by name and mnemonic (optional) in the keyring.

func (ChainClient) AccountGet

func (c ChainClient) AccountGet(accountName string) (spn.Account, error)

AccountGet retrieves an account by name from the keyring.

func (*ChainClient) AccountList

func (c *ChainClient) AccountList() (accounts []spn.Account, err error)

AccountList returns a list of accounts.

func (*ChainClient) Broadcast

func (c *ChainClient) Broadcast(fromName string, fromAddr types.AccAddress, clientCtx client.Context, msgs ...types.Msg) (*types.TxResponse, error)

Broadcast directly broadcasts the messages

func (*ChainClient) BuildClientCtx

func (c *ChainClient) BuildClientCtx(accountName string, accountAddress types.AccAddress) (client.Context, error)

BuildClientCtx builds the context for the client

func (*ChainClient) GetAccAddress

func (c *ChainClient) GetAccAddress(accountName string) (sdktypes.AccAddress, error)

GetAccAddress return hex address from given account name

func (ChainClient) GetAccountBalances

func (c ChainClient) GetAccountBalances(address, denom string) (*sdktypes.Coin, error)

GetAccountBalances returns the balance of the account

func (*ChainClient) GetAccountInfo

func (c *ChainClient) GetAccountInfo(address string) (authtypes.AccountI, error)

func (*ChainClient) GetBondedValidators

func (c *ChainClient) GetBondedValidators() (stakingtypes.Validators, error)

GetBondedValidators returns bonded validators list

func (*ChainClient) GetContext

func (c *ChainClient) GetContext() client.Context

GetContext return context of client

func (*ChainClient) GetDelegations

func (c *ChainClient) GetDelegations(address string) (stakingtypes.DelegationResponses, error)

GetDelegations returns delegation balance of delegator address

func (*ChainClient) GetKeyring

func (c *ChainClient) GetKeyring() keyring.Keyring

GetKeyring return keyring of client

func (*ChainClient) GetUnbondedValidators

func (c *ChainClient) GetUnbondedValidators() (stakingtypes.Validators, error)

GetUnbondedValidators returns bonded validators list

func (*ChainClient) GetUnbondingDelegations

func (c *ChainClient) GetUnbondingDelegations(address string) (stakingtypes.UnbondingDelegations, error)

GetUnbondingDelegations returns unbonding delegations of delegator address

func (ChainClient) ImportMnemonic

func (c ChainClient) ImportMnemonic(keyName, mnemonic, hdPath string) (acc spn.Account, err error)

ImportMnemonic is to import existing account mnemonic in keyring

func (*ChainClient) PrepareBroadcast

func (c *ChainClient) PrepareBroadcast(msgs ...types.Msg) error

PrepareBroadcast performs checks and operations before broadcasting messages

func (*ChainClient) SignTx

func (c *ChainClient) SignTx(fromName string, fromAddr types.AccAddress, clientCtx client.Context, msgs ...types.Msg) ([]byte, error)

SignTx signs tx and return tx bytes

func (ChainClient) ToAccount

func (c ChainClient) ToAccount(info keyring.Info) spn.Account

Jump to

Keyboard shortcuts

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