frostfs-node/pkg/morph/client/audit/list_results.go
Evgenii Stratonikov 1e8391d216 [#1141] morph/client: Allow to use more integer types as arguments
Also, use `*big.Int` as integer value, see nspcc-dev/neo-go#2413.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-05-16 15:09:35 +03:00

96 lines
3.1 KiB
Go

package audit
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
)
// ListAllAuditResultID returns a list of all audit result IDs inside audit contract.
func (c *Client) ListAllAuditResultID() ([]ResultID, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(listResultsMethod)
items, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listResultsMethod, err)
}
return parseAuditResults(items, listResultsMethod)
}
// ListAuditResultIDByEpoch returns a list of audit result IDs inside audit
// contract for specific epoch number.
func (c *Client) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, error) {
prm := client.TestInvokePrm{}
prm.SetMethod(listByEpochResultsMethod)
prm.SetArgs(epoch)
items, err := c.client.TestInvoke(prm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByEpochResultsMethod, err)
}
return parseAuditResults(items, listByEpochResultsMethod)
}
// ListAuditResultIDByCID returns a list of audit result IDs inside audit
// contract for specific epoch number and container ID.
func (c *Client) ListAuditResultIDByCID(epoch uint64, cid *cid.ID) ([]ResultID, error) {
v2 := cid.ToV2()
if v2 == nil {
return nil, errUnsupported // use other major version if there any
}
prm := client.TestInvokePrm{}
prm.SetMethod(listByCIDResultsMethod)
prm.SetArgs(epoch, v2.GetValue())
items, err := c.client.TestInvoke(prm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByCIDResultsMethod, err)
}
return parseAuditResults(items, listByCIDResultsMethod)
}
// ListAuditResultIDByNode returns a list of audit result IDs inside audit
// contract for specific epoch number, container ID and inner ring public key.
func (c *Client) ListAuditResultIDByNode(epoch uint64, cid *cid.ID, nodeKey []byte) ([]ResultID, error) {
v2 := cid.ToV2()
if v2 == nil {
return nil, errUnsupported // use other major version if there any
}
prm := client.TestInvokePrm{}
prm.SetMethod(listByNodeResultsMethod)
prm.SetArgs(epoch, v2.GetValue(), nodeKey)
items, err := c.client.TestInvoke(prm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByNodeResultsMethod, err)
}
return parseAuditResults(items, listByNodeResultsMethod)
}
func parseAuditResults(items []stackitem.Item, method string) ([]ResultID, error) {
if ln := len(items); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln)
}
items, err := client.ArrayFromStackItem(items[0])
if err != nil {
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", method, err)
}
res := make([]ResultID, 0, len(items))
for i := range items {
rawRes, err := client.BytesFromStackItem(items[i])
if err != nil {
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", method, err)
}
res = append(res, rawRes)
}
return res, nil
}