frostfs-node/pkg/morph/client/reputation/list.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

65 lines
1.7 KiB
Go

package reputation
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// ListByEpochArgs groups the arguments of
// "list reputation ids by epoch" test invoke call.
type ListByEpochArgs struct {
epoch uint64
}
// ListByEpochResult groups the stack parameters
// returned by "list reputation ids by epoch" test invoke.
type ListByEpochResult struct {
ids [][]byte
}
// SetEpoch sets epoch of expected reputation ids.
func (l *ListByEpochArgs) SetEpoch(v uint64) {
l.epoch = v
}
// IDs returns slice of reputation id values.
func (l ListByEpochResult) IDs() [][]byte {
return l.ids
}
// ListByEpoch invokes the call of "list reputation ids by epoch" method of
// reputation contract.
func (c *Client) ListByEpoch(args ListByEpochArgs) (*ListByEpochResult, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(listByEpochMethod)
invokePrm.SetArgs(int64(args.epoch))
prms, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByEpochMethod, err)
} else if ln := len(prms); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", listByEpochMethod, ln)
}
items, err := client.ArrayFromStackItem(prms[0])
if err != nil {
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", listByEpochMethod, err)
}
res := &ListByEpochResult{
ids: make([][]byte, 0, len(items)),
}
for i := range items {
rawReputation, err := client.BytesFromStackItem(items[i])
if err != nil {
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", listByEpochMethod, err)
}
res.ids = append(res.ids, rawReputation)
}
return res, nil
}