core: fix NEO balance state handler

We need to store NEO balance's LastUpdateHeight before GAS mint,
because mint can call onNEP17Payment and onNEP17Payment can call NEO
transfer which also calls GAS mint. Storing balance height allows to
avoid recursion.
This commit is contained in:
Anna Shaleva 2021-09-16 17:09:42 +03:00
parent 68af14100c
commit c113d682bd
7 changed files with 82 additions and 4 deletions

View file

@ -3,9 +3,12 @@ package testdata
import (
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
"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"
)
const (
@ -13,6 +16,8 @@ const (
decimals = 2
)
var owner = util.FromAddress("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB")
func Init() bool {
ctx := storage.GetContext()
h := runtime.GetExecutingScriptHash()
@ -22,6 +27,26 @@ func Init() bool {
return true
}
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
curr := runtime.GetExecutingScriptHash()
balance := neo.BalanceOf(curr)
if ledger.CurrentIndex() >= 100 {
ok := neo.Transfer(curr, owner, balance, nil)
if !ok {
panic("owner transfer failed")
}
ok = neo.Transfer(curr, owner, 0, nil)
if !ok {
panic("owner transfer failed")
}
}
}
// Verify always returns true and is aimed to serve the TestNEO_RecursiveGASMint.
func Verify() bool {
return true
}
func Transfer(from, to interop.Hash160, amount int, data interface{}) bool {
ctx := storage.GetContext()
if len(from) != 20 {