Skip to content

Commit

Permalink
[Fix] Patch minor (#22)
Browse files Browse the repository at this point in the history
* fix band client

* fix init and config

* fix tunnel relayer

* fix comment

* fix ListKeys

* remove private key from config

* fix command

* fix comment and error message

* remove checking empty tunnel

* add function CheckAndCreateFolder

* remove viper from app

* remove checking empty rpc
  • Loading branch information
nkitlabs authored Jan 6, 2025
1 parent e101efd commit 425f1e4
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 162 deletions.
2 changes: 1 addition & 1 deletion cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func chainsShowCmd(app *relayer.App) *cobra.Command {
cmd := &cobra.Command{
Use: "show [chain_name]",
Aliases: []string{"s"},
Short: "Return a chain's configuration data",
Short: "Return chain's configuration data",
Args: withUsage(cobra.ExactArgs(1)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s ch s eth
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func configInitCmd(app *relayer.App) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Aliases: []string{"i"},
Short: "Create a default configuration at home directory path defined by --home",
Short: "Create a default configuration at home directory path",
Args: withUsage(cobra.NoArgs),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s config init --home %s
Expand Down
2 changes: 1 addition & 1 deletion cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func queryCmd(app *relayer.App) *cobra.Command {
cmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Query commands on source and destination chains.",
Short: "Query commands on source and destination chains",
}

cmd.AddCommand(
Expand Down
32 changes: 20 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,32 @@ var defaultHome = filepath.Join(os.Getenv("HOME"), ".falcon")

// NewRootCmd returns the root command for falcon.
func NewRootCmd(log *zap.Logger) *cobra.Command {
app := falcon.NewApp(log, viper.New(), defaultHome, false, nil)
app := falcon.NewApp(log, defaultHome, false, nil)

// RootCmd represents the base command when called without any subcommands
rootCmd := &cobra.Command{
Use: appName,
Short: "This application relays tunnel messages to the target chains/contracts.",
Long: strings.TrimSpace(`falcon has:
1. Configuration management for destination chains
2. Key management for managing multiple keys for multiple chains
3. transaction Execution functionality on destination chains.
4. Query functionality on source and destination chains.
Short: "Falcon relays tss tunnel messages from BandChain to destination chains/smart contracts",
Long: strings.TrimSpace(`This application has:
1. Configuration Management: Handles the configuration of the program.
2. Key Management: Supports managing multiple keys across multiple chains.
3. Transaction Execution: Enables executing transactions on destination chains.
4. Query Functionality: Facilitates querying data from both source and destination chains.
NOTE: Most of the commands have aliases that make typing them much quicker
(i.e. 'falcon tx', 'falcon q', etc...)`),
}

rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
return app.Init(rootCmd.Context())
// retrieve log level from viper
logLevelViper := viper.GetString("log-level")
if viper.GetBool("debug") {
logLevelViper = "debug"
}

logFormat := viper.GetString("log-format")

return app.Init(rootCmd.Context(), logLevelViper, logFormat)
}

rootCmd.PersistentPostRun = func(cmd *cobra.Command, _ []string) {
Expand All @@ -58,25 +66,25 @@ func NewRootCmd(log *zap.Logger) *cobra.Command {

// Register --home flag
rootCmd.PersistentFlags().StringVar(&app.HomePath, flagHome, defaultHome, "set home directory")
if err := app.Viper.BindPFlag(flagHome, rootCmd.PersistentFlags().Lookup(flagHome)); err != nil {
if err := viper.BindPFlag(flagHome, rootCmd.PersistentFlags().Lookup(flagHome)); err != nil {
panic(err)
}

// Register --debug flag
rootCmd.PersistentFlags().BoolVarP(&app.Debug, "debug", "d", false, "debug output")
if err := app.Viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")); err != nil {
if err := viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")); err != nil {
panic(err)
}

// Register --log-format flag
rootCmd.PersistentFlags().String("log-format", "auto", "log output format (auto, logfmt, json, or console)")
if err := app.Viper.BindPFlag("log-format", rootCmd.PersistentFlags().Lookup("log-format")); err != nil {
if err := viper.BindPFlag("log-format", rootCmd.PersistentFlags().Lookup("log-format")); err != nil {
panic(err)
}

// Register --log-level flag
rootCmd.PersistentFlags().String("log-level", "", "log level format (info, debug, warn, error, panic or fatal)")
if err := app.Viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level")); err != nil {
if err := viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level")); err != nil {
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func startCmd(app *relayer.App) *cobra.Command {
cmd := &cobra.Command{
Use: "start [tunnel_id...]",
Aliases: []string{"st"},
Short: "Start the falcon tunnel relayer system.",
Short: "Start the falcon tunnel relayer program",
Args: withUsage(cobra.MinimumNArgs(0)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s start # start relaying data from every tunnel being registered on source chain.
Expand Down
24 changes: 12 additions & 12 deletions internal/relayertest/mocks/chain_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion internal/relayertest/testdata/chain_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ max_retry = 3
query_timeout = 3000000000
chain_id = 31337
tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
private_key = ''
block_confirmation = 5
waiting_tx_duration = 3000000000
checking_tx_interval = 1000000000
Expand Down
1 change: 0 additions & 1 deletion internal/relayertest/testdata/custom_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ query_timeout = 3000000000
execute_timeout = 3000000000
chain_id = 31337
tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
private_key = ''
block_confirmation = 5
waiting_tx_duration = 3000000000
liveliness_checking_interval = 900000000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ query_timeout = '3s'
execute_timeout = '3s'
chain_id = 31337
tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
private_key = ''
block_confirmation = 5
waiting_tx_duration = 3000000000
liveliness_checking_interval = '15m'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ query_timeout = 3000000000
execute_timeout = 3000000000
chain_id = 31337
tunnel_router_address = '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
private_key = ''
block_confirmation = 5
waiting_tx_duration = 3000000000
liveliness_checking_interval = 900000000000
Expand Down
19 changes: 19 additions & 0 deletions internal/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package internal

import "os"

// CheckAndCreateFolder checks if the folder exists and creates it if it doesn't.
func CheckAndCreateFolder(path string) error {
// If the folder exists and no error, return nil
_, err := os.Stat(path)
if err == nil {
return nil
}

// If the folder does not exist, create it.
if os.IsNotExist(err) {
return os.Mkdir(path, os.ModePerm)
}

return err
}
Loading

0 comments on commit 425f1e4

Please sign in to comment.