mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
non batched tx history fetching if server doesn't support batching
This commit is contained in:
parent
9c5c0cb179
commit
9df5bc4f36
1 changed files with 50 additions and 27 deletions
|
@ -936,10 +936,12 @@ class ECashWallet extends CoinServiceAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Map<String, dynamic>>> _fetchHistory(
|
Future<List<Map<String, dynamic>>> _fetchHistory(
|
||||||
List<String> allAddresses) async {
|
List<String> allAddresses,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
List<Map<String, dynamic>> allTxHashes = [];
|
List<Map<String, dynamic>> allTxHashes = [];
|
||||||
|
|
||||||
|
if (serverCanBatch) {
|
||||||
final Map<int, Map<String, List<dynamic>>> batches = {};
|
final Map<int, Map<String, List<dynamic>>> batches = {};
|
||||||
final Map<String, String> requestIdToAddressMap = {};
|
final Map<String, String> requestIdToAddressMap = {};
|
||||||
const batchSizeMax = 100;
|
const batchSizeMax = 100;
|
||||||
|
@ -948,12 +950,14 @@ class ECashWallet extends CoinServiceAPI
|
||||||
if (batches[batchNumber] == null) {
|
if (batches[batchNumber] == null) {
|
||||||
batches[batchNumber] = {};
|
batches[batchNumber] = {};
|
||||||
}
|
}
|
||||||
final scripthash =
|
final scriptHash = AddressUtils.convertToScriptHash(
|
||||||
AddressUtils.convertToScriptHash(allAddresses[i], _network);
|
allAddresses[i],
|
||||||
|
_network,
|
||||||
|
);
|
||||||
final id = Logger.isTestEnv ? "$i" : const Uuid().v1();
|
final id = Logger.isTestEnv ? "$i" : const Uuid().v1();
|
||||||
requestIdToAddressMap[id] = allAddresses[i];
|
requestIdToAddressMap[id] = allAddresses[i];
|
||||||
batches[batchNumber]!.addAll({
|
batches[batchNumber]!.addAll({
|
||||||
id: [scripthash]
|
id: [scriptHash]
|
||||||
});
|
});
|
||||||
if (i % batchSizeMax == batchSizeMax - 1) {
|
if (i % batchSizeMax == batchSizeMax - 1) {
|
||||||
batchNumber++;
|
batchNumber++;
|
||||||
|
@ -972,6 +976,25 @@ class ECashWallet extends CoinServiceAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < allAddresses.length; i++) {
|
||||||
|
final scriptHash = AddressUtils.convertToScriptHash(
|
||||||
|
allAddresses[i],
|
||||||
|
_network,
|
||||||
|
);
|
||||||
|
|
||||||
|
final response = await electrumXClient.getHistory(
|
||||||
|
scripthash: scriptHash,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int j = 0; j < response.length; j++) {
|
||||||
|
response[j]["address"] = allAddresses[i];
|
||||||
|
if (!allTxHashes.contains(response[j])) {
|
||||||
|
allTxHashes.add(response[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allTxHashes;
|
return allTxHashes;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
|
|
Loading…
Reference in a new issue