examples: use interop equality helpers where possible
This commit is contained in:
parent
c0186f8224
commit
079f68a8c3
5 changed files with 11 additions and 10 deletions
|
@ -203,7 +203,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool {
|
||||||
key := mkBalanceKey(owner, token)
|
key := mkBalanceKey(owner, token)
|
||||||
amount := getBalanceOf(ctx, key)
|
amount := getBalanceOf(ctx, key)
|
||||||
|
|
||||||
if string(owner) != string(to) {
|
if !owner.Equals(to) {
|
||||||
addToBalance(ctx, owner, token, -amount)
|
addToBalance(ctx, owner, token, -amount)
|
||||||
removeOwner(ctx, token, owner)
|
removeOwner(ctx, token, owner)
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ func TransferDivisible(from, to interop.Hash160, amount int, token []byte, data
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(from) != string(to) {
|
if !from.Equals(to) {
|
||||||
updBalance := addToBalance(ctx, from, token, -amount)
|
updBalance := addToBalance(ctx, from, token, -amount)
|
||||||
if updBalance == 0 {
|
if updBalance == 0 {
|
||||||
removeOwner(ctx, token, from)
|
removeOwner(ctx, token, from)
|
||||||
|
@ -357,7 +357,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
||||||
util.Abort()
|
util.Abort()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if string(runtime.GetCallingScriptHash()) != gas.Hash {
|
callingHash := runtime.GetCallingScriptHash()
|
||||||
|
if !callingHash.Equals(gas.Hash) {
|
||||||
panic("only GAS is accepted")
|
panic("only GAS is accepted")
|
||||||
}
|
}
|
||||||
if amount < 10_00000000 {
|
if amount < 10_00000000 {
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
"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/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Prefixes used for contract data storage.
|
// Prefixes used for contract data storage.
|
||||||
|
@ -164,7 +163,7 @@ func Transfer(to interop.Hash160, tokenID []byte, data interface{}) bool {
|
||||||
if !runtime.CheckWitness(from) {
|
if !runtime.CheckWitness(from) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !util.Equals(from, to) {
|
if !from.Equals(to) {
|
||||||
// update token info
|
// update token info
|
||||||
ns.Owner = to
|
ns.Owner = to
|
||||||
ns.Admin = nil
|
ns.Admin = nil
|
||||||
|
|
|
@ -186,7 +186,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(owner) != string(to) {
|
if !owner.Equals(to) {
|
||||||
addToBalance(ctx, owner, -1)
|
addToBalance(ctx, owner, -1)
|
||||||
removeToken(ctx, owner, token)
|
removeToken(ctx, owner, token)
|
||||||
|
|
||||||
|
@ -216,7 +216,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
||||||
util.Abort()
|
util.Abort()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if string(runtime.GetCallingScriptHash()) != gas.Hash {
|
callingHash := runtime.GetCallingScriptHash()
|
||||||
|
if !callingHash.Equals(gas.Hash) {
|
||||||
panic("only GAS is accepted")
|
panic("only GAS is accepted")
|
||||||
}
|
}
|
||||||
if amount < 10_00000000 {
|
if amount < 10_00000000 {
|
||||||
|
|
|
@ -26,7 +26,8 @@ func FilteredRequest(url string, filter []byte) {
|
||||||
func OracleCallback(url string, data interface{}, code int, res []byte) {
|
func OracleCallback(url string, data interface{}, code int, res []byte) {
|
||||||
// This function shouldn't be called directly, we only expect oracle native
|
// This function shouldn't be called directly, we only expect oracle native
|
||||||
// contract to be calling it.
|
// 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")
|
panic("not called from oracle contract")
|
||||||
}
|
}
|
||||||
if code != oracle.Success {
|
if code != oracle.Success {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
"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/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Token holds all token info
|
// Token holds all token info
|
||||||
|
@ -105,7 +104,7 @@ func IsUsableAddress(addr []byte) bool {
|
||||||
|
|
||||||
// Check if a smart contract is calling scripthash
|
// Check if a smart contract is calling scripthash
|
||||||
callingScriptHash := runtime.GetCallingScriptHash()
|
callingScriptHash := runtime.GetCallingScriptHash()
|
||||||
if util.Equals(callingScriptHash, addr) {
|
if callingScriptHash.Equals(addr) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue