mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-18 08:34:31 +00:00
spark mempool electrumx calls
This commit is contained in:
parent
dcdad38ec7
commit
2ada78e4b0
1 changed files with 33 additions and 10 deletions
|
@ -26,12 +26,20 @@ import '../services/event_bus/events/global/tor_status_changed_event.dart';
|
||||||
import '../services/event_bus/global_event_bus.dart';
|
import '../services/event_bus/global_event_bus.dart';
|
||||||
import '../services/tor_service.dart';
|
import '../services/tor_service.dart';
|
||||||
import '../utilities/amount/amount.dart';
|
import '../utilities/amount/amount.dart';
|
||||||
|
import '../utilities/extensions/impl/string.dart';
|
||||||
import '../utilities/logger.dart';
|
import '../utilities/logger.dart';
|
||||||
import '../utilities/prefs.dart';
|
import '../utilities/prefs.dart';
|
||||||
import '../wallets/crypto_currency/crypto_currency.dart';
|
import '../wallets/crypto_currency/crypto_currency.dart';
|
||||||
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
|
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
|
||||||
import 'client_manager.dart';
|
import 'client_manager.dart';
|
||||||
|
|
||||||
|
typedef SparkMempoolData = ({
|
||||||
|
String txid,
|
||||||
|
List<String> serialContext,
|
||||||
|
List<String> lTags,
|
||||||
|
List<String> coins,
|
||||||
|
});
|
||||||
|
|
||||||
class WifiOnlyException implements Exception {}
|
class WifiOnlyException implements Exception {}
|
||||||
|
|
||||||
class ElectrumXNode {
|
class ElectrumXNode {
|
||||||
|
@ -1038,10 +1046,9 @@ class ElectrumXClient {
|
||||||
command: "spark.getmempooltxids",
|
command: "spark.getmempooltxids",
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO verify once server is live
|
final txids = List<String>.from(response as List)
|
||||||
final txids = List<String>.from(response as List).toSet();
|
.map((e) => e.toHexReversedFromBase64)
|
||||||
// final map = Map<String, dynamic>.from(response as Map);
|
.toSet();
|
||||||
// final txids = List<String>.from(map["tags"] as List).toSet();
|
|
||||||
|
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"Finished ElectrumXClient.getMempoolTxids(). "
|
"Finished ElectrumXClient.getMempoolTxids(). "
|
||||||
|
@ -1057,7 +1064,7 @@ class ElectrumXClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the txids of the current transactions found in the mempool
|
/// Returns the txids of the current transactions found in the mempool
|
||||||
Future<Map<String, dynamic>> getMempoolSparkData({
|
Future<List<SparkMempoolData>> getMempoolSparkData({
|
||||||
String? requestID,
|
String? requestID,
|
||||||
required List<String> txids,
|
required List<String> txids,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -1066,11 +1073,27 @@ class ElectrumXClient {
|
||||||
final response = await request(
|
final response = await request(
|
||||||
requestID: requestID,
|
requestID: requestID,
|
||||||
command: "spark.getmempooltxs",
|
command: "spark.getmempooltxs",
|
||||||
args: txids,
|
args: [
|
||||||
|
{
|
||||||
|
"txids": txids,
|
||||||
|
},
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO verify once server is live
|
|
||||||
final map = Map<String, dynamic>.from(response as Map);
|
final map = Map<String, dynamic>.from(response as Map);
|
||||||
|
final List<SparkMempoolData> result = [];
|
||||||
|
for (final entry in map.entries) {
|
||||||
|
result.add(
|
||||||
|
(
|
||||||
|
txid: entry.key,
|
||||||
|
serialContext:
|
||||||
|
List<String>.from(entry.value["Serial_context"] as List),
|
||||||
|
// the space after lTags is required lol
|
||||||
|
lTags: List<String>.from(entry.value["lTags "] as List),
|
||||||
|
coins: List<String>.from(entry.value["Coins"] as List),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"Finished ElectrumXClient.getMempoolSparkData(txids: $txids). "
|
"Finished ElectrumXClient.getMempoolSparkData(txids: $txids). "
|
||||||
|
@ -1078,9 +1101,9 @@ class ElectrumXClient {
|
||||||
level: LogLevel.Info,
|
level: LogLevel.Info,
|
||||||
);
|
);
|
||||||
|
|
||||||
return map;
|
return result;
|
||||||
} catch (e) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(e, level: LogLevel.Error);
|
Logging.instance.log("$e\n$s", level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue