Skip to content

Commit

Permalink
Merge pull request #60 from attestantio/grpc-tidy
Browse files Browse the repository at this point in the history
Tidy up GRPC usage.
  • Loading branch information
mcdee authored Apr 2, 2024
2 parents b4472c1 + cc218a5 commit 37678e3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions services/api/grpc/handlers/receiver/abort.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 Attestant Limited.
// Copyright © 2020, 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -17,13 +17,13 @@ import (
context "context"

"github.com/attestantio/dirk/services/api/grpc/interceptors"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
pb "github.com/wealdtech/eth2-signer-api/pb/v1"
"google.golang.org/protobuf/types/known/emptypb"
)

// Abort handles the Abort() grpc call.
func (h *Handler) Abort(ctx context.Context, req *pb.AbortRequest) (*empty.Empty, error) {
func (h *Handler) Abort(ctx context.Context, req *pb.AbortRequest) (*emptypb.Empty, error) {
senderID := h.senderID(ctx)
if senderID == 0 {
log.Warn().Interface("client", ctx.Value(&interceptors.ClientName{})).Msg("Failed to obtain participant ID of sender")
Expand All @@ -37,5 +37,5 @@ func (h *Handler) Abort(ctx context.Context, req *pb.AbortRequest) (*empty.Empty
}

log.Trace().Msg("Completed abort successfully")
return &empty.Empty{}, nil
return &emptypb.Empty{}, nil
}
8 changes: 4 additions & 4 deletions services/api/grpc/handlers/receiver/execute.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 Attestant Limited.
// Copyright © 2020, 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -17,13 +17,13 @@ import (
context "context"

"github.com/attestantio/dirk/services/api/grpc/interceptors"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
pb "github.com/wealdtech/eth2-signer-api/pb/v1"
"google.golang.org/protobuf/types/known/emptypb"
)

// Execute handles the Execute() grpc call.
func (h *Handler) Execute(ctx context.Context, req *pb.ExecuteRequest) (*empty.Empty, error) {
func (h *Handler) Execute(ctx context.Context, req *pb.ExecuteRequest) (*emptypb.Empty, error) {
senderID := h.senderID(ctx)
if senderID == 0 {
log.Warn().Interface("client", ctx.Value(&interceptors.ClientName{})).Msg("Failed to obtain participant ID of sender")
Expand All @@ -38,5 +38,5 @@ func (h *Handler) Execute(ctx context.Context, req *pb.ExecuteRequest) (*empty.E
}

log.Trace().Msg("Completed execution successfully")
return &empty.Empty{}, nil
return &emptypb.Empty{}, nil
}
8 changes: 4 additions & 4 deletions services/api/grpc/handlers/receiver/prepare.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 Attestant Limited.
// Copyright © 2020, 2024 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -19,13 +19,13 @@ import (

"github.com/attestantio/dirk/core"
"github.com/attestantio/dirk/services/api/grpc/interceptors"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
pb "github.com/wealdtech/eth2-signer-api/pb/v1"
"google.golang.org/protobuf/types/known/emptypb"
)

// Prepare handles the Prepare() grpc call.
func (h *Handler) Prepare(ctx context.Context, req *pb.PrepareRequest) (*empty.Empty, error) {
func (h *Handler) Prepare(ctx context.Context, req *pb.PrepareRequest) (*emptypb.Empty, error) {
senderID := h.senderID(ctx)
if senderID == 0 {
log.Warn().Interface("client", ctx.Value(&interceptors.ClientName{})).Msg("Failed to obtain participant ID of sender")
Expand All @@ -48,5 +48,5 @@ func (h *Handler) Prepare(ctx context.Context, req *pb.PrepareRequest) (*empty.E
}

log.Trace().Msg("Completed preparation successfully")
return &empty.Empty{}, nil
return &emptypb.Empty{}, nil
}
2 changes: 1 addition & 1 deletion services/api/grpc/interceptors/clientinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ClientName struct{}

// ClientInfoInterceptor adds the client certificate common name to incoming requests.
func ClientInfoInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
grpcPeer, ok := peer.FromContext(ctx)
if !ok {
return nil, status.Error(codes.Internal, "Failure")
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/interceptors/reqid.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RequestID struct{}

// RequestIDInterceptor adds a request ID to incoming requests.
func RequestIDInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
// #nosec G404
newCtx := context.WithValue(ctx, &RequestID{}, fmt.Sprintf("%02x", rand.Int31()))
return handler(newCtx, req)
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/interceptors/sourceip.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ExternalIP struct{}

// SourceIPInterceptor adds the source IP address to incoming requests.
func SourceIPInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
grpcPeer, ok := peer.FromContext(ctx)
if !ok {
return nil, status.Error(codes.Internal, "Failure")
Expand Down
2 changes: 1 addition & 1 deletion services/sender/grpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (s *Service) obtainConnection(_ context.Context, address string) (*puddle.R
s.connectionPoolsMutex.Lock()
pool, exists := s.connectionPools[address]
if !exists {
constructor := func(ctx context.Context) (interface{}, error) {
constructor := func(_ context.Context) (interface{}, error) {
return grpc.Dial(address, []grpc.DialOption{
grpc.WithTransportCredentials(s.credentials),
}...)
Expand Down

0 comments on commit 37678e3

Please sign in to comment.