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)
|
multiValidatorAcc = make([]*wallet.Account, mv)
|
||||||
sort.Sort(pubs[:4])
|
sort.Sort(pubs[:4])
|
||||||
|
|
||||||
vloop:
|
sort.Slice(accs[:4], func(i, j int) bool {
|
||||||
for i := 0; i < mv; i++ {
|
p1 := accs[i].PrivateKey().PublicKey()
|
||||||
for j := range accs {
|
p2 := accs[j].PrivateKey().PublicKey()
|
||||||
if accs[j].PrivateKey().PublicKey().Equal(pubs[i]) {
|
return p1.Cmp(p2) == -1
|
||||||
multiValidatorAcc[i] = wallet.NewAccountFromPrivateKey(accs[j].PrivateKey())
|
})
|
||||||
|
for i := range multiValidatorAcc {
|
||||||
|
multiValidatorAcc[i] = wallet.NewAccountFromPrivateKey(accs[i].PrivateKey())
|
||||||
err := multiValidatorAcc[i].ConvertMultisig(mv, pubs[:4])
|
err := multiValidatorAcc[i].ConvertMultisig(mv, pubs[:4])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
continue vloop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic("invalid committee WIFs")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
multiCommitteeAcc = make([]*wallet.Account, mc)
|
multiCommitteeAcc = make([]*wallet.Account, mc)
|
||||||
sort.Sort(pubs)
|
sort.Sort(pubs)
|
||||||
|
|
||||||
cloop:
|
sort.Slice(accs, func(i, j int) bool {
|
||||||
for i := 0; i < mc; i++ {
|
p1 := accs[i].PrivateKey().PublicKey()
|
||||||
for j := range accs {
|
p2 := accs[j].PrivateKey().PublicKey()
|
||||||
if accs[j].PrivateKey().PublicKey().Equal(pubs[i]) {
|
return p1.Cmp(p2) == -1
|
||||||
multiCommitteeAcc[i] = wallet.NewAccountFromPrivateKey(accs[j].PrivateKey())
|
})
|
||||||
|
for i := range multiCommitteeAcc {
|
||||||
|
multiCommitteeAcc[i] = wallet.NewAccountFromPrivateKey(accs[i].PrivateKey())
|
||||||
err := multiCommitteeAcc[i].ConvertMultisig(mc, pubs)
|
err := multiCommitteeAcc[i].ConvertMultisig(mc, pubs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
continue cloop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic("invalid committee WIFs")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue