2021-03-24 09:54:19 +00:00
|
|
|
package grpcreputation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/reputation"
|
|
|
|
reputation2 "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
|
|
|
|
reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc"
|
|
|
|
)
|
|
|
|
|
2021-04-02 16:21:05 +00:00
|
|
|
// Server wraps NeoFS API v2 Reputation service server
|
|
|
|
// and provides gRPC Reputation service server interface.
|
2021-03-24 09:54:19 +00:00
|
|
|
type Server struct {
|
|
|
|
srv reputationrpc.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
|
|
|
func New(srv reputationrpc.Server) *Server {
|
|
|
|
return &Server{
|
|
|
|
srv: srv,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
func (s *Server) AnnounceLocalTrust(ctx context.Context, r *reputation2.AnnounceLocalTrustRequest) (*reputation2.AnnounceLocalTrustResponse, error) {
|
|
|
|
req := new(reputation.AnnounceLocalTrustRequest)
|
2021-03-24 09:54:19 +00:00
|
|
|
if err := req.FromGRPCMessage(r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
resp, err := s.srv.AnnounceLocalTrust(ctx, req)
|
2021-03-24 09:54:19 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
return resp.ToGRPCMessage().(*reputation2.AnnounceLocalTrustResponse), nil
|
2021-03-24 09:54:19 +00:00
|
|
|
}
|
2021-04-05 09:27:58 +00:00
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
func (s *Server) AnnounceIntermediateResult(ctx context.Context, r *reputation2.AnnounceIntermediateResultRequest) (*reputation2.AnnounceIntermediateResultResponse, error) {
|
|
|
|
req := new(reputation.AnnounceIntermediateResultRequest)
|
2021-04-05 09:27:58 +00:00
|
|
|
if err := req.FromGRPCMessage(r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
resp, err := s.srv.AnnounceIntermediateResult(ctx, req)
|
2021-04-05 09:27:58 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
return resp.ToGRPCMessage().(*reputation2.AnnounceIntermediateResultResponse), nil
|
2021-04-05 09:27:58 +00:00
|
|
|
}
|