Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Merge PR #98: Removing Provider implementation and migrating back t…
Browse files Browse the repository at this point in the history
…o the relayer

* WIP: removing Provider implementation from lens

* remove queries only needed in relayer & make some queries private so they dont appear twice behind CosmosProvider in relayer

* pull in updated relayer to use CosmosProvider

* remove additional Provider specific code no longer needed in lens

* remove ProviderConfig specific methods

* add Validate method back and goimport
  • Loading branch information
jtieri authored Feb 13, 2022
1 parent 8319cc8 commit b32611c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 2,607 deletions.
50 changes: 9 additions & 41 deletions client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/avast/retry-go"
"io"
"path"
"strings"
"time"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/relayer/relayer/provider"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/libs/log"
provtypes "github.com/tendermint/tendermint/light/provider"
Expand All @@ -22,6 +21,14 @@ import (
"gopkg.in/yaml.v3"
)

var (
// Variables used for retries
RtyAttNum = uint(5)
RtyAtt = retry.Attempts(RtyAttNum)
RtyDel = retry.Delay(time.Millisecond * 400)
RtyErr = retry.LastErrorOnly(true)
)

type ChainClient struct {
Config *ChainClientConfig
Keybase keyring.Keyring
Expand Down Expand Up @@ -138,45 +145,6 @@ func (cc *ChainClient) HandleAndPrintMsgSend(res *sdk.TxResponse, err error) err
return cc.PrintTxResponse(res)
}

// LogFailedTx takes the transaction and the messages to create it and logs the appropriate data
func (cc *ChainClient) LogFailedTx(res *provider.RelayerTxResponse, err error, msgs []provider.RelayerMessage) {
if cc.Config.Debug {
cc.Log(fmt.Sprintf("- [%s] -> failed sending transaction:", cc.ChainId()))
for _, msg := range msgs {
_ = cc.PrintObject(msg)
}
}

if err != nil {
cc.Logger.Error(fmt.Errorf("- [%s] -> err(%v)", cc.ChainId(), err).Error())
if res == nil {
return
}
}

if res.Code != 0 && res.Data != "" {
cc.Log(fmt.Sprintf("✘ [%s]@{%d} - msg(%s) err(%d:%s)", cc.ChainId(), res.Height, getMsgTypes(msgs), res.Code, res.Data))
}

if cc.Config.Debug && res != nil {
cc.Log("- transaction response:")
_ = cc.PrintObject(res)
}
}

func getMsgTypes(msgs []provider.RelayerMessage) string {
var out string
for i, msg := range msgs {
out += fmt.Sprintf("%d:%s,", i, msg.Type())
}
return strings.TrimSuffix(out, ",")
}

// LogSuccessTx take the transaction and the messages to create it and logs the appropriate data
func (cc *ChainClient) LogSuccessTx(res *sdk.TxResponse, msgs []provider.RelayerMessage) {
cc.Logger.Info(fmt.Sprintf("✔ [%s]@{%d} - msg(%s) hash(%s)", cc.ChainId(), res.Height, getMsgTypes(msgs), res.TxHash))
}

func (cc *ChainClient) PrintObject(res interface{}) error {
var (
bz []byte
Expand Down
20 changes: 2 additions & 18 deletions client/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package client

import (
"os"
"time"

"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authz "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
Expand All @@ -22,14 +22,10 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
"github.com/cosmos/ibc-go/v2/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v2/modules/core"

"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/relayer/relayer/provider"
)

var (
_ provider.ProviderConfig = &ChainClientConfig{}
ModuleBasics = []module.AppModuleBasic{
ModuleBasics = []module.AppModuleBasic{
auth.AppModuleBasic{},
authz.AppModuleBasic{},
bank.AppModuleBasic{},
Expand Down Expand Up @@ -69,18 +65,6 @@ type ChainClientConfig struct {
Modules []module.AppModuleBasic `json:"-" yaml:"-"`
}

func (ccc *ChainClientConfig) NewProvider(homepath string, debug bool) (provider.ChainProvider, error) {
if err := ccc.Validate(); err != nil {
return nil, err
}
ccc.Modules = append([]module.AppModuleBasic{}, ModuleBasics...)
p, err := NewChainClient(ccc, homepath, os.Stdin, os.Stdout)
if err != nil {
return nil, err
}
return p, err
}

func (ccc *ChainClientConfig) Validate() error {
if _, err := time.ParseDuration(ccc.Timeout); err != nil {
return err
Expand Down
Loading

0 comments on commit b32611c

Please sign in to comment.