Merge pull request #1542 from nspcc-dev/fix/daoseek

native: decode storage item in `Seek`
This commit is contained in:
Roman Khimov 2020-11-13 18:24:00 +03:00 committed by GitHub
commit ebaa431b4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -336,13 +337,19 @@ func (n *NEO) PostPersist(ic *interop.Context) error {
func (n *NEO) getGASPerVote(d dao.DAO, key []byte, index ...uint32) []big.Int {
var max = make([]uint32, len(index))
var reward = make([]big.Int, len(index))
var si state.StorageItem
d.Seek(n.ContractID, key, func(k, v []byte) {
if len(k) == 4 {
num := binary.BigEndian.Uint32(k)
for i, ind := range index {
if max[i] < num && num <= ind {
max[i] = num
reward[i] = *bigint.FromBytes(v)
r := io.NewBinReaderFromBuf(v)
si.DecodeBinary(r)
if r.Err != nil {
return
}
reward[i] = *bigint.FromBytes(si.Value)
}
}
}