fetchSelector4Byte method

Future<ExternalContractFunction?> fetchSelector4Byte(
  1. String selector
)

Implementation

Future<ExternalContractFunction?> fetchSelector4Byte(
  String selector,
) async {
  selector = selector.startsWith("0x") ? selector : "0x$selector";

  final endpoint = "$_4byteEndpoint/signatures/?hex_signature=$selector";
  final uri = Uri.parse(endpoint);

  if (functionCache.containsKey(endpoint)) {
    return await functionCache[endpoint]!.future;
  }

  final future = _4byteRequest(uri, selector);

  final completer = Completer<ExternalContractFunction?>();
  functionCache[endpoint] = completer;

  try {
    final function = await future;
    completer.complete(function);
    return function;
  } catch (e) {
    completer.complete(null);
    return null;
  }
}