Skip to content
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

CryptoConditions objects should know how to create themselves. #441

Open
jmjatlanta opened this issue May 18, 2021 · 0 comments
Open

CryptoConditions objects should know how to create themselves. #441

jmjatlanta opened this issue May 18, 2021 · 0 comments

Comments

@jmjatlanta
Copy link

jmjatlanta commented May 18, 2021

I will use an "Asset" as an example.

Currently the struct CCcontract_info is defined in CCinclude.h. This struct contains a number of generic fields for different contracts, as well as pointers to functions for validation and checking a CScript. To create an "Asset" contract object, requires the following (taken from faucet.cpp::FaucetInfo())

CCcontract_info C; 
CCcontract_info *cp = CCinit(&C,EVAL_FAUCET); 

This requires the creation of an object, and a method with a large case statement. In addition there are macros to help build the ismyvin function.

I believe all this to be unnecessary, and fairly easy to fix.

  • CCcontract_info should be moved to CCcontract_info.h
  • CCcontract_info will become a virtual struct which requires the definition of validate()
  • CCAssetContract_info should be defined in CCassets.h, and derives from CCcontract_info, defining its own validate method (in CCassets.cpp probably)
  • CCcustom.inc is no longer necessary, nor are the defines to make it work, as the ismyvin method can be moved into CCcontract_info. Any object-specific customizations can override this.
  • Existing methods that take in a CCcontract_info pointer should not need modification.
  • Classes that would like to take a subset of object types can overload methods. Invalid combinations could be caught a compile time.
  • CCinit is no longer necessary and should be replaced by simply creating the object desired. New way:
CCAssetContract_info C;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant