1515using System ;
1616using System . Collections ;
1717using System . Collections . Generic ;
18- using System . ComponentModel ;
1918using System . Diagnostics . CodeAnalysis ;
2019using System . Linq ;
2120using System . Runtime . CompilerServices ;
@@ -28,7 +27,6 @@ namespace Neo.Ledger
2827 /// </summary>
2928 public class MemoryPool : IReadOnlyCollection < Transaction >
3029 {
31- public event CancelEventHandler ? TransactionNew ;
3230 public event EventHandler < Transaction > ? TransactionAdded ;
3331 public event EventHandler < TransactionRemovedEventArgs > ? TransactionRemoved ;
3432
@@ -119,6 +117,13 @@ public int Count
119117 /// </summary>
120118 public int UnVerifiedCount => _unverifiedTransactions . Count ;
121119
120+ /// <summary>
121+ /// Transaction policy validator function.
122+ /// This function will be called to validate each transaction before adding it to the pool.
123+ /// If the function returns false, the transaction will be rejected.
124+ /// </summary>
125+ public Func < Transaction , IReadOnlyStore , bool > ? PolicyValidator { get ; set ; }
126+
122127 /// <summary>
123128 /// Initializes a new instance of the <see cref="MemoryPool"/> class.
124129 /// </summary>
@@ -309,11 +314,9 @@ internal bool CanTransactionFitInPool(Transaction tx)
309314
310315 internal VerifyResult TryAdd ( Transaction tx , DataCache snapshot )
311316 {
312- if ( TransactionNew != null )
317+ if ( PolicyValidator != null )
313318 {
314- var args = new CancelEventArgs ( ) ;
315- TransactionNew . Invoke ( this , args ) ;
316- if ( args . Cancel ) return VerifyResult . PolicyFail ;
319+ if ( ! PolicyValidator ( tx , snapshot ) ) return VerifyResult . PolicyFail ;
317320 }
318321
319322 var poolItem = new PoolItem ( tx ) ;
0 commit comments