2020-12-25 10:20:09 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
auditAPI "github.com/TrueCloudLab/frostfs-sdk-go/audit"
|
2020-12-25 10:20:09 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
// GetAuditResult returns audit result structure stored in audit contract.
|
|
|
|
func (c *Client) GetAuditResult(id ResultID) (*auditAPI.Result, error) {
|
|
|
|
prm := client.TestInvokePrm{}
|
|
|
|
prm.SetMethod(getResultMethod)
|
|
|
|
prm.SetArgs([]byte(id))
|
2020-12-25 10:20:09 +00:00
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
prms, 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", getResultMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", getResultMethod, ln)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 12:32:51 +00:00
|
|
|
value, err := client.BytesFromStackItem(prms[0])
|
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 get byte array from stack item (%s): %w", getResultMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
var auditRes auditAPI.Result
|
2022-01-31 12:32:51 +00:00
|
|
|
if err := auditRes.Unmarshal(value); err != nil {
|
|
|
|
return nil, fmt.Errorf("could not unmarshal audit result structure: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-11 10:26:22 +00:00
|
|
|
return &auditRes, nil
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|