fixed rail & operation names
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package plan
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
@@ -9,24 +10,24 @@ import (
|
||||
|
||||
func railFromEndpoint(endpoint model.PaymentEndpoint, attrs map[string]string, isSource bool) (model.Rail, string, error) {
|
||||
override := railOverrideFromAttributes(attrs, isSource)
|
||||
if override != model.RailUnspecified {
|
||||
if override != discovery.RailUnspecified {
|
||||
return override, networkFromEndpoint(endpoint), nil
|
||||
}
|
||||
switch endpoint.Type {
|
||||
case model.EndpointTypeLedger:
|
||||
return model.RailLedger, "", nil
|
||||
return discovery.RailLedger, "", nil
|
||||
case model.EndpointTypeManagedWallet, model.EndpointTypeExternalChain:
|
||||
return model.RailCrypto, networkFromEndpoint(endpoint), nil
|
||||
return discovery.RailCrypto, networkFromEndpoint(endpoint), nil
|
||||
case model.EndpointTypeCard:
|
||||
return model.RailCardPayout, "", nil
|
||||
return discovery.RailCardPayout, "", nil
|
||||
default:
|
||||
return model.RailUnspecified, "", merrors.InvalidArgument("plan builder: unsupported payment endpoint")
|
||||
return discovery.RailUnspecified, "", merrors.InvalidArgument("plan builder: unsupported payment endpoint")
|
||||
}
|
||||
}
|
||||
|
||||
func railOverrideFromAttributes(attrs map[string]string, isSource bool) model.Rail {
|
||||
if len(attrs) == 0 {
|
||||
return model.RailUnspecified
|
||||
return discovery.RailUnspecified
|
||||
}
|
||||
keys := []string{"source_rail", "sourceRail"}
|
||||
if !isSource {
|
||||
@@ -41,45 +42,45 @@ func railOverrideFromAttributes(attrs map[string]string, isSource bool) model.Ra
|
||||
continue
|
||||
}
|
||||
rail := parseRailValue(value)
|
||||
if rail != model.RailUnspecified {
|
||||
if rail != discovery.RailUnspecified {
|
||||
return rail
|
||||
}
|
||||
}
|
||||
return model.RailUnspecified
|
||||
return discovery.RailUnspecified
|
||||
}
|
||||
|
||||
func parseRailValue(value string) model.Rail {
|
||||
val := strings.ToUpper(strings.TrimSpace(value))
|
||||
switch val {
|
||||
case string(model.RailCrypto):
|
||||
return model.RailCrypto
|
||||
case string(model.RailProviderSettlement):
|
||||
return model.RailProviderSettlement
|
||||
case string(model.RailLedger):
|
||||
return model.RailLedger
|
||||
case string(model.RailCardPayout):
|
||||
return model.RailCardPayout
|
||||
case string(model.RailFiatOnRamp):
|
||||
return model.RailFiatOnRamp
|
||||
case string(discovery.RailCrypto):
|
||||
return discovery.RailCrypto
|
||||
case string(discovery.RailProviderSettlement):
|
||||
return discovery.RailProviderSettlement
|
||||
case string(discovery.RailLedger):
|
||||
return discovery.RailLedger
|
||||
case string(discovery.RailCardPayout):
|
||||
return discovery.RailCardPayout
|
||||
case string(discovery.RailFiatOnRamp):
|
||||
return discovery.RailFiatOnRamp
|
||||
default:
|
||||
return model.RailUnspecified
|
||||
return discovery.RailUnspecified
|
||||
}
|
||||
}
|
||||
|
||||
func gatewayNetworkForRail(rail model.Rail, sourceRail, destRail model.Rail, sourceNetwork, destNetwork string) string {
|
||||
switch rail {
|
||||
case model.RailCrypto:
|
||||
if sourceRail == model.RailCrypto {
|
||||
case discovery.RailCrypto:
|
||||
if sourceRail == discovery.RailCrypto {
|
||||
return strings.ToUpper(strings.TrimSpace(sourceNetwork))
|
||||
}
|
||||
if destRail == model.RailCrypto {
|
||||
if destRail == discovery.RailCrypto {
|
||||
return strings.ToUpper(strings.TrimSpace(destNetwork))
|
||||
}
|
||||
case model.RailFiatOnRamp:
|
||||
if sourceRail == model.RailFiatOnRamp {
|
||||
case discovery.RailFiatOnRamp:
|
||||
if sourceRail == discovery.RailFiatOnRamp {
|
||||
return strings.ToUpper(strings.TrimSpace(sourceNetwork))
|
||||
}
|
||||
if destRail == model.RailFiatOnRamp {
|
||||
if destRail == discovery.RailFiatOnRamp {
|
||||
return strings.ToUpper(strings.TrimSpace(destNetwork))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package plan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -73,7 +74,7 @@ const (
|
||||
|
||||
func sendDirectionForRail(rail model.Rail) sendDirection {
|
||||
switch rail {
|
||||
case model.RailFiatOnRamp:
|
||||
case discovery.RailFiatOnRamp:
|
||||
return sendDirectionIn
|
||||
default:
|
||||
return sendDirectionOut
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package plan
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"time"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
@@ -15,8 +16,8 @@ func buildFXConversionPlan(payment *model.Payment) (*model.PaymentPlan, error) {
|
||||
}
|
||||
step := &model.PaymentStep{
|
||||
StepID: "fx_convert",
|
||||
Rail: model.RailLedger,
|
||||
Action: model.RailOperationFXConvert,
|
||||
Rail: discovery.RailLedger,
|
||||
Action: discovery.RailOperationFXConvert,
|
||||
ReportVisibility: model.ReportVisibilityUser,
|
||||
CommitPolicy: model.CommitPolicyImmediate,
|
||||
Amount: cloneMoney(payment.Intent.Amount),
|
||||
|
||||
@@ -2,6 +2,7 @@ package gateway_funding_profile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/quotation/internal/shared"
|
||||
@@ -120,7 +121,7 @@ func (r *StaticFundingProfileResolver) ResolveGatewayFundingProfile(
|
||||
strings.TrimSpace(profile.InstanceID),
|
||||
strings.TrimSpace(req.InstanceID),
|
||||
)
|
||||
if profile.Rail == model.RailUnspecified {
|
||||
if profile.Rail == discovery.RailUnspecified {
|
||||
profile.Rail = req.Rail
|
||||
}
|
||||
if strings.TrimSpace(profile.Network) == "" {
|
||||
|
||||
@@ -2,6 +2,7 @@ package quotation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
|
||||
func (s *Service) resolveChainGatewayClient(ctx context.Context, network string, amount *paymenttypes.Money, actions []model.RailOperation, instanceID string, paymentRef string) (chainclient.Client, *model.GatewayInstanceDescriptor, error) {
|
||||
if s.deps.gatewayRegistry != nil && s.deps.gatewayInvokeResolver != nil {
|
||||
entry, err := selectGatewayForActions(ctx, s.deps.gatewayRegistry, model.RailCrypto, network, amount, actions, instanceID, sendDirectionForRail(model.RailCrypto))
|
||||
entry, err := selectGatewayForActions(ctx, s.deps.gatewayRegistry, discovery.RailCrypto, network, amount, actions, instanceID, sendDirectionForRail(discovery.RailCrypto))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -68,7 +69,7 @@ func selectGatewayForActions(ctx context.Context, registry GatewayRegistry, rail
|
||||
return nil, merrors.NoData("no gateway instances available")
|
||||
}
|
||||
if len(actions) == 0 {
|
||||
actions = []model.RailOperation{model.RailOperationSend}
|
||||
actions = []model.RailOperation{discovery.RailOperationSend}
|
||||
}
|
||||
|
||||
currency := ""
|
||||
@@ -104,7 +105,7 @@ func selectGatewayForActions(ctx context.Context, registry GatewayRegistry, rail
|
||||
}
|
||||
|
||||
if len(eligible) == 0 {
|
||||
action := model.RailOperationUnspecified
|
||||
var action model.RailOperation = discovery.RailOperationUnspecified
|
||||
if len(actions) > 0 {
|
||||
action = actions[0]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package graph_path_finder
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -12,7 +13,7 @@ func buildAdjacency(edges []Edge, network string) map[model.Rail][]normalizedEdg
|
||||
for _, edge := range edges {
|
||||
from := normalizeRail(edge.FromRail)
|
||||
to := normalizeRail(edge.ToRail)
|
||||
if from == model.RailUnspecified || to == model.RailUnspecified {
|
||||
if from == discovery.RailUnspecified || to == discovery.RailUnspecified {
|
||||
continue
|
||||
}
|
||||
en := normalizeNetwork(edge.Network)
|
||||
@@ -65,8 +66,8 @@ func networkPriority(edgeNetwork, requested string) int {
|
||||
|
||||
func normalizeRail(value model.Rail) model.Rail {
|
||||
normalized := model.ParseRail(string(value))
|
||||
if normalized == model.RailUnspecified {
|
||||
return model.RailUnspecified
|
||||
if normalized == discovery.RailUnspecified {
|
||||
return discovery.RailUnspecified
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package graph_path_finder
|
||||
|
||||
import "github.com/tech/sendico/payments/storage/model"
|
||||
import (
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
)
|
||||
|
||||
func shortestPath(
|
||||
source model.Rail,
|
||||
@@ -75,7 +78,7 @@ func shortestPath(
|
||||
}
|
||||
|
||||
func nextRail(best map[model.Rail]score, visited map[model.Rail]bool) (model.Rail, bool) {
|
||||
selected := model.RailUnspecified
|
||||
var selected model.Rail = discovery.RailUnspecified
|
||||
selectedScore := score{}
|
||||
found := false
|
||||
for rail, railScore := range best {
|
||||
|
||||
@@ -2,6 +2,7 @@ package graph_path_finder
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
)
|
||||
|
||||
@@ -26,10 +27,10 @@ type score struct {
|
||||
func (f *GraphPathFinder) Find(in FindInput) (*Path, error) {
|
||||
source := normalizeRail(in.SourceRail)
|
||||
destination := normalizeRail(in.DestinationRail)
|
||||
if source == model.RailUnspecified {
|
||||
if source == discovery.RailUnspecified {
|
||||
return nil, merrors.InvalidArgument("source_rail is required")
|
||||
}
|
||||
if destination == model.RailUnspecified {
|
||||
if destination == discovery.RailUnspecified {
|
||||
return nil, merrors.InvalidArgument("destination_rail is required")
|
||||
}
|
||||
if source == destination {
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
package graph_path_finder
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"testing"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
)
|
||||
|
||||
func TestFind_NetworkFiltersEdges(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Network: "TRON",
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger, Network: "ETH"},
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger, Network: "TRON"},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout, Network: "TRON"},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger, Network: "ETH"},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger, Network: "TRON"},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout, Network: "TRON"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -33,14 +32,14 @@ func TestFind_PrefersExactNetworkOverWildcard(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Network: "TRON",
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger, Network: ""},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout, Network: ""},
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailProviderSettlement, Network: "TRON"},
|
||||
{FromRail: model.RailProviderSettlement, ToRail: model.RailCardPayout, Network: "TRON"},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger, Network: ""},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout, Network: ""},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailProviderSettlement, Network: "TRON"},
|
||||
{FromRail: discovery.RailProviderSettlement, ToRail: discovery.RailCardPayout, Network: "TRON"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -54,13 +53,13 @@ func TestFind_DeterministicTieBreak(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout},
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailProviderSettlement},
|
||||
{FromRail: model.RailProviderSettlement, ToRail: model.RailCardPayout},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailProviderSettlement},
|
||||
{FromRail: discovery.RailProviderSettlement, ToRail: discovery.RailCardPayout},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -75,13 +74,13 @@ func TestFind_IgnoresInvalidEdges(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailUnspecified, ToRail: model.RailLedger},
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailUnspecified},
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout},
|
||||
{FromRail: discovery.RailUnspecified, ToRail: discovery.RailLedger},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailUnspecified},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package graph_path_finder
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"testing"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
@@ -12,14 +13,14 @@ func TestFind_ValidatesInput(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
_, err := finder.Find(FindInput{
|
||||
DestinationRail: model.RailCardPayout,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
})
|
||||
if !errors.Is(err, merrors.ErrInvalidArg) {
|
||||
t.Fatalf("expected invalid argument for missing source rail, got %v", err)
|
||||
}
|
||||
|
||||
_, err = finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
})
|
||||
if !errors.Is(err, merrors.ErrInvalidArg) {
|
||||
t.Fatalf("expected invalid argument for missing destination rail, got %v", err)
|
||||
@@ -30,8 +31,8 @@ func TestFind_SourceEqualsDestination(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCrypto,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCrypto,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -51,11 +52,11 @@ func TestFind_FindsIndirectPath(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -72,12 +73,12 @@ func TestFind_PrefersShortestPath(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailCardPayout},
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailCardPayout},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -91,12 +92,12 @@ func TestFind_HandlesCycles(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
path, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCrypto},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCrypto},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -110,10 +111,10 @@ func TestFind_ReturnsErrorWhenPathUnavailable(t *testing.T) {
|
||||
finder := New()
|
||||
|
||||
_, err := finder.Find(FindInput{
|
||||
SourceRail: model.RailCrypto,
|
||||
DestinationRail: model.RailCardPayout,
|
||||
SourceRail: discovery.RailCrypto,
|
||||
DestinationRail: discovery.RailCardPayout,
|
||||
Edges: []Edge{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger},
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, merrors.ErrInvalidArg) {
|
||||
|
||||
@@ -3,10 +3,10 @@ package quotation
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
chainpkg "github.com/tech/sendico/pkg/chain"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
||||
@@ -165,7 +165,7 @@ func (r *managedWalletNetworkResolver) listDiscoveredGatewayCandidates(ctx conte
|
||||
candidates := make([]discoveredGatewayCandidate, 0, len(entries))
|
||||
seenInvokeURI := map[string]struct{}{}
|
||||
for _, entry := range entries {
|
||||
if entry == nil || !entry.IsEnabled || entry.Rail != model.RailCrypto {
|
||||
if entry == nil || !entry.IsEnabled || entry.Rail != discovery.RailCrypto {
|
||||
continue
|
||||
}
|
||||
invokeURI := strings.TrimSpace(entry.InvokeURI)
|
||||
|
||||
@@ -3,6 +3,7 @@ package quotation
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -37,8 +38,8 @@ func TestManagedWalletNetworkResolver_ResolvesAcrossDiscoveredGateways(t *testin
|
||||
resolver := &managedWalletNetworkResolver{
|
||||
gatewayRegistry: fakeGatewayRegistry{
|
||||
items: []*model.GatewayInstanceDescriptor{
|
||||
{ID: "gw-a", Rail: model.RailCrypto, IsEnabled: true, InvokeURI: "gw-a:50053"},
|
||||
{ID: "gw-b", Rail: model.RailCrypto, IsEnabled: true, InvokeURI: "gw-b:50053"},
|
||||
{ID: "gw-a", Rail: discovery.RailCrypto, IsEnabled: true, InvokeURI: "gw-a:50053"},
|
||||
{ID: "gw-b", Rail: discovery.RailCrypto, IsEnabled: true, InvokeURI: "gw-b:50053"},
|
||||
},
|
||||
},
|
||||
gatewayInvokeResolver: invokeResolver,
|
||||
|
||||
@@ -200,7 +200,7 @@ func (r *discoveryGatewayRegistry) List(_ context.Context) ([]*model.GatewayInst
|
||||
items := make([]*model.GatewayInstanceDescriptor, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
railID := railFromDiscovery(entry.Rail)
|
||||
if railID == model.RailUnspecified {
|
||||
if railID == discovery.RailUnspecified {
|
||||
continue
|
||||
}
|
||||
operations := operationsFromDiscovery(entry.Operations)
|
||||
@@ -223,17 +223,17 @@ func (r *discoveryGatewayRegistry) List(_ context.Context) ([]*model.GatewayInst
|
||||
func railFromDiscovery(value string) model.Rail {
|
||||
switch discovery.NormalizeRail(value) {
|
||||
case discovery.RailCrypto:
|
||||
return model.RailCrypto
|
||||
return discovery.RailCrypto
|
||||
case discovery.RailProviderSettlement:
|
||||
return model.RailProviderSettlement
|
||||
return discovery.RailProviderSettlement
|
||||
case discovery.RailLedger:
|
||||
return model.RailLedger
|
||||
return discovery.RailLedger
|
||||
case discovery.RailCardPayout:
|
||||
return model.RailCardPayout
|
||||
return discovery.RailCardPayout
|
||||
case discovery.RailFiatOnRamp:
|
||||
return model.RailFiatOnRamp
|
||||
return discovery.RailFiatOnRamp
|
||||
default:
|
||||
return model.RailUnspecified
|
||||
return discovery.RailUnspecified
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package quotation_service_v2
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -522,7 +523,7 @@ func TestQuotePayment_SelectsEligibleGatewaysAndIgnoresIrrelevant(t *testing.T)
|
||||
{
|
||||
ID: "crypto-disabled",
|
||||
InstanceID: "crypto-disabled",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -533,7 +534,7 @@ func TestQuotePayment_SelectsEligibleGatewaysAndIgnoresIrrelevant(t *testing.T)
|
||||
{
|
||||
ID: "crypto-network-mismatch",
|
||||
InstanceID: "crypto-network-mismatch",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "ETH",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -544,7 +545,7 @@ func TestQuotePayment_SelectsEligibleGatewaysAndIgnoresIrrelevant(t *testing.T)
|
||||
{
|
||||
ID: "crypto-currency-mismatch",
|
||||
InstanceID: "crypto-currency-mismatch",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"EUR"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -555,7 +556,7 @@ func TestQuotePayment_SelectsEligibleGatewaysAndIgnoresIrrelevant(t *testing.T)
|
||||
{
|
||||
ID: "crypto-gw-1",
|
||||
InstanceID: "crypto-gw-1",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -566,7 +567,7 @@ func TestQuotePayment_SelectsEligibleGatewaysAndIgnoresIrrelevant(t *testing.T)
|
||||
{
|
||||
ID: "payout-disabled",
|
||||
InstanceID: "payout-disabled",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -576,7 +577,7 @@ func TestQuotePayment_SelectsEligibleGatewaysAndIgnoresIrrelevant(t *testing.T)
|
||||
{
|
||||
ID: "payout-currency-mismatch",
|
||||
InstanceID: "payout-currency-mismatch",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"EUR"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -586,7 +587,7 @@ func TestQuotePayment_SelectsEligibleGatewaysAndIgnoresIrrelevant(t *testing.T)
|
||||
{
|
||||
ID: "payout-gw-1",
|
||||
InstanceID: "payout-gw-1",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
|
||||
@@ -3,6 +3,7 @@ package quote_computation_service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -58,10 +59,10 @@ func TestBuildPlan_BuildsStepsAndFundingGate(t *testing.T) {
|
||||
if len(item.Steps) != 2 {
|
||||
t.Fatalf("expected 2 steps, got %d", len(item.Steps))
|
||||
}
|
||||
if item.Steps[0].Operation != model.RailOperationMove {
|
||||
if item.Steps[0].Operation != discovery.RailOperationMove {
|
||||
t.Fatalf("expected source operation MOVE, got %q", item.Steps[0].Operation)
|
||||
}
|
||||
if item.Steps[1].Operation != model.RailOperationSend {
|
||||
if item.Steps[1].Operation != discovery.RailOperationSend {
|
||||
t.Fatalf("expected destination operation SEND, got %q", item.Steps[1].Operation)
|
||||
}
|
||||
if item.Funding == nil {
|
||||
@@ -118,7 +119,7 @@ func TestBuildPlan_RequiresFXAddsMiddleStep(t *testing.T) {
|
||||
if len(planModel.Items) != 1 || len(planModel.Items[0].Steps) != 3 {
|
||||
t.Fatalf("expected 3 steps for FX intent")
|
||||
}
|
||||
if got := planModel.Items[0].Steps[1].Operation; got != model.RailOperationFXConvert {
|
||||
if got := planModel.Items[0].Steps[1].Operation; got != discovery.RailOperationFXConvert {
|
||||
t.Fatalf("expected middle step FX_CONVERT, got %q", got)
|
||||
}
|
||||
if planModel.Items[0].Route == nil {
|
||||
@@ -163,8 +164,8 @@ func TestBuildPlan_RequiresFXUsesSettlementCurrencyForDestinationStep(t *testing
|
||||
if got, want := strings.TrimSpace(last.Amount.GetCurrency()), "RUB"; got != want {
|
||||
t.Fatalf("unexpected destination step currency: got=%q want=%q", got, want)
|
||||
}
|
||||
if got, want := last.Operation, model.RailOperationSend; got != want {
|
||||
t.Fatalf("unexpected destination operation: got=%q want=%q", got, want)
|
||||
if got := last.Operation; got != discovery.RailOperationSend {
|
||||
t.Fatalf("unexpected destination operation: got=%q want=%q", got, discovery.RailOperationSend)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,8 +227,8 @@ func TestBuildPlan_UsesSourceAssetCurrencyForSourceStep(t *testing.T) {
|
||||
if got, want := strings.TrimSpace(last.Amount.GetCurrency()), "RUB"; got != want {
|
||||
t.Fatalf("unexpected destination step currency: got=%q want=%q", got, want)
|
||||
}
|
||||
if got, want := steps[1].Operation, model.RailOperationFXConvert; got != want {
|
||||
t.Fatalf("unexpected middle operation: got=%q want=%q", got, want)
|
||||
if got := steps[1].Operation; got != discovery.RailOperationFXConvert {
|
||||
t.Fatalf("unexpected middle operation: got=%q want=%q", got, discovery.RailOperationFXConvert)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +300,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "crypto-disabled",
|
||||
InstanceID: "crypto-disabled",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -310,7 +311,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "crypto-network-mismatch",
|
||||
InstanceID: "crypto-network-mismatch",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "ETH",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -321,7 +322,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "crypto-currency-mismatch",
|
||||
InstanceID: "crypto-currency-mismatch",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"EUR"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -332,7 +333,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "crypto-gw-1",
|
||||
InstanceID: "crypto-gw-1",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -343,7 +344,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "payout-disabled",
|
||||
InstanceID: "payout-disabled",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -353,7 +354,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "payout-currency-mismatch",
|
||||
InstanceID: "payout-currency-mismatch",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"EUR"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -363,7 +364,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "payout-gw-1",
|
||||
InstanceID: "payout-gw-1",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -373,7 +374,7 @@ func TestBuildPlan_SelectsGatewaysAndIgnoresIrrelevant(t *testing.T) {
|
||||
{
|
||||
ID: "provider-ignored",
|
||||
InstanceID: "provider-ignored",
|
||||
Rail: model.RailProviderSettlement,
|
||||
Rail: discovery.RailProviderSettlement,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
IsEnabled: true,
|
||||
|
||||
@@ -2,6 +2,7 @@ package quote_computation_service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -61,7 +62,7 @@ func (s *QuoteComputationService) resolveStepGateways(
|
||||
continue
|
||||
}
|
||||
|
||||
if step.Rail == model.RailLedger {
|
||||
if step.Rail == discovery.RailLedger {
|
||||
step.GatewayID = "internal"
|
||||
step.GatewayInvokeURI = ""
|
||||
|
||||
@@ -201,7 +202,7 @@ func parseDecimalAmount(m *moneyv1.Money) (decimal.Decimal, error) {
|
||||
|
||||
func networkForGatewaySelection(rail model.Rail, routeNetwork string) string {
|
||||
switch rail {
|
||||
case model.RailCrypto, model.RailProviderSettlement, model.RailFiatOnRamp:
|
||||
case discovery.RailCrypto, discovery.RailProviderSettlement, discovery.RailFiatOnRamp:
|
||||
return strings.ToUpper(strings.TrimSpace(routeNetwork))
|
||||
default:
|
||||
return ""
|
||||
|
||||
@@ -2,6 +2,7 @@ package quote_computation_service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"testing"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
@@ -23,7 +24,7 @@ func TestResolveStepGateways_FallsBackToInvokeURI(t *testing.T) {
|
||||
ID: "aaa",
|
||||
InstanceID: "inst-a",
|
||||
InvokeURI: "grpc://gw-a:50051",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -35,7 +36,7 @@ func TestResolveStepGateways_FallsBackToInvokeURI(t *testing.T) {
|
||||
ID: "bbb",
|
||||
InstanceID: "inst-b",
|
||||
InvokeURI: "grpc://gw-b:50051",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -48,8 +49,8 @@ func TestResolveStepGateways_FallsBackToInvokeURI(t *testing.T) {
|
||||
steps := []*QuoteComputationStep{
|
||||
{
|
||||
StepID: "i0.destination",
|
||||
Rail: model.RailCrypto,
|
||||
Operation: model.RailOperationExternalCredit,
|
||||
Rail: discovery.RailCrypto,
|
||||
Operation: discovery.RailOperationExternalCredit,
|
||||
GatewayID: "legacy-id",
|
||||
InstanceID: "legacy-instance",
|
||||
GatewayInvokeURI: "grpc://gw-b:50051",
|
||||
@@ -78,7 +79,7 @@ func TestResolveStepGateways_FallsBackToGatewayIDWhenInstanceChanges(t *testing.
|
||||
ID: "aaa",
|
||||
InstanceID: "inst-a",
|
||||
InvokeURI: "grpc://gw-a:50051",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -90,7 +91,7 @@ func TestResolveStepGateways_FallsBackToGatewayIDWhenInstanceChanges(t *testing.
|
||||
ID: "crypto_rail_gateway_tron",
|
||||
InstanceID: "inst-new",
|
||||
InvokeURI: "grpc://gw-tron:50051",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -103,8 +104,8 @@ func TestResolveStepGateways_FallsBackToGatewayIDWhenInstanceChanges(t *testing.
|
||||
steps := []*QuoteComputationStep{
|
||||
{
|
||||
StepID: "i0.destination",
|
||||
Rail: model.RailCrypto,
|
||||
Operation: model.RailOperationExternalCredit,
|
||||
Rail: discovery.RailCrypto,
|
||||
Operation: discovery.RailOperationExternalCredit,
|
||||
GatewayID: "crypto_rail_gateway_tron",
|
||||
InstanceID: "inst-old",
|
||||
Amount: &moneyv1.Money{Currency: "USDT", Amount: "10"},
|
||||
|
||||
@@ -3,6 +3,7 @@ package quote_computation_service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"testing"
|
||||
|
||||
"github.com/tech/sendico/payments/quotation/internal/service/quotation/transfer_intent_hydrator"
|
||||
@@ -25,7 +26,7 @@ func TestBuildPlan_ResolvesManagedWalletNetworkFromResolver(t *testing.T) {
|
||||
{
|
||||
ID: "crypto-arbitrum",
|
||||
InstanceID: "crypto-arbitrum",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "ARBITRUM_SEPOLIA",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -36,7 +37,7 @@ func TestBuildPlan_ResolvesManagedWalletNetworkFromResolver(t *testing.T) {
|
||||
{
|
||||
ID: "crypto-tron",
|
||||
InstanceID: "crypto-tron",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON_NILE",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -47,7 +48,7 @@ func TestBuildPlan_ResolvesManagedWalletNetworkFromResolver(t *testing.T) {
|
||||
{
|
||||
ID: "card-gw",
|
||||
InstanceID: "card-gw",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -101,7 +102,7 @@ func TestBuildPlan_ManagedWalletNetworkResolverCachesByWalletRef(t *testing.T) {
|
||||
{
|
||||
ID: "crypto-tron",
|
||||
InstanceID: "crypto-tron",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON_NILE",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -112,7 +113,7 @@ func TestBuildPlan_ManagedWalletNetworkResolverCachesByWalletRef(t *testing.T) {
|
||||
{
|
||||
ID: "card-gw",
|
||||
InstanceID: "card-gw",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -167,7 +168,7 @@ func TestBuildPlan_ResolvesManagedWalletAssetTokenForSourceCurrency(t *testing.T
|
||||
{
|
||||
ID: "crypto-tron",
|
||||
InstanceID: "crypto-tron",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON_NILE",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -178,16 +179,16 @@ func TestBuildPlan_ResolvesManagedWalletAssetTokenForSourceCurrency(t *testing.T
|
||||
{
|
||||
ID: "fx-tron",
|
||||
InstanceID: "fx-tron",
|
||||
Rail: model.RailProviderSettlement,
|
||||
Rail: discovery.RailProviderSettlement,
|
||||
Network: "TRON_NILE",
|
||||
Currencies: []string{"USDT", "RUB"},
|
||||
Operations: []model.RailOperation{model.RailOperationFXConvert},
|
||||
Operations: []model.RailOperation{discovery.RailOperationFXConvert},
|
||||
IsEnabled: true,
|
||||
},
|
||||
{
|
||||
ID: "card-gw",
|
||||
InstanceID: "card-gw",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"RUB"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
|
||||
@@ -3,6 +3,7 @@ package quote_computation_service
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/quotation/internal/service/plan"
|
||||
@@ -217,7 +218,7 @@ func (s *QuoteComputationService) buildPlanItem(
|
||||
destinationGatewayFromSteps(steps),
|
||||
gatewayKeyForFunding(modelIntent.Attributes, destination),
|
||||
)
|
||||
if provider == "" && destRail == model.RailLedger {
|
||||
if provider == "" && destRail == discovery.RailLedger {
|
||||
provider = "internal"
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package quote_computation_service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/quotation/internal/service/quotation/graph_path_finder"
|
||||
@@ -25,13 +26,13 @@ func (s *QuoteComputationService) resolveRouteRails(
|
||||
zap.String("network", network),
|
||||
)
|
||||
|
||||
if sourceRail == model.RailUnspecified {
|
||||
if sourceRail == discovery.RailUnspecified {
|
||||
s.logger.Warn("Route rails resolution failed: source rail is unspecified")
|
||||
|
||||
return nil, merrors.InvalidArgument("source rail is required")
|
||||
}
|
||||
|
||||
if destinationRail == model.RailUnspecified {
|
||||
if destinationRail == discovery.RailUnspecified {
|
||||
s.logger.Warn("Route rails resolution failed: destination rail is unspecified")
|
||||
|
||||
return nil, merrors.InvalidArgument("destination rail is required")
|
||||
@@ -185,7 +186,7 @@ func (s *QuoteComputationService) routeGraphEdges(ctx context.Context) ([]graph_
|
||||
from := model.ParseRail(string(route.FromRail))
|
||||
to := model.ParseRail(string(route.ToRail))
|
||||
|
||||
if from == model.RailUnspecified || to == model.RailUnspecified {
|
||||
if from == discovery.RailUnspecified || to == discovery.RailUnspecified {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -210,7 +211,7 @@ func fallbackRouteRails(sourceRail, destinationRail model.Rail) []model.Rail {
|
||||
}
|
||||
|
||||
if requiresTransitBridgeStep(sourceRail, destinationRail) {
|
||||
return []model.Rail{sourceRail, model.RailLedger, destinationRail}
|
||||
return []model.Rail{sourceRail, discovery.RailLedger, destinationRail}
|
||||
}
|
||||
|
||||
return []model.Rail{sourceRail, destinationRail}
|
||||
|
||||
@@ -3,6 +3,7 @@ package quote_computation_service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -15,15 +16,15 @@ import (
|
||||
func TestBuildPlan_UsesRouteGraphPath(t *testing.T) {
|
||||
svc := New(nil,
|
||||
WithRouteStore(staticRouteStore{items: []*model.PaymentRoute{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailProviderSettlement, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: model.RailProviderSettlement, ToRail: model.RailCardPayout, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailProviderSettlement, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: discovery.RailProviderSettlement, ToRail: discovery.RailCardPayout, Network: "TRON", IsEnabled: true},
|
||||
}}),
|
||||
WithGatewayRegistry(staticGatewayRegistry{
|
||||
items: []*model.GatewayInstanceDescriptor{
|
||||
{
|
||||
ID: "crypto-gw",
|
||||
InstanceID: "crypto-gw",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -34,7 +35,7 @@ func TestBuildPlan_UsesRouteGraphPath(t *testing.T) {
|
||||
{
|
||||
ID: "provider-gw",
|
||||
InstanceID: "provider-gw",
|
||||
Rail: model.RailProviderSettlement,
|
||||
Rail: discovery.RailProviderSettlement,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
IsEnabled: true,
|
||||
@@ -42,7 +43,7 @@ func TestBuildPlan_UsesRouteGraphPath(t *testing.T) {
|
||||
{
|
||||
ID: "card-gw",
|
||||
InstanceID: "card-gw",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
@@ -71,7 +72,7 @@ func TestBuildPlan_UsesRouteGraphPath(t *testing.T) {
|
||||
if got, want := len(item.Steps), 3; got != want {
|
||||
t.Fatalf("unexpected step count: got=%d want=%d", got, want)
|
||||
}
|
||||
if got, want := string(item.Steps[1].Rail), string(model.RailProviderSettlement); got != want {
|
||||
if got, want := string(item.Steps[1].Rail), string(discovery.RailProviderSettlement); got != want {
|
||||
t.Fatalf("unexpected transit rail: got=%q want=%q", got, want)
|
||||
}
|
||||
if got := strings.ToUpper(strings.TrimSpace(item.Route.GetHops()[1].GetRail())); got != "SETTLEMENT" {
|
||||
@@ -81,7 +82,7 @@ func TestBuildPlan_UsesRouteGraphPath(t *testing.T) {
|
||||
|
||||
func TestBuildPlan_RouteGraphNoPathReturnsError(t *testing.T) {
|
||||
svc := New(nil, WithRouteStore(staticRouteStore{items: []*model.PaymentRoute{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger, Network: "TRON", IsEnabled: true},
|
||||
}}))
|
||||
|
||||
orgID := bson.NewObjectID()
|
||||
@@ -99,16 +100,16 @@ func TestBuildPlan_RouteGraphNoPathReturnsError(t *testing.T) {
|
||||
func TestBuildPlan_RouteGraphPrefersDirectPath(t *testing.T) {
|
||||
svc := New(nil,
|
||||
WithRouteStore(staticRouteStore{items: []*model.PaymentRoute{
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailCardPayout, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: model.RailCrypto, ToRail: model.RailLedger, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: model.RailLedger, ToRail: model.RailCardPayout, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailCardPayout, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: discovery.RailCrypto, ToRail: discovery.RailLedger, Network: "TRON", IsEnabled: true},
|
||||
{FromRail: discovery.RailLedger, ToRail: discovery.RailCardPayout, Network: "TRON", IsEnabled: true},
|
||||
}}),
|
||||
WithGatewayRegistry(staticGatewayRegistry{
|
||||
items: []*model.GatewayInstanceDescriptor{
|
||||
{
|
||||
ID: "crypto-gw",
|
||||
InstanceID: "crypto-gw",
|
||||
Rail: model.RailCrypto,
|
||||
Rail: discovery.RailCrypto,
|
||||
Network: "TRON",
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
@@ -119,7 +120,7 @@ func TestBuildPlan_RouteGraphPrefersDirectPath(t *testing.T) {
|
||||
{
|
||||
ID: "card-gw",
|
||||
InstanceID: "card-gw",
|
||||
Rail: model.RailCardPayout,
|
||||
Rail: discovery.RailCardPayout,
|
||||
Currencies: []string{"USDT"},
|
||||
Capabilities: model.RailCapabilities{
|
||||
CanPayOut: true,
|
||||
|
||||
@@ -2,6 +2,7 @@ package quote_computation_service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
@@ -56,14 +57,14 @@ func buildComputationSteps(
|
||||
lastStepID := sourceStepID
|
||||
fxAssigned := false
|
||||
if intent.RequiresFX {
|
||||
if len(rails) > 1 && rails[1] == model.RailProviderSettlement {
|
||||
if len(rails) > 1 && rails[1] == discovery.RailProviderSettlement {
|
||||
fxAssigned = true
|
||||
} else {
|
||||
fxStepID := fmt.Sprintf("i%d.fx", index)
|
||||
steps = append(steps, &QuoteComputationStep{
|
||||
StepID: fxStepID,
|
||||
Rail: model.RailProviderSettlement,
|
||||
Operation: model.RailOperationFXConvert,
|
||||
Rail: discovery.RailProviderSettlement,
|
||||
Operation: discovery.RailOperationFXConvert,
|
||||
DependsOn: []string{sourceStepID},
|
||||
Amount: cloneProtoMoney(sourceAmount),
|
||||
Optional: false,
|
||||
@@ -78,14 +79,14 @@ func buildComputationSteps(
|
||||
for i := 1; i < len(rails)-1; i++ {
|
||||
rail := rails[i]
|
||||
stepID := fmt.Sprintf("i%d.transit%d", index, transitIndex)
|
||||
operation := model.RailOperationMove
|
||||
if intent.RequiresFX && !fxAssigned && rail == model.RailProviderSettlement {
|
||||
var operation model.RailOperation = discovery.RailOperationMove
|
||||
if intent.RequiresFX && !fxAssigned && rail == discovery.RailProviderSettlement {
|
||||
stepID = fmt.Sprintf("i%d.fx", index)
|
||||
operation = model.RailOperationFXConvert
|
||||
operation = discovery.RailOperationFXConvert
|
||||
fxAssigned = true
|
||||
}
|
||||
stepAmount := amount
|
||||
if operation == model.RailOperationFXConvert {
|
||||
if operation == discovery.RailOperationFXConvert {
|
||||
stepAmount = sourceAmount
|
||||
}
|
||||
steps = append(steps, &QuoteComputationStep{
|
||||
@@ -120,14 +121,14 @@ func buildComputationSteps(
|
||||
func normalizeRouteRails(sourceRail, destinationRail model.Rail, routeRails []model.Rail) []model.Rail {
|
||||
if len(routeRails) == 0 {
|
||||
if requiresTransitBridgeStep(sourceRail, destinationRail) {
|
||||
return []model.Rail{sourceRail, model.RailLedger, destinationRail}
|
||||
return []model.Rail{sourceRail, discovery.RailLedger, destinationRail}
|
||||
}
|
||||
return []model.Rail{sourceRail, destinationRail}
|
||||
}
|
||||
|
||||
result := make([]model.Rail, 0, len(routeRails))
|
||||
for _, rail := range routeRails {
|
||||
if rail == model.RailUnspecified {
|
||||
if rail == discovery.RailUnspecified {
|
||||
continue
|
||||
}
|
||||
if len(result) > 0 && result[len(result)-1] == rail {
|
||||
@@ -152,13 +153,13 @@ func normalizeRouteRails(sourceRail, destinationRail model.Rail, routeRails []mo
|
||||
}
|
||||
|
||||
func requiresTransitBridgeStep(sourceRail, destinationRail model.Rail) bool {
|
||||
if sourceRail == model.RailUnspecified || destinationRail == model.RailUnspecified {
|
||||
if sourceRail == discovery.RailUnspecified || destinationRail == discovery.RailUnspecified {
|
||||
return false
|
||||
}
|
||||
if sourceRail == destinationRail {
|
||||
return false
|
||||
}
|
||||
if sourceRail == model.RailLedger || destinationRail == model.RailLedger {
|
||||
if sourceRail == discovery.RailLedger || destinationRail == discovery.RailLedger {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -166,42 +167,42 @@ func requiresTransitBridgeStep(sourceRail, destinationRail model.Rail) bool {
|
||||
|
||||
func sourceRailForIntent(intent model.PaymentIntent) model.Rail {
|
||||
if intent.Source.Type == model.EndpointTypeLedger {
|
||||
return model.RailLedger
|
||||
return discovery.RailLedger
|
||||
}
|
||||
if intent.Source.Type == model.EndpointTypeManagedWallet || intent.Source.Type == model.EndpointTypeExternalChain {
|
||||
return model.RailCrypto
|
||||
return discovery.RailCrypto
|
||||
}
|
||||
return model.RailLedger
|
||||
return discovery.RailLedger
|
||||
}
|
||||
|
||||
func destinationRailForIntent(intent model.PaymentIntent) model.Rail {
|
||||
switch intent.Destination.Type {
|
||||
case model.EndpointTypeCard:
|
||||
return model.RailCardPayout
|
||||
return discovery.RailCardPayout
|
||||
case model.EndpointTypeManagedWallet, model.EndpointTypeExternalChain:
|
||||
return model.RailCrypto
|
||||
return discovery.RailCrypto
|
||||
case model.EndpointTypeLedger:
|
||||
return model.RailLedger
|
||||
return discovery.RailLedger
|
||||
default:
|
||||
return model.RailProviderSettlement
|
||||
return discovery.RailProviderSettlement
|
||||
}
|
||||
}
|
||||
|
||||
func sourceOperationForRail(rail model.Rail) model.RailOperation {
|
||||
if rail == model.RailLedger {
|
||||
return model.RailOperationMove
|
||||
if rail == discovery.RailLedger {
|
||||
return discovery.RailOperationMove
|
||||
}
|
||||
return model.RailOperationExternalDebit
|
||||
return discovery.RailOperationExternalDebit
|
||||
}
|
||||
|
||||
func destinationOperationForRail(rail model.Rail) model.RailOperation {
|
||||
switch rail {
|
||||
case model.RailLedger:
|
||||
return model.RailOperationMove
|
||||
case model.RailCardPayout:
|
||||
return model.RailOperationSend
|
||||
case discovery.RailLedger:
|
||||
return discovery.RailOperationMove
|
||||
case discovery.RailCardPayout:
|
||||
return discovery.RailOperationSend
|
||||
default:
|
||||
return model.RailOperationExternalCredit
|
||||
return discovery.RailOperationExternalCredit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package quote_computation_service
|
||||
|
||||
import (
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/payments/storage/model"
|
||||
@@ -60,7 +61,7 @@ func normalizeSettlementParts(src *quotationv2.RouteSettlement) (chain, token, c
|
||||
}
|
||||
|
||||
func normalizeRail(value string) string {
|
||||
if rail := model.ParseRail(value); rail != model.RailUnspecified {
|
||||
if rail := model.ParseRail(value); rail != discovery.RailUnspecified {
|
||||
return string(rail)
|
||||
}
|
||||
return strings.ToUpper(strings.TrimSpace(value))
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -116,7 +117,7 @@ func buildRouteHops(steps []*QuoteComputationStep, fallbackNetwork string) []*qu
|
||||
Network: normalizeNetwork(firstNonEmpty(fallbackNetwork)),
|
||||
Role: roleForHopIndex(i, lastIndex),
|
||||
}
|
||||
if hop.Gateway == "" && hop.Rail == normalizeRail(string(model.RailLedger)) {
|
||||
if hop.Gateway == "" && hop.Rail == normalizeRail(string(discovery.RailLedger)) {
|
||||
hop.Gateway = "internal"
|
||||
}
|
||||
result = append(result, hop)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -427,7 +428,7 @@ func (s *Service) estimateNetworkFee(ctx context.Context, intent *sharedv1.Payme
|
||||
if instanceID == "" {
|
||||
instanceID = strings.TrimSpace(intent.GetDestination().GetInstanceId())
|
||||
}
|
||||
client, _, err := s.resolveChainGatewayClient(ctx, network, moneyFromProto(req.Amount), []model.RailOperation{model.RailOperationSend}, instanceID, "")
|
||||
client, _, err := s.resolveChainGatewayClient(ctx, network, moneyFromProto(req.Amount), []model.RailOperation{discovery.RailOperationSend}, instanceID, "")
|
||||
if err != nil {
|
||||
if errors.Is(err, merrors.ErrNoData) {
|
||||
s.logger.Debug("Network fee estimation skipped: gateway unavailable", zap.Error(err))
|
||||
@@ -519,7 +520,7 @@ func (s *Service) requestFXQuote(ctx context.Context, orgRef string, req *quoteR
|
||||
}
|
||||
|
||||
func feesRequiredForRails(sourceRail, destRail model.Rail) bool {
|
||||
if sourceRail == model.RailLedger && destRail == model.RailLedger {
|
||||
if sourceRail == discovery.RailLedger && destRail == discovery.RailLedger {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user