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

Delete id from hist_assets and change id to asset_id in claimable_balances and offer #224

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 cmd/export_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var assetsCmd = &cobra.Command{
}

// With seenIDs, the code doesn't export duplicate assets within a single export. Note that across exports, assets may be duplicated
seenIDs := map[uint64]bool{}
seenIDs := map[int64]bool{}
cayod marked this conversation as resolved.
Show resolved Hide resolved
numFailures := 0
totalNumBytes := 0
for _, transformInput := range paymentOps {
Expand Down
20 changes: 1 addition & 19 deletions internal/transform/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package transform

import (
"fmt"
"hash/fnv"

"github.com/dgryski/go-farm"
"github.com/stellar/stellar-etl/internal/toid"
Expand Down Expand Up @@ -52,33 +51,16 @@ func transformSingleAsset(asset xdr.Asset) (AssetOutput, error) {
return AssetOutput{}, fmt.Errorf("could not extract asset from this operation")
}

outputAssetID, err := hashAsset(outputAssetCode, outputAssetIssuer)
if err != nil {
return AssetOutput{}, fmt.Errorf("unable to hash asset for payment operation")
}

farmAssetID := FarmHashAsset(outputAssetCode, outputAssetIssuer, outputAssetType)

return AssetOutput{
AssetCode: outputAssetCode,
AssetIssuer: outputAssetIssuer,
AssetType: outputAssetType,
AssetID: outputAssetID,
ID: farmAssetID,
AssetID: farmAssetID,
}, nil
}

func hashAsset(assetCode, assetIssuer string) (uint64, error) {
asset := fmt.Sprintf("%s:%s", assetCode, assetIssuer)
fnvHasher := fnv.New64a()
if _, err := fnvHasher.Write([]byte(asset)); err != nil {
return 0, err
}

hash := fnvHasher.Sum64()
return hash, nil
}

func FarmHashAsset(assetCode, assetIssuer, assetType string) int64 {
asset := fmt.Sprintf("%s%s%s", assetCode, assetIssuer, assetType)
hash := farm.Fingerprint64([]byte(asset))
Expand Down
7 changes: 2 additions & 5 deletions internal/transform/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,13 @@ func makeAssetTestOutput() (transformedAssets []AssetOutput) {
AssetCode: "USDT",
AssetIssuer: "GBVVRXLMNCJQW3IDDXC3X6XCH35B5Q7QXNMMFPENSOGUPQO7WO7HGZPA",
AssetType: "credit_alphanum4",
AssetID: 1229977787683536144,

ID: -8205667356306085451,
AssetID: -8205667356306085451,
},
{
AssetCode: "",
AssetIssuer: "",
AssetType: "native",
AssetID: 12638146518625398189,
ID: -5706705804583548011,
AssetID: -5706705804583548011,
},
}
return
Expand Down
2 changes: 1 addition & 1 deletion internal/transform/claimable_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TransformClaimableBalance(ledgerChange ingest.Change, header xdr.LedgerHead
AssetCode: outputAsset.AssetCode,
AssetIssuer: outputAsset.AssetIssuer,
AssetType: outputAsset.AssetType,
AssetID: outputAsset.ID,
AssetID: outputAsset.AssetID,
Claimants: outputClaimants,
AssetAmount: float64(outputAmount) / 1.0e7,
Sponsor: ledgerEntrySponsorToNullString(ledgerEntry),
Expand Down
4 changes: 2 additions & 2 deletions internal/transform/offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func TransformOffer(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEn
SellingAssetType: outputSellingAsset.AssetType,
SellingAssetCode: outputSellingAsset.AssetCode,
SellingAssetIssuer: outputSellingAsset.AssetIssuer,
SellingAssetID: outputSellingAsset.ID,
SellingAssetID: outputSellingAsset.AssetID,
BuyingAssetType: outputBuyingAsset.AssetType,
BuyingAssetCode: outputBuyingAsset.AssetCode,
BuyingAssetIssuer: outputBuyingAsset.AssetIssuer,
BuyingAssetID: outputBuyingAsset.ID,
BuyingAssetID: outputBuyingAsset.AssetID,
Amount: utils.ConvertStroopValueToReal(outputAmount),
PriceN: outputPriceN,
PriceD: outputPriceD,
Expand Down
3 changes: 1 addition & 2 deletions internal/transform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ type AssetOutput struct {
AssetCode string `json:"asset_code"`
AssetIssuer string `json:"asset_issuer"`
AssetType string `json:"asset_type"`
AssetID uint64 `json:"id"`
ID int64 `json:"asset_id"`
AssetID int64 `json:"asset_id"`
}

// TrustlineOutput is a representation of a trustline that aligns with the BigQuery table trust_lines
Expand Down
Loading