Validate threshold rather than letting it panic
This commit is contained in:
parent
ca049fd453
commit
230c69b438
|
@ -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":
|
||||
|
|
Loading…
Reference in New Issue