-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add IBlockPolicy.IsTransactionValid #827
Conversation
08be8e4
to
d9874d7
Compare
Codecov Report
@@ Coverage Diff @@
## master #827 +/- ##
==========================================
+ Coverage 87.38% 87.44% +0.06%
==========================================
Files 243 244 +1
Lines 22156 22288 +132
==========================================
+ Hits 19360 19489 +129
Misses 1453 1453
- Partials 1343 1346 +3
|
d9874d7
to
0f4ad5d
Compare
0f4ad5d
to
f8e886f
Compare
@@ -13,6 +14,8 @@ namespace Libplanet.Blockchain.Policies | |||
public class BlockPolicy<T> : IBlockPolicy<T> | |||
where T : IAction, new() | |||
{ | |||
private readonly Predicate<Transaction<T>> _isTransactionValid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsTransactionInvalid
method just calls _isTransactionsValid
and pass its return value. so how about using property?
private readonly Predicate<Transaction<T>> _isTransactionValid; | |
public Predicate<Transaction<T>> IsTransactionValid { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moreal I believe the way you suggested does not satisfy the interface anyway, because in the IL level delegate properties and methods are merely distinct each other; the same looking syntax between delegate properties and methods in C# is just a coincidence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dahlia If I had understood correctly, it means that method bool IsTransactionValid(Transaction<T>)
and delegate property Predicate<Transaction<T>>
are distinct each other so it will not be achieved.
If then, it was what I really wanted to suggest to replace IBlockPolicy><T>.IsTransactionValid(Transaction<T>)
with Predicate<Transaction<T>>
. As code, it will be like below.
public interface IBlockPolicy<T>
where T : IAction, new()
{
// bool IsTransactionValid(Transaction<T> transaction);
Predicate<Transaction<T>> IsTransactionValid { get; }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moreal That was how this patch looked before it's amended, but then it became like the current way in a reason: .NET interfaces say nothing about constructors, so an interface anyway cannot enforce its implementations to take a delegate. On the other hand, it's unclear what's benefit of having a predicate as a delegate property instead of a method, which is more common and natural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I understood. Thanks for your good explanation.
014f992
to
96e8a24
Compare
96e8a24
to
700d403
Compare
700d403
to
9ff67d1
Compare
This adds
IBlockPolicy.IsValidTransaction
method which is a method to determine if a transaction is valid.