Skip to content

Commit

Permalink
[Fix] Falcon fix issues (#19)
Browse files Browse the repository at this point in the history
* add version command

* fix to pendingNonceAt

* fix command init

* add version comment

* fix log

* remove todo

* fix check signing status error

* remove get effectiveGas

* fix comment
  • Loading branch information
nkitlabs authored Dec 6, 2024
1 parent 5d93646 commit 9515de5
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 306 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ empty = $(whitespace) $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(empty),$(comma),$(build_tags))

ldflags = -X github.com/bandprotocol/falcon/version.Name=falcon \
-X github.com/bandprotocol/falcon/version.AppName=falcon \
-X github.com/bandprotocol/falcon/version.Commit=$(COMMIT) \
-X github.com/bandprotocol/falcon/version.Version=$(VERSION) \
-X "github.com/bandprotocol/falcon/version.BuildTags=$(build_tags_comma_sep)"
ldflags = -X github.com/bandprotocol/falcon/main.Name=falcon \
-X github.com/bandprotocol/falcon/cmd.AppName=falcon \
-X github.com/bandprotocol/falcon/cmd.Commit=$(COMMIT) \
-X github.com/bandprotocol/falcon/cmd.Version=$(VERSION) \
-X "github.com/bandprotocol/falcon/cmd.BuildTags=$(build_tags_comma_sep)"

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $ %s cfg list`, appName, defaultHome, appName)),
return cmd
}

// configInitCmd returns the commands that for initializing an empty config at the --home location
// configInitCmd returns the commands that initializes an empty config at the --home location
func configInitCmd(app *relayer.App) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Expand Down
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import (
)

const (
appName = "falcon"

appName = "falcon"
defaultCoinType = 60
)

Expand Down Expand Up @@ -69,6 +68,7 @@ func NewRootCmd(log *zap.Logger) *cobra.Command {
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 {
panic(err)
Expand All @@ -90,7 +90,9 @@ func NewRootCmd(log *zap.Logger) *cobra.Command {
transactionCmd(app),
queryCmd(app),
startCmd(app),

lineBreakCommand(),
versionCmd(app),
)

return rootCmd
Expand Down
59 changes: 59 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cmd

import (
"fmt"
"runtime"
"strings"

"github.com/pelletier/go-toml/v2"
"github.com/spf13/cobra"

"github.com/bandprotocol/falcon/relayer"
)

var (
// Version defines the application version (defined at compile time)
Version = ""
Commit = ""
Dirty = ""
)

type versionInfo struct {
Version string `json:"version" yaml:"version"`
Commit string `json:"commit" yaml:"commit"`
Go string `json:"go" yaml:"go"`
}

// versionCmd returns a command that prints the falcon version information.
func versionCmd(_ *relayer.App) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Aliases: []string{"v"},
Short: "Print the falcon version info",
Args: withUsage(cobra.NoArgs),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s version
$ %s v`,
appName, appName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
commit := Commit
if Dirty != "0" {
commit += " (dirty)"
}

verInfo := versionInfo{
Version: Version,
Commit: commit,
Go: fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
}

bz, err := toml.Marshal(&verInfo)

fmt.Fprintln(cmd.OutOrStdout(), string(bz))
return err
},
}

return versionCmd
}
12 changes: 6 additions & 6 deletions relayer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ func (a *App) initLogger(configLogLevel string) error {
func (a *App) initTargetChains(ctx context.Context) error {
a.targetChains = make(chains.ChainProviders)
if a.Config == nil || a.Config.TargetChains == nil {
a.Log.Error("target chains not found in config")
a.Log.Error("Target chains not found in config")
return nil
}

for chainName, chainConfig := range a.Config.TargetChains {
cp, err := chainConfig.NewChainProvider(chainName, a.Log, a.HomePath, a.Debug)
if err != nil {
a.Log.Error("cannot create chain provider",
a.Log.Error("Cannot create chain provider",
zap.Error(err),
zap.String("chain_name", chainName),
)
return err
}

if err := cp.Init(ctx); err != nil {
a.Log.Error("cannot initialize chain provider",
a.Log.Error("Cannot initialize chain provider",
zap.Error(err),
zap.String("chain_name", chainName),
)
Expand Down Expand Up @@ -554,7 +554,7 @@ func (a *App) validatePassphrase(envPassphrase string) error {

// Start starts the tunnel relayer program.
func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error {
a.Log.Info("starting tunnel relayer")
a.Log.Info("Starting tunnel relayer")

isSyncTunnelsAllowed := false

Expand All @@ -579,7 +579,7 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error {
}

if len(tunnels) == 0 {
a.Log.Error("no tunnel ID provided")
a.Log.Error("No tunnel ID provided")
return fmt.Errorf("no tunnel ID provided")
}

Expand Down Expand Up @@ -628,7 +628,7 @@ func (a *App) Start(ctx context.Context, tunnelIDs []uint64) error {

// Relay relays the packet from the source chain to the destination chain.
func (a *App) Relay(ctx context.Context, tunnelID uint64) error {
a.Log.Debug("query tunnel info on band chain", zap.Uint64("tunnel_id", tunnelID))
a.Log.Debug("Query tunnel info on band chain", zap.Uint64("tunnel_id", tunnelID))
tunnel, err := a.BandClient.GetTunnel(ctx, tunnelID)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 9515de5

Please sign in to comment.