core: add NEP5 transfer tracking stub

See #498.
This commit is contained in:
Roman Khimov 2019-11-15 17:52:47 +03:00
parent 01082a8988
commit a16c2c3825

View file

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"math" "math"
"math/big"
"sort" "sort"
"sync/atomic" "sync/atomic"
"time" "time"
@ -468,15 +469,39 @@ func (bc *Blockchain) storeBlock(block *Block) error {
case *transaction.InvocationTX: case *transaction.InvocationTX:
systemInterop := newInteropContext(0x10, bc, tmpStore, block, tx) systemInterop := newInteropContext(0x10, bc, tmpStore, block, tx)
vm := bc.spawnVMWithInterops(systemInterop) v := bc.spawnVMWithInterops(systemInterop)
vm.SetCheckedHash(tx.VerificationHash().Bytes()) v.SetCheckedHash(tx.VerificationHash().Bytes())
vm.LoadScript(t.Script) v.LoadScript(t.Script)
err := vm.Run() err := v.Run()
if !vm.HasFailed() { if !v.HasFailed() {
_, err = systemInterop.mem.Persist() _, err = systemInterop.mem.Persist()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to persist invocation results") return errors.Wrap(err, "failed to persist invocation results")
} }
for _, note := range systemInterop.notifications {
arr, ok := note.Item.Value().([]vm.StackItem)
if !ok || len(arr) != 4 {
continue
}
op, ok := arr[0].Value().([]byte)
if !ok || string(op) != "transfer" {
continue
}
from, ok := arr[1].Value().([]byte)
if !ok {
continue
}
to, ok := arr[2].Value().([]byte)
if !ok {
continue
}
amount, ok := arr[3].Value().(*big.Int)
if !ok {
continue
}
// TODO: #498
_, _, _, _ = op, from, to, amount
}
} else { } else {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"tx": tx.Hash().ReverseString(), "tx": tx.Hash().ReverseString(),
@ -487,9 +512,9 @@ func (bc *Blockchain) storeBlock(block *Block) error {
aer := &AppExecResult{ aer := &AppExecResult{
TxHash: tx.Hash(), TxHash: tx.Hash(),
Trigger: 0x10, Trigger: 0x10,
VMState: vm.State(), VMState: v.State(),
GasConsumed: util.Fixed8(0), GasConsumed: util.Fixed8(0),
Stack: vm.Stack("estack"), Stack: v.Stack("estack"),
Events: systemInterop.notifications, Events: systemInterop.notifications,
} }
err = putAppExecResultIntoStore(tmpStore, aer) err = putAppExecResultIntoStore(tmpStore, aer)