Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the data type of AssetType in trustline tables #268

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/transform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ type TrustlineOutput struct {
AccountID string `json:"account_id"`
AssetCode string `json:"asset_code"`
AssetIssuer string `json:"asset_issuer"`
AssetType int32 `json:"asset_type"`
AssetType string `json:"asset_type"`
AssetID int64 `json:"asset_id"`
Balance float64 `json:"balance"`
TrustlineLimit int64 `json:"trust_line_limit"`
Expand Down
5 changes: 4 additions & 1 deletion internal/transform/trustline.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ func TransformTrustline(ledgerChange ingest.Change, header xdr.LedgerHeaderHisto
return TrustlineOutput{}, errors.Wrap(err, fmt.Sprintf("could not create ledger key string for trustline with account %s and asset %s", outputAccountID, asset.ToAsset().StringCanonical()))
}

var assetTypeString string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think you don't need to create a new variable and can just reuse assetType because it is already a string variable defined on line 33

In any case this is a non blocking suggestion

if asset.Type == xdr.AssetTypeAssetTypePoolShare {
poolID = PoolIDToString(trustEntry.Asset.MustLiquidityPoolId())
assetTypeString = "pool_share"
} else {
if err = asset.Extract(&assetType, &outputAssetCode, &outputAssetIssuer); err != nil {
return TrustlineOutput{}, errors.Wrap(err, fmt.Sprintf("could not parse asset for trustline with account %s", outputAccountID))
}
assetTypeString = assetType
}

outputAssetID := FarmHashAsset(outputAssetCode, outputAssetIssuer, asset.Type.String())
Expand All @@ -61,7 +64,7 @@ func TransformTrustline(ledgerChange ingest.Change, header xdr.LedgerHeaderHisto
transformedTrustline := TrustlineOutput{
LedgerKey: outputLedgerKey,
AccountID: outputAccountID,
AssetType: int32(asset.Type),
AssetType: assetTypeString,
AssetCode: outputAssetCode,
AssetIssuer: outputAssetIssuer,
AssetID: outputAssetID,
Expand Down
4 changes: 2 additions & 2 deletions internal/transform/trustline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func makeTrustlineTestOutput() []TrustlineOutput {
{
LedgerKey: "AAAAAQAAAACI4aa0pXFSj6qfJuIObLw/5zyugLRGYwxb7wFSr3B9eAAAAAFFVEgAAAAAAGfMAIZMO4kWjGqv4Lw0cJ7QIcUFcuL5iGE0IggsIily",
AccountID: testAccount1Address,
AssetType: 1,
AssetType: "credit_alphanum4",
AssetIssuer: testAccount3Address,
AssetCode: "ETH",
AssetID: -2311386320395871674,
Expand All @@ -146,7 +146,7 @@ func makeTrustlineTestOutput() []TrustlineOutput {
{
LedgerKey: "AAAAAQAAAAAcR0GXGO76pFs4y38vJVAanjnLg4emNun7zAx0pHcDGAAAAAMBAwQFBwkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
AccountID: testAccount2Address,
AssetType: 3,
AssetType: "pool_share",
AssetID: -1967220342708457407,
Balance: 0.5,
TrustlineLimit: 1111111111111111111,
Expand Down
Loading