2020-12-21 13:47:02 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-12-25 10:20:09 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-12-21 13:47:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ListResultsArgs groups the arguments
|
2020-12-25 10:20:09 +00:00
|
|
|
// of "list all audit result IDs" test invoke call.
|
2020-12-21 13:47:02 +00:00
|
|
|
type ListResultsArgs struct{}
|
|
|
|
|
2020-12-25 10:20:09 +00:00
|
|
|
// ListResultsByEpochArgs groups the arguments
|
|
|
|
// of "list audit result IDs by epoch" test invoke call.
|
|
|
|
type ListResultsByEpochArgs struct {
|
|
|
|
epoch int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListResultsByCIDArgs groups the arguments
|
|
|
|
// of "list audit result IDs by epoch and CID" test invoke call.
|
|
|
|
type ListResultsByCIDArgs struct {
|
|
|
|
ListResultsByEpochArgs
|
|
|
|
|
|
|
|
cid []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListResultsByNodeArgs groups the arguments
|
|
|
|
// of "list audit result IDs by epoch, CID, and node key" test invoke call.
|
|
|
|
type ListResultsByNodeArgs struct {
|
|
|
|
ListResultsByCIDArgs
|
|
|
|
|
|
|
|
nodeKey []byte
|
|
|
|
}
|
|
|
|
|
2020-12-21 13:47:02 +00:00
|
|
|
// ListResultsValues groups the stack parameters
|
|
|
|
// returned by "list audit results" test invoke.
|
|
|
|
type ListResultsValues struct {
|
|
|
|
rawResults [][]byte // audit results in a binary format
|
|
|
|
}
|
|
|
|
|
2020-12-25 10:20:09 +00:00
|
|
|
// RawResults returns list of audit result IDs
|
2020-12-21 13:47:02 +00:00
|
|
|
// in a binary format.
|
|
|
|
func (v *ListResultsValues) RawResults() [][]byte {
|
|
|
|
return v.rawResults
|
|
|
|
}
|
|
|
|
|
2020-12-25 10:20:09 +00:00
|
|
|
// SetEpoch sets epoch of listing audit results.
|
|
|
|
func (v *ListResultsByEpochArgs) SetEpoch(epoch int64) {
|
|
|
|
v.epoch = epoch
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCID sets container ID of listing audit results.
|
|
|
|
func (v *ListResultsByCIDArgs) SetCID(cid []byte) {
|
|
|
|
v.cid = cid
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNodeKey sets public key of node that produced listing audit results.
|
|
|
|
func (v *ListResultsByNodeArgs) SetNodeKey(key []byte) {
|
|
|
|
v.nodeKey = key
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListAuditResults performs the test invoke of "list all audit result IDs"
|
2020-12-21 13:47:02 +00:00
|
|
|
// method of NeoFS Audit contract.
|
|
|
|
func (c *Client) ListAuditResults(args ListResultsArgs) (*ListResultsValues, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(listResultsMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
items, err := c.client.TestInvoke(invokePrm)
|
2020-12-21 13:47:02 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listResultsMethod, err)
|
2020-12-21 13:47:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
return parseAuditResults(items, listResultsMethod)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListAuditResultsByEpoch performs the test invoke of "list audit result IDs
|
|
|
|
// by epoch" method of NeoFS Audit contract.
|
|
|
|
func (c *Client) ListAuditResultsByEpoch(args ListResultsByEpochArgs) (*ListResultsValues, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(listByEpochResultsMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm.SetArgs(args.epoch)
|
|
|
|
|
|
|
|
items, err := c.client.TestInvoke(invokePrm)
|
2020-12-25 10:20:09 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByEpochResultsMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
return parseAuditResults(items, listByEpochResultsMethod)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListAuditResultsByCID performs the test invoke of "list audit result IDs
|
|
|
|
// by epoch and CID" method of NeoFS Audit contract.
|
|
|
|
func (c *Client) ListAuditResultsByCID(args ListResultsByCIDArgs) (*ListResultsValues, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(listByCIDResultsMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm.SetArgs(args.epoch, args.cid)
|
|
|
|
|
|
|
|
items, err := c.client.TestInvoke(invokePrm)
|
2020-12-25 10:20:09 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByCIDResultsMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
return parseAuditResults(items, listByCIDResultsMethod)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListAuditResultsByNode performs the test invoke of "list audit result IDs
|
|
|
|
// by epoch, CID, and node key" method of NeoFS Audit contract.
|
|
|
|
func (c *Client) ListAuditResultsByNode(args ListResultsByNodeArgs) (*ListResultsValues, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(listByNodeResultsMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm.SetArgs(args.epoch, args.cid, args.nodeKey)
|
|
|
|
|
|
|
|
items, err := c.client.TestInvoke(invokePrm)
|
2020-12-25 10:20:09 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByNodeResultsMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
return parseAuditResults(items, listByNodeResultsMethod)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func parseAuditResults(items []stackitem.Item, method string) (*ListResultsValues, error) {
|
|
|
|
if ln := len(items); ln != 1 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
items, err := client.ArrayFromStackItem(items[0])
|
2020-12-21 13:47:02 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", method, err)
|
2020-12-21 13:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := &ListResultsValues{
|
|
|
|
rawResults: make([][]byte, 0, len(items)),
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range items {
|
|
|
|
rawRes, err := client.BytesFromStackItem(items[i])
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", method, err)
|
2020-12-21 13:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res.rawResults = append(res.rawResults, rawRes)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|