cosmos

package
v0.0.0-...-eb7f6a3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 58 Imported by: 1

Documentation

Overview

Package cosmos provides an implementation of ibc.Chain backed by Cosmos-based blockchains.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastTx

func BroadcastTx(ctx context.Context, broadcaster *Broadcaster, broadcastingUser User, msgs ...sdk.Msg) (sdk.TxResponse, error)

BroadcastTx uses the provided Broadcaster to broadcast all the provided messages which will be signed by the User provided. The sdk.TxResponse and an error are returned.

func CondenseMoniker

func CondenseMoniker(m string) string

CondenseMoniker fits a moniker into the cosmos character limit for monikers. If the moniker already fits, it is returned unmodified. Otherwise, the middle is truncated, and a hash is appended to the end in case the only unique data was in the middle.

func DefaultEncoding

func DefaultEncoding() simappparams.EncodingConfig

func NewCosmosHeighlinerChainConfig

func NewCosmosHeighlinerChainConfig(name string,
	binary string,
	bech32Prefix string,
	denom string,
	gasPrices string,
	gasAdjustment float64,
	trustingPeriod string,
	noHostMount bool) ibc.ChainConfig

Types

type Broadcaster

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

func NewBroadcaster

func NewBroadcaster(t *testing.T, chain *CosmosChain) *Broadcaster

NewBroadcaster returns a instance of Broadcaster which can be used with broadcast.Tx to broadcast messages sdk messages.

func (*Broadcaster) ConfigureClientContextOptions

func (b *Broadcaster) ConfigureClientContextOptions(opts ...ClientContextOpt)

ConfigureClientContextOptions ensure the given configuration functions are run when calling GetClientContext after all default options have been applied.

func (*Broadcaster) ConfigureFactoryOptions

func (b *Broadcaster) ConfigureFactoryOptions(opts ...FactoryOpt)

ConfigureFactoryOptions ensure the given configuration functions are run when calling GetFactory after all default options have been applied.

func (*Broadcaster) GetClientContext

func (b *Broadcaster) GetClientContext(ctx context.Context, user User) (client.Context, error)

GetClientContext returns a client context that is configured with this Broadcaster's CosmosChain and the provided user. ConfigureClientContextOptions can be used to configure arbitrary options to configure the returned client.Context.

func (*Broadcaster) GetFactory

func (b *Broadcaster) GetFactory(ctx context.Context, user User) (tx.Factory, error)

GetFactory returns an instance of tx.Factory that is configured with this Broadcaster's CosmosChain and the provided user. ConfigureFactoryOptions can be used to specify arbitrary options to configure the returned factory.

func (*Broadcaster) GetTxResponseBytes

func (b *Broadcaster) GetTxResponseBytes(ctx context.Context, user User) ([]byte, error)

GetTxResponseBytes returns the sdk.TxResponse bytes which returned from broadcast.Tx.

func (*Broadcaster) UnmarshalTxResponseBytes

func (b *Broadcaster) UnmarshalTxResponseBytes(ctx context.Context, bytes []byte) (sdk.TxResponse, error)

UnmarshalTxResponseBytes accepts the sdk.TxResponse bytes and unmarshalls them into an instance of sdk.TxResponse.

type ChainNode

type ChainNode struct {
	VolumeName   string
	Index        int
	Chain        ibc.Chain
	Validator    bool
	NetworkID    string
	DockerClient *dockerclient.Client
	Client       rpcclient.Client
	TestName     string
	Image        ibc.DockerImage
	// contains filtered or unexported fields
}

ChainNode represents a node in the test network that is being created

func (*ChainNode) AddGenesisAccount

func (tn *ChainNode) AddGenesisAccount(ctx context.Context, address string, genesisAmount []types.Coin) error

AddGenesisAccount adds a genesis account for each key

func (*ChainNode) BinCommand

func (tn *ChainNode) BinCommand(command ...string) []string

BinCommand is a helper to retrieve a full command for a chain node binary. For example, if chain node binary is `gaiad`, and desired command is `gaiad keys show key1`, pass ("keys", "show", "key1") for command to return the full command. Will include additional flags for home directory and chain ID.

func (*ChainNode) Bind

func (tn *ChainNode) Bind() []string

Bind returns the home folder bind point for running the node

