From e5fbe40b9a49d84d76302b2d1aea75c41911eab1 Mon Sep 17 00:00:00 2001 From: Cuteivist Date: Thu, 26 Oct 2023 20:39:31 +0200 Subject: [PATCH] fix: Show community token mint as Mint tx type (#4214) --- services/wallet/activity/activity.go | 10 ++++++++-- services/wallet/activity/filter.sql | 26 ++++++++++++-------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/services/wallet/activity/activity.go b/services/wallet/activity/activity.go index 23db4c34f..e2bb54b76 100644 --- a/services/wallet/activity/activity.go +++ b/services/wallet/activity/activity.go @@ -492,10 +492,12 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses var tokenCode, fromTokenCode, toTokenCode sql.NullString var methodHash sql.NullString var transferType *TransferType + var communityMintEventDB sql.NullBool + var communityMintEvent bool err := rows.Scan(&transferHash, &pendingHash, &chainID, &multiTxID, ×tamp, &dbMtType, &dbTrType, &fromAddress, &toAddressDB, &ownerAddressDB, &dbTrAmount, &dbMtFromAmount, &dbMtToAmount, &aggregatedStatus, &aggregatedCount, &tokenAddress, &dbTokenID, &tokenCode, &fromTokenCode, &toTokenCode, &outChainIDDB, &inChainIDDB, &contractType, - &contractAddressDB, &methodHash) + &contractAddressDB, &methodHash, &communityMintEventDB) if err != nil { return nil, err } @@ -508,6 +510,10 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses transferType = contractTypeFromDBType(contractType.String) } + if communityMintEventDB.Valid { + communityMintEvent = communityMintEventDB.Bool + } + if len(contractAddressDB) > 0 { contractAddress = new(eth.Address) *contractAddress = eth.BytesToAddress(contractAddressDB) @@ -523,7 +529,7 @@ func getActivityEntries(ctx context.Context, deps FilterDependencies, addresses } else if trType.Byte == toTrType { at := ReceiveAT if fromAddress == ZeroAddress && transferType != nil { - if *transferType == TransferTypeErc721 || (*transferType == TransferTypeErc20 && methodHash.Valid && sliceContains(inputDataMethods, methodHash.String)) { + if *transferType == TransferTypeErc721 || (*transferType == TransferTypeErc20 && methodHash.Valid && (communityMintEvent || sliceContains(inputDataMethods, methodHash.String))) { at = MintAT } } diff --git a/services/wallet/activity/filter.sql b/services/wallet/activity/filter.sql index 24413d0e3..1b7612daa 100644 --- a/services/wallet/activity/filter.sql +++ b/services/wallet/activity/filter.sql @@ -45,7 +45,7 @@ WITH filter_conditions AS ( ? AS layer2FinalisationDuration, ? AS layer1FinalisationDuration, X'0000000000000000000000000000000000000000' AS zeroAddress, - '0x28c427b0611d99da5c4f7368abe57e86b045b483c4689ae93e90745802335b87' as statusMintEvent + '0x28c427b0611d99da5c4f7368abe57e86b045b483c4689ae93e90745802335b87' as communityMintEvent ), -- This UNION between CTE and TEMP TABLE acts as an optimization. As soon as we drop one or use them interchangeably the performance drops significantly. filter_addresses(address) AS ( @@ -207,7 +207,11 @@ SELECT CASE WHEN transfers.tx_from_address = zeroAddress AND transfers.type = "erc20" THEN substr(json_extract(tx, '$.input'), 1, 10) ELSE NULL - END AS method_hash + END AS method_hash, + CASE + WHEN transfers.tx_from_address = zeroAddress AND transfers.type = "erc20" THEN (SELECT 1 FROM json_each(transfers.receipt, '$.logs' ) WHERE json_extract( value, '$.topics[0]' ) = communityMintEvent) + ELSE NULL + END AS community_mint_event FROM transfers CROSS JOIN filter_conditions @@ -253,11 +257,7 @@ WHERE transfers.type = 'erc20' AND ( (method_hash IS NOT NULL AND method_hash IN mint_methods) - OR ( - (SELECT 1 - FROM json_each(transfers.receipt, '$.logs' ) - WHERE json_extract( value, '$.topics[0]' ) = statusMintEvent) IS NOT NULL - ) + OR community_mint_event IS NOT NULL ) ) ) @@ -284,11 +284,7 @@ WHERE transfers.type = 'erc20' AND ( (method_hash IS NOT NULL AND method_hash IN mint_methods) - OR ( - (SELECT 1 - FROM json_each(transfers.receipt, '$.logs' ) - WHERE json_extract( value, '$.topics[0]' ) = statusMintEvent) IS NOT NULL - ) + OR community_mint_event IS NOT NULL ) ) ) @@ -386,7 +382,8 @@ SELECT NULL AS in_network_id, pending_transactions.type AS type, NULL as contract_address, - NULL AS method_hash + NULL AS method_hash, + NULL AS community_mint_event FROM pending_transactions CROSS JOIN filter_conditions @@ -476,7 +473,8 @@ SELECT multi_transactions.to_network_id AS in_network_id, NULL AS type, NULL as contract_address, - NULL AS method_hash + NULL AS method_hash, + NULL AS community_mint_event FROM multi_transactions CROSS JOIN filter_conditions