Skip to content

Commit

Permalink
Merge pull request #200 from stellar/fix-farmhash
Browse files Browse the repository at this point in the history
fixed history_trade and liquidity_pool asset_id field
  • Loading branch information
cayod authored Oct 13, 2023
2 parents 1132c44 + 835d509 commit 32c5434
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions internal/transform/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func transformSingleAsset(asset xdr.Asset) (AssetOutput, error) {
AssetCode: outputAssetCode,
AssetIssuer: outputAssetIssuer,
AssetType: outputAssetType,
AssetID: outputAssetID,
ID: farmAssetID,
AssetID: farmAssetID,
ID: outputAssetID,
}, nil
}

Expand Down
9 changes: 5 additions & 4 deletions internal/transform/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ func makeAssetTestOutput() (transformedAssets []AssetOutput) {
AssetCode: "USDT",
AssetIssuer: "GBVVRXLMNCJQW3IDDXC3X6XCH35B5Q7QXNMMFPENSOGUPQO7WO7HGZPA",
AssetType: "credit_alphanum4",
AssetID: 1229977787683536144,
ID: -8205667356306085451,
AssetID: -8205667356306085451,

ID: 1229977787683536144,
},
AssetOutput{
AssetCode: "",
AssetIssuer: "",
AssetType: "native",
AssetID: 12638146518625398189,
ID: -5706705804583548011,
AssetID: -5706705804583548011,
ID: 12638146518625398189,
},
}
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 @@ -50,7 +50,7 @@ func TransformClaimableBalance(ledgerChange ingest.Change) (ClaimableBalanceOutp
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/liquidity_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func TransformPool(ledgerChange ingest.Change) (PoolOutput, error) {
if err != nil {
return PoolOutput{}, err
}
assetAID := FarmHashAsset(assetAType, assetACode, assetAIssuer)
assetAID := FarmHashAsset(assetACode, assetAIssuer, assetAType)

var assetBType, assetBCode, assetBIssuer string
err = cp.Params.AssetB.Extract(&assetBType, &assetBCode, &assetBIssuer)
assetBID := FarmHashAsset(assetBType, assetBCode, assetBIssuer)
assetBID := FarmHashAsset(assetBCode, assetBIssuer, assetBType)

transformedPool := PoolOutput{
PoolID: PoolIDToString(lp.LiquidityPoolId),
Expand Down
2 changes: 1 addition & 1 deletion internal/transform/liquidity_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func makePoolTestOutput() PoolOutput {
AssetAReserve: 0.0000105,
AssetBType: "credit_alphanum4",
AssetBCode: lpAssetB.GetCode(),
AssetBID: -9138108998176092786,
AssetBID: 6690054458235693884,
AssetBIssuer: lpAssetB.GetIssuer(),
AssetBReserve: 0.0000010,
LastModifiedLedger: 30705278,
Expand Down
4 changes: 2 additions & 2 deletions internal/transform/offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func TransformOffer(ledgerChange ingest.Change) (OfferOutput, error) {
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
4 changes: 2 additions & 2 deletions internal/transform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ 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"`
ID uint64 `json:"id"`
}

// TrustlineOutput is a representation of a trustline that aligns with the BigQuery table trust_lines
Expand Down
4 changes: 2 additions & 2 deletions internal/transform/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TransformTrade(operationIndex int32, operationID int64, transaction ingest.
if err != nil {
return []TradeOutput{}, err
}
outputSellingAssetID := FarmHashAsset(outputSellingAssetType, outputSellingAssetCode, outputSellingAssetIssuer)
outputSellingAssetID := FarmHashAsset(outputSellingAssetCode, outputSellingAssetIssuer, outputSellingAssetType)

outputSellingAmount := claimOffer.AmountSold()
if outputSellingAmount < 0 {
Expand All @@ -58,7 +58,7 @@ func TransformTrade(operationIndex int32, operationID int64, transaction ingest.
if err != nil {
return []TradeOutput{}, err
}
outputBuyingAssetID := FarmHashAsset(outputBuyingAssetType, outputBuyingAssetCode, outputBuyingAssetIssuer)
outputBuyingAssetID := FarmHashAsset(outputBuyingAssetCode, outputBuyingAssetIssuer, outputBuyingAssetType)

outputBuyingAmount := int64(claimOffer.AmountBought())
if outputBuyingAmount < 0 {
Expand Down
14 changes: 7 additions & 7 deletions internal/transform/trade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,13 @@ func makeTradeTestOutput() [][]TradeOutput {
SellingAssetCode: "ETH",
SellingAssetIssuer: testAccount3Address,
SellingAssetType: "credit_alphanum4",
SellingAssetID: 7452978348057887059,
SellingAssetID: 4476940172956910889,
SellingAmount: 13300347 * 0.0000001,
BuyingAccountAddress: testAccount3Address,
BuyingAssetCode: "USDT",
BuyingAssetIssuer: testAccount4Address,
BuyingAssetType: "credit_alphanum4",
BuyingAssetID: 4483110387055733902,
BuyingAssetID: -8205667356306085451,
BuyingAmount: 12634 * 0.0000001,
PriceN: 12634,
PriceD: 13300347,
Expand All @@ -749,7 +749,7 @@ func makeTradeTestOutput() [][]TradeOutput {
SellingAssetCode: "USDT",
SellingAssetIssuer: testAccount4Address,
SellingAssetType: "credit_alphanum4",
SellingAssetID: 4483110387055733902,
SellingAssetID: -8205667356306085451,
SellingAmount: 500 * 0.0000001,
BuyingAccountAddress: testAccount3Address,
BuyingAssetCode: "",
Expand All @@ -771,13 +771,13 @@ func makeTradeTestOutput() [][]TradeOutput {
SellingAssetCode: "WER",
SellingAssetIssuer: testAccount4Address,
SellingAssetType: "credit_alphanum4",
SellingAssetID: -7191734819702017351,
SellingAssetID: -7615773297180926952,
SellingAmount: 123 * 0.0000001,
BuyingAccountAddress: testAccount3Address,
BuyingAssetCode: "NIJ",
BuyingAssetIssuer: testAccount1Address,
BuyingAssetType: "credit_alphanum4",
BuyingAssetID: 4209855448155423050,
BuyingAssetID: -8061435944444096568,
BuyingAmount: 456 * 0.0000001,
PriceN: 456,
PriceD: 123,
Expand All @@ -796,13 +796,13 @@ func makeTradeTestOutput() [][]TradeOutput {
SellingAssetCode: "HAH",
SellingAssetIssuer: testAccount1Address,
SellingAssetType: "credit_alphanum4",
SellingAssetID: 1757348098415471193,
SellingAssetID: -6231594281606355691,
SellingAmount: 1 * 0.0000001,
BuyingAccountAddress: testAccount3Address,
BuyingAssetCode: "WHO",
BuyingAssetIssuer: testAccount4Address,
BuyingAssetType: "credit_alphanum4",
BuyingAssetID: -1343268855198636280,
BuyingAssetID: -680582465233747022,
BuyingAmount: 1 * 0.0000001,
PriceN: 1,
PriceD: 1,
Expand Down

0 comments on commit 32c5434

Please sign in to comment.