getSeedListFromCFG static method

List<Seed> getSeedListFromCFG(
  1. String input
)

Get a list of seeds from a configuration string.

The method is designed to process a configuration string and extract information about seeds. The configuration string should be in a format where seeds are separated by spaces, represented by the input value.

If input is an empty string, the method returns an empty list.

It is assumed that the configuration string has at least 5 values; otherwise, the method may return an empty list.

Each seed is defined by a string in the format "ip;port", where:

  • "ip" is the IP address of the seed,
  • "port" is the port of the seed (parsed as an integer).

Objects of the Seed class are created and added to the seedList.

Returns the seedList containing Seed objects with information about seeds from the configuration string.

Implementation

static List<Seed> getSeedListFromCFG(String input) {
  if (input.isEmpty) return [];

  List<Seed> seedList = [];
  try {
    List<String> values = input.split(' ');

    if (values.length >= 5) {
      List<String> poolData = values[1].split(':');
      for (String data in poolData) {
        List<String> seed = data.split(';');
        if (seed.length >= 2) {
          seedList.add(Seed(ip: seed[0], port: int.parse(seed[1])));
        }
      }
    }

    return seedList;
  } catch (e) {
    return seedList;
  }
}