Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Jan 20, 2025
1 parent 5199019 commit 9f5fe6c
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 88 deletions.
2 changes: 1 addition & 1 deletion client/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func New(cfg *config.BabylonConfig, logger *zap.Logger) (*Client, error) {
encCfg := bbn.GetEncodingConfig()
cp.Cdc = relayerclient.Codec{
InterfaceRegistry: encCfg.InterfaceRegistry,
Marshaler: encCfg.Codec,
Marshaller: encCfg.Codec,
TxConfig: encCfg.TxConfig,
Amino: encCfg.Amino,
}
Expand Down
8 changes: 2 additions & 6 deletions client/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (c *Client) SendMessageWithSigner(
cliCtx := client.Context{}.WithClient(cc.RPCClient).
WithInterfaceRegistry(cc.Cdc.InterfaceRegistry).
WithChainID(cc.PCfg.ChainID).
WithCodec(cc.Cdc.Marshaler).
WithCodec(cc.Cdc.Marshaller).
WithFromAddress(signerAddr)

txf := cc.TxFactory()
Expand Down Expand Up @@ -260,10 +260,6 @@ func (c *Client) SendMessageWithSigner(
if cc.PCfg.MaxGasAmount != 0 {
txf = txf.WithGas(cc.PCfg.MaxGasAmount)
}
txf, err = cc.SetWithExtensionOptions(txf)
if err != nil {
return nil, err
}

// txf ready
_, adjusted, err := c.CalculateGas(ctx, txf, signerPvKey.PubKey(), cMsgs...)
Expand All @@ -284,7 +280,7 @@ func (c *Client) SendMessageWithSigner(
// c.LogFailedTx(nil, err, msgs)
// Force encoding in the chain specific address
for _, msg := range cMsgs {
cc.Cdc.Marshaler.MustMarshalJSON(msg)
cc.Cdc.Marshaller.MustMarshalJSON(msg)
}
if err := Sign(ctx, txf, signerPvKey, txb, cc.Cdc.TxConfig.SignModeHandler(), false); err != nil {
return nil, err
Expand Down
46 changes: 46 additions & 0 deletions client/relayer/app_module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package relayerclient

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

tmlightclient "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
)

// AppModuleBasic defines the basic application module used by the module.
type AppModuleBasic struct{}

// Name returns the module's name.
func (AppModuleBasic) Name() string {
return "cosmos_chain_provider"
}

// RegisterLegacyAminoCodec does nothing. IBC does not support amino.
func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {}

// RegisterInterfaces registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
tmlightclient.RegisterInterfaces(registry)
solomachine.RegisterInterfaces(registry)
localhost.RegisterInterfaces(registry)
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
panic("not implemented")
}

// GetTxCmd returns the root tx command for the ibc module.
func (AppModuleBasic) GetTxCmd() *cobra.Command {
panic("not implemented")
}

// GetQueryCmd returns no root query command for the ibc module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
panic("not implemented")
}
27 changes: 5 additions & 22 deletions client/relayer/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ import (
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v8/modules/core"

cosmosmodule "github.com/cosmos/relayer/v2/relayer/chains/cosmos/module"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos/stride"
ethermintcodecs "github.com/cosmos/relayer/v2/relayer/codecs/ethermint"
injectivecodecs "github.com/cosmos/relayer/v2/relayer/codecs/injective"
)

var ModuleBasics = []module.AppModuleBasic{
auth.AppModuleBasic{},
authz.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
// TODO: add osmosis governance proposal types here
// TODO: add other proposal types here
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
Expand All @@ -57,14 +52,14 @@ var ModuleBasics = []module.AppModuleBasic{
upgrade.AppModuleBasic{},
transfer.AppModuleBasic{},
ibc.AppModuleBasic{},
cosmosmodule.AppModuleBasic{},
AppModuleBasic{},
stride.AppModuleBasic{},
ibcfee.AppModuleBasic{},
}

type Codec struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
Marshaller codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
Expand All @@ -76,18 +71,6 @@ func MakeCodec(moduleBasics []module.AppModuleBasic, extraCodecs []string, accBe
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
modBasic.RegisterLegacyAminoCodec(encodingConfig.Amino)
modBasic.RegisterInterfaces(encodingConfig.InterfaceRegistry)
for _, c := range extraCodecs {
switch c {
case "ethermint":
ethermintcodecs.RegisterInterfaces(encodingConfig.InterfaceRegistry)
encodingConfig.Amino.RegisterConcrete(&ethermintcodecs.PubKey{}, ethermintcodecs.PubKeyName, nil)
encodingConfig.Amino.RegisterConcrete(&ethermintcodecs.PrivKey{}, ethermintcodecs.PrivKeyName, nil)
case "injective":
injectivecodecs.RegisterInterfaces(encodingConfig.InterfaceRegistry)
encodingConfig.Amino.RegisterConcrete(&injectivecodecs.PubKey{}, injectivecodecs.PubKeyName, nil)
encodingConfig.Amino.RegisterConcrete(&injectivecodecs.PrivKey{}, injectivecodecs.PrivKeyName, nil)
}
}

return encodingConfig
}
Expand All @@ -103,15 +86,15 @@ func MakeCodecConfig(accBech32Prefix, valBech32Prefix string) Codec {
if err != nil {
panic(err)
}
marshaler := codec.NewProtoCodec(interfaceRegistry)
marshaller := codec.NewProtoCodec(interfaceRegistry)

done := SetSDKConfigContext(accBech32Prefix)
defer done()

return Codec{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: tx.NewTxConfig(marshaler, tx.DefaultSignModes),
Marshaller: marshaller,
TxConfig: tx.NewTxConfig(marshaller, tx.DefaultSignModes),
Amino: codec.NewLegacyAmino(),
}
}
2 changes: 1 addition & 1 deletion client/relayer/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (cc *CosmosProvider) Invoke(ctx context.Context, method string, req, reply
}

if cc.Cdc.InterfaceRegistry != nil {
return types.UnpackInterfaces(reply, cc.Cdc.Marshaler)
return types.UnpackInterfaces(reply, cc.Cdc.Marshaller)
}

return nil
Expand Down
21 changes: 3 additions & 18 deletions client/relayer/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/go-bip39"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos/keys/sr25519"
"github.com/cosmos/relayer/v2/relayer/codecs/ethermint"
"github.com/cosmos/relayer/v2/relayer/codecs/injective"
)

const ethereumCoinType = uint32(60)

var (
// SupportedAlgorithms defines the list of signing algorithms used on Evmos:
// - secp256k1 (Cosmos)
// - sr25519 (Cosmos)
// - eth_secp256k1 (Ethereum, Injective)
SupportedAlgorithms = keyring.SigningAlgoList{hd.Secp256k1, sr25519.Sr25519, ethermint.EthSecp256k1, injective.EthSecp256k1}
SupportedAlgorithms = keyring.SigningAlgoList{hd.Secp256k1, sr25519.Sr25519}
// 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, sr25519.Sr25519, ethermint.EthSecp256k1, injective.EthSecp256k1}
SupportedAlgorithmsLedger = keyring.SigningAlgoList{hd.Secp256k1, sr25519.Sr25519}
)

// KeyringAlgoOptions defines a function keys options for the ethereum Secp256k1 curve.
Expand All @@ -40,7 +34,7 @@ func KeyringAlgoOptions() keyring.Option {

// CreateKeystore initializes a new instance of a keyring at the specified path in the local filesystem.
func (cc *CosmosProvider) CreateKeystore(path string) error {
keybase, err := keyring.New(cc.PCfg.ChainID, cc.PCfg.KeyringBackend, cc.PCfg.KeyDirectory, cc.Input, cc.Cdc.Marshaler, KeyringAlgoOptions())
keybase, err := keyring.New(cc.PCfg.ChainID, cc.PCfg.KeyringBackend, cc.PCfg.KeyDirectory, cc.Input, cc.Cdc.Marshaller, KeyringAlgoOptions())
if err != nil {
return err
}
Expand Down Expand Up @@ -108,15 +102,6 @@ func (cc *CosmosProvider) KeyAddOrRestore(keyName string, coinType uint32, signi
}
}

if coinType == ethereumCoinType {
algo = keyring.SignatureAlgo(ethermint.EthSecp256k1)
for _, codec := range cc.PCfg.ExtraCodecs {
if codec == "injective" {
algo = keyring.SignatureAlgo(injective.EthSecp256k1)
}
}
}

done := SetSDKConfigContext(cc.PCfg.AccountPrefix)

info, err := cc.Keybase.NewAccount(keyName, mnemonicStr, "", hd.CreateHDPath(coinType, 0, 0).String(), algo)
Expand Down
6 changes: 3 additions & 3 deletions client/relayer/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ func (cc *CosmosProvider) AccountFromKeyOrAddress(keyOrAddress string) (out sdk.

// Sprint returns the json representation of the specified proto message.
func (cc *CosmosProvider) Sprint(toPrint proto.Message) (string, error) {
out, err := cc.Cdc.Marshaler.MarshalJSON(toPrint)
out, err := cc.Cdc.Marshaller.MarshalJSON(toPrint)
if err != nil {
return "", err
}
return string(out), nil
}

// SetPCAddr sets the rpc-addr for the chain.
// SetRpcAddr sets the rpc-addr for the chain.
// It will fail if the rpcAddr is invalid(not a url).
func (cc *CosmosProvider) SetRpcAddr(rpcAddr string) error {
cc.PCfg.RPCAddr = rpcAddr
Expand All @@ -241,7 +241,7 @@ func (cc *CosmosProvider) Init(ctx context.Context) error {
cc.PCfg.KeyringBackend,
cc.PCfg.KeyDirectory,
cc.Input,
cc.Cdc.Marshaler,
cc.Cdc.Marshaller,
cc.KeyringOptions...,
)
if err != nil {
Expand Down
39 changes: 2 additions & 37 deletions client/relayer/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package relayerclient
import (
"context"
sdkerrors "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"cosmossdk.io/store/rootmulti"
"errors"
"fmt"
Expand All @@ -12,15 +11,13 @@ import (
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
legacyerrors "github.com/cosmos/cosmos-sdk/types/errors"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/relayer/v2/relayer/ethermint"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -560,7 +557,7 @@ func (cc *CosmosProvider) PrepareFactory(txf tx.Factory, signingKey string) (tx.
cliCtx := client.Context{}.WithClient(cc.RPCClient).
WithInterfaceRegistry(cc.Cdc.InterfaceRegistry).
WithChainID(cc.PCfg.ChainID).
WithCodec(cc.Cdc.Marshaler).
WithCodec(cc.Cdc.Marshaller).
WithFromAddress(from)

// Set the account number and sequence on the transaction factory and retry if fail
Expand Down Expand Up @@ -602,40 +599,8 @@ func (cc *CosmosProvider) PrepareFactory(txf tx.Factory, signingKey string) (tx.
if cc.PCfg.MaxGasAmount != 0 {
txf = txf.WithGas(cc.PCfg.MaxGasAmount)
}
txf, err = cc.SetWithExtensionOptions(txf)
if err != nil {
return tx.Factory{}, err
}
return txf, nil
}

// SetWithExtensionOptions sets the dynamic fee extension options on the given
// transaction factory using the configuration options from the CosmosProvider.
// The function creates an extension option for each configuration option and
// serializes it into a byte slice before adding it to the list of extension
// options. The function returns the updated transaction factory with the new
// extension options or an error if the serialization fails or an invalid option
// value is encountered.
func (cc *CosmosProvider) SetWithExtensionOptions(txf tx.Factory) (tx.Factory, error) {
extOpts := make([]*types.Any, 0, len(cc.PCfg.ExtensionOptions))
for _, opt := range cc.PCfg.ExtensionOptions {
max, ok := sdkmath.NewIntFromString(opt.Value)
if !ok {
return txf, fmt.Errorf("invalid opt value")
}
extensionOption := ethermint.ExtensionOptionDynamicFeeTx{
MaxPriorityPrice: max,
}
extBytes, err := extensionOption.Marshal()
if err != nil {
return txf, err
}
extOpts = append(extOpts, &types.Any{
TypeUrl: "/ethermint.types.v1.ExtensionOptionDynamicFeeTx",
Value: extBytes,
})
}
return txf.WithExtensionOptions(extOpts...), nil
return txf, nil
}

// TxFactory instantiates a new tx factory with the appropriate configuration settings for this chain.
Expand Down

0 comments on commit 9f5fe6c

Please sign in to comment.