Make gaiacli keys show multisig-ready
This commit is contained in:
parent
5aae4740db
commit
322a029ab5
|
@ -2,6 +2,8 @@ package keys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
@ -9,39 +11,73 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/tendermint/tendermint/libs/cli"
|
"github.com/tendermint/tendermint/libs/cli"
|
||||||
|
"github.com/tendermint/tendermint/crypto/multisig"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// FlagAddress is the flag for the user's address on the command line.
|
// 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 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 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 {
|
func showKeysCmd() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "show [name]",
|
Use: "show [name]",
|
||||||
Short: "Show key info for the given name",
|
Short: "Show key info for the given name",
|
||||||
Long: `Return public details of one local key.`,
|
Long: `Return public details of one local key.`,
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: runShowCmd,
|
RunE: runShowCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().String(FlagBechPrefix, "acc", "The Bech32 prefix encoding for a key (acc|val|cons)")
|
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(FlagAddress, false, "output the address only (overrides --output)")
|
||||||
cmd.Flags().Bool(FlagPublicKey, false, "output the public key 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
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runShowCmd(cmd *cobra.Command, args []string) error {
|
func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||||
name := args[0]
|
var info keys.Info
|
||||||
|
|
||||||
info, err := GetKeyInfo(name)
|
if len(args) == 1 {
|
||||||
if err != nil {
|
info, err = GetKeyInfo(args[0])
|
||||||
return err
|
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)
|
isShowAddr := viper.GetBool(FlagAddress)
|
||||||
|
|
Loading…
Reference in New Issue