func (*ChainNode) CliContext

func (tn *ChainNode) CliContext() client.Context

CliContext creates a new Cosmos SDK client context

func (*ChainNode) CollectGentxs

func (tn *ChainNode) CollectGentxs(ctx context.Context) error

CollectGentxs runs collect gentxs on the node's home folders

func (*ChainNode) CreateKey

func (tn *ChainNode) CreateKey(ctx context.Context, name string) error

CreateKey creates a key in the keyring backend test for the given node

func (*ChainNode) CreateNodeContainer

func (tn *ChainNode) CreateNodeContainer(ctx context.Context) error

func (*ChainNode) CreatePool

func (tn *ChainNode) CreatePool(ctx context.Context, keyName string, contractAddress string, swapFee float64, exitFee float64, assets []ibc.WalletAmount) error

func (*ChainNode) DumpContractState

func (tn *ChainNode) DumpContractState(ctx context.Context, contractAddress string, height int64) (*ibc.DumpContractStateResponse, error)

func (*ChainNode) Exec

func (tn *ChainNode) Exec(ctx context.Context, cmd []string, env []string) ([]byte, []byte, error)

func (*ChainNode) ExecBin

func (tn *ChainNode) ExecBin(ctx context.Context, command ...string) ([]byte, []byte, error)

ExecBin is a helper to execute a command for a chain node binary. For example, if chain node binary is `gaiad`, and desired command is `gaiad keys show key1`, pass ("keys", "show", "key1") for command to execute the command against the node. Will include additional flags for home directory and chain ID.

func (*ChainNode) ExecQuery

func (tn *ChainNode) ExecQuery(ctx context.Context, command ...string) ([]byte, []byte, error)

ExecQuery is a helper to execute a query command. For example, if chain node binary is gaiad, and desired command is `gaiad query gov params`, pass ("gov", "params") for command to execute the query against the node. Returns response in json format.

func (*ChainNode) ExecTx

func (tn *ChainNode) ExecTx(ctx context.Context, keyName string, command ...string) (string, error)

ExecTx executes a transaction, waits for 2 blocks if successful, then returns the tx hash.

func (*ChainNode) ExecuteContract

func (tn *ChainNode) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string) error

func (*ChainNode) ExportState

func (tn *ChainNode) ExportState(ctx context.Context, height int64) (string, error)

func (*ChainNode) FindTxs

func (tn *ChainNode) FindTxs(ctx context.Context, height uint64) ([]blockdb.Tx, error)

FindTxs implements blockdb.BlockSaver.

func (*ChainNode) Gentx

func (tn *ChainNode) Gentx(ctx context.Context, name string, genesisSelfDelegation types.Coin) error

Gentx generates the gentx for a given node

func (*ChainNode) Height

func (tn *ChainNode) Height(ctx context.Context) (uint64, error)

func (*ChainNode) HomeDir

func (tn *ChainNode) HomeDir() string

func (*ChainNode) HostName

func (tn *ChainNode) HostName() string

hostname of the test node container

func (*ChainNode) InitFullNodeFiles

func (tn *ChainNode) InitFullNodeFiles(ctx context.Context) error

func (*ChainNode) InitHomeFolder

func (tn *ChainNode) InitHomeFolder(ctx context.Context) error

InitHomeFolder initializes a home folder for the given node

func (*ChainNode) InitValidatorGenTx

func (tn *ChainNode) InitValidatorGenTx(
	ctx context.Context,
	chainType *ibc.ChainConfig,
	genesisAmounts []types.Coin,
	genesisSelfDelegation types.Coin,
) error

InitValidatorFiles creates the node files and signs a genesis transaction

func (*ChainNode) InstantiateContract

func (tn *ChainNode) InstantiateContract(ctx context.Context, keyName string, amount ibc.WalletAmount, fileName, initMessage string, needsNoAdminFlag bool) (string, error)

func (*ChainNode) KeyBech32

func (tn *ChainNode) KeyBech32(ctx context.Context, name string) (string, error)

KeyBech32 retrieves the named key's address in bech32 format from the node.

func (*ChainNode) Name

func (tn *ChainNode) Name() string

Name of the test node container

func (*ChainNode) NewClient

func (tn *ChainNode) NewClient(addr string) error

