parseDataNode static method
Parses the network response to extract Node information based on the provided active seed.
This method takes a response
, which is a list of integers representing the raw data received from the network,
and a seedActive
, which is the active seed associated with the Node. It returns a Node object if the parsing
is successful, otherwise returns null.
The response
is expected to contain space-separated values, and the method attempts to extract relevant information
to construct a Node object. If the response is null or does not contain enough values, the method returns null.
Input:
- response: List of integers representing the raw data received from the network.
- seedActive: The active seed associated with the Node.
Output:
- Node A constructed Node object if parsing is successful, otherwise null.
Example Usage:
List<int> response = ... // Raw network response as a list of integers.
Seed activeSeed = ... // Active seed associated with the Node.
Node? parsedNode = NodeParser.parseResponseNode(response, activeSeed);
Note: The method uses try-catch to handle potential exceptions during parsing, returning null in case of an error.
Implementation
static Node? parseDataNode(List<int>? response, Seed seedActive) {
if (response == null) {
return null;
}
try {
List<String> values = String.fromCharCodes(response).split(" ");
if (values.length <= 2) {
return null;
}
return Node(
seed: seedActive,
connections: int.tryParse(values[1]) ?? 0,
lastblock: int.tryParse(values[2]) ?? 0,
pendings: int.tryParse(values[3]) ?? 0,
delta: int.tryParse(values[4]) ?? 0,
branch: values[5],
version: values[6],
utcTime: int.tryParse(values[7]) ?? 0,
lastblockhash: values[10].substring(0, 5),
headershash: values[15],
sumaryhash: values[17],
);
} catch (e) {
return null;
}
}