2021-03-31 14:59:07 +00:00
|
|
|
package wrapper
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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.
|
2021-06-02 16:24:30 +00:00
|
|
|
//
|
|
|
|
// If TryNotary is provided, calls notary contract.
|
2021-03-31 14:59:07 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-05 09:29:33 +00:00
|
|
|
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 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return args, fmt.Errorf("can't marshal global trust value: %w", err)
|
2021-04-05 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:59:07 +00:00
|
|
|
args.SetEpoch(v.epoch)
|
2021-05-07 11:13:11 +00:00
|
|
|
args.SetPeerID(v.peerID.ToV2().GetPublicKey())
|
2021-04-05 09:29:33 +00:00
|
|
|
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
|
|
|
}
|