2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
"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) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(listMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm.SetArgs(args.ownerID)
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2021-11-09 20:52:29 +00:00
|
|
|
prms, err := c.client.TestInvoke(invokePrm)
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", listMethod, ln)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 11:57:13 +00:00
|
|
|
prms, err = client.ArrayFromStackItem(prms[0])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", listMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := &ListValues{
|
|
|
|
cidList: make([][]byte, 0, len(prms)),
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range prms {
|
2020-08-27 11:57:13 +00:00
|
|
|
cid, err := client.BytesFromStackItem(prms[i])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", listMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res.cidList = append(res.cidList, cid)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|