2021-03-31 14:02:02 +00:00
|
|
|
package reputation
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-03-31 14:02:02 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
type (
|
|
|
|
// ID is an ID of the reputation record in reputation contract.
|
|
|
|
ID []byte
|
|
|
|
|
|
|
|
// ListByEpochArgs groups the arguments of
|
|
|
|
// "list reputation ids by epoch" test invoke call.
|
|
|
|
ListByEpochArgs struct {
|
|
|
|
epoch uint64
|
|
|
|
}
|
|
|
|
)
|
2021-03-31 14:02:02 +00:00
|
|
|
|
|
|
|
// SetEpoch sets epoch of expected reputation ids.
|
|
|
|
func (l *ListByEpochArgs) SetEpoch(v uint64) {
|
|
|
|
l.epoch = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListByEpoch invokes the call of "list reputation ids by epoch" method of
|
|
|
|
// reputation contract.
|
2022-01-31 12:19:10 +00:00
|
|
|
func (c *Client) ListByEpoch(p ListByEpochArgs) ([]ID, error) {
|
2021-11-09 20:52:29 +00:00
|
|
|
invokePrm := client.TestInvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
invokePrm.SetMethod(listByEpochMethod)
|
2022-03-11 09:28:34 +00:00
|
|
|
invokePrm.SetArgs(p.epoch)
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
prms, err := c.client.TestInvoke(invokePrm)
|
2021-03-31 14:02:02 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByEpochMethod, err)
|
2021-03-31 14:02:02 +00:00
|
|
|
} else if ln := len(prms); ln != 1 {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", listByEpochMethod, ln)
|
2021-03-31 14:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
items, err := client.ArrayFromStackItem(prms[0])
|
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", listByEpochMethod, err)
|
2021-03-31 14:02:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
result := make([]ID, 0, len(items))
|
2021-03-31 14:02:02 +00:00
|
|
|
for i := range items {
|
|
|
|
rawReputation, err := client.BytesFromStackItem(items[i])
|
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", listByEpochMethod, err)
|
2021-03-31 14:02:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
result = append(result, rawReputation)
|
2021-03-31 14:02:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
return result, nil
|
2021-03-31 14:02:02 +00:00
|
|
|
}
|