forked from TrueCloudLab/frostfs-node
[#452] morph/client: Add reputation contract client
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
ee29ee2c47
commit
9f1a49a562
4 changed files with 337 additions and 0 deletions
62
pkg/morph/client/reputation/list.go
Normal file
62
pkg/morph/client/reputation/list.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
package reputation
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
prms, err := c.client.TestInvoke(
|
||||
c.listByEpochMethod,
|
||||
int64(args.epoch),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listByEpochMethod)
|
||||
} else if ln := len(prms); ln != 1 {
|
||||
return nil, errors.Errorf("unexpected stack item count (%s): %d", c.listByEpochMethod, ln)
|
||||
}
|
||||
|
||||
items, err := client.ArrayFromStackItem(prms[0])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", c.listByEpochMethod)
|
||||
}
|
||||
|
||||
res := &ListByEpochResult{
|
||||
ids: make([][]byte, 0, len(items)),
|
||||
}
|
||||
|
||||
for i := range items {
|
||||
rawReputation, err := client.BytesFromStackItem(items[i])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.listByEpochMethod)
|
||||
}
|
||||
|
||||
res.ids = append(res.ids, rawReputation)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue