AVM
AVM copied to clipboard
There should be a deploy method for the main class
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:
- It hides the details of ABI decoding, which the programmer does not care about
- It makes the ABI more clear because the types in
deploymatch 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
deploymethod and any class has an@Instantiatablevariable
This is what the @Initializable annotation is for.
@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.