From 4147e357a8d4e2a110251819d5fea1014c86eb30 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 12 Feb 2024 16:30:45 -0600 Subject: [PATCH] use electrum_adapter package methods for all spark calls add spark methods and tests, remove some Ravencoin references and use cypherstack remote. much trust, veryfy --- electrum_adapter | 2 +- lib/electrumx_rpc/electrumx_client.dart | 62 +++++++++++++++++++++++++ pubspec.lock | 15 ++++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/electrum_adapter b/electrum_adapter index 978404ced..89dae750e 160000 --- a/electrum_adapter +++ b/electrum_adapter @@ -1 +1 @@ -Subproject commit 978404cedadeb5f5670c2b2e1dfea595598614cc +Subproject commit 89dae750e1c9457c13db6a0103a48615154579e8 diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 931c9334f..4a32cd337 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -14,6 +14,11 @@ import 'dart:io'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:decimal/decimal.dart'; +import 'package:electrum_adapter/electrum_adapter.dart' as electrum_adapter; +import 'package:electrum_adapter/methods/spark/get_spark_anonymity_set.dart'; +import 'package:electrum_adapter/methods/spark/get_spark_latest_coin_id.dart'; +import 'package:electrum_adapter/methods/spark/get_spark_mint_meta_data.dart'; +import 'package:electrum_adapter/methods/spark/get_used_coins_tags.dart'; import 'package:event_bus/event_bus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_libsparkmobile/flutter_libsparkmobile.dart'; @@ -906,6 +911,19 @@ class ElectrumXClient { String? requestID, }) async { try { + // Use electrum_adapter package's getSparkAnonymitySet method. + Logging.instance.log("attempting to fetch spark.getsparkanonymityset...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + Map anonymitySet = await client.getSparkAnonymitySet( + coinGroupId: coinGroupId, startBlockHash: startBlockHash); + Logging.instance.log("Fetching spark.getsparkanonymityset finished", + level: LogLevel.Info); + return anonymitySet; + + /* + // Original ElectrumXClient: Logging.instance.log("attempting to fetch spark.getsparkanonymityset...", level: LogLevel.Info); final response = await request( @@ -919,6 +937,7 @@ class ElectrumXClient { Logging.instance.log("Fetching spark.getsparkanonymityset finished", level: LogLevel.Info); return Map.from(response["result"] as Map); + */ } catch (e) { rethrow; } @@ -931,6 +950,21 @@ class ElectrumXClient { required int startNumber, }) async { try { + // Use electrum_adapter package's getSparkUsedCoinsTags method. + Logging.instance.log("attempting to fetch spark.getusedcoinstags...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + Map usedCoinsTags = + await client.getUsedCoinsTags(startNumber: startNumber); + Logging.instance.log("Fetching spark.getusedcoinstags finished", + level: LogLevel.Info); + final map = Map.from(usedCoinsTags); + final set = Set.from(map["tags"] as List); + return await compute(_ffiHashTagsComputeWrapper, set); + + /* + // Original ElectrumXClient: final response = await request( requestID: requestID, command: 'spark.getusedcoinstags', @@ -942,6 +976,7 @@ class ElectrumXClient { final map = Map.from(response["result"] as Map); final set = Set.from(map["tags"] as List); return await compute(_ffiHashTagsComputeWrapper, set); + */ } catch (e) { Logging.instance.log(e, level: LogLevel.Error); rethrow; @@ -963,6 +998,19 @@ class ElectrumXClient { required List sparkCoinHashes, }) async { try { + // Use electrum_adapter package's getSparkMintMetaData method. + Logging.instance.log("attempting to fetch spark.getsparkmintmetadata...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + List mintMetaData = + await client.getSparkMintMetaData(sparkCoinHashes: sparkCoinHashes); + Logging.instance.log("Fetching spark.getsparkmintmetadata finished", + level: LogLevel.Info); + return List>.from(mintMetaData); + + /* + // Original ElectrumXClient: final response = await request( requestID: requestID, command: 'spark.getsparkmintmetadata', @@ -973,6 +1021,7 @@ class ElectrumXClient { ], ); return List>.from(response["result"] as List); + */ } catch (e) { Logging.instance.log(e, level: LogLevel.Error); rethrow; @@ -986,11 +1035,24 @@ class ElectrumXClient { String? requestID, }) async { try { + // Use electrum_adapter package's getSparkLatestCoinId method. + Logging.instance.log("attempting to fetch spark.getsparklatestcoinid...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + int latestCoinId = await client.getSparkLatestCoinId(); + Logging.instance.log("Fetching spark.getsparklatestcoinid finished", + level: LogLevel.Info); + return latestCoinId; + + /* + // Original ElectrumXClient: final response = await request( requestID: requestID, command: 'spark.getsparklatestcoinid', ); return response["result"] as int; + */ } catch (e) { Logging.instance.log(e, level: LogLevel.Error); rethrow; diff --git a/pubspec.lock b/pubspec.lock index 840efc472..3506e1d2e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -524,6 +524,13 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" + electrum_adapter: + dependency: "direct main" + description: + path: electrum_adapter + relative: true + source: path + version: "3.0.0" emojis: dependency: "direct main" description: @@ -1258,6 +1265,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.1" + pedantic: + dependency: transitive + description: + name: pedantic + sha256: "67fc27ed9639506c856c840ccce7594d0bdcd91bc8d53d6e52359449a1d50602" + url: "https://pub.dev" + source: hosted + version: "1.11.1" permission_handler: dependency: "direct main" description: