Merge pull request 'fixed address normalizatoin' (#203) from tron-202 into main
All checks were successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/mntx_gateway Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful

Reviewed-on: #203
This commit was merged in pull request #203.
This commit is contained in:
2025-12-26 16:25:01 +00:00
3 changed files with 59 additions and 6 deletions

View File

@@ -58,7 +58,8 @@ func resolveDestination(ctx context.Context, deps Deps, dest *chainv1.TransferDe
return model.TransferDestination{}, err
}
return model.TransferDestination{
ExternalAddress: normalized,
Memo: strings.TrimSpace(dest.GetMemo()),
ExternalAddress: normalized,
ExternalAddressOriginal: external,
Memo: strings.TrimSpace(dest.GetMemo()),
}, nil
}

View File

@@ -28,9 +28,10 @@ type ServiceFee struct {
}
type TransferDestination struct {
ManagedWalletRef string `bson:"managedWalletRef,omitempty" json:"managedWalletRef,omitempty"`
ExternalAddress string `bson:"externalAddress,omitempty" json:"externalAddress,omitempty"`
Memo string `bson:"memo,omitempty" json:"memo,omitempty"`
ManagedWalletRef string `bson:"managedWalletRef,omitempty" json:"managedWalletRef,omitempty"`
ExternalAddress string `bson:"externalAddress,omitempty" json:"externalAddress,omitempty"`
ExternalAddressOriginal string `bson:"externalAddressOriginal,omitempty" json:"externalAddressOriginal,omitempty"`
Memo string `bson:"memo,omitempty" json:"memo,omitempty"`
}
// Transfer models an on-chain transfer orchestrated by the gateway.
@@ -85,7 +86,8 @@ func (t *Transfer) Normalize() {
t.TokenSymbol = strings.TrimSpace(strings.ToUpper(t.TokenSymbol))
t.ContractAddress = strings.TrimSpace(strings.ToLower(t.ContractAddress))
t.Destination.ManagedWalletRef = strings.TrimSpace(t.Destination.ManagedWalletRef)
t.Destination.ExternalAddress = strings.TrimSpace(strings.ToLower(t.Destination.ExternalAddress))
t.Destination.ExternalAddress = normalizeWalletAddress(t.Destination.ExternalAddress)
t.Destination.ExternalAddressOriginal = strings.TrimSpace(t.Destination.ExternalAddressOriginal)
t.Destination.Memo = strings.TrimSpace(t.Destination.Memo)
t.ClientReference = strings.TrimSpace(t.ClientReference)
}

View File

@@ -0,0 +1,50 @@
package model
import (
"strings"
"testing"
)
func TestTransferNormalizePreservesBase58ExternalAddress(t *testing.T) {
address := "TGBDXEg9rxSqGFJDcb889zqTjDwx1bmLRF"
transfer := &Transfer{
IdempotencyKey: "idemp",
TransferRef: "ref",
OrganizationRef: "org",
SourceWalletRef: "wallet",
Network: "tron_mainnet",
TokenSymbol: "USDT",
Destination: TransferDestination{
ExternalAddress: address,
ExternalAddressOriginal: address,
},
}
transfer.Normalize()
if transfer.Destination.ExternalAddress != address {
t.Fatalf("expected external address to preserve case, got %q", transfer.Destination.ExternalAddress)
}
if transfer.Destination.ExternalAddressOriginal != address {
t.Fatalf("expected external address original to preserve case, got %q", transfer.Destination.ExternalAddressOriginal)
}
}
func TestTransferNormalizeLowercasesHexExternalAddress(t *testing.T) {
address := "0xAABBCCDDEEFF00112233445566778899AABBCCDD"
transfer := &Transfer{
Destination: TransferDestination{
ExternalAddress: address,
ExternalAddressOriginal: address,
},
}
transfer.Normalize()
if transfer.Destination.ExternalAddress != strings.ToLower(address) {
t.Fatalf("expected hex external address to be lowercased, got %q", transfer.Destination.ExternalAddress)
}
if transfer.Destination.ExternalAddressOriginal != address {
t.Fatalf("expected external address original to preserve case, got %q", transfer.Destination.ExternalAddressOriginal)
}
}