Evgenii Stratonikov
e3487d5af5
All checks were successful
Tests and linters / Run gofumpt (push) Successful in 2m10s
Tests and linters / Staticcheck (push) Successful in 2m52s
Vulncheck / Vulncheck (push) Successful in 2m50s
Build / Build Components (push) Successful in 3m23s
Pre-commit hooks / Pre-commit (push) Successful in 3m33s
Tests and linters / gopls check (push) Successful in 4m8s
Tests and linters / Lint (push) Successful in 4m16s
Tests and linters / Tests (push) Successful in 4m19s
Tests and linters / Tests with -race (push) Successful in 5m1s
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package container
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
|
)
|
|
|
|
// list returns a list of container identifiers belonging
|
|
// to the specified user of FrostFS system. The list is composed
|
|
// through Container contract call.
|
|
//
|
|
// Returns the identifiers of all FrostFS containers if pointer
|
|
// to user identifier is nil.
|
|
func (c *Client) list(idUser *user.ID) ([]cid.ID, error) {
|
|
var rawID []byte
|
|
|
|
if idUser != nil {
|
|
rawID = idUser.WalletBytes()
|
|
}
|
|
|
|
prm := client.TestInvokePrm{}
|
|
prm.SetMethod(listMethod)
|
|
prm.SetArgs(rawID)
|
|
|
|
res, err := c.client.TestInvoke(prm)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("test invoke (%s): %w", listMethod, err)
|
|
} else if ln := len(res); ln != 1 {
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", listMethod, ln)
|
|
}
|
|
|
|
res, err = client.ArrayFromStackItem(res[0])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", listMethod, err)
|
|
}
|
|
|
|
cidList := make([]cid.ID, 0, len(res))
|
|
for i := range res {
|
|
rawID, err := client.BytesFromStackItem(res[i])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", listMethod, err)
|
|
}
|
|
|
|
var id cid.ID
|
|
|
|
err = id.Decode(rawID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("decode container ID: %w", err)
|
|
}
|
|
|
|
cidList = append(cidList, id)
|
|
}
|
|
|
|
return cidList, nil
|
|
}
|