Skip to content

Commit

Permalink
feat: local chain registry endpoint (#1204)
Browse files Browse the repository at this point in the history
* feat: read chain registry file if found

* chain_registry_assets optional endpoint
  • Loading branch information
Reecepbcups authored Aug 20, 2024
1 parent a2d674e commit 2a355c8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ type PathUpdateOptions struct {
}

type ICSConfig struct {
ProviderVerOverride string `yaml:"provider,omitempty" json:"provider,omitempty"`
ConsumerVerOverride string `yaml:"consumer,omitempty" json:"consumer,omitempty"`
ConsumerCopyProviderKey func(int) bool
ProviderVerOverride string `yaml:"provider,omitempty" json:"provider,omitempty"`
ConsumerVerOverride string `yaml:"consumer,omitempty" json:"consumer,omitempty"`
ConsumerCopyProviderKey func(int) bool `yaml:"-" json:"-"`
}
31 changes: 31 additions & 0 deletions local-interchain/interchain/handlers/chain_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package handlers

import (
"net/http"
"os"
)

// If the chain_registry.json file is found within the current running directory, show it as an enpoint.
// Used in: spawn

type chainRegistry struct {
DataJSON []byte `json:"data_json"`
}

// NewChainRegistry creates a new chainRegistry with the JSON from the file at location.
func NewChainRegistry(loc string) *chainRegistry {
dataJSON, err := os.ReadFile(loc)
if err != nil {
panic(err)
}

return &chainRegistry{
DataJSON: dataJSON,
}
}

func (cr chainRegistry) GetChainRegistry(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(cr.DataJSON)
}
24 changes: 24 additions & 0 deletions local-interchain/interchain/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package router
import (
"context"
"encoding/json"
"log"
"net/http"
"os"
"path/filepath"

"github.com/gorilla/mux"
ictypes "github.com/strangelove-ventures/interchaintest/local-interchain/interchain/types"
Expand Down Expand Up @@ -36,6 +39,27 @@ func NewRouter(
infoH := handlers.NewInfo(config, installDir, ctx, ic, cosmosChains, vals, relayer, eRep)
r.HandleFunc("/info", infoH.GetInfo).Methods(http.MethodGet)

wd, err := os.Getwd()
if err != nil {
panic(err)
}

chainRegistryFile := filepath.Join(wd, "chain_registry.json")
if _, err := os.Stat(chainRegistryFile); err == nil {
crH := handlers.NewChainRegistry(chainRegistryFile)
r.HandleFunc("/chain_registry", crH.GetChainRegistry).Methods(http.MethodGet)
} else {
log.Printf("chain_registry.json not found in %s, not exposing endpoint.", wd)
}

chainRegistryAssetsFile := filepath.Join(wd, "chain_registry_assets.json")
if _, err := os.Stat(chainRegistryAssetsFile); err == nil {
crH := handlers.NewChainRegistry(chainRegistryAssetsFile)
r.HandleFunc("/chain_registry_assets", crH.GetChainRegistry).Methods(http.MethodGet)
} else {
log.Printf("chain_registry_assets.json not found in %s, not exposing endpoint.", wd)
}

actionsH := handlers.NewActions(ctx, ic, cosmosChains, vals, relayer, eRep, authKey)
r.HandleFunc("/", actionsH.PostActions).Methods(http.MethodPost)

Expand Down

0 comments on commit 2a355c8

Please sign in to comment.