mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-03-01 19:30:24 +00:00
Merge pull request #979 from nspcc-dev/fix/state
core: make GetUnspentCoins interop return array, fix #978.
This commit is contained in:
commit
3675502927
3 changed files with 28 additions and 10 deletions
|
@ -69,6 +69,7 @@ var syscalls = map[string]map[string]string{
|
||||||
"GetReferences": "Neo.Transaction.GetReferences",
|
"GetReferences": "Neo.Transaction.GetReferences",
|
||||||
"GetScript": "Neo.InvocationTransaction.GetScript",
|
"GetScript": "Neo.InvocationTransaction.GetScript",
|
||||||
"GetType": "Neo.Transaction.GetType",
|
"GetType": "Neo.Transaction.GetType",
|
||||||
|
"GetUnspentCoins": "Neo.Transaction.GetUnspentCoins",
|
||||||
"GetWitnesses": "Neo.Transaction.GetWitnesses",
|
"GetWitnesses": "Neo.Transaction.GetWitnesses",
|
||||||
},
|
},
|
||||||
"asset": {
|
"asset": {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"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/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"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")
|
return errors.New("value is not a transaction")
|
||||||
}
|
}
|
||||||
ucs, err := ic.dao.GetUnspentCoinState(tx.Hash())
|
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")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,12 @@ func GetReferences(t Transaction) []interface{} {
|
||||||
return []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
|
// 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`
|
// package on how to use them. This function uses `Neo.Transaction.GetInputs`
|
||||||
// syscall.
|
// syscall.
|
||||||
|
|
Loading…
Add table
Reference in a new issue