2021-03-31 14:59:07 +00:00
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
2021-04-05 09:29:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
2021-03-31 14:59:07 +00:00
|
|
|
reputationClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
2021-04-05 09:29:33 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-03-31 14:59:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// PutArgs groups the arguments of "put reputation value" invocation call.
|
|
|
|
PutArgs struct {
|
|
|
|
epoch uint64
|
|
|
|
peerID reputation.PeerID
|
2021-04-05 09:29:33 +00:00
|
|
|
value reputation.GlobalTrust
|
2021-03-31 14:59:07 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetEpoch sets epoch of reputation value.
|
|
|
|
func (p *PutArgs) SetEpoch(v uint64) {
|
|
|
|
p.epoch = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPeerID sets peer id of reputation value.
|
|
|
|
func (p *PutArgs) SetPeerID(v reputation.PeerID) {
|
|
|
|
p.peerID = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetValue sets reputation value.
|
2021-04-05 09:29:33 +00:00
|
|
|
func (p *PutArgs) SetValue(v reputation.GlobalTrust) {
|
2021-03-31 14:59:07 +00:00
|
|
|
p.value = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put invokes direct call of "put reputation value" method of reputation contract.
|
|
|
|
func (w *ClientWrapper) Put(v PutArgs) error {
|
2021-04-05 09:29:33 +00:00
|
|
|
args, err := preparePutArgs(v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-03-31 14:59:07 +00:00
|
|
|
|
|
|
|
return (*reputationClient.Client)(w).Put(args)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutViaNotary invokes notary call of "put reputation value" method of
|
|
|
|
// reputation contract.
|
|
|
|
func (w *ClientWrapper) PutViaNotary(v PutArgs) error {
|
2021-04-05 09:29:33 +00:00
|
|
|
args, err := preparePutArgs(v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*reputationClient.Client)(w).PutViaNotary(args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func preparePutArgs(v PutArgs) (reputationClient.PutArgs, error) {
|
2021-03-31 14:59:07 +00:00
|
|
|
args := reputationClient.PutArgs{}
|
2021-04-05 09:29:33 +00:00
|
|
|
|
|
|
|
data, err := v.value.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return args, errors.Wrap(err, "can't marshal global trust value")
|
|
|
|
}
|
|
|
|
|
2021-03-31 14:59:07 +00:00
|
|
|
args.SetEpoch(v.epoch)
|
2021-04-05 09:29:33 +00:00
|
|
|
args.SetPeerID(v.peerID.ToV2().GetValue())
|
|
|
|
args.SetValue(data)
|
2021-03-31 14:59:07 +00:00
|
|
|
|
2021-04-05 09:29:33 +00:00
|
|
|
return args, nil
|
2021-03-31 14:59:07 +00:00
|
|
|
}
|