mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 09:29:38 +00:00
*: use maps.Equal/slices.Equal where appropriate
Testing for equality has never been easier. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
93ecd61079
commit
9cce148d83
4 changed files with 14 additions and 57 deletions
|
@ -43,10 +43,8 @@ func (a *ApplicationConfiguration) EqualsButServices(o *ApplicationConfiguration
|
|||
oCp := slices.Clone(o.P2P.Addresses)
|
||||
sort.Strings(aCp)
|
||||
sort.Strings(oCp)
|
||||
for i := range aCp {
|
||||
if aCp[i] != oCp[i] {
|
||||
return false
|
||||
}
|
||||
if !slices.Equal(aCp, oCp) {
|
||||
return false
|
||||
}
|
||||
if a.P2P.AttemptConnPeers != o.P2P.AttemptConnPeers ||
|
||||
a.P2P.BroadcastFactor != o.P2P.BroadcastFactor ||
|
||||
|
|
|
@ -3,6 +3,8 @@ package config
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
|
@ -231,40 +233,12 @@ func (p *ProtocolConfiguration) Equals(o *ProtocolConfiguration) bool {
|
|||
p.TimePerBlock != o.TimePerBlock ||
|
||||
p.ValidatorsCount != o.ValidatorsCount ||
|
||||
p.VerifyTransactions != o.VerifyTransactions ||
|
||||
len(p.CommitteeHistory) != len(o.CommitteeHistory) ||
|
||||
len(p.Hardforks) != len(o.Hardforks) ||
|
||||
len(p.SeedList) != len(o.SeedList) ||
|
||||
len(p.StandbyCommittee) != len(o.StandbyCommittee) ||
|
||||
len(p.ValidatorsHistory) != len(o.ValidatorsHistory) {
|
||||
!maps.Equal(p.CommitteeHistory, o.CommitteeHistory) ||
|
||||
!maps.Equal(p.Hardforks, o.Hardforks) ||
|
||||
!slices.Equal(p.SeedList, o.SeedList) ||
|
||||
!slices.Equal(p.StandbyCommittee, o.StandbyCommittee) ||
|
||||
!maps.Equal(p.ValidatorsHistory, o.ValidatorsHistory) {
|
||||
return false
|
||||
}
|
||||
for k, v := range p.CommitteeHistory {
|
||||
vo, ok := o.CommitteeHistory[k]
|
||||
if !ok || v != vo {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for k, v := range p.Hardforks {
|
||||
vo, ok := o.Hardforks[k]
|
||||
if !ok || v != vo {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for i := range p.SeedList {
|
||||
if p.SeedList[i] != o.SeedList[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for i := range p.StandbyCommittee {
|
||||
if p.StandbyCommittee[i] != o.StandbyCommittee[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for k, v := range p.ValidatorsHistory {
|
||||
vo, ok := o.ValidatorsHistory[k]
|
||||
if !ok || v != vo {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package oracle
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
|
@ -13,17 +15,8 @@ func (o *Oracle) UpdateOracleNodes(oracleNodes keys.PublicKeys) {
|
|||
o.accMtx.Lock()
|
||||
defer o.accMtx.Unlock()
|
||||
|
||||
old := o.oracleNodes
|
||||
if isEqual := len(old) == len(oracleNodes); isEqual {
|
||||
for i := range old {
|
||||
if !old[i].Equal(oracleNodes[i]) {
|
||||
isEqual = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if isEqual {
|
||||
return
|
||||
}
|
||||
if slices.EqualFunc(o.oracleNodes, oracleNodes, (*keys.PublicKey).Equal) {
|
||||
return
|
||||
}
|
||||
|
||||
var acc *wallet.Account
|
||||
|
|
|
@ -51,15 +51,7 @@ func (f Field) And(m Field) {
|
|||
|
||||
// Equals compares two Fields and returns true if they're equal.
|
||||
func (f Field) Equals(o Field) bool {
|
||||
if len(f) != len(o) {
|
||||
return false
|
||||
}
|
||||
for i := range f {
|
||||
if f[i] != o[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return slices.Equal(f, o)
|
||||
}
|
||||
|
||||
// IsSubset returns true when f is a subset of o (only has bits set that are
|
||||
|
|
Loading…
Reference in a new issue