First steps for encapsulating the policy code. An interface (abstract class) CPolicy and a concrete implementation CStandardPolicy are created. “Users” (people capable of modify and build Bitcoin core) can implement alternative policies and select them with the option -policy=<policy_name>. They can define new policy options and make their help messages be accesible to the users without having to touch init.cpp, only modifying policy.cpp is enough for all this. The help messages can also be accessed (per available policy) as a vector of string pairs to make it easier to implement a GUI to configure those options (although I don’t plan to do that myself). As more parts of the policy code move to policy.cpp, this encapsulation gets more useful.
To start using it. The function script/standard.o::IsStandard() is turned into a method: ApproveScript(). Many more policy-related improvements can be cleanly proposed after this first steps are merged.
OUTDATED: This is an attempt to get a first commit for moving policy-related code together as proposed in #4943. The main purpose of this PR is therefore discuss the commit “Policy: Create CPolicy interface and CStandardPolicy implemention” (https://github.com/jtimon/bitcoin/commit/572f12948285b14fcb2c2d1c9e2f51e749cc6cb6) which may change with suggestions. The commit “Policy: MOVEONLY: script/standard.o::IsStandard() -> CPolicy::ValidateScript()” (https://github.com/jtimon/bitcoin/commit/9e99ebafc38718ca54730e764091a82a248a1a3c) acts as an example for adding a method to CPolicy. The commit “Policy: Refactor: Move datacarrier policy logic to policy.o” (https://github.com/jtimon/bitcoin/commit/f141dd0b9b4059c2d54d0762d5dd0fe86976a18a) is an example of adding an attribute to CStandardPolicy without exposing it on CPolicy or exposing CStandardPolicy itself. An example of a crazy custom policy that a user could implement for its local node can be found in https://github.com/jtimon/bitcoin/compare/policy_example
The commit “Policy: Refactor: Move datacarrier policy logic to policy.o” may be considered too risky and may be left for later to avoid delaying the first step. Maybe https://github.com/jtimon/bitcoin/commit/a2954632879076d3b9763001aca21bf768797e54 is not welcomed. It is only necessary if you want to make InitPolicyFromArgs() and CPolicy::InitFromArgs() param mapArgs const and don’t want to duplicate code.
I am very sorry for letting the ut acks rot.