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

transaction search with destination address #12604

Merged
merged 6 commits into from Mar 11, 2024

Conversation

collins-okafor
Copy link
Contributor

This pull request makes the following changes:

@collins-okafor
Copy link
Contributor Author

Hi @lontivero
This PR is ready for review

@turbolay
Copy link
Collaborator

turbolay commented Mar 4, 2024

I'm not able to review 100% this PR, but many things are incorrect:

  • We always work with the current network, so for example we don't want to search for transactions that are on Testnet when we are on Main
  • We do not use try/catch as part of the logic that way
  • The logic is really weird because you first search in TransactionStore, which will search in absolutely all transactions, but then apply the results on transactions of loaded wallets. Well, why not look directly in the transactions of the loaded wallets?
  • Your function GetDestinationAddresses is really weird because it takes a DestinationAddress and returns a DestinationAddress... Something is clearly wrong.
  • At least one variable is created but unused
  • Have you tested your PR? Because it doesn't work correctly, and finds too many results.

Here would be my approach for this PR, which is based on your idea but greatly simplifies the logic. It's still not perfect for several reasons, and takes a design choice of presenting in the same way a found transaction Id and an address found as destination in a transaction, which might be rejected, but you can modify your PR based on this code:

index 7f59d1e92..e54aeffe0 100644
--- a/WalletWasabi.Fluent/ViewModels/SearchBar/Sources/TransactionsSearchSource.cs
+++ b/WalletWasabi.Fluent/ViewModels/SearchBar/Sources/TransactionsSearchSource.cs
@@ -4,6 +4,7 @@ using System.Reactive.Disposables;
 using System.Reactive.Linq;
 using System.Threading.Tasks;
 using DynamicData;
+using NBitcoin;
 using ReactiveUI;
 using WalletWasabi.Fluent.Extensions;
 using WalletWasabi.Fluent.ViewModels.SearchBar.Patterns;
@@ -49,6 +50,13 @@ public class TransactionsSearchSource : ReactiveObject, ISearchSource, IDisposab
                return historyItemViewModelBase.Transaction.Id.ToString().Contains(queryStr, StringComparison.CurrentCultureIgnoreCase);
        }
 
+       private static bool ContainsDestinationAddress((WalletViewModel, HistoryItemViewModelBase) tupleWalletHistoryItem, string queryStr)
+       {
+               var txid = tupleWalletHistoryItem.Item2.Transaction.Id;
+               return tupleWalletHistoryItem.Item1.WalletModel.Transactions.GetDestinationAddresses(txid)
+                       .Contains(BitcoinAddress.Create(queryStr, tupleWalletHistoryItem.Item1.WalletModel.Network));
+       }
+
        private static Task NavigateTo(WalletViewModel wallet, HistoryItemViewModelBase item)
        {
                var walletPageViewModel = MainViewModel.Instance.NavBar.Wallets.FirstOrDefault(x => x.WalletViewModel == wallet);
@@ -117,6 +125,6 @@ public class TransactionsSearchSource : ReactiveObject, ISearchSource, IDisposab
        private static IEnumerable<(WalletViewModel, HistoryItemViewModelBase)> Filter(string queryStr)
        {
                return Flatten(GetTransactionsByWallet())
-                       .Where(tuple => ContainsId(tuple.Item2, queryStr));
+                       .Where(tuple => ContainsId(tuple.Item2, queryStr) || ContainsDestinationAddress(tuple, queryStr));
        }
 }

@collins-okafor
Copy link
Contributor Author

Thanks for the corrections and suggestions. I will look into all of them now.

@collins-okafor
Copy link
Contributor Author

Hi @turbolay,
Pls, check this out. I've made some changes based on the suggestions you gave earlier. The issue is resolved now. Though had to put a check before calling the ContainsDestinationAddress method as it expects only addresses and not a string (txid).

Copy link
Collaborator

@turbolay turbolay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's much better!

Still few minor comments:

  • Dont create unused variables, instead discard the returned result
  • Follow the style, maybe you need CodeMaid or configure your IDE with StyleCop? See https://github.com/zkSNACKs/WalletWasabi/blob/master/CONTRIBUTING.md
  • Prefer lambda expression rather than if/else if readability is still good
  • Use as small objects as you can as arguments (eg: don't pass the whole WalletModel if you only need one field out of it, the Network)

I applied those suggestions here: 0ad5222
Can you cherry-pick this commit and add it to your branch, please? You can simply apply the diff if you prefer.

Your logic still contains a try/catch but I think it's OK, I don't know how to do it better, maybe others will.

@pull-request-size pull-request-size bot added size/S and removed size/M labels Mar 6, 2024
@collins-okafor
Copy link
Contributor Author

Thanks a lot @turbolay

All corrections have been applied.

Copy link
Collaborator

@turbolay turbolay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@turbolay turbolay requested review from SuperJMN and soosr March 6, 2024 00:56
Copy link
Collaborator

@soosr soosr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last bit

Copy link
Collaborator

@soosr soosr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@soosr soosr requested a review from lontivero March 7, 2024 10:18
Copy link
Collaborator

@yahiheb yahiheb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@soosr soosr merged commit 0dc050c into zkSNACKs:master Mar 11, 2024
7 checks passed
@turbolay
Copy link
Collaborator

turbolay commented Mar 11, 2024

Congrats @collins-okafor !!! Nice PR handling, thank you for your contribution.

@MaxHillebrand
Copy link
Member

Thanks @collins-okafor and congrats on your first merged PR, much appreciated!

@collins-okafor
Copy link
Contributor Author

Congrats @collins-okafor !!! Nice PR handling, thank you for your contribution.

Glad I could contribute. And thanks for the corrections and feedbacks. I really appreciate. Looking forward to doing more😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants