diff --git a/client/keys/show.go b/client/keys/show.go index b567daf12..f81df3263 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -2,6 +2,8 @@ package keys import ( "fmt" + "github.com/cosmos/cosmos-sdk/crypto/keys" + "github.com/tendermint/tendermint/crypto" "net/http" "github.com/gorilla/mux" @@ -9,39 +11,73 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/crypto/multisig" + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( // FlagAddress is the flag for the user's address on the command line. - FlagAddress = "address" + FlagAddress = "address" // FlagPublicKey represents the user's public key on the command line. - FlagPublicKey = "pubkey" + FlagPublicKey = "pubkey" // FlagBechPrefix defines a desired Bech32 prefix encoding for a key. - FlagBechPrefix = "bech" + FlagBechPrefix = "bech" + + flagMultiSigThreshold = "multisig-threshold" ) +var _ keys.Info = (keys.Info)(nil) + +type multiSigKey struct { + name string + key crypto.PubKey +} + +func (m multiSigKey) GetName() string { return m.name } +func (m multiSigKey) GetType() keys.KeyType { return keys.TypeLocal } +func (m multiSigKey) GetPubKey() crypto.PubKey { return m.key } +func (m multiSigKey) GetAddress() sdk.AccAddress { return sdk.AccAddress(m.key.Address())} + + func showKeysCmd() *cobra.Command { cmd := &cobra.Command{ Use: "show [name]", Short: "Show key info for the given name", Long: `Return public details of one local key.`, - Args: cobra.ExactArgs(1), + Args: cobra.MinimumNArgs(1), RunE: runShowCmd, } cmd.Flags().String(FlagBechPrefix, "acc", "The Bech32 prefix encoding for a key (acc|val|cons)") cmd.Flags().Bool(FlagAddress, false, "output the address only (overrides --output)") cmd.Flags().Bool(FlagPublicKey, false, "output the public key only (overrides --output)") + cmd.Flags().UintP(flagMultiSigThreshold, "m", 1, "K out of N required signatures") return cmd } -func runShowCmd(cmd *cobra.Command, args []string) error { - name := args[0] +func runShowCmd(cmd *cobra.Command, args []string) (err error) { + var info keys.Info - info, err := GetKeyInfo(name) - if err != nil { - return err + if len(args) == 1 { + info, err = GetKeyInfo(args[0]) + if err != nil { + return err + } + } else { + pks := make([]crypto.PubKey, len(args)) + for i, keyName := range args { + info, err := GetKeyInfo(keyName) + if err != nil { + return err + } + pks[i] = info.GetPubKey() + } + multikey := multisig.NewPubKeyMultisigThreshold(viper.GetInt(flagMultiSigThreshold), pks) + info = multiSigKey{ + name: "multi", + key: multikey, + } } isShowAddr := viper.GetBool(FlagAddress)