examples: Use "or" operator in transfer check of NEP5 token

CanTransfer function checks if "to" and "from" values are
correct script hashes. If one of these values is correct and one
incorrect, then function returns false positive result. It uses "and"
operator which requires both "to" and "from" script hashes to be
incorrect to fail transaction.

Instead transaction must fail if at least one argument is incorrect,
so it should be "or" operator.
This commit is contained in:
alexvanin 2020-05-12 16:30:31 +03:00
parent 8e916f5ab8
commit 7f3392680d

View file

@ -58,7 +58,7 @@ func (t Token) Transfer(ctx storage.Context, from []byte, to []byte, amount int)
// CanTransfer returns the amount it can transfer // CanTransfer returns the amount it can transfer
func (t Token) CanTransfer(ctx storage.Context, from []byte, to []byte, amount int) int { func (t Token) CanTransfer(ctx storage.Context, from []byte, to []byte, amount int) int {
if len(to) != 20 && !IsUsableAddress(from) { if len(to) != 20 || !IsUsableAddress(from) {
return -1 return -1
} }