Skip to content

Commit

Permalink
Add --show_node_id and --show_validator flags
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Mar 27, 2019
1 parent e33635f commit 05fc0f3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.15.1

IMPROVEMENT

- [cmd] Add `--show_node_id` and `--show_validator` flags

## 0.15.0

BREAKING CHANGES
Expand Down
40 changes: 40 additions & 0 deletions cmd/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (
"github.com/MinterTeam/minter-go-node/genesis"
"github.com/MinterTeam/minter-go-node/gui"
"github.com/MinterTeam/minter-go-node/log"
"github.com/pkg/errors"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/abci/types"
bc "github.com/tendermint/tendermint/blockchain"
tmCfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/encoding/amino"
"github.com/tendermint/tendermint/libs/common"
tmNode "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p"
Expand All @@ -32,6 +35,16 @@ func main() {
os.Exit(1)
}

if *utils.ShowNodeId {
showNodeID()
return
}

if *utils.ShowValidator {
showValidator()
return
}

app := minter.NewMinterBlockchain()

tmCfg := config.GetTmConfig()
Expand Down Expand Up @@ -133,3 +146,30 @@ func startTendermintNode(app types.Application, cfg *tmCfg.Config) *tmNode.Node

return node
}

func showNodeID() {
nodeKey, err := p2p.LoadNodeKey(cfg.NodeKeyFile())
if err != nil {
panic(err)
}

fmt.Println(nodeKey.ID())
}

func showValidator() {
cdc := amino.NewCodec()
cryptoAmino.RegisterAmino(cdc)

keyFilePath := cfg.PrivValidatorKeyFile()
if !common.FileExists(keyFilePath) {
panic(fmt.Errorf("private validator file %s does not exist", keyFilePath))
}

pv := privval.LoadFilePV(keyFilePath, cfg.PrivValidatorStateFile())
bz, err := cdc.MarshalJSON(pv.GetPubKey())
if err != nil {
panic(errors.Wrap(err, "failed to marshal private validator pubkey"))
}

fmt.Println(string(bz))
}
4 changes: 3 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
)

var (
MinterHome = flag.String("home", "", "Path to minter data directory")
MinterHome = flag.String("home", "", "Path to minter data directory")
ShowNodeId = flag.Bool("show_node_id", false, "Show node id")
ShowValidator = flag.Bool("show_validator", false, "Show validator info")
)

func init() {
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ func (cfg BaseConfig) NodeKeyFile() string {
return rootify(cfg.NodeKey, cfg.RootDir)
}

func (cfg BaseConfig) PrivValidatorKeyFile() string {
return rootify(cfg.PrivValidatorKey, cfg.RootDir)
}

// DBDir returns the full path to the database directory
func (cfg BaseConfig) DBDir() string {
return rootify(cfg.DBPath, cfg.RootDir)
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package version
const (
Maj = "0"
Min = "15"
Fix = "0"
Fix = "1"

AppVer = 2
)

var (
// Must be a string because scripts like dist.sh read this file.
Version = "0.15.0"
Version = "0.15.1"

// GitCommit is the current HEAD set using ldflags.
GitCommit string
Expand Down

0 comments on commit 05fc0f3

Please sign in to comment.