getCurrentPeriod method
Implementation
Future<String> getCurrentPeriod() async {
String currentPeriod = "";
Completer<String> _completer = new Completer<String>();
Map<String, dynamic> mapParams;
try {
DnaGetEpochRequest dnaGetEpochRequest;
DnaGetEpochResponse dnaGetEpochResponse;
if (this.nodeType == DEMO_NODE) {
currentPeriod = DM_EPOCH_CURRENT_PERIOD;
} else {
mapParams = {
'method': DnaGetEpochRequest.METHOD_NAME,
'params': [],
'id': 101,
'key': this.keyApp
};
if (this.nodeType == NORMAL_VPS_NODE) {
SSHClientStatus sshClientStatus;
sshClientStatus = await VpsUtil().connectVps(this.apiUrl, keyApp);
if (sshClientStatus.sshClientStatus) {
sshClient = sshClientStatus.sshClient;
}
var response = await ssh.HttpClientImpl(
clientFactory: () =>
ssh.SSHTunneledBaseClient(sshClientStatus.sshClient)).request(
this.apiUrl,
method: 'POST',
data: jsonEncode(mapParams),
headers: requestHeaders);
if (response.status == 200) {
dnaGetEpochResponse = dnaGetEpochResponseFromJson(response.text);
if (dnaGetEpochResponse.result != null) {
currentPeriod = dnaGetEpochResponse.result.currentPeriod;
} else {
currentPeriod = EpochPeriod.None;
}
}
} else {
dnaGetEpochRequest = DnaGetEpochRequest.fromJson(mapParams);
String body = json.encode(dnaGetEpochRequest.toJson());
http.Response responseHttp = await http.post(Uri.parse(this.apiUrl),
body: body, headers: requestHeaders);
if (responseHttp.statusCode == 200) {
dnaGetEpochResponse =
dnaGetEpochResponseFromJson(responseHttp.body);
if (dnaGetEpochResponse.result != null) {
currentPeriod = dnaGetEpochResponse.result.currentPeriod;
} else {
currentPeriod = EpochPeriod.None;
}
}
}
}
} catch (e) {
logger.e(e.toString());
currentPeriod = EpochPeriod.None;
}
_completer.complete(currentPeriod);
return _completer.future;
}