move async call to a synchronouse one

This commit is contained in:
Czarek Nakamoto 2024-11-10 22:10:19 -05:00
parent 013144c919
commit 09b02f9b0b
No known key found for this signature in database
GPG key ID: 04FB77CB56AB1DF4

View file

@ -84,7 +84,11 @@ mixin ZanoWalletApi {
Future<String> invokeMethod(String methodName, Object params) async {
var invokeResult =
zano.PlainWallet_asyncCall('invoke', hWallet, '{"method": "$methodName","params": ${jsonEncode(params)}}');
zano.PlainWallet_syncCall('invoke', hWallet, jsonEncode(
{
"method": "$methodName",
"params": params,
}));
Map<String, dynamic> map;
try {
map = jsonDecode(invokeResult) as Map<String, dynamic>;
@ -93,24 +97,6 @@ mixin ZanoWalletApi {
error('exception in parsing json in invokeMethod: $invokeResult');
rethrow;
}
int attempts = 0;
if (map['job_id'] != null) {
final jobId = map['job_id'] as int;
do {
await Future.delayed(Duration(milliseconds: attempts < 2 ? 100 : 500));
final result = zano.PlainWallet_tryPullResult(jobId);
try {
map = jsonDecode(result) as Map<String, dynamic>;
} catch (e) {
if (result.contains(Consts.errorWalletWrongId)) throw ZanoWalletException('Wrong wallet id');
error('exception in parsing json in invokeMethod: $result');
rethrow;
}
if (map['status'] != null && map['status'] == _statusDelivered && map['result'] != null) {
return result;
}
} while (++attempts < _maxInvokeAttempts);
}
return invokeResult;
}