2021-07-22 04:26:19 -07:00
|
|
|
package guardiand
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-03 11:03:00 -07:00
|
|
|
"github.com/certusone/wormhole/bridge/pkg/common"
|
2021-07-30 17:25:22 -07:00
|
|
|
"github.com/certusone/wormhole/bridge/pkg/db"
|
2021-07-22 04:26:19 -07:00
|
|
|
publicrpcv1 "github.com/certusone/wormhole/bridge/pkg/proto/publicrpc/v1"
|
|
|
|
"github.com/certusone/wormhole/bridge/pkg/publicrpc"
|
|
|
|
"github.com/certusone/wormhole/bridge/pkg/supervisor"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2021-08-21 13:47:15 -07:00
|
|
|
func publicrpcServiceRunnable(logger *zap.Logger, listenAddr string, db *db.Database, gst *common.GuardianSetState) (supervisor.Runnable, *grpc.Server, error) {
|
2021-07-22 04:26:19 -07:00
|
|
|
l, err := net.Listen("tcp", listenAddr)
|
|
|
|
if err != nil {
|
2021-08-20 15:44:37 -07:00
|
|
|
return nil, nil, fmt.Errorf("failed to listen: %w", err)
|
2021-07-22 04:26:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
logger.Info("publicrpc server listening", zap.String("addr", l.Addr().String()))
|
|
|
|
|
2021-08-21 13:47:15 -07:00
|
|
|
rpcServer := publicrpc.NewPublicrpcServer(logger, db, gst)
|
2021-08-21 02:39:22 -07:00
|
|
|
grpcServer := newGRPCServer(logger)
|
2021-08-21 15:34:58 -07:00
|
|
|
publicrpcv1.RegisterPublicRPCServiceServer(grpcServer, rpcServer)
|
2021-07-22 04:26:19 -07:00
|
|
|
|
2021-08-20 15:44:37 -07:00
|
|
|
return supervisor.GRPCServer(grpcServer, l, false), grpcServer, nil
|
2021-07-22 04:26:19 -07:00
|
|
|
}
|