From 2ada78e4b025b45d58264246288a8d7610d9a162 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 14 Jun 2024 13:33:27 -0600 Subject: [PATCH] spark mempool electrumx calls --- lib/electrumx_rpc/electrumx_client.dart | 43 +++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 442281532..a49d7675a 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -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/tor_service.dart'; import '../utilities/amount/amount.dart'; +import '../utilities/extensions/impl/string.dart'; import '../utilities/logger.dart'; import '../utilities/prefs.dart'; import '../wallets/crypto_currency/crypto_currency.dart'; import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart'; import 'client_manager.dart'; +typedef SparkMempoolData = ({ + String txid, + List serialContext, + List lTags, + List coins, +}); + class WifiOnlyException implements Exception {} class ElectrumXNode { @@ -1038,10 +1046,9 @@ class ElectrumXClient { command: "spark.getmempooltxids", ); - // TODO verify once server is live - final txids = List.from(response as List).toSet(); - // final map = Map.from(response as Map); - // final txids = List.from(map["tags"] as List).toSet(); + final txids = List.from(response as List) + .map((e) => e.toHexReversedFromBase64) + .toSet(); Logging.instance.log( "Finished ElectrumXClient.getMempoolTxids(). " @@ -1057,7 +1064,7 @@ class ElectrumXClient { } /// Returns the txids of the current transactions found in the mempool - Future> getMempoolSparkData({ + Future> getMempoolSparkData({ String? requestID, required List txids, }) async { @@ -1066,11 +1073,27 @@ class ElectrumXClient { final response = await request( requestID: requestID, command: "spark.getmempooltxs", - args: txids, + args: [ + { + "txids": txids, + }, + ], ); - // TODO verify once server is live final map = Map.from(response as Map); + final List result = []; + for (final entry in map.entries) { + result.add( + ( + txid: entry.key, + serialContext: + List.from(entry.value["Serial_context"] as List), + // the space after lTags is required lol + lTags: List.from(entry.value["lTags "] as List), + coins: List.from(entry.value["Coins"] as List), + ), + ); + } Logging.instance.log( "Finished ElectrumXClient.getMempoolSparkData(txids: $txids). " @@ -1078,9 +1101,9 @@ class ElectrumXClient { level: LogLevel.Info, ); - return map; - } catch (e) { - Logging.instance.log(e, level: LogLevel.Error); + return result; + } catch (e, s) { + Logging.instance.log("$e\n$s", level: LogLevel.Error); rethrow; } }