NewClient creates and assigns a new Tendermint RPC client to the ChainNode

func (*ChainNode) NodeCommand

func (tn *ChainNode) NodeCommand(command ...string) []string

NodeCommand is a helper to retrieve a full command for a chain node binary. when interactions with the RPC endpoint are necessary. For example, if chain node binary is `gaiad`, and desired command is `gaiad keys show key1`, pass ("keys", "show", "key1") for command to return the full command. Will include additional flags for node URL, home directory, and chain ID.

func (*ChainNode) NodeID

func (tn *ChainNode) NodeID(ctx context.Context) (string, error)

NodeID returns the persistent ID of a given node.

func (*ChainNode) QueryCommand

func (tn *ChainNode) QueryCommand(command ...string) []string

QueryCommand is a helper to retrieve the full query command. For example, if chain node binary is gaiad, and desired command is `gaiad query gov params`, pass ("gov", "params") for command to return the full command with all necessary flags to query the specific node.

func (*ChainNode) QueryICA

func (tn *ChainNode) QueryICA(ctx context.Context, connectionID, address string) (string, error)

QueryICA will query for an interchain account controlled by the specified address on the counterparty chain.

func (*ChainNode) RecoverKey

func (tn *ChainNode) RecoverKey(ctx context.Context, keyName, mnemonic string) error

RecoverKey restores a key from a given mnemonic.

func (*ChainNode) RegisterICA

func (tn *ChainNode) RegisterICA(ctx context.Context, keyName, connectionID string) (string, error)

RegisterICA will attempt to register an interchain account on the counterparty chain.

func (*ChainNode) RemoveContainer

func (tn *ChainNode) RemoveContainer(ctx context.Context) error

func (*ChainNode) SendFunds

func (tn *ChainNode) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error

func (*ChainNode) SendIBCTransfer

func (tn *ChainNode) SendIBCTransfer(ctx context.Context, channelID string, keyName string, amount ibc.WalletAmount, timeout *ibc.IBCTimeout) (string, error)

func (*ChainNode) SendICABankTransfer

func (tn *ChainNode) SendICABankTransfer(ctx context.Context, connectionID, fromAddr string, amount ibc.WalletAmount) error

SendICABankTransfer builds a bank transfer message for a specified address and sends it to the specified interchain account.

func (*ChainNode) SetPeers

func (tn *ChainNode) SetPeers(ctx context.Context, peers string) error

SetPeers modifies the config persistent_peers for a node

func (*ChainNode) SetTestConfig

func (tn *ChainNode) SetTestConfig(ctx context.Context) error

SetTestConfig modifies the config to reasonable values for use within ibctest.

func (*ChainNode) StartContainer

func (tn *ChainNode) StartContainer(ctx context.Context) error

func (*ChainNode) StopContainer

func (tn *ChainNode) StopContainer(ctx context.Context) error

func (*ChainNode) TxCommand

func (tn *ChainNode) TxCommand(keyName string, command ...string) []string

TxCommand is a helper to retrieve a full command for broadcasting a tx with the chain node binary.

func (*ChainNode) UnsafeResetAll

func (tn *ChainNode) UnsafeResetAll(ctx context.Context) error

func (*ChainNode) UpgradeProposal

func (tn *ChainNode) UpgradeProposal(ctx context.Context, keyName string, prop ibc.SoftwareUpgradeProposal) (string, error)

UpgradeProposal submits a software-upgrade proposal to the chain.

func (*ChainNode) VoteOnProposal

func (tn *ChainNode) VoteOnProposal(ctx context.Context, keyName string, proposalID string, vote string) error

VoteOnProposal submits a vote for the specified proposal.

type ChainNodes

type ChainNodes []*ChainNode

ChainNodes is a collection of ChainNode

func (ChainNodes) LogGenesisHashes

func (nodes ChainNodes) LogGenesisHashes(ctx context.Context) error

LogGenesisHashes logs the genesis hashes for the various nodes

func (ChainNodes) PeerString

func (nodes ChainNodes) PeerString(ctx context.Context) string

PeerString returns the string for connecting the nodes passed in

type ClientContextOpt

type ClientContextOpt func(clientContext client.Context) client.Context

type CodeInfo

type CodeInfo struct {
	CodeID string `json:"code_id"`
}

