Skip to content

Commit

Permalink
replace custom iteration with keyring built-in function
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed Oct 21, 2022
1 parent 096e3b0 commit 8910f5d
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,30 +338,15 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
}

func verifyMultisigTarget(kb keyring.Keyring, multisigKeys []string, newkey string) error {
kl, err := kb.List()
if err != nil {
return err
}

kmap := make(map[string]bool)
for i := 0; i < len(kl); i++ {
kmap[kl[i].GetName()] = true
}

if _, ok := kmap[newkey]; ok {
if _, err := kb.Key(newkey); err == nil {
return errors.New("you cannot specify a new key as one of the names of the keys that make up a multisig")
}

cnt := 0
for _, k := range multisigKeys {
if _, ok := kmap[k]; ok {
cnt++
if _, err := kb.Key(k); err != nil {
return errors.New("part of the multisig target key does not exist")
}
}

if cnt != len(multisigKeys) {
return errors.New("part of the multisig target key does not exist")
}

return nil
}

0 comments on commit 8910f5d

Please sign in to comment.