Merge pull request #3222 from nspcc-dev/doc/contracts-storage-seek-call-improvement

doc/Mention prefix trimming in `Seek` operations where applicable
This commit is contained in:
Roman Khimov 2023-11-23 23:03:20 +03:00 committed by GitHub
commit 1f84756c21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View file

@ -2149,7 +2149,7 @@ func (bc *Blockchain) GetStorageItem(id int32, key []byte) state.StorageItem {
return bc.dao.GetStorageItem(id, key)
}
// SeekStorage performs seek operation over contract storage.
// SeekStorage performs seek operation over contract storage. Prefix is trimmed in the resulting pair's key.
func (bc *Blockchain) SeekStorage(id int32, prefix []byte, cont func(k, v []byte) bool) {
bc.dao.Seek(id, storage.SeekRange{Prefix: prefix}, cont)
}

View file

@ -380,7 +380,8 @@ func (dao *Simple) DeleteStorageItem(id int32, key []byte) {
// Seek executes f for all storage items matching the given `rng` (matching the given prefix and
// starting from the point specified). If the key or the value is to be used outside of f, they
// may not be copied. Seek continues iterating until false is returned from f.
// may not be copied. Seek continues iterating until false is returned from f. A requested prefix
// (if any non-empty) is trimmed before passing to f.
func (dao *Simple) Seek(id int32, rng storage.SeekRange, f func(k, v []byte) bool) {
rng.Prefix = slice.Copy(dao.makeStorageItemKey(id, rng.Prefix)) // f() can use dao too.
dao.Store.Seek(rng, func(k, v []byte) bool {

View file

@ -114,7 +114,7 @@ type (
}
// ContractStorageSeeker is the interface `findstorage*` handlers need to be able to
// seek over contract storage.
// seek over contract storage. Prefix is trimmed in the resulting pair's key.
ContractStorageSeeker interface {
SeekStorage(id int32, prefix []byte, cont func(k, v []byte) bool)
}