diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index a507db63f..aa452bf86 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1147,7 +1147,7 @@ func (bc *Blockchain) GetStorageItem(scripthash util.Uint160, key []byte) *state // GetStorageItems returns all storage items for a given scripthash. func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error) { - siMap, err := bc.dao.GetStorageItems(hash) + siMap, err := bc.dao.GetStorageItems(hash, nil) if err != nil { return nil, err } diff --git a/pkg/core/dao/cacheddao.go b/pkg/core/dao/cacheddao.go index f35627712..39e65cc22 100644 --- a/pkg/core/dao/cacheddao.go +++ b/pkg/core/dao/cacheddao.go @@ -321,7 +321,7 @@ type StorageIteratorFunc func() ([]byte, []byte, error) // GetStorageItemsIterator returns iterator over all storage items. // Function returned can be called until first error. func (cd *Cached) GetStorageItemsIterator(hash util.Uint160, prefix []byte) (StorageIteratorFunc, error) { - items, err := cd.DAO.GetStorageItems(hash) + items, err := cd.DAO.GetStorageItems(hash, prefix) if err != nil { return nil, err } @@ -352,7 +352,7 @@ func (cd *Cached) GetStorageItemsIterator(hash util.Uint160, prefix []byte) (Sto index++ for ; index < len(items); index++ { _, ok := cache[string(items[index].Key)] - if !ok && bytes.HasPrefix(items[index].Key, prefix) { + if !ok { return items[index].Key, items[index].Value, nil } } @@ -362,8 +362,8 @@ func (cd *Cached) GetStorageItemsIterator(hash util.Uint160, prefix []byte) (Sto } // GetStorageItems returns all storage items for a given scripthash. -func (cd *Cached) GetStorageItems(hash util.Uint160) ([]StorageItemWithKey, error) { - items, err := cd.DAO.GetStorageItems(hash) +func (cd *Cached) GetStorageItems(hash util.Uint160, prefix []byte) ([]StorageItemWithKey, error) { + items, err := cd.DAO.GetStorageItems(hash, prefix) if err != nil { return nil, err } diff --git a/pkg/core/dao/dao.go b/pkg/core/dao/dao.go index 41a892058..7126969ac 100644 --- a/pkg/core/dao/dao.go +++ b/pkg/core/dao/dao.go @@ -35,7 +35,7 @@ type DAO interface { GetNEP5Balances(acc util.Uint160) (*state.NEP5Balances, error) GetNEP5TransferLog(acc util.Uint160, index uint32) (*state.NEP5TransferLog, error) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem - GetStorageItems(hash util.Uint160) ([]StorageItemWithKey, error) + GetStorageItems(hash util.Uint160, prefix []byte) ([]StorageItemWithKey, error) GetTransaction(hash util.Uint256) (*transaction.Transaction, uint32, error) GetUnspentCoinState(hash util.Uint256) (*state.UnspentCoin, error) GetValidatorState(publicKey *keys.PublicKey) (*state.Validator, error) @@ -442,7 +442,7 @@ type StorageItemWithKey struct { } // GetStorageItems returns all storage items for a given scripthash. -func (dao *Simple) GetStorageItems(hash util.Uint160) ([]StorageItemWithKey, error) { +func (dao *Simple) GetStorageItems(hash util.Uint160, prefix []byte) ([]StorageItemWithKey, error) { var res []StorageItemWithKey var err error @@ -462,7 +462,7 @@ func (dao *Simple) GetStorageItems(hash util.Uint160) ([]StorageItemWithKey, err s.Key = k[21:] res = append(res, s) } - dao.Store.Seek(storage.AppendPrefix(storage.STStorage, hash.BytesLE()), saveToMap) + dao.Store.Seek(makeStorageItemKey(hash, prefix), saveToMap) if err != nil { return nil, err } diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index ccddb26b6..cd3c0d8fd 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -582,7 +582,7 @@ func (ic *interopContext) contractMigrate(v *vm.VM) error { } if contract.HasStorage() { hash := getContextScriptHash(v, 0) - siMap, err := ic.dao.GetStorageItems(hash) + siMap, err := ic.dao.GetStorageItems(hash, nil) if err != nil { return err } diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index bfa669bda..84855717f 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -561,7 +561,7 @@ func (ic *interopContext) contractDestroy(v *vm.VM) error { return err } if cs.HasStorage() { - siMap, err := ic.dao.GetStorageItems(hash) + siMap, err := ic.dao.GetStorageItems(hash, nil) if err != nil { return err }