frostfs-node/pkg/morph/client/audit/get_result.go
Evgenii Stratonikov 3c5b62d839 [#625] morph/client: make method names constant
We don't use custom names and the only place where custom method option
is used it provides the default name and can be omitted.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-02-01 15:47:54 +03:00

54 lines
1.4 KiB
Go

package audit
import (
"fmt"
"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) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(getResultMethod)
invokePrm.SetArgs(args.id)
prms, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", getResultMethod, err)
} else if ln := len(prms); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", getResultMethod, ln)
}
resultBytes, err := client.BytesFromStackItem(prms[0])
if err != nil {
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", getResultMethod, err)
}
return &GetAuditResultValue{
rawResult: resultBytes,
}, nil
}