type CodeInfosResponse

type CodeInfosResponse struct {
	CodeInfos []CodeInfo `json:"code_infos"`
}

type CosmosChain

type CosmosChain struct {
	Validators ChainNodes
	FullNodes  ChainNodes
	// contains filtered or unexported fields
}

func NewCosmosChain

func NewCosmosChain(testName string, chainConfig ibc.ChainConfig, numValidators int, numFullNodes int, log *zap.Logger) *CosmosChain

func (*CosmosChain) Acknowledgements

func (c *CosmosChain) Acknowledgements(ctx context.Context, height uint64) ([]ibc.PacketAcknowledgement, error)

Acknowledgements implements ibc.Chain, returning all acknowledgments in block at height

func (*CosmosChain) AddFullNodes

func (c *CosmosChain) AddFullNodes(ctx context.Context, configFileOverrides map[string]any, inc int) error

AddFullNodes adds new fullnodes to the network, peering with the existing nodes.

func (*CosmosChain) Config

func (c *CosmosChain) Config() ibc.ChainConfig

Implements Chain interface

func (*CosmosChain) CreateKey

func (c *CosmosChain) CreateKey(ctx context.Context, keyName string) error

Implements Chain interface

func (*CosmosChain) CreatePool

func (c *CosmosChain) CreatePool(ctx context.Context, keyName string, contractAddress string, swapFee float64, exitFee float64, assets []ibc.WalletAmount) error

Implements Chain interface

func (*CosmosChain) DumpContractState

func (c *CosmosChain) DumpContractState(ctx context.Context, contractAddress string, height int64) (*ibc.DumpContractStateResponse, error)

Implements Chain interface

func (*CosmosChain) Exec

func (c *CosmosChain) Exec(ctx context.Context, cmd []string, env []string) (stdout, stderr []byte, err error)

Exec implements ibc.Chain.

func (*CosmosChain) ExecuteContract

func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string) error

Implements Chain interface

func (*CosmosChain) ExportState

func (c *CosmosChain) ExportState(ctx context.Context, height int64) (string, error)

Implements Chain interface

func (*CosmosChain) FindTxs

func (c *CosmosChain) FindTxs(ctx context.Context, height uint64) ([]blockdb.Tx, error)

FindTxs implements blockdb.BlockSaver.

func (*CosmosChain) GetAddress

func (c *CosmosChain) GetAddress(ctx context.Context, keyName string) ([]byte, error)

Implements Chain interface

func (*CosmosChain) GetBalance

func (c *CosmosChain) GetBalance(ctx context.Context, address string, denom string) (int64, error)

Implements Chain interface

func (*CosmosChain) GetGRPCAddress

func (c *CosmosChain) GetGRPCAddress() string

Implements Chain interface

func (*CosmosChain) GetGasFeesInNativeDenom

func (c *CosmosChain) GetGasFeesInNativeDenom(gasPaid int64) int64

func (*CosmosChain) GetHostGRPCAddress

func (c *CosmosChain) GetHostGRPCAddress() string

GetHostGRPCAddress returns the address of the gRPC server accessible by the host. This will not return a valid address until the chain has been started.

func (*CosmosChain) GetHostRPCAddress

func (c *CosmosChain) GetHostRPCAddress() string

GetHostRPCAddress returns the address of the RPC server accessible by the host. This will not return a valid address until the chain has been started.

func (*CosmosChain) GetRPCAddress

func (c *CosmosChain) GetRPCAddress() string

Implements Chain interface

func (*CosmosChain) Height

func (c *CosmosChain) Height(ctx context.Context) (uint64, error)

Height implements ibc.Chain

func (*CosmosChain) HomeDir

func (c *CosmosChain) HomeDir() string

HomeDir implements ibc.Chain.

func (*CosmosChain) Initialize

func (c *CosmosChain) Initialize(ctx context.Context, testName string, cli *client.Client, networkID string) error

Implements Chain interface

func (*CosmosChain) InstantiateContract

func (c *CosmosChain) InstantiateContract(ctx context.Context, keyName string, amount ibc.WalletAmount, fileName, initMessage string, needsNoAdminFlag bool) (string, error)

Implements Chain interface

func (*CosmosChain) NewChainNode

