aionnetwork / AVM

Enabling Java code to run in a blockchain environment
https://theoan.com/
MIT License
49 stars 25 forks source link

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

Open fulldecent opened 5 years ago

fulldecent commented 5 years ago

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

jeff-aion commented 5 years ago

This is what the @Initializable annotation is for.

fulldecent commented 5 years ago

@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.