Skip to content

Commit

Permalink
Delete id from asset_id and change id to asset_id in claimable_balanc…
Browse files Browse the repository at this point in the history
…es and offer
  • Loading branch information
cayod committed Feb 16, 2024
1 parent 1ba69a5 commit 232f829
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 30 deletions.
2 changes: 1 addition & 1 deletion cmd/export_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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{}
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,
},
AssetOutput{
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 @@ -206,8 +206,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

0 comments on commit 232f829

Please sign in to comment.