fixed rail & operation names
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user