Skip to content

Commit

Permalink
feat: Add loading spinner with status on roller init, register and run (
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Jul 3, 2023
1 parent b975d93 commit 63d166d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
12 changes: 9 additions & 3 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package initconfig

import (
"fmt"
"os"

"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
"os"
)

const validDenomMsg = "A valid denom should consist of exactly 3 English alphabet letters, for example 'btc', 'eth'"
Expand Down Expand Up @@ -46,6 +45,9 @@ func InitCmd() *cobra.Command {
return nil
},
Run: func(cmd *cobra.Command, args []string) {
spin := utils.GetLoadingSpinner()
spin.Suffix = consts.SpinnerMsgs.UniqueIdVerification
spin.Start()
initConfig, err := GetInitConfig(cmd, args)
utils.PrettifyErrorIfExists(err)

Expand All @@ -57,18 +59,21 @@ func InitCmd() *cobra.Command {
isRootExist, err := dirNotEmpty(initConfig.Home)
utils.PrettifyErrorIfExists(err)
if isRootExist {
spin.Stop()
shouldOverwrite, err := promptOverwriteConfig(initConfig.Home)
utils.PrettifyErrorIfExists(err)
if shouldOverwrite {
utils.PrettifyErrorIfExists(os.RemoveAll(initConfig.Home))
} else {
os.Exit(0)
}
spin.Start()
}
utils.PrettifyErrorIfExists(os.MkdirAll(initConfig.Home, 0755))

//TODO: create all dirs here

spin.Suffix = " Initializing RollApp configuration files..."
spin.Restart()
/* ---------------------------- Initilize relayer --------------------------- */
utils.PrettifyErrorIfExists(initializeRelayerConfig(ChainConfig{
ID: initConfig.RollappID,
Expand Down Expand Up @@ -101,6 +106,7 @@ func InitCmd() *cobra.Command {
utils.PrettifyErrorIfExists(utils.WriteConfigToTOML(initConfig))

/* ------------------------------ Print output ------------------------------ */
spin.Stop()
printInitOutput(initConfig, addresses, initConfig.RollappID)
},
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ const (

// TODO: Check DA LC write price on arabica and update this value.
var OneDAWritePrice = big.NewInt(1)

var SpinnerMsgs = struct {
UniqueIdVerification string
BalancesVerification string
}{
UniqueIdVerification: " Verifying unique RollApp ID...\n",
BalancesVerification: " Verifying balances...\n",
}
12 changes: 11 additions & 1 deletion cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"errors"
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"math/big"

"strings"

"encoding/json"
Expand All @@ -23,18 +23,28 @@ func Cmd() *cobra.Command {
Use: "register",
Short: "Registers the rollapp and the sequencer to the Dymension hub.",
Run: func(cmd *cobra.Command, args []string) {
spin := utils.GetLoadingSpinner()
spin.Suffix = consts.SpinnerMsgs.BalancesVerification
spin.Start()
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := utils.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
notFundedAddrs, err := utils.GetSequencerInsufficientAddrs(rollappConfig, *registerUdymPrice)
utils.PrettifyErrorIfExists(err)
utils.PrintInsufficientBalancesIfAny(notFundedAddrs)
spin.Suffix = consts.SpinnerMsgs.UniqueIdVerification
spin.Restart()
utils.PrettifyErrorIfExists(initconfig.VerifyUniqueRollappID(rollappConfig.RollappID, rollappConfig))
spin.Suffix = " Registering RollApp to hub...\n"
spin.Restart()
utils.PrettifyErrorIfExists(registerRollapp(rollappConfig))
registerSequencerCmd, err := getRegisterSequencerCmd(rollappConfig)
utils.PrettifyErrorIfExists(err)
spin.Suffix = " Registering RollApp sequencer...\n"
spin.Restart()
_, err = utils.ExecBashCommand(registerSequencerCmd)
utils.PrettifyErrorIfExists(err)
spin.Stop()
printRegisterOutput(rollappConfig)
},
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func Cmd() *cobra.Command {
Use: "run",
Short: "Runs the rollapp on the local machine.",
Run: func(cmd *cobra.Command, args []string) {
spin := utils.GetLoadingSpinner()
spin.Suffix = consts.SpinnerMsgs.BalancesVerification
spin.Start()
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := utils.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
Expand All @@ -32,14 +35,17 @@ func Cmd() *cobra.Command {
Context: ctx,
WaitGroup: &waitingGroup,
}
spin.Suffix = " Starting RollApp services..."
spin.Restart()
runDaWithRestarts(rollappConfig, serviceConfig)
runSequencerWithRestarts(rollappConfig, serviceConfig)
runRelayerWithRestarts(rollappConfig, serviceConfig)
PrintServicesStatus(rollappConfig)
cancel()
logger.Println("Killing subprocesses")
spin.Suffix = " Killing subprocesses..."
spin.Restart()
waitingGroup.Wait()
logger.Println("killed them")
spin.Stop()
},
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/utils/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package utils
import (
"errors"
"fmt"
"github.com/briandowns/spinner"
"github.com/olekukonko/tablewriter"
"math/big"
"os"
"time"
)

func PrintInsufficientBalancesIfAny(addressesData []NotFundedAddressData) {
Expand Down Expand Up @@ -44,3 +46,7 @@ type NotFundedAddressData struct {
RequiredBalance *big.Int
Denom string
}

func GetLoadingSpinner() *spinner.Spinner {
return spinner.New(spinner.CharSets[9], 100*time.Millisecond)
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/armon/go-metrics v0.4.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
Expand Down Expand Up @@ -105,7 +106,7 @@ require (
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
google.golang.org/grpc v1.51.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A=
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BRcvO8T0UEPu53cnw4IbV63x1bEjildYhO0=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
Expand Down Expand Up @@ -679,6 +681,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down

0 comments on commit 63d166d

Please sign in to comment.