func (c *CosmosChain) NewChainNode(
	ctx context.Context,
	testName string,
	cli *client.Client,
	networkID string,
	image ibc.DockerImage,
	validator bool,
) (*ChainNode, error)

NewChainNode constructs a new cosmos chain node with a docker volume.

func (*CosmosChain) Nodes

func (c *CosmosChain) Nodes() ChainNodes

Nodes returns all nodes, including validators and fullnodes.

func (*CosmosChain) RecoverKey

func (c *CosmosChain) RecoverKey(ctx context.Context, keyName, mnemonic string) error

Implements Chain interface

func (*CosmosChain) SendFunds

func (c *CosmosChain) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error

Implements Chain interface

func (*CosmosChain) SendIBCTransfer

func (c *CosmosChain) SendIBCTransfer(ctx context.Context, channelID, keyName string, amount ibc.WalletAmount, timeout *ibc.IBCTimeout) (tx ibc.Tx, _ error)

Implements Chain interface

func (*CosmosChain) Start

func (c *CosmosChain) Start(testName string, ctx context.Context, additionalGenesisWallets ...ibc.WalletAmount) error

Bootstraps the chain and starts it from genesis

func (*CosmosChain) StartAllNodes

func (c *CosmosChain) StartAllNodes(ctx context.Context) error

StartAllNodes creates and starts new containers for each node. Should only be used if the chain has previously been started with .Start.

func (*CosmosChain) StopAllNodes

func (c *CosmosChain) StopAllNodes(ctx context.Context) error

StopAllNodes stops and removes all long running containers (validators and full nodes)

func (*CosmosChain) Timeouts

func (c *CosmosChain) Timeouts(ctx context.Context, height uint64) ([]ibc.PacketTimeout, error)

Timeouts implements ibc.Chain, returning all timeouts in block at height

func (*CosmosChain) UpgradeProposal

func (c *CosmosChain) UpgradeProposal(ctx context.Context, keyName string, prop ibc.SoftwareUpgradeProposal) (tx ibc.SoftwareUpgradeTx, _ error)

Implements Chain interface

func (*CosmosChain) UpgradeVersion

func (c *CosmosChain) UpgradeVersion(ctx context.Context, cli *client.Client, version string)

func (*CosmosChain) VoteOnProposalAllValidators

func (c *CosmosChain) VoteOnProposalAllValidators(ctx context.Context, proposalID string, vote string) error

type CosmosTx

type CosmosTx struct {
	TxHash string `json:"txhash"`
	Code   int    `json:"code"`
	RawLog string `json:"raw_log"`
}

type FactoryOpt

type FactoryOpt func(factory tx.Factory) tx.Factory

type GenesisFile

type GenesisFile struct {
	Validators []GenesisValidators `json:"validators"`
}

type GenesisValidatorPubKey

type GenesisValidatorPubKey struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

type GenesisValidators

type GenesisValidators struct {
	Address string                 `json:"address"`
	Name    string                 `json:"name"`
	Power   string                 `json:"power"`
	PubKey  GenesisValidatorPubKey `json:"pub_key"`
}

type InstantiateContractAttribute

type InstantiateContractAttribute struct {
	Value string `json:"value"`
}

type InstantiateContractEvent

type InstantiateContractEvent struct {
	Attributes []InstantiateContractAttribute `json:"attributes"`
}

type InstantiateContractLog

type InstantiateContractLog struct {
	Events []InstantiateContractEvent `json:"event"`
}

type InstantiateContractResponse

type InstantiateContractResponse struct {
	Logs []InstantiateContractLog `json:"log"`
}

type PrivValidatorKey

type PrivValidatorKey struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

type PrivValidatorKeyFile

type PrivValidatorKeyFile struct {
	Address string           `json:"address"`
	PubKey  PrivValidatorKey `json:"pub_key"`
	PrivKey PrivValidatorKey `json:"priv_key"`
}

type QueryContractResponse

type QueryContractResponse struct {
	Contracts []string `json:"contracts"`
}

type User

type User interface {
	GetKeyName() string
	Bech32Address(bech32Prefix string) string
}

type ValidatorWithIntPower

type ValidatorWithIntPower struct {
	Address      string
	Power        int64
	PubKeyBase64 string
}

Jump to

Keyboard shortcuts

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