getMethodByName static method

AbiMethod getMethodByName(
  1. List<AbiMethod> methods,
  2. String name
)

Find the ABI method with the given name in this contract.

Implementation

static AbiMethod getMethodByName(List<AbiMethod> methods, String name) {
  final filteredMethods = <AbiMethod>[];

  for (var method in methods) {
    if (method.name == name) {
      filteredMethods.add(method);
    }
  }

  if (filteredMethods.length > 1) {
    final sigs = <String>[];

    for (var idx = 0; idx < filteredMethods.length; idx++) {
      sigs[idx] = filteredMethods[idx].signature;
    }

    final found = sigs.join(',');
    throw ArgumentError(
        'found ${filteredMethods.length} methods with the same name: $found');
  }

  if (filteredMethods.isEmpty) {
    throw ArgumentError('foud 0 methods with the name $name');
  }

  return filteredMethods.first;
}