Skip to content

Commit

Permalink
fix: improve custom env support for rollapp and relayer (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Oct 16, 2024
1 parent 55afb56 commit 3fa7d04
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
35 changes: 34 additions & 1 deletion cmd/relayer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -79,7 +80,39 @@ Consider using 'services' if you want to run a 'systemd' service instead.
_, hd, found := roller.FindHubDataByID(consts.Hubs, hubChainID)
if !found {
pterm.Error.Println("Hub Data not found for ", hubChainID)
return
runCustomHub, _ := pterm.DefaultInteractiveConfirm.WithDefaultText("would you like to provide custom hub?").
WithDefaultValue(false).
Show()

if !runCustomHub {
pterm.Error.Println("cancelled by user")
return
}

id, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub chain id").
Show()
rpcUrl, _ := pterm.DefaultInteractiveTextInput.WithDefaultText(
"provide hub rpc endpoint (including port, example: http://dym.dev:26657)",
).Show()
restUrl, _ := pterm.DefaultInteractiveTextInput.WithDefaultText(
"provide hub rest api endpoint (including port, example: http://dym.dev:1318)",
).Show()
gasPrice, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide gas price").
WithDefaultValue("2000000000").
Show()

id = strings.TrimSpace(id)
rpcUrl = strings.TrimSpace(rpcUrl)
restUrl = strings.TrimSpace(restUrl)
gasPrice = strings.TrimSpace(gasPrice)

hd = consts.HubData{
API_URL: restUrl,
ID: id,
RPC_URL: rpcUrl,
ARCHIVE_RPC_URL: rpcUrl,
GAS_PRICE: gasPrice,
}
}

getRaCmd := rollapp.GetRollappCmd(raChainID, hd)
Expand Down
9 changes: 8 additions & 1 deletion cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func Cmd() *cobra.Command {
gasPrice, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide gas price").
WithDefaultValue("2000000000").Show()

id = strings.TrimSpace(id)
rpcUrl = strings.TrimSpace(rpcUrl)
restUrl = strings.TrimSpace(restUrl)
gasPrice = strings.TrimSpace(gasPrice)

hd = consts.HubData{
API_URL: restUrl,
ID: id,
Expand All @@ -124,6 +129,7 @@ func Cmd() *cobra.Command {
dymdCommit, _ := pterm.DefaultInteractiveTextInput.WithDefaultText(
"provide dymensionxyz/dymension commit to build (example: 2cd612aaa6c21b473dbbb7dca9fd03b5aaae6583)",
).Show()
dymdCommit = strings.TrimSpace(dymdCommit)

dymdDep := types.Dependency{
DependencyName: "dymension",
Expand Down Expand Up @@ -186,6 +192,7 @@ func Cmd() *cobra.Command {
err := runInit(
cmd,
env,
consts.HubData{},
raRespMock,
)
if err != nil {
Expand Down Expand Up @@ -271,7 +278,7 @@ func Cmd() *cobra.Command {
return
}

err = runInit(cmd, env, raResponse)
err = runInit(cmd, env, hd, raResponse)
if err != nil {
pterm.Error.Printf("failed to initialize the RollApp: %v\n", err)
return
Expand Down
14 changes: 13 additions & 1 deletion cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
func runInit(
cmd *cobra.Command,
env string,
customHubData consts.HubData,
raResp rollapp.ShowRollappResponse,
) error {
raID := raResp.Rollapp.RollappId
Expand All @@ -34,7 +35,12 @@ func runInit(
}
rollerConfigFilePath := filepath.Join(home, consts.RollerConfigFileName)

hd := consts.Hubs[env]
var hd consts.HubData
if env != "custom" {
hd = consts.Hubs[env]
} else {
hd = customHubData
}
// TODO: refactor
var initConfigPtr *roller.RollappConfig

Expand Down Expand Up @@ -141,6 +147,12 @@ func runInit(
} else {
return fmt.Errorf("unsupported DA backend: %s", daBackend)
}
case "custom":
if daBackend == string(consts.Celestia) {
daNetwork = string(consts.CelestiaTestnet)
} else {
return fmt.Errorf("unsupported DA backend: %s", daBackend)
}
case "mock":
daNetwork = "mock"
default:
Expand Down
7 changes: 2 additions & 5 deletions utils/rollapp/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,9 @@ func GetRollappMetadataFromChain(
var DA consts.DaData

switch hd.ID {
case consts.PlaygroundHubID:
DA = consts.DaNetworks[string(consts.CelestiaTestnet)]
// case consts.MainnetHubID:
// DA = consts.DaNetworks[string(consts.CelestiaMainnet)]
case consts.MockHubID:
default:
fmt.Println("unsupported Hub: ", hd.ID)
DA = consts.DaNetworks[string(consts.CelestiaTestnet)]
}

cfg = roller.RollappConfig{
Expand Down

0 comments on commit 3fa7d04

Please sign in to comment.