From 8ed77f0d25e7fec4b1ee2459945d85ada49bf62d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 22 May 2020 11:49:36 +0300 Subject: [PATCH 1/2] 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 c0156c3a9..20fbcec56 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -7,6 +7,7 @@ import ( "math" "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" @@ -177,10 +178,20 @@ func (ic *interopContext) txGetUnspentCoins(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 } From eeeb05fc2cb7c1d1487252ed0165732f029a4dbf Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 22 May 2020 12:18:03 +0300 Subject: [PATCH 2/2] compiler: restore support for GetUnspentCoins Revert a587274. --- pkg/compiler/syscall.go | 17 +++++++++-------- pkg/interop/transaction/transaction.go | 6 ++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 26307270d..086112040 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -62,14 +62,15 @@ var syscalls = map[string]map[string]string{ "GetTransaction": "Neo.Block.GetTransaction", }, "transaction": { - "GetAttributes": "Neo.Transaction.GetAttributes", - "GetHash": "Neo.Transaction.GetHash", - "GetInputs": "Neo.Transaction.GetInputs", - "GetOutputs": "Neo.Transaction.GetOutputs", - "GetReferences": "Neo.Transaction.GetReferences", - "GetScript": "Neo.InvocationTransaction.GetScript", - "GetType": "Neo.Transaction.GetType", - "GetWitnesses": "Neo.Transaction.GetWitnesses", + "GetAttributes": "Neo.Transaction.GetAttributes", + "GetHash": "Neo.Transaction.GetHash", + "GetInputs": "Neo.Transaction.GetInputs", + "GetOutputs": "Neo.Transaction.GetOutputs", + "GetReferences": "Neo.Transaction.GetReferences", + "GetScript": "Neo.InvocationTransaction.GetScript", + "GetType": "Neo.Transaction.GetType", + "GetUnspentCoins": "Neo.Transaction.GetUnspentCoins", + "GetWitnesses": "Neo.Transaction.GetWitnesses", }, "asset": { "Create": "Neo.Asset.Create", diff --git a/pkg/interop/transaction/transaction.go b/pkg/interop/transaction/transaction.go index 00d06c25e..e354d7baf 100644 --- a/pkg/interop/transaction/transaction.go +++ b/pkg/interop/transaction/transaction.go @@ -53,6 +53,12 @@ func GetReferences(t Transaction) []interface{} { return []interface{}{} } +// GetUnspentCoins returns a slice of not yet spent ouputs of a given transaction. +// This function uses `Neo.Transaction.GetUnspentCoint` syscall. +func GetUnspentCoins(t Transaction) []output.Output { + return []output.Output{} +} + // GetInputs returns a slice of inputs of a given Transaction. Refer to input // package on how to use them. This function uses `Neo.Transaction.GetInputs` // syscall.