From 079f68a8c3c2838c782a9861384e1134a386b9a0 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 11 Jul 2022 17:29:25 +0300 Subject: [PATCH] examples: use interop equality helpers where possible --- examples/nft-d/nft.go | 7 ++++--- examples/nft-nd-nns/nns.go | 3 +-- examples/nft-nd/nft.go | 5 +++-- examples/oracle/oracle.go | 3 ++- examples/token/nep17/nep17.go | 3 +-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/nft-d/nft.go b/examples/nft-d/nft.go index 6257adce5..66afd2ef6 100644 --- a/examples/nft-d/nft.go +++ b/examples/nft-d/nft.go @@ -203,7 +203,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool { key := mkBalanceKey(owner, token) amount := getBalanceOf(ctx, key) - if string(owner) != string(to) { + if !owner.Equals(to) { addToBalance(ctx, owner, token, -amount) removeOwner(ctx, token, owner) @@ -293,7 +293,7 @@ func TransferDivisible(from, to interop.Hash160, amount int, token []byte, data return false } - if string(from) != string(to) { + if !from.Equals(to) { updBalance := addToBalance(ctx, from, token, -amount) if updBalance == 0 { removeOwner(ctx, token, from) @@ -357,7 +357,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { util.Abort() } }() - if string(runtime.GetCallingScriptHash()) != gas.Hash { + callingHash := runtime.GetCallingScriptHash() + if !callingHash.Equals(gas.Hash) { panic("only GAS is accepted") } if amount < 10_00000000 { diff --git a/examples/nft-nd-nns/nns.go b/examples/nft-nd-nns/nns.go index 3ffce9ace..516f476c2 100644 --- a/examples/nft-nd-nns/nns.go +++ b/examples/nft-nd-nns/nns.go @@ -18,7 +18,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/storage" - "github.com/nspcc-dev/neo-go/pkg/interop/util" ) // Prefixes used for contract data storage. @@ -164,7 +163,7 @@ func Transfer(to interop.Hash160, tokenID []byte, data interface{}) bool { if !runtime.CheckWitness(from) { return false } - if !util.Equals(from, to) { + if !from.Equals(to) { // update token info ns.Owner = to ns.Admin = nil diff --git a/examples/nft-nd/nft.go b/examples/nft-nd/nft.go index b0e469328..f4f87b743 100644 --- a/examples/nft-nd/nft.go +++ b/examples/nft-nd/nft.go @@ -186,7 +186,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool { return false } - if string(owner) != string(to) { + if !owner.Equals(to) { addToBalance(ctx, owner, -1) removeToken(ctx, owner, token) @@ -216,7 +216,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { util.Abort() } }() - if string(runtime.GetCallingScriptHash()) != gas.Hash { + callingHash := runtime.GetCallingScriptHash() + if !callingHash.Equals(gas.Hash) { panic("only GAS is accepted") } if amount < 10_00000000 { diff --git a/examples/oracle/oracle.go b/examples/oracle/oracle.go index dcaefb614..62e711454 100644 --- a/examples/oracle/oracle.go +++ b/examples/oracle/oracle.go @@ -26,7 +26,8 @@ func FilteredRequest(url string, filter []byte) { func OracleCallback(url string, data interface{}, code int, res []byte) { // This function shouldn't be called directly, we only expect oracle native // contract to be calling it. - if string(runtime.GetCallingScriptHash()) != oracle.Hash { + callingHash := runtime.GetCallingScriptHash() + if !callingHash.Equals(oracle.Hash) { panic("not called from oracle contract") } if code != oracle.Success { diff --git a/examples/token/nep17/nep17.go b/examples/token/nep17/nep17.go index 280384bef..6ee9a474e 100644 --- a/examples/token/nep17/nep17.go +++ b/examples/token/nep17/nep17.go @@ -6,7 +6,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/storage" - "github.com/nspcc-dev/neo-go/pkg/interop/util" ) // Token holds all token info @@ -105,7 +104,7 @@ func IsUsableAddress(addr []byte) bool { // Check if a smart contract is calling scripthash callingScriptHash := runtime.GetCallingScriptHash() - if util.Equals(callingScriptHash, addr) { + if callingScriptHash.Equals(addr) { return true } }