From 195214765b31abd01993ade8dc70456f279c1137 Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 11 Sep 2023 16:46:49 +0200 Subject: [PATCH] fix(wallet) fix filter by activity type The activity type filtering was not stable in relation to addresses filter which was generating unexpected Send/Receive type in the corner-case when both sender and receiver was in the address list. Updates status-desktop #11960 --- services/wallet/activity/activity_test.go | 6 ++++++ services/wallet/activity/filter.sql | 16 ++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/services/wallet/activity/activity_test.go b/services/wallet/activity/activity_test.go index d1d2ad82b..ea201712a 100644 --- a/services/wallet/activity/activity_test.go +++ b/services/wallet/activity/activity_test.go @@ -734,6 +734,12 @@ func TestGetActivityEntriesFilterByType(t *testing.T) { require.Equal(t, 0, mintCount) require.Equal(t, 0, swapCount) require.Equal(t, 0, bridgeCount) + + // Filter with all addresses regression + filter.Types = []Type{SendAT} + entries, err = getActivityEntries(context.Background(), deps, allAddressesFilter(), []common.ChainID{}, filter, 0, 15) + require.NoError(t, err) + require.Equal(t, 5, len(entries)) } func TestGetActivityEntriesFilterByAddresses(t *testing.T) { diff --git a/services/wallet/activity/filter.sql b/services/wallet/activity/filter.sql index f62a85e6d..e15a0afab 100644 --- a/services/wallet/activity/filter.sql +++ b/services/wallet/activity/filter.sql @@ -10,7 +10,7 @@ -- -- Only status FailedAS, PendingAS and CompleteAS are returned. FinalizedAS requires correlation with blockchain current state. As an optimization we approximate it by using timestamp information; see startTimestamp and endTimestamp -- --- ContractDeploymentAT is subtype of SendAT and MintAT is subtype of ReceiveAT. It means query must prevent returning MintAT when filtering by ReceiveAT or ContractDeploymentAT when filtering by SendAT. That required duplicated code in filter by type query, to maintain perforamnce. +-- ContractDeploymentAT is subtype of SendAT and MintAT is subtype of ReceiveAT. It means query must prevent returning MintAT when filtering by ReceiveAT or ContractDeploymentAT when filtering by SendAT. That required duplicated code in filter by type query, to maintain performance. -- -- Token filtering has two parts -- 1. Filtering by symbol (multi_transactions and pending_transactions tables) where the chain ID is ignored, basically the filter_networks will account for that @@ -157,7 +157,7 @@ SELECT AND from_join.address IS NULL THEN toTrType WHEN from_join.address IS NOT NULL AND to_join.address IS NOT NULL THEN CASE - WHEN from_join.address < to_join.address THEN fromTrType + WHEN transfers.address = transfers.tx_from_address THEN fromTrType ELSE toTrType END ELSE NULL @@ -205,12 +205,7 @@ WHERE filterActivityTypeAll OR ( filterActivityTypeSend - AND ( - filterAllAddresses - OR ( - HEX(transfers.tx_from_address) IN filter_addresses - ) - ) + AND tr_type = fromTrType AND NOT ( tr_type = fromTrType and transfers.tx_to_address IS NULL @@ -221,10 +216,7 @@ WHERE ) OR ( filterActivityTypeReceive - AND ( - filterAllAddresses - OR (HEX(transfers.tx_to_address) IN filter_addresses) - ) + AND tr_type = toTrType AND NOT ( tr_type = toTrType AND transfers.type = "erc721"