mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-05 10:29:23 +00:00
Fix Bitcoin transactions not showing (#978)
* handle multiple responses coming in a single event * Add timeout for getting transaction info, to allow other transactions to be returned in case of any failure or network issue * Handle other cases of receiving multiple messages in the same response
This commit is contained in:
parent
d7fa9991e1
commit
bc432b1042
1 changed files with 51 additions and 37 deletions
|
@ -66,8 +66,30 @@ class ElectrumClient {
|
||||||
socket!.listen((Uint8List event) {
|
socket!.listen((Uint8List event) {
|
||||||
try {
|
try {
|
||||||
final msg = utf8.decode(event.toList());
|
final msg = utf8.decode(event.toList());
|
||||||
final response =
|
final messagesList = msg.split("\n");
|
||||||
json.decode(msg) as Map<String, dynamic>;
|
for (var message in messagesList) {
|
||||||
|
if (message.isEmpty) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_parseResponse(message);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e.toString());
|
||||||
|
}
|
||||||
|
}, onError: (Object error) {
|
||||||
|
print(error.toString());
|
||||||
|
unterminatedString = '';
|
||||||
|
_setIsConnected(false);
|
||||||
|
}, onDone: () {
|
||||||
|
unterminatedString = '';
|
||||||
|
_setIsConnected(false);
|
||||||
|
});
|
||||||
|
keepAlive();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _parseResponse(String message) {
|
||||||
|
try {
|
||||||
|
final response = json.decode(message) as Map<String, dynamic>;
|
||||||
_handleResponse(response);
|
_handleResponse(response);
|
||||||
} on FormatException catch (e) {
|
} on FormatException catch (e) {
|
||||||
final msg = e.message.toLowerCase();
|
final msg = e.message.toLowerCase();
|
||||||
|
@ -92,8 +114,7 @@ class ElectrumClient {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final source = utf8.decode(event.toList());
|
unterminatedString += message;
|
||||||
unterminatedString += source;
|
|
||||||
|
|
||||||
if (isJSONStringCorrect(unterminatedString)) {
|
if (isJSONStringCorrect(unterminatedString)) {
|
||||||
final response =
|
final response =
|
||||||
|
@ -105,13 +126,6 @@ class ElectrumClient {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e.toString());
|
print(e.toString());
|
||||||
}
|
}
|
||||||
}, onError: (Object error) {
|
|
||||||
print(error.toString());
|
|
||||||
_setIsConnected(false);
|
|
||||||
}, onDone: () {
|
|
||||||
_setIsConnected(false);
|
|
||||||
});
|
|
||||||
keepAlive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void keepAlive() {
|
void keepAlive() {
|
||||||
|
@ -217,7 +231,7 @@ class ElectrumClient {
|
||||||
|
|
||||||
Future<Map<String, dynamic>> getTransactionRaw(
|
Future<Map<String, dynamic>> getTransactionRaw(
|
||||||
{required String hash}) async =>
|
{required String hash}) async =>
|
||||||
call(method: 'blockchain.transaction.get', params: [hash, true])
|
callWithTimeout(method: 'blockchain.transaction.get', params: [hash, true], timeout: 10000)
|
||||||
.then((dynamic result) {
|
.then((dynamic result) {
|
||||||
if (result is Map<String, dynamic>) {
|
if (result is Map<String, dynamic>) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -228,7 +242,7 @@ class ElectrumClient {
|
||||||
|
|
||||||
Future<String> getTransactionHex(
|
Future<String> getTransactionHex(
|
||||||
{required String hash}) async =>
|
{required String hash}) async =>
|
||||||
call(method: 'blockchain.transaction.get', params: [hash, false])
|
callWithTimeout(method: 'blockchain.transaction.get', params: [hash, false], timeout: 10000)
|
||||||
.then((dynamic result) {
|
.then((dynamic result) {
|
||||||
if (result is String) {
|
if (result is String) {
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue