mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
core: make GetUnspentCoins interop return array, fix #978.
This commit is contained in:
parent
f8093e415e
commit
44709cf6fe
1 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue