cached gateway routing

This commit is contained in:
Stephan D
2026-02-20 15:38:22 +01:00
parent bc2bc3770d
commit 671ccc55a0
23 changed files with 777 additions and 23 deletions

View File

@@ -2,11 +2,13 @@ package wallet
import (
"context"
"errors"
"strings"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mservice"
paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
@@ -45,8 +47,15 @@ func (c *listManagedWalletsCommand) Execute(ctx context.Context, req *chainv1.Li
result, err := c.deps.Storage.Wallets().List(ctx, filter)
if err != nil {
c.deps.Logger.Warn("Storage list failed", zap.Error(err))
return gsresponse.Auto[chainv1.ListManagedWalletsResponse](c.deps.Logger, mservice.ChainGateway, err)
if errors.Is(err, merrors.ErrNoData) {
result = &model.ManagedWalletList{}
} else {
c.deps.Logger.Warn("Storage list failed", zap.Error(err))
return gsresponse.Auto[chainv1.ListManagedWalletsResponse](c.deps.Logger, mservice.ChainGateway, err)
}
}
if result == nil {
result = &model.ManagedWalletList{}
}
protoWallets := make([]*chainv1.ManagedWallet, 0, len(result.Items))

View File

@@ -128,6 +128,20 @@ func TestListAccounts_OrganizationRefFilters(t *testing.T) {
require.Equal(t, "org-1", orgField.GetStringValue())
}
func TestListAccounts_NoWalletsNotError(t *testing.T) {
baseRepo := newInMemoryRepository()
svc := newTestServiceWithRepository(t, &walletsNoDataRepository{inMemoryRepository: baseRepo})
ctx := context.Background()
resp, err := svc.ListAccounts(ctx, &connectorv1.ListAccountsRequest{
OrganizationRef: "org-1",
Kind: connectorv1.AccountKind_CHAIN_MANAGED_WALLET,
})
require.NoError(t, err)
require.NotNil(t, resp)
require.Empty(t, resp.GetAccounts())
}
func TestSubmitTransfer_ManagedDestination(t *testing.T) {
svc, repo := newTestService(t)
ctx := context.Background()
@@ -256,6 +270,22 @@ func newInMemoryRepository() *inMemoryRepository {
}
}
type walletsNoDataRepository struct {
*inMemoryRepository
}
func (r *walletsNoDataRepository) Wallets() storage.WalletsStore {
return &walletsNoDataStore{WalletsStore: r.inMemoryRepository.wallets}
}
type walletsNoDataStore struct {
storage.WalletsStore
}
func (w *walletsNoDataStore) List(context.Context, model.ManagedWalletFilter) (*model.ManagedWalletList, error) {
return nil, merrors.NoData("no wallets")
}
func (r *inMemoryRepository) Ping(context.Context) error { return nil }
func (r *inMemoryRepository) Wallets() storage.WalletsStore { return r.wallets }
func (r *inMemoryRepository) Transfers() storage.TransfersStore { return r.transfers }
@@ -628,6 +658,11 @@ func sanitizeLimit(requested int32, def, max int64) int64 {
func newTestService(t *testing.T) (*Service, *inMemoryRepository) {
repo := newInMemoryRepository()
svc := newTestServiceWithRepository(t, repo)
return svc, repo
}
func newTestServiceWithRepository(t *testing.T, repo storage.Repository) *Service {
logger := zap.NewNop()
networks := []shared.Network{{
Name: pmodel.ChainNetworkTronMainnet,
@@ -644,7 +679,7 @@ func newTestService(t *testing.T) (*Service, *inMemoryRepository) {
WithServiceWallet(shared.ServiceWallet{Network: pmodel.ChainNetworkTronMainnet, Address: "TServiceWalletAddress"}),
WithDriverRegistry(driverRegistry),
)
return svc, repo
return svc
}
type fakeKeyManager struct{}