frostfs-node/pkg/morph/client/reputation/put.go
Evgenii Stratonikov 71b87155ef [#521] *: use stdlib errors package
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-05-19 16:42:54 +03:00

58 lines
1.1 KiB
Go

package reputation
import (
"fmt"
)
// PutArgs groups the arguments of "put reputation value" invocation call.
type PutArgs struct {
epoch uint64
peerID []byte
value []byte
}
// 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 []byte) {
p.peerID = v
}
// SetValue sets marshaled reputation value.
func (p *PutArgs) SetValue(v []byte) {
p.value = v
}
// Put invokes direct call of "put reputation value" method of reputation contract.
func (c *Client) Put(args PutArgs) error {
err := c.client.Invoke(
c.putMethod,
int64(args.epoch),
args.peerID,
args.value,
)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", c.putMethod, err)
}
return nil
}
// PutViaNotary invokes notary call of "put reputation value" method of
// reputation contract.
func (c *Client) PutViaNotary(args PutArgs) error {
err := c.client.NotaryInvoke(
c.putMethod,
int64(args.epoch),
args.peerID,
args.value,
)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", c.putMethod, err)
}
return err
}