parseDataPendings static method

List<Pending>? parseDataPendings(
  1. List<int>? response
)

Parses a network response containing pending transaction information into a list of Pending objects.

This method takes a response, which is a list of integers representing the raw data received from the network. It returns a list of Pending objects based on the parsed information. If the parsing encounters errors or the response is null or empty, an empty list is returned.

Input:

  • response: List of integers representing the raw data received from the network.

Output:

  • List<Pending> A list of Pending objects based on the parsed information.

Example Usage:

List<int> response = ... // Raw network response as a list of integers.
List<Pending> parsedPendings = NodeParser.parsePendings(response);

Note: The method uses try-catch to handle potential exceptions during parsing, returning an empty list in case of an error.

Implementation

static List<Pending>? parseDataPendings(List<int>? response) {
  if (response == null || response.isEmpty) {
    return null;
  }

  List<String> array = String.fromCharCodes(response).split(" ");
  List<Pending> pendingList = [];

  try {
    for (String value in array) {
      var pending = value.split(",");

      if (pending.length >= 8) {
        pendingList.add(Pending(
          orderId: pending[0],
          orderType: pending[2],
          sender: pending[3],
          receiver: pending[4],
          amountTransfer:
              NosoMath().bigIntToDouble(valueInt: int.parse(pending[5])),
          amountFee:
              NosoMath().bigIntToDouble(valueInt: int.parse(pending[6])),
        ));
      }
    }

    return pendingList;
  } catch (e) {
    return null;
  }
}