Closed s2quake closed 2 months ago
This PR has 75
quantified lines of changes. In general, a change size of upto 200
lines is ideal for the best PR experience!
Was this comment helpful? :thumbsup: :ok_hand: :thumbsdown: (Email) Customize PullRequestQuantifier for this repository.
How do you think Services
should be retrieved from Application?
Note: I suggested https://github.com/riemannulus/ActionEvaluatorExp/blob/main/ActionEvaluatorExp.Modules/Bank/Actions/Transfer.cs before and I think your suggestion is also like this.
The code below is a simple example of retrieving services from application.
sealed class SlashingAction : IAction
{
IWorld IAction.Execute(IActionContext context)
{
var world = context.PreviousState;
if (context.GetService(typeof(IEvidenceContext)) is IEvidenceContext evidenceContext)
{
// Console.WriteLine("SlashingAction executed!");
}
else
{
throw new NotSupportedException();
}
return world;
}
}
This PR shows the fundamental way of providing information to IAction
in libplanet.
I haven't thought about how to change the state or provide additional modules or services needed in the application.
Finally, Both are good ways, so it would be nice to think about it from various aspects.
This PR has 98
quantified lines of changes. In general, a change size of upto 200
lines is ideal for the best PR experience!
Was this comment helpful? :thumbsup: :ok_hand: :thumbsdown: (Email) Customize PullRequestQuantifier for this repository.
Action
,BeginAction
,EndAction
is implemented as the sameIAction
, but they have different purposes. Therefore, they have slightly different information and permissions. Currently,IActionContext
provides only the same information, so different information and permissions cannot be granted for each Action.IServiceProvider
is an interface that can solve this problem. Each action can useIServiceProvider.GetService
to get the information it needs. AndActionEvaluator
has the obligation to provide different information depending on the purpose of the Action.