getDnaGetEpoch method
Implementation
Future<DnaGetEpochResponse> getDnaGetEpoch() async {
DnaGetEpochRequest dnaGetEpochRequest;
DnaGetEpochResponse dnaGetEpochResponse;
Map<String, dynamic> mapParams;
Completer<DnaGetEpochResponse> _completer =
new Completer<DnaGetEpochResponse>();
if (this.nodeType == DEMO_NODE) {
dnaGetEpochResponse = new DnaGetEpochResponse();
dnaGetEpochResponse.result = new DnaGetEpochResponseResult();
dnaGetEpochResponse.result.currentPeriod = DM_EPOCH_CURRENT_PERIOD;
dnaGetEpochResponse.result.epoch = DM_EPOCH_EPOCH;
dnaGetEpochResponse.result.nextValidation = DM_EPOCH_NEXT_VALIDATION;
} else {
if (this.nodeType == PUBLIC_NODE) {
mapParams = {
'method': DnaGetEpochRequest.METHOD_NAME,
'params': [],
'id': 101,
};
} else {
mapParams = {
'method': DnaGetEpochRequest.METHOD_NAME,
'params': [],
'id': 101,
'key': this.keyApp
};
}
try {
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);
}
} 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);
}
}
} catch (e) {
logger.e(e.toString());
}
}
_completer.complete(dnaGetEpochResponse);
return _completer.future;
}