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
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
If a class has a method named
deployand 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:Instead the type safe alternative is:
Benefits:
deploymatch the types in the ABIWork plan
deploymethod and any class has an@Instantiatablevariable