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
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
collins-okafor marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using DynamicData;
using NBitcoin;
using ReactiveUI;
using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.Models.Wallets;
using WalletWasabi.Fluent.ViewModels.SearchBar.Patterns;
using WalletWasabi.Fluent.ViewModels.SearchBar.SearchItems;
using WalletWasabi.Fluent.ViewModels.Wallets;
Expand Down Expand Up @@ -117,6 +119,36 @@ private static IEnumerable<ISearchItem> Search(string query)
private static IEnumerable<(WalletViewModel, HistoryItemViewModelBase)> Filter(string queryStr)
{
return Flatten(GetTransactionsByWallet())
.Where(tuple => ContainsId(tuple.Item2, queryStr));
.Where(tuple =>
{
if (IsBitcoinAddress(tuple.Item1.WalletModel, queryStr))
{
return ContainsDestinationAddress(tuple, queryStr);
}
else
{
return ContainsId(tuple.Item2, queryStr);
}
});
}

private static bool ContainsDestinationAddress((WalletViewModel, HistoryItemViewModelBase) tupleWalletHistoryItem, string queryStr)
{
var txid = tupleWalletHistoryItem.Item2.Transaction.Id;
return tupleWalletHistoryItem.Item1.WalletModel.Transactions.GetDestinationAddresses(txid)
collins-okafor marked this conversation as resolved.
Show resolved Hide resolved
collins-okafor marked this conversation as resolved.
Show resolved Hide resolved
.Contains(BitcoinAddress.Create(queryStr, tupleWalletHistoryItem.Item1.WalletModel.Network));
}

private static bool IsBitcoinAddress(IWalletModel walletModel, string queryStr)
{
try
{
var address = BitcoinAddress.Create(queryStr, walletModel.Network);
return true;
}
catch (FormatException)
{
return false;
}
}
}