From 208f48ce370e23ab6ac77b6f31335efe6122732a Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Tue, 24 Oct 2023 11:40:42 -0700 Subject: [PATCH] #4909: follow xdr Asset for String serialization of loader AssetKey --- .../internal/db2/history/asset_loader.go | 3 +++ .../internal/db2/history/asset_loader_test.go | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/services/horizon/internal/db2/history/asset_loader.go b/services/horizon/internal/db2/history/asset_loader.go index e54319af12..39703d530f 100644 --- a/services/horizon/internal/db2/history/asset_loader.go +++ b/services/horizon/internal/db2/history/asset_loader.go @@ -23,6 +23,9 @@ type AssetKey struct { } func (key AssetKey) String() string { + if key.Type == xdr.AssetTypeToString[xdr.AssetTypeAssetTypeNative] { + return key.Type + } return key.Type + "/" + key.Code + "/" + key.Issuer } diff --git a/services/horizon/internal/db2/history/asset_loader_test.go b/services/horizon/internal/db2/history/asset_loader_test.go index c7458c7789..d67163d764 100644 --- a/services/horizon/internal/db2/history/asset_loader_test.go +++ b/services/horizon/internal/db2/history/asset_loader_test.go @@ -12,6 +12,28 @@ import ( "github.com/stellar/go/xdr" ) +func TestAssetKeyToString(t *testing.T) { + num4key := AssetKey{ + Type: "credit_alphanum4", + Code: "USD", + Issuer: "A1B2C3", + } + + num12key := AssetKey{ + Type: "credit_alphanum12", + Code: "USDABC", + Issuer: "A1B2C3", + } + + nativekey := AssetKey{ + Type: "native", + } + + assert.Equal(t, num4key.String(), "credit_alphanum4/USD/A1B2C3") + assert.Equal(t, num12key.String(), "credit_alphanum12/USDABC/A1B2C3") + assert.Equal(t, nativekey.String(), "native") +} + func TestAssetLoader(t *testing.T) { tt := test.Start(t) defer tt.Finish()