fromTextSignature static method

ExternalContractFunction? fromTextSignature({
  1. required String textSignature,
})

Implementation

static ExternalContractFunction? fromTextSignature({
  required String textSignature,
}) {
  final opening = textSignature.indexOf("(");
  final closing = textSignature.lastIndexOf(")");

  if (opening == -1 || closing == -1) {
    return null;
  }

  try {
    final name = textSignature.substring(0, opening);
    final params_s = extractParams(
      textSignature.substring(opening + 1, closing),
    );
    final params = [
      for (final (type_s, name) in params_s)
        FunctionParam(
          name: name,
          type: FunctionParamType.fromString(type_s),
        ),
    ];

    return ExternalContractFunction(
      name: name,
      parameters: params,
    );
  } catch (e, s) {
    Logger.logError(
      e,
      s: s,
      hint: "Failed to parse function text signature: $textSignature",
    );
    return null;
  }
}