Validate threshold rather than letting it panic

This commit is contained in:
Alessio Treglia 2018-10-22 17:13:36 -07:00
parent ca049fd453
commit 230c69b438
No known key found for this signature in database
GPG Key ID: E8A48AE5311D765A
1 changed files with 18 additions and 1 deletions

View File

@ -72,7 +72,13 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
}
pks[i] = info.GetPubKey()
}
multikey := multisig.NewPubKeyMultisigThreshold(viper.GetInt(flagMultiSigThreshold), pks)
multisigThreshold := viper.GetInt(flagMultiSigThreshold)
err = validateMultisigThreshold(multisigThreshold, len(args))
if err != nil {
return err
}
multikey := multisig.NewPubKeyMultisigThreshold(multisigThreshold, pks)
info = multiSigKey{
name: "multi",
key: multikey,
@ -108,6 +114,17 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
return nil
}
func validateMultisigThreshold(k, nKeys int) error {
if k <= 0 {
return fmt.Errorf("threshold must be a positive integer")
}
if nKeys < k {
return fmt.Errorf(
"threshold k of n multisignature: %d < %d", nKeys, k)
}
return nil
}
func getBechKeyOut(bechPrefix string) (bechKeyOutFn, error) {
switch bechPrefix {
case "acc":