diff --git a/neo/Wallets/WalletIndexer.cs b/neo/Wallets/WalletIndexer.cs index 5e1b347ed7..3581dd6728 100644 --- a/neo/Wallets/WalletIndexer.cs +++ b/neo/Wallets/WalletIndexer.cs @@ -127,8 +127,9 @@ public IEnumerable GetTransactions(IEnumerable accounts) yield return hash; } - private void ProcessBlock(Block block, HashSet accounts, WriteBatch batch) + private (Transaction, UInt160[])[] ProcessBlock(Block block, HashSet accounts, WriteBatch batch) { + var change_set = new List<(Transaction, UInt160[])>(); foreach (Transaction tx in block.Transactions) { HashSet accounts_changed = new HashSet(); @@ -218,15 +219,10 @@ private void ProcessBlock(Block block, HashSet accounts, WriteBatch bat { foreach (UInt160 account in accounts_changed) batch.Put(SliceBuilder.Begin(DataEntryPrefix.ST_Transaction).Add(account).Add(tx.Hash), false); - WalletTransaction?.Invoke(null, new WalletTransactionEventArgs - { - Transaction = tx, - RelatedAccounts = accounts_changed.ToArray(), - Height = block.Index, - Time = block.Timestamp - }); + change_set.Add((tx, accounts_changed.ToArray())); } } + return change_set.ToArray(); } private void ProcessBlocks() @@ -234,15 +230,18 @@ private void ProcessBlocks() while (!disposed) { while (!disposed) + { + Block block; + (Transaction, UInt160[])[] change_set; lock (SyncRoot) { if (indexes.Count == 0) break; uint height = indexes.Keys.Min(); - Block block = Blockchain.Singleton.Store.GetBlock(height); + block = Blockchain.Singleton.Store.GetBlock(height); if (block == null) break; WriteBatch batch = new WriteBatch(); HashSet accounts = indexes[height]; - ProcessBlock(block, accounts, batch); + change_set = ProcessBlock(block, accounts, batch); ReadOptions options = ReadOptions.Default; byte[] groupId = db.Get(options, SliceBuilder.Begin(DataEntryPrefix.IX_Group).Add(height)).ToArray(); indexes.Remove(height); @@ -261,6 +260,17 @@ private void ProcessBlocks() } db.Write(WriteOptions.Default, batch); } + foreach (var (tx, accounts) in change_set) + { + WalletTransaction?.Invoke(null, new WalletTransactionEventArgs + { + Transaction = tx, + RelatedAccounts = accounts, + Height = block.Index, + Time = block.Timestamp + }); + } + } for (int i = 0; i < 20 && !disposed; i++) Thread.Sleep(100); }