frostfs-node/pkg/morph/client/reputation/wrapper/put.go
Leonard Lyubich d6c0307431 [#627] morph: Inherit internal.StaticClient interface in all wrappers
There is a need to provide contract address getter from all contract client
wrappers.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-09-30 14:47:04 +03:00

59 lines
1.3 KiB
Go

package wrapper
import (
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg/reputation"
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
value reputation.GlobalTrust
}
)
// 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.
func (p *PutArgs) SetValue(v reputation.GlobalTrust) {
p.value = v
}
// Put invokes direct call of "put reputation value" method of reputation contract.
//
// If TryNotary is provided, calls notary contract.
func (w *ClientWrapper) Put(v PutArgs) error {
args, err := preparePutArgs(v)
if err != nil {
return err
}
return w.client.Put(args)
}
func preparePutArgs(v PutArgs) (reputationClient.PutArgs, error) {
args := reputationClient.PutArgs{}
data, err := v.value.Marshal()
if err != nil {
return args, fmt.Errorf("can't marshal global trust value: %w", err)
}
args.SetEpoch(v.epoch)
args.SetPeerID(v.peerID.ToV2().GetPublicKey())
args.SetValue(data)
return args, nil
}