2020-12-25 10:20:09 +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/neofs-node/pkg/morph/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetAuditResultArgs groups the arguments
|
|
|
|
// of "get audit result" invocation call.
|
|
|
|
type GetAuditResultArgs struct {
|
|
|
|
id []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAuditResultValue groups the stack parameters
|
|
|
|
// returned by "get audit result" test invoke.
|
|
|
|
type GetAuditResultValue struct {
|
|
|
|
rawResult []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetID sets audit result ID generated by audit contract.
|
|
|
|
func (g *GetAuditResultArgs) SetID(id []byte) {
|
|
|
|
g.id = id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Result returns audit result structure in binary format.
|
|
|
|
func (v *GetAuditResultValue) Result() []byte {
|
|
|
|
return v.rawResult
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAuditResult invokes the call of "get audit result" method
|
|
|
|
// of NeoFS Audit contract.
|
|
|
|
func (c *Client) GetAuditResult(args GetAuditResultArgs) (*GetAuditResultValue, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
|
|
|
|
|
|
|
invokePrm.SetMethod(c.getResultMethod)
|
|
|
|
invokePrm.SetArgs(args.id)
|
|
|
|
|
|
|
|
prms, err := c.client.TestInvoke(invokePrm)
|
2020-12-25 10:20:09 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.getResultMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.getResultMethod, ln)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resultBytes, err := client.BytesFromStackItem(prms[0])
|
|
|
|
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", c.getResultMethod, err)
|
2020-12-25 10:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &GetAuditResultValue{
|
|
|
|
rawResult: resultBytes,
|
|
|
|
}, nil
|
|
|
|
}
|