frostfs-node/pkg/morph/client/frostfsid/subject.go
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
[#1535] morph: Unify test invoke error messages
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-12-04 09:50:20 +00:00

73 lines
2.1 KiB
Go

package frostfsid
import (
"fmt"
frostfsidclient "git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
)
const (
methodGetSubject = "getSubject"
methodGetSubjectExtended = "getSubjectExtended"
)
func (c *Client) GetSubject(addr util.Uint160) (*frostfsidclient.Subject, error) {
prm := client.TestInvokePrm{}
prm.SetMethod(methodGetSubject)
prm.SetArgs(addr)
res, err := c.client.TestInvoke(prm)
if err != nil {
return nil, fmt.Errorf("test invoke (%s): %w", methodGetSubject, err)
}
structArr, err := checkStackItem(res)
if err != nil {
return nil, fmt.Errorf("invalid test invocation result (%s): %w", methodGetSubjectExtended, err)
}
subj, err := frostfsidclient.ParseSubject(structArr)
if err != nil {
return nil, fmt.Errorf("could not parse test invocation result (%s): %w", methodGetSubject, err)
}
return subj, nil
}
func (c *Client) GetSubjectExtended(addr util.Uint160) (*frostfsidclient.SubjectExtended, error) {
prm := client.TestInvokePrm{}
prm.SetMethod(methodGetSubjectExtended)
prm.SetArgs(addr)
res, err := c.client.TestInvoke(prm)
if err != nil {
return nil, fmt.Errorf("test invoke (%s): %w", methodGetSubjectExtended, err)
}
structArr, err := checkStackItem(res)
if err != nil {
return nil, fmt.Errorf("invalid test invocation result (%s): %w", methodGetSubjectExtended, err)
}
subj, err := frostfsidclient.ParseSubjectExtended(structArr)
if err != nil {
return nil, fmt.Errorf("could not parse test invocation result (%s): %w", methodGetSubject, err)
}
return subj, nil
}
func checkStackItem(res []stackitem.Item) (structArr []stackitem.Item, err error) {
if ln := len(res); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", methodGetSubject, ln)
}
structArr, err = client.ArrayFromStackItem(res[0])
if err != nil {
return nil, fmt.Errorf("could not get item array of container (%s): %w", methodGetSubject, err)
}
return
}