Skip to content

Commit

Permalink
*: use (Hash160).Equals instead of common.BytesEqual where possible
Browse files Browse the repository at this point in the history
Part 1 from #307.

Signed-off-by: Anna Shaleva <anna@nspcc.ru>
  • Loading branch information
AnnaShaleva committed Jan 31, 2023
1 parent 7b31fb3 commit 9c8d3c0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion alphabet/alphabet_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
// contracts.
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, []byte(gas.Hash)) && !common.BytesEqual(caller, []byte(neo.Hash)) {
if !caller.Equals(gas.Hash) && !caller.Equals(neo.Hash) {
common.AbortWithMessage("alphabet contract accepts GAS and NEO only")
}
}
Expand Down
2 changes: 1 addition & 1 deletion balance/balance_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func isUsableAddress(addr interop.Hash160) bool {

// Check if a smart contract is calling script hash
callingScriptHash := runtime.GetCallingScriptHash()
if common.BytesEqual(callingScriptHash, addr) {
if callingScriptHash.Equals(addr) {
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ func InvokeID(args []interface{}, prefix []byte) []byte {

func FromKnownContract(ctx storage.Context, caller interop.Hash160, key string) bool {
addr := storage.Get(ctx, key).(interop.Hash160)
return BytesEqual(caller, addr)
return caller.Equals(addr)
}
4 changes: 2 additions & 2 deletions neofs/neofs_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func InnerRingCandidateAdd(key interop.PublicKey) {
// break JSON limits for integers when precision is converted.
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
rcv := data.(interop.Hash160)
if common.BytesEqual(rcv, []byte(ignoreDepositNotification)) {
if rcv.Equals(ignoreDepositNotification) {
return
}

Expand All @@ -247,7 +247,7 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
}

caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, interop.Hash160(gas.Hash)) {
if !caller.Equals(gas.Hash) {
common.AbortWithMessage("only GAS can be accepted for deposit")
}

Expand Down
2 changes: 1 addition & 1 deletion processing/processing_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, []byte(gas.Hash)) {
if !caller.Equals(gas.Hash) {
common.AbortWithMessage("processing contract accepts GAS only")
}
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, []byte(gas.Hash)) {
if !caller.Equals(gas.Hash) {
common.AbortWithMessage("proxy contract accepts GAS only")
}
}
Expand Down

0 comments on commit 9c8d3c0

Please sign in to comment.