frostfs-node/pkg/morph/client/container/list.go
Evgenii Stratonikov 3c5b62d839 [#625] morph/client: make method names constant
We don't use custom names and the only place where custom method option
is used it provides the default name and can be omitted.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-02-01 15:47:54 +03:00

67 lines
1.7 KiB
Go

package container
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// ListArgs groups the arguments
// of list containers test invoke call.
type ListArgs struct {
ownerID []byte // container owner identifier
}
// ListValues groups the stack parameters
// returned by list containers test invoke.
type ListValues struct {
cidList [][]byte // list of container identifiers
}
// SetOwnerID sets the container owner identifier
// in a binary format.
func (l *ListArgs) SetOwnerID(v []byte) {
l.ownerID = v
}
// CIDList returns the list of container
// identifiers in a binary format.
func (l *ListValues) CIDList() [][]byte {
return l.cidList
}
// List performs the test invoke of list container
// method of NeoFS Container contract.
func (c *Client) List(args ListArgs) (*ListValues, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(listMethod)
invokePrm.SetArgs(args.ownerID)
prms, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listMethod, err)
} else if ln := len(prms); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", listMethod, ln)
}
prms, err = client.ArrayFromStackItem(prms[0])
if err != nil {
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", listMethod, err)
}
res := &ListValues{
cidList: make([][]byte, 0, len(prms)),
}
for i := range prms {
cid, err := client.BytesFromStackItem(prms[i])
if err != nil {
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", listMethod, err)
}
res.cidList = append(res.cidList, cid)
}
return res, nil
}