neotest: simplify committee account construction
Simple `sort.Slice` is more readable than multi-level for-loop. Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
37ecf51d13
commit
8886fa8ca9
1 changed files with 20 additions and 24 deletions
|
@ -75,37 +75,33 @@ func init() {
|
|||
multiValidatorAcc = make([]*wallet.Account, mv)
|
||||
sort.Sort(pubs[:4])
|
||||
|
||||
vloop:
|
||||
for i := 0; i < mv; i++ {
|
||||
for j := range accs {
|
||||
if accs[j].PrivateKey().PublicKey().Equal(pubs[i]) {
|
||||
multiValidatorAcc[i] = wallet.NewAccountFromPrivateKey(accs[j].PrivateKey())
|
||||
sort.Slice(accs[:4], func(i, j int) bool {
|
||||
p1 := accs[i].PrivateKey().PublicKey()
|
||||
p2 := accs[j].PrivateKey().PublicKey()
|
||||
return p1.Cmp(p2) == -1
|
||||
})
|
||||
for i := range multiValidatorAcc {
|
||||
multiValidatorAcc[i] = wallet.NewAccountFromPrivateKey(accs[i].PrivateKey())
|
||||
err := multiValidatorAcc[i].ConvertMultisig(mv, pubs[:4])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
continue vloop
|
||||
}
|
||||
}
|
||||
panic("invalid committee WIFs")
|
||||
}
|
||||
|
||||
multiCommitteeAcc = make([]*wallet.Account, mc)
|
||||
sort.Sort(pubs)
|
||||
|
||||
cloop:
|
||||
for i := 0; i < mc; i++ {
|
||||
for j := range accs {
|
||||
if accs[j].PrivateKey().PublicKey().Equal(pubs[i]) {
|
||||
multiCommitteeAcc[i] = wallet.NewAccountFromPrivateKey(accs[j].PrivateKey())
|
||||
sort.Slice(accs, func(i, j int) bool {
|
||||
p1 := accs[i].PrivateKey().PublicKey()
|
||||
p2 := accs[j].PrivateKey().PublicKey()
|
||||
return p1.Cmp(p2) == -1
|
||||
})
|
||||
for i := range multiCommitteeAcc {
|
||||
multiCommitteeAcc[i] = wallet.NewAccountFromPrivateKey(accs[i].PrivateKey())
|
||||
err := multiCommitteeAcc[i].ConvertMultisig(mc, pubs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
continue cloop
|
||||
}
|
||||
}
|
||||
panic("invalid committee WIFs")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue