Skip to content

Commit

Permalink
go/oasis-node: Add identity show-address subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Aug 20, 2024
1 parent 207b0d1 commit db6daf9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .changelog/5820.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/oasis-node: Add `identity show-address` subcommand

This subcommand makes it easier to get the address associated with the node
identity public key.
13 changes: 9 additions & 4 deletions go/oasis-node/cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var (
logger = logging.GetLogger("cmd/control")
)

// DoConnect connects to the runtime client grpc server.
// DoConnect connects to the node's gRPC server.
func DoConnect(cmd *cobra.Command) (*grpc.ClientConn, control.NodeController) {
if err := cmdCommon.Init(); err != nil {
cmdCommon.EarlyLogAndExit(err)
Expand Down Expand Up @@ -268,12 +268,11 @@ func doCancelUpgrade(cmd *cobra.Command, args []string) {
}
}

func doStatus(cmd *cobra.Command, _ []string) {
// DoFetchStatus connects to the node's gRPC server and fetches its status.
func DoFetchStatus(cmd *cobra.Command) *control.Status {
conn, client := DoConnect(cmd)
defer conn.Close()

logger.Debug("querying status")

// Use background context to block until the result comes in.
status, err := client.GetStatus(context.Background())
if err != nil {
Expand All @@ -282,6 +281,12 @@ func doStatus(cmd *cobra.Command, _ []string) {
)
os.Exit(128)
}
return status
}

func doStatus(cmd *cobra.Command, _ []string) {
status := DoFetchStatus(cmd)

prettyStatus, err := cmdCommon.PrettyJSONMarshal(status)
if err != nil {
logger.Error("failed to get pretty JSON of node status",
Expand Down
19 changes: 19 additions & 0 deletions go/oasis-node/cmd/identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/logging"
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
cmdGrpc "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/grpc"
cmdControl "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/control"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/identity/cometbft"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
)

const CfgDataDir = "datadir"
Expand Down Expand Up @@ -48,6 +51,12 @@ var (
Run: doShowTLSPubkey,
}

identityShowAddressCmd = &cobra.Command{
Use: "show-address",
Short: "outputs node's address",
Run: doShowAddress,
}

logger = logging.GetLogger("cmd/identity")
)

Expand Down Expand Up @@ -141,6 +150,13 @@ func doShowSentryTLSPubkey(cmd *cobra.Command, args []string) {
doShowPubkey(cmd, args, true)
}

func doShowAddress(cmd *cobra.Command, _ []string) {
status := cmdControl.DoFetchStatus(cmd)

addr := staking.NewAddress(status.Identity.Node)
fmt.Println(addr)
}

// Register registers the client sub-command and all of it's children.
func Register(parentCmd *cobra.Command) {
cometbft.Register(identityCmd)
Expand All @@ -149,9 +165,12 @@ func Register(parentCmd *cobra.Command) {

identityInitCmd.Flags().AddFlagSet(cmdFlags.VerboseFlags)

identityShowAddressCmd.Flags().AddFlagSet(cmdGrpc.ClientFlags)

identityCmd.AddCommand(identityInitCmd)
identityCmd.AddCommand(identityShowSentryPubkeyCmd)
identityCmd.AddCommand(identityShowTLSPubkeyCmd)
identityCmd.AddCommand(identityShowAddressCmd)

parentCmd.AddCommand(identityCmd)
}
Expand Down

0 comments on commit db6daf9

Please sign in to comment.