2020-12-21 13:47:02 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2022-05-12 16:37:46 +00:00
|
|
|
"crypto/sha256"
|
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"
|
2022-01-31 12:32:51 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2020-12-21 13:47:02 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
// ListAllAuditResultID returns a list of all audit result IDs inside audit contract.
|
|
|
|
func (c *Client) ListAllAuditResultID() ([]ResultID, 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
|
|
|
}
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
// 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)
|
2022-03-11 09:28:34 +00:00
|
|
|
prm.SetArgs(epoch)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
items, err := c.client.TestInvoke(prm)
|
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
|
|
|
}
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
// ListAuditResultIDByCID returns a list of audit result IDs inside audit
|
|
|
|
// contract for specific epoch number and container ID.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (c *Client) ListAuditResultIDByCID(epoch uint64, cnr cid.ID) ([]ResultID, error) {
|
2022-05-12 16:37:46 +00:00
|
|
|
binCnr := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(binCnr)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
prm := client.TestInvokePrm{}
|
|
|
|
prm.SetMethod(listByCIDResultsMethod)
|
2022-05-12 16:37:46 +00:00
|
|
|
prm.SetArgs(epoch, binCnr)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
items, err := c.client.TestInvoke(prm)
|
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
|
|
|
}
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
// ListAuditResultIDByNode returns a list of audit result IDs inside audit
|
|
|
|
// contract for specific epoch number, container ID and inner ring public key.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (c *Client) ListAuditResultIDByNode(epoch uint64, cnr cid.ID, nodeKey []byte) ([]ResultID, error) {
|
2022-05-12 16:37:46 +00:00
|
|
|
binCnr := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(binCnr)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
prm := client.TestInvokePrm{}
|
|
|
|
prm.SetMethod(listByNodeResultsMethod)
|
2022-05-12 16:37:46 +00:00
|
|
|
prm.SetArgs(epoch, binCnr, nodeKey)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
items, err := c.client.TestInvoke(prm)
|
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
|
|
|
}
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
func parseAuditResults(items []stackitem.Item, method string) ([]ResultID, error) {
|
2020-12-25 10:20:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
res := make([]ResultID, 0, len(items))
|
2020-12-21 13:47:02 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
res = append(res, rawRes)
|
2020-12-21 13:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|