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) {
|
|
|
|
items, err := c.client.TestInvoke(
|
|
|
|
c.listResultsMethod,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listResultsMethod, err)
|
2020-12-21 13:47:02 +00:00
|
|
|
}
|
|
|
|
|
2020-12-25 10:20:09 +00:00
|
|
|
return parseAuditResults(items, c.listResultsMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
items, err := c.client.TestInvoke(
|
|
|
|
c.listByEpochResultsMethod,
|
|
|
|
args.epoch,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByEpochResultsMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parseAuditResults(items, c.listByEpochResultsMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
items, err := c.client.TestInvoke(
|
|
|
|
c.listByCIDResultsMethod,
|
|
|
|
args.epoch,
|
|
|
|
args.cid,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByCIDResultsMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parseAuditResults(items, c.listByCIDResultsMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
items, err := c.client.TestInvoke(
|
|
|
|
c.listByNodeResultsMethod,
|
|
|
|
args.epoch,
|
|
|
|
args.cid,
|
|
|
|
args.nodeKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByNodeResultsMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parseAuditResults(items, c.listByNodeResultsMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|