unified gateway interface

This commit is contained in:
Stephan D
2025-12-31 17:47:32 +01:00
parent 19b7b69bd8
commit 97ba7500dc
104 changed files with 8228 additions and 1742 deletions

View File

@@ -3,6 +3,7 @@ package gateway
import (
"context"
"github.com/tech/sendico/gateway/chain/internal/appversion"
"github.com/tech/sendico/gateway/chain/internal/keymanager"
"github.com/tech/sendico/gateway/chain/internal/service/gateway/commands"
"github.com/tech/sendico/gateway/chain/internal/service/gateway/commands/transfer"
@@ -14,6 +15,7 @@ import (
"github.com/tech/sendico/pkg/api/routers"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
clockpkg "github.com/tech/sendico/pkg/clock"
"github.com/tech/sendico/pkg/discovery"
msg "github.com/tech/sendico/pkg/messaging"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mservice"
@@ -47,6 +49,7 @@ type Service struct {
networkRegistry *rpcclient.Registry
drivers *drivers.Registry
commands commands.Registry
announcers []*discovery.Announcer
chainv1.UnimplementedChainGatewayServiceServer
}
@@ -83,6 +86,7 @@ func NewService(logger mlogger.Logger, repo storage.Repository, producer msg.Pro
Wallet: commandsWalletDeps(svc),
Transfer: commandsTransferDeps(svc),
})
svc.startDiscoveryAnnouncers()
return svc
}
@@ -94,6 +98,17 @@ func (s *Service) Register(router routers.GRPC) error {
})
}
func (s *Service) Shutdown() {
if s == nil {
return
}
for _, announcer := range s.announcers {
if announcer != nil {
announcer.Stop()
}
}
}
func (s *Service) CreateManagedWallet(ctx context.Context, req *chainv1.CreateManagedWalletRequest) (*chainv1.CreateManagedWalletResponse, error) {
return executeUnary(ctx, s, "CreateManagedWallet", s.commands.CreateManagedWallet.Execute, req)
}
@@ -174,3 +189,29 @@ func executeUnary[TReq any, TResp any](ctx context.Context, svc *Service, method
observeRPC(method, err, svc.clock.Now().Sub(start))
return resp, err
}
func (s *Service) startDiscoveryAnnouncers() {
if s == nil || s.producer == nil || len(s.networks) == 0 {
return
}
version := appversion.Create().Short()
for _, network := range s.networks {
currencies := []string{shared.NativeCurrency(network)}
for _, token := range network.TokenConfigs {
if token.Symbol != "" {
currencies = append(currencies, token.Symbol)
}
}
announce := discovery.Announcement{
Service: "CRYPTO_RAIL_GATEWAY",
Rail: "CRYPTO",
Network: network.Name,
Operations: []string{"balance.read", "payin.crypto", "payout.crypto", "fee.send"},
Currencies: currencies,
Version: version,
}
announcer := discovery.NewAnnouncer(s.logger, s.producer, string(mservice.ChainGateway), announce)
announcer.Start()
s.announcers = append(s.announcers, announcer)
}
}