2 ms·
I wouldn't call this validation (except at the very end). I would call it parsing. In fact it serves the purpose of not having to duplicate the validation code
by iraqmtpizza 3y ago
I wouldn't call this validation (except at the very end). I would call it parsing. In fact it serves the purpose of not having to duplicate the validation code which is centralized in the canonical constructor.
public Function(String signature) {
this(signature, signature.indexOf('('), TupleType.EMPTY);
}
public Function(String signature, String outputs) {
this(signature, signature.indexOf('('), outputs != null ? TupleType.parse(outputs) : TupleType.EMPTY);
}
private Function(final String signature, final int nameLength, final TupleType<?> outputs) {
this(
TypeEnum.FUNCTION,
signature.substring(0, nameLength),
TupleType.parse(signature.substring(nameLength)),
outputs,
null,
Function.newMessageDigest()
);
}
public Function(TypeEnum type, String name, TupleType<?> inputs, TupleType<?> outputs, String stateMutability, MessageDigest messageDigest) {
this.type = Objects.requireNonNull(type);
this.name = name != null ? validateName(name) : null;
this.inputTypes = Objects.requireNonNull(inputs);
this.outputTypes = Objects.requireNonNull(outputs);
this.stateMutability = stateMutability;
this.hashAlgorithm = Objects.requireNonNull(messageDigest.getAlgorithm());
validateFunction();
generateSelector(messageDigest);
}