diff --git a/.changelog/5820.feature.md b/.changelog/5820.feature.md new file mode 100644 index 00000000000..5d6dad5f965 --- /dev/null +++ b/.changelog/5820.feature.md @@ -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. diff --git a/go/oasis-node/cmd/control/control.go b/go/oasis-node/cmd/control/control.go index 3adf5a8ab8e..b18b49532d8 100644 --- a/go/oasis-node/cmd/control/control.go +++ b/go/oasis-node/cmd/control/control.go @@ -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) @@ -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 { @@ -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", diff --git a/go/oasis-node/cmd/identity/identity.go b/go/oasis-node/cmd/identity/identity.go index 801179b6ea6..06b69dc0b63 100644 --- a/go/oasis-node/cmd/identity/identity.go +++ b/go/oasis-node/cmd/identity/identity.go @@ -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" @@ -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") ) @@ -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) @@ -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) }