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
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-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 {
|
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(putMethod)
|
2022-07-04 13:24:51 +00:00
|
|
|
prm.SetArgs(p.epoch, p.peerID.PublicKey(), p.value.Marshal())
|
2021-05-18 08:12:51 +00:00
|
|
|
|
2022-07-04 13:24:51 +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
|
|
|
}
|