Request timeout fix (#1584)
Some checks failed
Cache Dependencies / test (push) Has been cancelled

* always handle RequestFailedTimeoutException

* undo change that was for testing
This commit is contained in:
Matthew Fosse 2024-08-08 03:27:04 -07:00 committed by GitHub
parent 15d88e0f8d
commit ba433ef6f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -236,25 +236,37 @@ class ElectrumClient {
return [];
});
Future<Map<String, dynamic>> getTransactionRaw({required String hash}) async =>
callWithTimeout(method: 'blockchain.transaction.get', params: [hash, true], timeout: 10000)
.then((dynamic result) {
if (result is Map<String, dynamic>) {
return result;
}
Future<Map<String, dynamic>> getTransactionRaw({required String hash}) async {
try {
final result = await callWithTimeout(
method: 'blockchain.transaction.get', params: [hash, true], timeout: 10000);
if (result is Map<String, dynamic>) {
return result;
}
} on RequestFailedTimeoutException catch (_) {
return <String, dynamic>{};
} catch (e) {
print("getTransactionRaw: ${e.toString()}");
return <String, dynamic>{};
}
return <String, dynamic>{};
}
return <String, dynamic>{};
});
Future<String> getTransactionHex({required String hash}) async =>
callWithTimeout(method: 'blockchain.transaction.get', params: [hash, false], timeout: 10000)
.then((dynamic result) {
if (result is String) {
return result;
}
return '';
});
Future<String> getTransactionHex({required String hash}) async {
try {
final result = await callWithTimeout(
method: 'blockchain.transaction.get', params: [hash, false], timeout: 10000);
if (result is String) {
return result;
}
} on RequestFailedTimeoutException catch (_) {
return '';
} catch (e) {
print("getTransactionHex: ${e.toString()}");
return '';
}
return '';
}
Future<String> broadcastTransaction(
{required String transactionRaw,
@ -353,14 +365,21 @@ class ElectrumClient {
// "height": 520481,
// "hex": "00000020890208a0ae3a3892aa047c5468725846577cfcd9b512b50000000000000000005dc2b02f2d297a9064ee103036c14d678f9afc7e3d9409cf53fd58b82e938e8ecbeca05a2d2103188ce804c4"
// }
Future<int?> getCurrentBlockChainTip() =>
callWithTimeout(method: 'blockchain.headers.subscribe').then((result) {
if (result is Map<String, dynamic>) {
return result["height"] as int;
}
return null;
});
Future<int?> getCurrentBlockChainTip() async {
try {
final result = await callWithTimeout(method: 'blockchain.headers.subscribe');
if (result is Map<String, dynamic>) {
return result["height"] as int;
}
return null;
} on RequestFailedTimeoutException catch (_) {
return null;
} catch (e) {
print("getCurrentBlockChainTip: ${e.toString()}");
return null;
}
}
BehaviorSubject<Object>? chainTipSubscribe() {
_id += 1;