From 9c8d3c0e4e240d6a6596c074824871c230d84f80 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 31 Jan 2023 14:17:23 +0300 Subject: [PATCH] *: use (Hash160).Equals instead of common.BytesEqual where possible Part 1 from #307. Signed-off-by: Anna Shaleva --- alphabet/alphabet_contract.go | 2 +- balance/balance_contract.go | 2 +- common/vote.go | 2 +- neofs/neofs_contract.go | 4 ++-- processing/processing_contract.go | 2 +- proxy/proxy_contract.go | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/alphabet/alphabet_contract.go b/alphabet/alphabet_contract.go index 9ae74c37..4abefbcc 100644 --- a/alphabet/alphabet_contract.go +++ b/alphabet/alphabet_contract.go @@ -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") } } diff --git a/balance/balance_contract.go b/balance/balance_contract.go index cf8e305d..a2e7abdb 100644 --- a/balance/balance_contract.go +++ b/balance/balance_contract.go @@ -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 } } diff --git a/common/vote.go b/common/vote.go index 63d10cc6..f7ab1402 100644 --- a/common/vote.go +++ b/common/vote.go @@ -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) } diff --git a/neofs/neofs_contract.go b/neofs/neofs_contract.go index 6bd6685e..ff986c41 100644 --- a/neofs/neofs_contract.go +++ b/neofs/neofs_contract.go @@ -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 } @@ -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") } diff --git a/processing/processing_contract.go b/processing/processing_contract.go index aff92a1f..8678e41b 100644 --- a/processing/processing_contract.go +++ b/processing/processing_contract.go @@ -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") } } diff --git a/proxy/proxy_contract.go b/proxy/proxy_contract.go index 59996489..e30b0be2 100644 --- a/proxy/proxy_contract.go +++ b/proxy/proxy_contract.go @@ -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") } }