Skip to content

Commit

Permalink
deduplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojtek committed Aug 16, 2023
1 parent c397678 commit b8d9a5c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
25 changes: 2 additions & 23 deletions infra/apps/cored/cored.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
sdkmath "cosmossdk.io/math"
cosmosclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -30,15 +29,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/CoreumFoundation/coreum-tools/pkg/must"
"github.com/CoreumFoundation/coreum/v2/app"
"github.com/CoreumFoundation/coreum/v2/pkg/client"
"github.com/CoreumFoundation/coreum/v2/pkg/config"
"github.com/CoreumFoundation/coreum/v2/pkg/config/constant"
"github.com/CoreumFoundation/crust/infra"
"github.com/CoreumFoundation/crust/infra/cosmoschain"
"github.com/CoreumFoundation/crust/infra/targets"
)

Expand Down Expand Up @@ -218,7 +216,7 @@ func (c Cored) ClientContext() client.Context {
must.OK(err)

mm := newBasicManager()
grpcClient, err := dialGRPCClient(infra.JoinNetAddr("", c.Info().HostFromHost, c.Config().Ports.GRPC), mm)
grpcClient, err := cosmoschain.GRPCClient(infra.JoinNetAddr("", c.Info().HostFromHost, c.Config().Ports.GRPC), mm)
must.OK(err)

return client.NewContext(client.DefaultContextConfig(), mm).
Expand Down Expand Up @@ -439,22 +437,3 @@ func copyFile(src, dst string, perm os.FileMode) error {

return nil
}

func dialGRPCClient(url string, mm module.BasicManager) (*grpc.ClientConn, error) {
encodingConfig := config.NewEncodingConfig(mm)
pc, ok := encodingConfig.Codec.(codec.GRPCCodecProvider)
if !ok {
return nil, errors.New("failed to cast codec to codec.GRPCCodecProvider)")
}

grpClient, err := grpc.Dial(
url,
grpc.WithDefaultCallOptions(grpc.ForceCodec(pc.GRPCCodec())),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return nil, errors.WithStack(err)
}

return grpClient, nil
}
5 changes: 3 additions & 2 deletions infra/cosmoschain/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (ba BaseApp) ClientContext() client.Context {
must.OK(err)

mm := newBasicManager()
grpcClient, err := dialGRPCClient(infra.JoinNetAddr("", ba.Info().HostFromHost, ba.appConfig.Ports.GRPC), mm)
grpcClient, err := GRPCClient(infra.JoinNetAddr("", ba.Info().HostFromHost, ba.appConfig.Ports.GRPC), mm)
must.OK(err)

return client.NewContext(client.DefaultContextConfig(), mm).
Expand Down Expand Up @@ -191,7 +191,8 @@ func (ba BaseApp) prepare() error {
return nil
}

func dialGRPCClient(url string, mm module.BasicManager) (*grpc.ClientConn, error) {
// GRPCClient prepares GRPC client.
func GRPCClient(url string, mm module.BasicManager) (*grpc.ClientConn, error) {
encodingConfig := config.NewEncodingConfig(mm)
pc, ok := encodingConfig.Codec.(codec.GRPCCodecProvider)
if !ok {
Expand Down

0 comments on commit b8d9a5c

Please sign in to comment.