mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-08 19:59:29 +00:00
fetch server cached anonymity sets for huge increase in firo restore speed
This commit is contained in:
parent
f92209c3a5
commit
1e89f4e58b
2 changed files with 24 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/hive/db.dart';
|
||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.dart';
|
||||
|
@ -59,6 +60,20 @@ class CachedElectrumX {
|
|||
"setHash": "",
|
||||
"coins": <dynamic>[],
|
||||
};
|
||||
|
||||
// try up to 3 times
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final result = await getInitialAnonymitySetCache(groupId);
|
||||
if (result != null) {
|
||||
set["setHash"] = result["setHash"];
|
||||
set["blockHash"] = result["blockHash"];
|
||||
set["coins"] = result["coins"];
|
||||
Logging.instance.log(
|
||||
"Populated initial anon set cache for group $groupId",
|
||||
level: LogLevel.Info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set = Map<String, dynamic>.from(cachedSet);
|
||||
}
|
||||
|
|
|
@ -731,8 +731,10 @@ Future<void> _setTestnetWrapper(bool isTestnet) async {
|
|||
// setTestnet(isTestnet);
|
||||
}
|
||||
|
||||
Future<dynamic> getAnonymity(int groupID) async {
|
||||
Logging.instance.log("getAnonymity", level: LogLevel.Info);
|
||||
Future<Map<String, dynamic>?> getInitialAnonymitySetCache(
|
||||
String groupID,
|
||||
) async {
|
||||
Logging.instance.log("getInitialAnonymitySetCache", level: LogLevel.Info);
|
||||
final Client client = Client();
|
||||
try {
|
||||
final uri = Uri.parse("$kStackCommunityNodesEndpoint/getAnonymity");
|
||||
|
@ -743,26 +745,22 @@ Future<dynamic> getAnonymity(int groupID) async {
|
|||
body: jsonEncode({
|
||||
"jsonrpc": "2.0",
|
||||
"id": "0",
|
||||
'aset': groupID.toString(),
|
||||
'aset': groupID,
|
||||
}),
|
||||
);
|
||||
|
||||
// TODO: should the following be removed for security reasons in production?
|
||||
Logging.instance
|
||||
.log(anonSetResult.statusCode.toString(), level: LogLevel.Info);
|
||||
Logging.instance.log(anonSetResult.body.toString(), level: LogLevel.Info);
|
||||
final response = jsonDecode(anonSetResult.body.toString());
|
||||
if (response['status'] == 'success') {
|
||||
final anonResponse = jsonDecode(response['result'] as String);
|
||||
|
||||
Logging.instance.log(anonResponse, level: LogLevel.Info);
|
||||
return response;
|
||||
final setData = Map<String, dynamic>.from(anonResponse["result"] as Map);
|
||||
return setData;
|
||||
} else {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("$e $s", level: LogLevel.Error);
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue