-
Notifications
You must be signed in to change notification settings - Fork 98
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
Refactor CryptoConditions to use more OO features #444
Conversation
I generally support refactoring CCcontract_info structure to make it more OOP-like.
|
Interesting. I can not say I understand the full process, but at first glance it sounds good. Getting rid of variables that are rarely used by including their storage and logic only when they are used is a good thing IMO. I will try to learn more about the functionality you are adding. |
I suggest we first make this improvement into a research-like branch to concentrate all cc changes there |
Fixes #441
Existing contracts were very "C"-like. Methods take long lists of parameters, methods scattered in different files, macros to generate functions, etc.
This PR takes a step in the OO direction. Contracts are now structs that derive from a base
CCcontract_info
struct. The former "macroed" functions are now simply a part of the base class, which can be overridden if need be.A new contract will be a struct that derives from
CCcontract_info
and overrides the validate function. Any methods needed by the contract can be a class method, which aides in naming without collisions.Common functionality that all (or at least most) contracts need can be moved into the CCcontract_info base class (i.e. GetUnspendable).
The CCinit method has now been simplified to return a shared pointer to the desired contract type. In addition, most methods have been modified to use the desired contract class instead of the (more generic) base class.
These changes keep a large portion of contract logic within the bounds of the contract itself. The hope is that eventually anything contract-specific will be in the corresponding .cpp file as a private method, and can rely on
this
instead of passing pointers around.** Current Status ** This PR should contain no logic changes. The system should work exactly as before, with the exceptions of: