Make gaiacli keys show multisig-ready
This commit is contained in:
parent
5aae4740db
commit
322a029ab5
|
@ -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,6 +11,8 @@ 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 (
|
||||
|
@ -18,31 +22,63 @@ const (
|
|||
FlagPublicKey = "pubkey"
|
||||
// FlagBechPrefix defines a desired Bech32 prefix encoding for a key.
|
||||
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 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)
|
||||
isShowPubKey := viper.GetBool(FlagPublicKey)
|
||||
|
|
Loading…
Reference in New Issue