2021-03-31 14:02:02 +00:00
|
|
|
package reputation
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2022-01-31 12:19:10 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
2021-03-31 14:02:02 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
type (
|
|
|
|
// PutPrm groups the arguments of "put reputation value" invocation call.
|
|
|
|
PutPrm struct {
|
|
|
|
epoch uint64
|
|
|
|
peerID reputation.PeerID
|
|
|
|
value reputation.GlobalTrust
|
|
|
|
}
|
|
|
|
)
|
2021-03-31 14:02:02 +00:00
|
|
|
|
|
|
|
// SetEpoch sets epoch of reputation value.
|
2022-01-31 12:19:10 +00:00
|
|
|
func (p *PutPrm) SetEpoch(v uint64) {
|
2021-03-31 14:02:02 +00:00
|
|
|
p.epoch = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPeerID sets peer id of reputation value.
|
2022-01-31 12:19:10 +00:00
|
|
|
func (p *PutPrm) SetPeerID(v reputation.PeerID) {
|
2021-03-31 14:02:02 +00:00
|
|
|
p.peerID = v
|
|
|
|
}
|
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
// SetValue sets reputation value.
|
|
|
|
func (p *PutPrm) SetValue(v reputation.GlobalTrust) {
|
2021-03-31 14:02:02 +00:00
|
|
|
p.value = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put invokes direct call of "put reputation value" method of reputation contract.
|
2022-01-31 12:19:10 +00:00
|
|
|
//
|
|
|
|
// If TryNotary is provided, calls notary contract.
|
|
|
|
func (c *Client) Put(p PutPrm) error {
|
|
|
|
data, err := p.value.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't marshal global trust value: %w", err)
|
|
|
|
}
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(putMethod)
|
2022-01-31 12:19:10 +00:00
|
|
|
prm.SetArgs(int64(p.epoch), p.peerID.ToV2().GetPublicKey(), data)
|
2021-05-18 08:12:51 +00:00
|
|
|
|
2022-01-31 12:19:10 +00:00
|
|
|
err = c.client.Invoke(prm)
|
2021-05-18 08:12:51 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", putMethod, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
2021-03-31 14:02:02 +00:00
|
|
|
}
|