mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-02-02 03:06:35 +00:00
move async call to a synchronouse one
This commit is contained in:
parent
013144c919
commit
09b02f9b0b
1 changed files with 5 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue