From 44709cf6fe8fc7c83ff220563ca5c897ca5486dd Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 22 May 2020 11:49:36 +0300 Subject: [PATCH] core: make GetUnspentCoins interop return array, fix #978. --- pkg/core/interop_neo.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index 0507764dc..b5bfea395 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/smartcontract" @@ -169,10 +170,20 @@ func txGetUnspentCoins(ic *interop.Context, v *vm.VM) error { return errors.New("value is not a transaction") } ucs, err := ic.DAO.GetUnspentCoinState(tx.Hash()) - if err != nil { + if err == storage.ErrKeyNotFound { + v.Estack().PushVal([]vm.StackItem{}) + return nil + } else if err != nil { return errors.New("no unspent coin state found") } - v.Estack().PushVal(vm.NewInteropItem(ucs)) + + items := make([]vm.StackItem, 0, len(ucs.States)) + for i := range items { + if ucs.States[i].State&state.CoinSpent == 0 { + items = append(items, vm.NewInteropItem(&ucs.States[i].Output)) + } + } + v.Estack().PushVal(items) return nil }