frostfs-node/pkg/morph/client/audit/get_result.go

52 lines
1.3 KiB
Go
Raw Normal View History

package audit
import (
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/pkg/errors"
)
// 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) {
prms, err := c.client.TestInvoke(
c.getResultMethod,
args.id,
)
if err != nil {
return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.getResultMethod)
} else if ln := len(prms); ln != 1 {
return nil, errors.Errorf("unexpected stack item count (%s): %d", c.getResultMethod, ln)
}
resultBytes, err := client.BytesFromStackItem(prms[0])
if err != nil {
return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.getResultMethod)
}
return &GetAuditResultValue{
rawResult: resultBytes,
}, nil
}