cosmos

package
v0.0.0-...-3063be3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 62 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SupportedAlgorithms defines the list of signing algorithms used on Evmos:
	//  - secp256k1     (Cosmos)
	//  - sr25519		(Cosmos)
	//  - eth_secp256k1 (Ethereum, Injective)
	SupportedAlgorithms = keyring.SigningAlgoList{hd.Secp256k1}
	// SupportedAlgorithmsLedger defines the list of signing algorithms used on Evmos for the Ledger device:
	//  - secp256k1     (Cosmos)
	//  - sr25519		(Cosmos)
	//  - eth_secp256k1 (Ethereum, Injective)
	SupportedAlgorithmsLedger = keyring.SigningAlgoList{hd.Secp256k1}
)

Functions

func BuildSimTx

func BuildSimTx(pubKey cryptotypes.PubKey, txf tx.Factory, msgs ...sdk.Msg) ([]byte, error)

BuildSimTx creates an unsigned tx with an empty single signature and returns the encoded transaction or an error if the unsigned transaction cannot be built.

func CreateMnemonic

func CreateMnemonic() (string, error)

CreateMnemonic generates a new mnemonic.

func KeyringAlgoOptions

func KeyringAlgoOptions() keyring.Option

KeyringAlgoOptions defines a function keys options for the ethereum Secp256k1 curve. It supports secp256k1 and eth_secp256k1 keys for accounts.

Types

type Codec

type Codec struct {
	InterfaceRegistry types.InterfaceRegistry
	Marshaler         codec.Codec
	TxConfig          client.TxConfig
	Amino             *codec.LegacyAmino
}

type CosmosProvider

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

func NewProvider

func NewProvider(rpcURL string, keyDir string, timeout time.Duration) (*CosmosProvider, error)

NewProvider validates the CosmosProviderConfig, instantiates a ChainClient and then instantiates a CosmosProvider

func (*CosmosProvider) AccountInfo

func (cc *CosmosProvider) AccountInfo(ctx context.Context, address string) (authtypes.AccountI, error)

func (*CosmosProvider) AddKey

func (cc *CosmosProvider) AddKey(name string, coinType uint32, signingAlgorithm string) (output *KeyOutput, err error)

AddKey generates a new mnemonic which is then converted to a private key and BIP-39 HD Path and persists it to the keystore. It fails if there is an existing key with the same address.

func (*CosmosProvider) Broadcast

func (cc *CosmosProvider) Broadcast(
	ctx context.Context,
	sequence uint64,
	walletState *WalletState,
	txBz []byte,
) (*coretypes.ResultBroadcastTxCommit, error)

func (*CosmosProvider) CreateKeystore

func (cc *CosmosProvider) CreateKeystore() error

CreateKeystore initializes a new instance of a keyring at the specified path in the local filesystem.

func (*CosmosProvider) DeleteKey

func (cc *CosmosProvider) DeleteKey(name string) error

DeleteKey removes a key from the keystore for the specified name.

func (*CosmosProvider) EncodeTxJSON

func (cc *CosmosProvider) EncodeTxJSON(txb client.TxBuilder) ([]byte, error)

func (*CosmosProvider) EnsureWalletState

func (cc *CosmosProvider) EnsureWalletState(address string) *WalletState

func (*CosmosProvider) EstimateGas

func (cc *CosmosProvider) EstimateGas(ctx context.Context, txf tx.Factory, pubKey cryptotypes.PubKey, msgs ...sdk.Msg) (uint64, error)

EstimateGas simulates a tx to generate the appropriate gas settings before broadcasting a tx.

func (*CosmosProvider) ExportPrivKeyArmor

func (cc *CosmosProvider) ExportPrivKeyArmor(keyName string) (armor string, err error)

ExportPrivKeyArmor returns a private key in ASCII armored format. It returns an error if the key does not exist or a wrong encryption passphrase is supplied.

func (*CosmosProvider) GetBlockAtHeight

func (cc *CosmosProvider) GetBlockAtHeight(ctx context.Context, height int64) (*coretypes.ResultBlock, error)

GetBlockAtHeight queries the block at a given height

func (*CosmosProvider) GetKeyAddress

func (cc *CosmosProvider) GetKeyAddress(key string) (sdk.AccAddress, error)

GetKeyAddress returns the account address representation for the currently configured key.

func (*CosmosProvider) Invoke

func (cc *CosmosProvider) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error)

Invoke implements the grpc ClientConn.Invoke method

func (*CosmosProvider) KeyAddOrRestore

func (cc *CosmosProvider) KeyAddOrRestore(keyName string, coinType uint32, signingAlgorithm string, mnemonic ...string) (*KeyOutput, error)

KeyAddOrRestore either generates a new mnemonic or uses the specified mnemonic and converts it to a private key and BIP-39 HD Path which is then persisted to the keystore. It fails if there is an existing key with the same address.

func (*CosmosProvider) KeyExists

func (cc *CosmosProvider) KeyExists(name string) bool

KeyExists returns true if a key with the specified name exists in the keystore, it returns false otherwise.

func (*CosmosProvider) KeyFromKeyOrAddress

func (cc *CosmosProvider) KeyFromKeyOrAddress(keyOrAddress string) (string, error)

func (*CosmosProvider) KeystoreCreated

func (cc *CosmosProvider) KeystoreCreated() bool

KeystoreCreated returns true if there is an existing keystore instance at the specified path, it returns false otherwise.

func (*CosmosProvider) ListAddresses

func (cc *CosmosProvider) ListAddresses(bech32Prefix string) (map[string]string, error)

ListAddresses returns a map of bech32 encoded strings representing all keys currently in the keystore.

