forked from TrueCloudLab/frostfs-contract
[#64] commonclient: Use partial unwrap in ReadIteratorItems()
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
8c7925d3c0
commit
86e6d4d334
2 changed files with 13 additions and 2 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
// Invoker is a subset of methods provided by struct invoker.Invoker. The subset contains only those
|
// Invoker is a subset of methods provided by struct invoker.Invoker. The subset contains only those
|
||||||
// methods that are used by ActorWrapper and clients of the contracts.
|
// methods that are used by ActorWrapper and clients of the contracts.
|
||||||
type Invoker interface {
|
type Invoker interface {
|
||||||
|
Run([]byte) (*result.Invoke, error)
|
||||||
Call(contract util.Uint160, method string, params ...any) (*result.Invoke, error)
|
Call(contract util.Uint160, method string, params ...any) (*result.Invoke, error)
|
||||||
TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error)
|
TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error)
|
||||||
TerminateSession(sessionID uuid.UUID) error
|
TerminateSession(sessionID uuid.UUID) error
|
||||||
|
|
|
@ -3,7 +3,9 @@ package commonclient
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
)
|
)
|
||||||
|
@ -14,13 +16,21 @@ func ReadIteratorItems(inv Invoker, batchSize int, contract util.Uint160, method
|
||||||
panic("batch size must be positive")
|
panic("batch size must be positive")
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionID, iter, err := unwrap.SessionIterator(inv.Call(contract, method, params...))
|
script, err := smartcontract.CreateCallAndPrefetchIteratorScript(contract, method, batchSize, params...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("couldn't create unwrap script: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
arr, sessionID, iter, err := unwrap.ArrayAndSessionIterator(inv.Run(script))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unwrap session iterator: %w", err)
|
return nil, fmt.Errorf("unwrap session iterator: %w", err)
|
||||||
}
|
}
|
||||||
|
if (sessionID == uuid.UUID{}) {
|
||||||
|
return arr, nil
|
||||||
|
}
|
||||||
|
|
||||||
var shouldStop bool
|
var shouldStop bool
|
||||||
res := make([]stackitem.Item, 0, len(iter.Values))
|
res := arr
|
||||||
for !shouldStop {
|
for !shouldStop {
|
||||||
items, err := inv.TraverseIterator(sessionID, &iter, batchSize)
|
items, err := inv.TraverseIterator(sessionID, &iter, batchSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue