Skip to content

Commit

Permalink
removed paths fetch dependency for interchain/chains dir (cosmos#582)
Browse files Browse the repository at this point in the history
* removed dependency for interchain/chains dir

* check that a chain does have path metadata available in the GitHub repo's interchain/ directory

* remove redundant check against the GH repo since we clone the repo locally

* changed break to continue

* ensuring to remove temp repo

* removed interchain/chains folder

Co-authored-by: jtieri <[email protected]>
  • Loading branch information
boojamya and jtieri authored Feb 22, 2022
1 parent fcde1bf commit ab6bc21
Show file tree
Hide file tree
Showing 19 changed files with 11 additions and 192 deletions.
37 changes: 11 additions & 26 deletions cmd/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@ package cmd

import (
"encoding/json"
"errors"
"fmt"
"github.com/go-git/go-git/v5"
"io/ioutil"
"net/http"
"net/url"
"os"
"path"
"strings"

"github.com/cosmos/relayer/relayer"
"github.com/go-git/go-git/v5"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

const (
jsonURL = "https://raw.githubusercontent.com/cosmos/relayer/main/interchain/chains/"
repoURL = "https://github.com/cosmos/relayer"
REPOURL = "https://github.com/cosmos/relayer"
PATHSURL = "https://github.com/cosmos/relayer/tree/main/interchain"
)

func pathsCmd() *cobra.Command {
Expand Down Expand Up @@ -274,7 +271,7 @@ $ %s pth fch`, appName, defaultHome, appName)),
}

if _, err = git.PlainClone(localRepo, false, &git.CloneOptions{
URL: repoURL,
URL: REPOURL,
Progress: ioutil.Discard,
ReferenceName: "refs/heads/main",
}); err != nil {
Expand All @@ -284,47 +281,36 @@ $ %s pth fch`, appName, defaultHome, appName)),
// Try to fetch path info for each configured chain that has canonical chain/path info in the GH repo
for _, srcChain := range config.Chains {
for _, dstChain := range config.Chains {
fName := fmt.Sprintf("%s.json", srcChain.ChainID())

// Check that the constructed URL is valid
u, err := url.Parse(fmt.Sprintf("%s%s", jsonURL, fName))
if err != nil || u.Scheme == "" || u.Host == "" {
cleanupDir(localRepo)
return errors.New("invalid URL")
}

// Check that the chain srcChain, has provided canonical chain/path info in GH repo
resp, err := http.Get(u.String())
if err != nil || resp.StatusCode == 404 {
fmt.Printf("Chain %s is not currently supported by fetch. Consider adding it's info to %s \n", srcChain.ChainID(), repoURL)
continue
}

// Add paths to rly config from {localRepo}/interchain/chaind-id/
pathsDir := path.Join(localRepo, "interchain", srcChain.ChainID())
localPathsDir := path.Join(localRepo, "interchain", srcChain.ChainID())

dir := path.Clean(pathsDir)
dir := path.Clean(localPathsDir)
files, err := ioutil.ReadDir(dir)
if err != nil {
return err
fmt.Printf("path info does not exist for chain: %s. Consider adding it's info to %s. Error: %v \n", srcChain.ChainID(), path.Join(PATHSURL, "interchain"), err)
break
}
cfg := config

// For each path file, check that the dst is also a configured chain in the relayers config
for _, f := range files {
pth := fmt.Sprintf("%s/%s", dir, f.Name())
fmt.Println(pth)
if f.IsDir() {
fmt.Printf("directory at %s, skipping...\n", pth)
continue
}

byt, err := ioutil.ReadFile(pth)
if err != nil {
cleanupDir(localRepo)
return fmt.Errorf("failed to read file %s: %w", pth, err)
}

p := &relayer.Path{}
if err = json.Unmarshal(byt, p); err != nil {
cleanupDir(localRepo)
return fmt.Errorf("failed to unmarshal file %s: %w", pth, err)
}

Expand Down Expand Up @@ -358,7 +344,6 @@ $ %s pth fch`, appName, defaultHome, appName)),
}
}
}

cleanupDir(localRepo)
return nil
},
Expand Down
9 changes: 0 additions & 9 deletions interchain/chains/akashnet-2.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/bitcanna-1.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/columbus-5.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/core-1.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/cosmoshub-4.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/crypto-org-chain-mainnet-1.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/emoney-3.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/impacthub-3.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/iov-mainnet-ibc.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/irishub-1.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/juno-1.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/likecoin-mainnet-2.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/microtick-1.json

This file was deleted.

13 changes: 0 additions & 13 deletions interchain/chains/osmosis-1-new.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/osmosis-1.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/regen-1.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/sentinelhub-2.json

This file was deleted.

9 changes: 0 additions & 9 deletions interchain/chains/sifchain-1.json

This file was deleted.

0 comments on commit ab6bc21

Please sign in to comment.