Skip to content

Commit

Permalink
feat: multi arch block explorer (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Jan 3, 2025
1 parent 72de46a commit 6c90024
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 68 deletions.
105 changes: 40 additions & 65 deletions cmd/block-explorer/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"fmt"
"path/filepath"
"runtime"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/blockexplorer"
rollerfilesystemutils "github.com/dymensionxyz/roller/utils/filesystem"
"github.com/dymensionxyz/roller/utils/rollapp"
"github.com/dymensionxyz/roller/utils/roller"
"github.com/dymensionxyz/roller/utils/config"
relayerutils "github.com/dymensionxyz/roller/utils/relayer"
)

func Cmd() *cobra.Command {
Expand All @@ -23,72 +23,47 @@ func Cmd() *cobra.Command {
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(initconfig.GlobalFlagNames.Home).Value.String()
isFlagChanged := cmd.Flags().Changed("block-explorer-rpc-endpoint")
defaultBeRpcEndpoint, _ := cmd.Flags().GetString("block-explorer-rpc-endpoint")

var beRpcEndpoint string
raID, _, _, err := relayerutils.GetRollappToRunFor(home)
if err != nil {
pterm.Error.Println("failed to determine what RollApp to run for:", err)
return
}

for {
// Prompt the user for the RPC URL
beRpcEndpoint, _ = pterm.DefaultInteractiveTextInput.WithDefaultText(
"rollapp block explorer rpc endpoint that you will provide (example: be.rollapp.dym.xyz)",
).Show()

if strings.HasPrefix(beRpcEndpoint, "http://") {
pterm.Error.Println("Invalid URL. Please try again.")
continue // This will restart the loop from the beginning
}

if !strings.HasPrefix(beRpcEndpoint, "https://") {
beRpcEndpoint = "https://" + beRpcEndpoint
}

isValid := config.IsValidURL(beRpcEndpoint)

// Validate the URL
if !isValid {
pterm.Error.Println("Invalid URL. Please try again.")
continue // This will also restart the loop
}

// Valid URL, break out of the loop
break
}

hostAddress := "host.docker.internal"
if runtime.GOOS == "linux" {
hostAddress = "172.17.0.1" // Default Docker bridge network gateway
}
var raID string
fmt.Println(hostAddress)

var beRpcEndpoint string
if !isFlagChanged {
useDefaultEndpoint, _ := pterm.DefaultInteractiveConfirm.WithDefaultValue(false).
WithDefaultText(
fmt.Sprintf(
`'--block-explorer-rpc-endpoint' is not set,
would you like to continue with the default endpoint (%s)?'
if you're running a rollapp locally, press 'y',
if you want to run block explorer for a rollapp on a different host, press 'n' and provide the endpoint and RollApp ID`,
defaultBeRpcEndpoint,
),
).
Show()
if useDefaultEndpoint {
beRpcEndpoint = fmt.Sprintf("http://%s:11100", hostAddress)

err := rollerfilesystemutils.UpdateHostsFile(
"127.0.0.1",
"host.docker.internal",
)
if err != nil {
pterm.Error.Println("failed to update hosts file", err)
return
}

rollerData, err := roller.LoadConfig(home)
if err != nil {
pterm.Error.Println("failed to load roller config file", err)
return
}

raID = rollerData.RollappID
} else {
newBeRpcEndpoint, _ := pterm.DefaultInteractiveTextInput.WithDefaultText(
"provide block explorer json rpc endpoint (running on port 11100 by default):",
).Show()
if newBeRpcEndpoint == "" {
pterm.Error.Println("invalid endpoint")
return
}

raIDInput, _ := pterm.DefaultInteractiveTextInput.WithDefaultText(
"provide a rollapp ID that you want to run the node for",
).Show()

_, err := rollapp.ValidateChainID(raIDInput)
if err != nil {
pterm.Error.Println("invalid rollapp ID", err)
}

raID = raIDInput

beRpcEndpoint = newBeRpcEndpoint
}
}

beChainConfigPath := filepath.Join(
home,
consts.ConfigDirName.BlockExplorer,
Expand All @@ -102,7 +77,7 @@ if you want to run block explorer for a rollapp on a different host, press 'n' a

fmt.Println(beChainConfig)

err := blockexplorer.WriteChainsYAML(beChainConfigPath, beChainConfig)
err = blockexplorer.WriteChainsYAML(beChainConfigPath, beChainConfig)
if err != nil {
pterm.Error.Println("failed to generate block explorer config", err)
}
Expand All @@ -117,8 +92,8 @@ if you want to run block explorer for a rollapp on a different host, press 'n' a
},
}

cmd.Flags().
String("block-explorer-rpc-endpoint", "http://localhost:11100", "block explorer rpc endpoint")
// cmd.Flags().
// String("block-explorer-rpc-endpoint", "http://localhost:11100", "block explorer rpc endpoint")

return cmd
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/block-explorer/run/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ func createBlockExplorerContainers(home, hostAddress string) error {
},
"frontend": {
Name: "be-frontend",
Image: "public.ecr.aws/a3d4b9r3/block-explorer-frontend:latest",
Image: "public.ecr.aws/a3d4b9r3/block-explorer-frontend:next",
Port: "3000",
Envs: []string{
fmt.Sprintf("DATABASE_URL=postgresql://be:psw@%s:5432/blockexplorer", domain),
"DATABASE_URL=postgresql://be:psw@be-postgresql:5432/blockexplorer",
fmt.Sprintf("HOST_ADDRESS=%s", domain),
},
Mounts: []mount.Mount{},
},
"indexer": {
Name: "be-indexer",
Image: "public.ecr.aws/a3d4b9r3/block-explorer-indexer:latest",
Image: "public.ecr.aws/a3d4b9r3/block-explorer-indexer:next",
Port: "8080",
Envs: []string{
fmt.Sprintf("HOST_ADDRESS=%s", domain),
Expand Down

0 comments on commit 6c90024

Please sign in to comment.