Files
ark/asp/internal/interface/grpc/service.go
Louis Singer 287db4e08a Support round expiration and sweep vtxos (#70)
* sweeper base implementation

* sweeper service final implementation

* fixes

* fix CSV script

* RoundSwept event fix & test

* remove Vtxos after a sweep transaction

* ARK_ROUND_LIFETIME config

* remove TxBuilder.GetLifetime

* refactor sweeper

* use GetTransaction blocktime

* polish and comments

* fix linting

* pair programming fixes

* several fixes

* clean Println

* fixes

* linter fixes

* remove infrastructure deps from application layer

* Fixes

---------

Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
2024-02-08 16:58:04 +01:00

65 lines
1.8 KiB
Go

package grpcservice
import (
"fmt"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
appconfig "github.com/ark-network/ark/internal/app-config"
interfaces "github.com/ark-network/ark/internal/interface"
"github.com/ark-network/ark/internal/interface/grpc/handlers"
"github.com/ark-network/ark/internal/interface/grpc/interceptors"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
type service struct {
config Config
appConfig *appconfig.Config
server *grpc.Server
}
func NewService(
svcConfig Config, appConfig *appconfig.Config,
) (interfaces.Service, error) {
if err := svcConfig.Validate(); err != nil {
return nil, fmt.Errorf("invalid service config: %s", err)
}
if err := appConfig.Validate(); err != nil {
return nil, fmt.Errorf("invalid app config: %s", err)
}
grpcConfig := []grpc.ServerOption{
interceptors.UnaryInterceptor(), interceptors.StreamInterceptor(),
}
if !svcConfig.NoTLS {
return nil, fmt.Errorf("tls termination not supported yet")
}
creds := insecure.NewCredentials()
grpcConfig = append(grpcConfig, grpc.Creds(creds))
server := grpc.NewServer(grpcConfig...)
handler := handlers.NewHandler(appConfig.AppService())
arkv1.RegisterArkServiceServer(server, handler)
return &service{svcConfig, appConfig, server}, nil
}
func (s *service) Start() error {
// nolint:all
go s.server.Serve(s.config.listener())
log.Infof("started listening at %s", s.config.address())
if err := s.appConfig.AppService().Start(); err != nil {
return fmt.Errorf("failed to start app service: %s", err)
}
log.Info("started app service")
return nil
}
func (s *service) Stop() {
s.server.Stop()
log.Info("stopped grpc server")
s.appConfig.AppService().Stop()
log.Info("stopped app service")
}