diff --git a/services/horizon/internal/db2/history/asset_loader.go b/services/horizon/internal/db2/history/asset_loader.go index ca30c671e9..ec29e5560b 100644 --- a/services/horizon/internal/db2/history/asset_loader.go +++ b/services/horizon/internal/db2/history/asset_loader.go @@ -5,6 +5,7 @@ import ( "database/sql/driver" "fmt" "sort" + "strings" sq "github.com/Masterminds/squirrel" @@ -25,7 +26,7 @@ type AssetKey struct { func AssetKeyFromXDR(asset xdr.Asset) AssetKey { return AssetKey{ Type: xdr.AssetTypeToString[asset.Type], - Code: asset.GetCode(), + Code: strings.TrimRight(asset.GetCode(), "\x00"), Issuer: asset.GetIssuer(), } } diff --git a/services/horizon/internal/db2/history/asset_loader_test.go b/services/horizon/internal/db2/history/asset_loader_test.go index 65932abbd3..f28ce6c022 100644 --- a/services/horizon/internal/db2/history/asset_loader_test.go +++ b/services/horizon/internal/db2/history/asset_loader_test.go @@ -22,15 +22,24 @@ func TestAssetLoader(t *testing.T) { for i := 0; i < 100; i++ { var key AssetKey if i == 0 { - key.Type = "native" + key = AssetKeyFromXDR(xdr.Asset{Type: xdr.AssetTypeAssetTypeNative}) } else if i%2 == 0 { - key.Type = "credit_alphanum4" - key.Code = fmt.Sprintf("ab%d", i) - key.Issuer = keypair.MustRandom().Address() + code := [4]byte{0,0,0,0} + copy(code[:], fmt.Sprintf("ab%d", i)) + key = AssetKeyFromXDR(xdr.Asset{ + Type: xdr.AssetTypeAssetTypeCreditAlphanum4, + AlphaNum4: &xdr.AlphaNum4{ + AssetCode: code, + Issuer: xdr.MustAddress(keypair.MustRandom().Address())}}) } else { - key.Type = "credit_alphanum12" - key.Code = fmt.Sprintf("abcdef%d", i) - key.Issuer = keypair.MustRandom().Address() + code := [12]byte{0,0,0,0,0,0,0,0,0,0,0,0} + copy(code[:], fmt.Sprintf("abcdef%d", i)) + key = AssetKeyFromXDR(xdr.Asset{ + Type: xdr.AssetTypeAssetTypeCreditAlphanum12, + AlphaNum12: &xdr.AlphaNum12{ + AssetCode: code, + Issuer: xdr.MustAddress(keypair.MustRandom().Address())}}) + } keys = append(keys, key) }