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

There should be a deploy method for the main class #410

Open
2 tasks
fulldecent opened this issue Aug 15, 2019 · 2 comments
Open
2 tasks

There should be a deploy method for the main class #410

fulldecent opened this issue Aug 15, 2019 · 2 comments

Comments

@fulldecent
Copy link
Contributor

If a class has a method named deploy and this method is annotated Callable then it should be called at deploy time.

This will remove the need for accessing Blockchain.getData() directly, like this:

    /**
     * This initialization is run at deploy time.
     */
    static {
        ABIDecoder decoder = new ABIDecoder(Blockchain.getData());
        String tokenName = decoder.decodeOneString();
        String tokenSymbol = decoder.decodeOneString();
        String tokenUriPrefix = decoder.decodeOneString();
        String tokenUriPostfix = decoder.decodeOneString();
        NFTokenMock.setTokenNameSymbolAndUriAffixes(tokenName, tokenSymbol, tokenUriPrefix, tokenUriPostfix);
    }

Instead the type safe alternative is:

@Callable
public static void deploy(String newTokenName, String newTokenSymbol, String newUriPrefix, String newUriPostfix) {
    ...
}

Benefits:

  1. It hides the details of ABI decoding, which the programmer does not care about
  2. It makes the ABI more clear because the types in deploy match the types in the ABI
    • The deployment call types actually are not part of the ABI anyway and they are an implementation detail for the contract users (this is a separate issue)

Work plan

  • Call deploy if exists
  • It shall be a compiler error if a the contract has a deploy method and any class has an @Instantiatable variable
@jeff-aion
Copy link
Contributor

This is what the @Initializable annotation is for.

@fulldecent
Copy link
Contributor Author

@Initializable allows you to set values only for static variables. Static variables have an extremely narrow use case and and probably none of those use cases overlap with setting the static variables at deploy time.

The only use case of @Initializable therefore is spells and counterfactuals.

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

2 participants