func (*CosmosProvider) LoadKeystore

func (cc *CosmosProvider) LoadKeystore(keyring keyring.Keyring)

func (*CosmosProvider) NewStream

NewStream implements the grpc ClientConn.NewStream method

func (*CosmosProvider) QueryABCI

QueryABCI performs an ABCI query and returns the appropriate response and error sdk error code.

func (*CosmosProvider) QueryChainID

func (cc *CosmosProvider) QueryChainID(ctx context.Context) (string, error)

QueryChainID queries the chain ID from the RPC client

func (*CosmosProvider) QueryLatestHeight

func (cc *CosmosProvider) QueryLatestHeight(ctx context.Context) (int64, error)

QueryLatestHeight queries the latest height from the RPC client

func (*CosmosProvider) RestoreKey

func (cc *CosmosProvider) RestoreKey(name, mnemonic string, coinType uint32, signingAlgorithm string) (address sdk.AccAddress, err error)

RestoreKey converts a mnemonic to a private key and BIP-39 HD Path and persists it to the keystore. It fails if there is an existing key with the same address.

func (*CosmosProvider) SaveLedgerKey

func (cc *CosmosProvider) SaveLedgerKey(keyName string, coinType uint32, bech32Prefix string) (*KeyOutput, error)

SaveLedgerKey persists a ledger key to the keystore with the specified name.

func (*CosmosProvider) SaveOfflineKey

func (cc *CosmosProvider) SaveOfflineKey(keyName string, pubKey cryptotypes.PubKey) (*KeyOutput, error)

SaveOfflineKey persists a public key to the keystore with the specified name.

func (*CosmosProvider) ShowAddress

func (cc *CosmosProvider) ShowAddress(name string, bech32Prefix string) (address string, err error)

ShowAddress retrieves a key by name from the keystore and returns the bech32 encoded string representation of that key.

func (*CosmosProvider) Sign

func (cc *CosmosProvider) Sign(
	ctx context.Context,
	walletState *WalletState,
	chainID string,
	gasPrices string,
	gasAdjustment float64,
	gasOverride uint64,
	bech32Prefix string,
	keyName string,
	feeGranter sdk.AccAddress,
	msgs []sdk.Msg,
	memo string,
) (uint64, []byte, error)

func (*CosmosProvider) SignAndBroadcast

func (cc *CosmosProvider) SignAndBroadcast(
	ctx context.Context,
	chainID string,
	gasPrices string,
	gasAdjustment float64,
	gasOverride uint64,
	bech32Prefix string,
	keyName string,
	feeGranter sdk.AccAddress,
	msgs []sdk.Msg,
	memo string,
) (*coretypes.ResultBroadcastTxCommit, error)

type KeyOutput

type KeyOutput struct {
	Mnemonic string `json:"mnemonic"`
	CoinType uint32 `json:"coin_type"`
	Account  sdk.AccAddress
}

type RPCClient

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

RPCClient wraps our slimmed down CometBFT client and converts the returned types to the upstream CometBFT types. This is useful so that it can be used in any function calls that expect the upstream types.

func NewRPCClient

func NewRPCClient(c *client.Client) RPCClient

func (RPCClient) ABCIInfo

func (r RPCClient) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error)

func (RPCClient) ABCIQuery

func (r RPCClient) ABCIQuery(
	ctx context.Context,
	path string,
	data bytes.HexBytes,
) (*coretypes.ResultABCIQuery, error)

func (RPCClient) ABCIQueryWithOptions

func (r RPCClient) ABCIQueryWithOptions(
	ctx context.Context,
	path string,
	data bytes.HexBytes,
	opts rpcclient.ABCIQueryOptions,
) (*coretypes.ResultABCIQuery, error)

func (RPCClient) Block

func (r RPCClient) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error)

func (RPCClient) BlockByHash

func (r RPCClient) BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error)

func (RPCClient) BlockResults

func (r RPCClient) BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error)

func (RPCClient) BlockSearch

func (r RPCClient) BlockSearch(
	ctx context.Context,
	query string,
	page, perPage *int,
	orderBy string,
) (*coretypes.ResultBlockSearch, error)

func (RPCClient) BlockchainInfo

func (r RPCClient) BlockchainInfo(
	ctx context.Context,
	minHeight, maxHeight int64,
) (*coretypes.ResultBlockchainInfo, error)

func (RPCClient) BroadcastTxAsync

func (r RPCClient) BroadcastTxAsync(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTx, error)

func (RPCClient) BroadcastTxCommit

func (r RPCClient) BroadcastTxCommit(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTxCommit, error)

func (RPCClient) BroadcastTxSync

func (r RPCClient) BroadcastTxSync(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTx, error)

func (RPCClient) Commit

func (r RPCClient) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error)

func (RPCClient) Status

func (RPCClient) Tx

func (r RPCClient) Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error)

func (RPCClient) TxSearch

func (r RPCClient) TxSearch(
	ctx context.Context,
	query string,
	prove bool,
	page, perPage *int,
	orderBy string,
) (*coretypes.ResultTxSearch, error)

func (RPCClient) Validators

func (r RPCClient) Validators(
	ctx context.Context,
	height *int64,
	page, perPage *int,
) (*coretypes.ResultValidators, error)

type WalletState

type WalletState struct {
	NextAccountSequence uint64
	Mu                  sync.Mutex
}

func (*WalletState) HandleAccountSequenceMismatchError

func (ws *WalletState) HandleAccountSequenceMismatchError(err error)

handleAccountSequenceMismatchError will parse the error string, e.g.: "account sequence mismatch, expected 10, got 9: incorrect account sequence" and update the next account sequence with the expected value.

Jump to

Keyboard shortcuts

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