From 831d1951c1cd03d954869a987b61d033463d549e Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 12 Feb 2024 14:58:40 -0600 Subject: [PATCH 01/10] add electrum_adapter as submodule, TODO replace with git ref when stable also replace sneurlax remote with cypherstack remote. is safe tho just trust me bro --- .gitmodules | 3 +++ electrum_adapter | 1 + pubspec.yaml | 2 ++ 3 files changed, 6 insertions(+) create mode 160000 electrum_adapter diff --git a/.gitmodules b/.gitmodules index 7474c8a54..92fc72b5e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "crypto_plugins/flutter_liblelantus"] path = crypto_plugins/flutter_liblelantus url = https://github.com/cypherstack/flutter_liblelantus.git +[submodule "electrum_adapter"] + path = electrum_adapter + url = https://github.com/cypherstack/electrum_adapter diff --git a/electrum_adapter b/electrum_adapter new file mode 160000 index 000000000..978404ced --- /dev/null +++ b/electrum_adapter @@ -0,0 +1 @@ +Subproject commit 978404cedadeb5f5670c2b2e1dfea595598614cc diff --git a/pubspec.yaml b/pubspec.yaml index df60947c5..f0f099737 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -173,6 +173,8 @@ dependencies: url: https://github.com/cypherstack/coinlib.git path: coinlib_flutter ref: 376d520b4516d4eb7c3f0bd4b1522f7769f3f2a7 + electrum_adapter: + path: electrum_adapter dev_dependencies: flutter_test: From 4147e357a8d4e2a110251819d5fea1014c86eb30 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 12 Feb 2024 16:30:45 -0600 Subject: [PATCH 02/10] 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: From 543b47497f6678730c57df1f873c20b3f33d783b Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 12 Feb 2024 16:36:27 -0600 Subject: [PATCH 03/10] Removed submodule electrum_adapter and update lock --- .gitmodules | 5 +---- electrum_adapter | 1 - pubspec.lock | 8 +++++--- pubspec.yaml | 4 +++- 4 files changed, 9 insertions(+), 9 deletions(-) delete mode 160000 electrum_adapter diff --git a/.gitmodules b/.gitmodules index 92fc72b5e..95b02e580 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,4 @@ url = https://github.com/cypherstack/flutter_libmonero.git [submodule "crypto_plugins/flutter_liblelantus"] path = crypto_plugins/flutter_liblelantus - url = https://github.com/cypherstack/flutter_liblelantus.git -[submodule "electrum_adapter"] - path = electrum_adapter - url = https://github.com/cypherstack/electrum_adapter + url = https://github.com/cypherstack/flutter_liblelantus.git \ No newline at end of file diff --git a/electrum_adapter b/electrum_adapter deleted file mode 160000 index 89dae750e..000000000 --- a/electrum_adapter +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 89dae750e1c9457c13db6a0103a48615154579e8 diff --git a/pubspec.lock b/pubspec.lock index 3506e1d2e..1f438f2bb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -527,9 +527,11 @@ packages: electrum_adapter: dependency: "direct main" description: - path: electrum_adapter - relative: true - source: path + path: "." + ref: "2bffd84753d2c37503d0626c1b74706f63bc91bf" + resolved-ref: "2bffd84753d2c37503d0626c1b74706f63bc91bf" + url: "https://github.com/cypherstack/electrum_adapter.git" + source: git version: "3.0.0" emojis: dependency: "direct main" diff --git a/pubspec.yaml b/pubspec.yaml index f0f099737..222a04801 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -174,7 +174,9 @@ dependencies: path: coinlib_flutter ref: 376d520b4516d4eb7c3f0bd4b1522f7769f3f2a7 electrum_adapter: - path: electrum_adapter + git: + url: https://github.com/cypherstack/electrum_adapter.git + ref: 2bffd84753d2c37503d0626c1b74706f63bc91bf dev_dependencies: flutter_test: From 2df0dff59cf3ef02ba193723f7ecb2061b5863f7 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 13 Feb 2024 00:03:30 -0600 Subject: [PATCH 04/10] update electrum_adapter ref to firo_testing branch --- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 1f438f2bb..3f7b34268 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -528,8 +528,8 @@ packages: dependency: "direct main" description: path: "." - ref: "2bffd84753d2c37503d0626c1b74706f63bc91bf" - resolved-ref: "2bffd84753d2c37503d0626c1b74706f63bc91bf" + ref: "89dae750e1c9457c13db6a0103a48615154579e8" + resolved-ref: "89dae750e1c9457c13db6a0103a48615154579e8" url: "https://github.com/cypherstack/electrum_adapter.git" source: git version: "3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 222a04801..010c703f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -176,7 +176,7 @@ dependencies: electrum_adapter: git: url: https://github.com/cypherstack/electrum_adapter.git - ref: 2bffd84753d2c37503d0626c1b74706f63bc91bf + ref: 89dae750e1c9457c13db6a0103a48615154579e8 dev_dependencies: flutter_test: From cd951f10cc17f78b6fc6c3fae78b7c76255a6516 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 13 Feb 2024 14:25:03 -0600 Subject: [PATCH 05/10] temporarily use electrum_adapter's firo branch for testing integration --- lib/electrumx_rpc/electrumx_client.dart | 5 +---- pubspec.lock | 20 ++++++-------------- pubspec.yaml | 4 ++-- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 4a32cd337..84ec11e8e 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -15,10 +15,7 @@ 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:electrum_adapter/methods/specific/firo.dart'; import 'package:event_bus/event_bus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_libsparkmobile/flutter_libsparkmobile.dart'; diff --git a/pubspec.lock b/pubspec.lock index 3f7b34268..fa92540a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -528,8 +528,8 @@ packages: dependency: "direct main" description: path: "." - ref: "89dae750e1c9457c13db6a0103a48615154579e8" - resolved-ref: "89dae750e1c9457c13db6a0103a48615154579e8" + ref: "9efe2af7fb39a40a17261f8050a65737b7a1618b" + resolved-ref: "9efe2af7fb39a40a17261f8050a65737b7a1618b" url: "https://github.com/cypherstack/electrum_adapter.git" source: git version: "3.0.0" @@ -683,10 +683,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 url: "https://pub.dev" source: hosted - version: "2.0.3" + version: "3.0.1" flutter_local_notifications: dependency: "direct main" description: @@ -1047,10 +1047,10 @@ packages: dependency: transitive description: name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "3.0.0" local_auth: dependency: "direct main" description: @@ -1267,14 +1267,6 @@ 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: diff --git a/pubspec.yaml b/pubspec.yaml index 010c703f5..416a02672 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -176,7 +176,7 @@ dependencies: electrum_adapter: git: url: https://github.com/cypherstack/electrum_adapter.git - ref: 89dae750e1c9457c13db6a0103a48615154579e8 + ref: 9efe2af7fb39a40a17261f8050a65737b7a1618b dev_dependencies: flutter_test: @@ -193,7 +193,7 @@ dev_dependencies: # lint: ^1.10.0 analyzer: ^5.13.0 import_sorter: ^4.6.0 - flutter_lints: ^2.0.1 + flutter_lints: ^3.0.1 isar_generator: 3.0.5 flutter_launcher_icons: From ceec698a44cc0dbe783b1521d4137805f863c439 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 13 Feb 2024 15:34:45 -0600 Subject: [PATCH 06/10] add lelantus electrum_adapter methods --- lib/electrumx_rpc/electrumx_client.dart | 54 +++++++++++++++++++++++++ pubspec.lock | 4 +- pubspec.yaml | 2 +- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 84ec11e8e..71a222543 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -799,6 +799,19 @@ class ElectrumXClient { String blockhash = "", String? requestID, }) async { + // Use electrum_adapter package's getSparkAnonymitySet method. + Logging.instance.log("attempting to fetch lelantus.getanonymityset...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + Map anonymitySet = await client.getLelantusAnonymitySet( + groupId: groupId, blockHash: blockhash); + Logging.instance.log("Fetching lelantus.getanonymityset finished", + level: LogLevel.Info); + return anonymitySet; + + /* + // Original ElectrumXClient: try { Logging.instance.log("attempting to fetch lelantus.getanonymityset...", level: LogLevel.Info); @@ -816,6 +829,7 @@ class ElectrumXClient { } catch (e) { rethrow; } + */ } //TODO add example to docs @@ -826,6 +840,18 @@ class ElectrumXClient { dynamic mints, String? requestID, }) async { + // Use electrum_adapter package's getLelantusMintData method. + Logging.instance.log("attempting to fetch lelantus.getmintmetadata...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + dynamic mintData = await client.getLelantusMintData(mints: mints); + Logging.instance.log("Fetching lelantus.getmintmetadata finished", + level: LogLevel.Info); + return mintData; + + /* + // Original ElectrumXClient: try { final response = await request( requestID: requestID, @@ -838,6 +864,7 @@ class ElectrumXClient { } catch (e) { rethrow; } + */ } //TODO add example to docs @@ -846,6 +873,19 @@ class ElectrumXClient { String? requestID, required int startNumber, }) async { + // Use electrum_adapter package's getLelantusUsedCoinSerials method. + Logging.instance.log("attempting to fetch lelantus.getusedcoinserials...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + Map usedCoinSerials = + await client.getLelantusUsedCoinSerials(startNumber: startNumber); + Logging.instance.log("Fetching lelantus.getusedcoinserials finished", + level: LogLevel.Info); + return usedCoinSerials; + + /* + // Original ElectrumXClient: try { int retryCount = 3; dynamic result; @@ -869,12 +909,25 @@ class ElectrumXClient { Logging.instance.log(e, level: LogLevel.Error); rethrow; } + */ } /// Returns the latest Lelantus set id /// /// ex: 1 Future getLelantusLatestCoinId({String? requestID}) async { + // Use electrum_adapter package's getLelantusLatestCoinId method. + Logging.instance.log("attempting to fetch lelantus.getlatestcoinid...", + level: LogLevel.Info); + var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var client = electrum_adapter.FiroElectrumClient(channel); + int latestCoinId = await client.getLatestCoinId(); + Logging.instance.log("Fetching lelantus.getlatestcoinid finished", + level: LogLevel.Info); + return latestCoinId; + + /* + // Original ElectrumXClient: try { final response = await request( requestID: requestID, @@ -885,6 +938,7 @@ class ElectrumXClient { Logging.instance.log(e, level: LogLevel.Error); rethrow; } + */ } // ============== Spark ====================================================== diff --git a/pubspec.lock b/pubspec.lock index fa92540a6..d376b9bd0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -528,8 +528,8 @@ packages: dependency: "direct main" description: path: "." - ref: "9efe2af7fb39a40a17261f8050a65737b7a1618b" - resolved-ref: "9efe2af7fb39a40a17261f8050a65737b7a1618b" + ref: "1c4962bf6fa8fe639be8540f8c61e89e625c7034" + resolved-ref: "1c4962bf6fa8fe639be8540f8c61e89e625c7034" url: "https://github.com/cypherstack/electrum_adapter.git" source: git version: "3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 416a02672..9dd0bc7d0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -176,7 +176,7 @@ dependencies: electrum_adapter: git: url: https://github.com/cypherstack/electrum_adapter.git - ref: 9efe2af7fb39a40a17261f8050a65737b7a1618b + ref: 1c4962bf6fa8fe639be8540f8c61e89e625c7034 dev_dependencies: flutter_test: From 13a50cdacedd3eccda72ba786ceaf5109f3c0d3c Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 13 Feb 2024 18:28:20 -0600 Subject: [PATCH 07/10] use electrum_adapter getTransaction --- lib/electrumx_rpc/electrumx_client.dart | 14 ++++++++++++++ pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 71a222543..34fc50a6d 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -743,6 +743,19 @@ class ElectrumXClient { bool verbose = true, String? requestID, }) async { + // Use electrum_adapter package's getTransaction method. + Logging.instance.log("attempting to fetch blockchain.transaction.get...", + level: LogLevel.Info); + var channel = + await electrum_adapter.connect(host, port: port); // TODO pass useSLL. + var client = electrum_adapter.ElectrumClient(channel, host, port); + dynamic response = await client.getTransaction(txHash); + Logging.instance.log("Fetching blockchain.transaction.get finished", + level: LogLevel.Info); + return Map.from(response as Map); + + /* + // Original ElectrumXClient: dynamic response; try { response = await request( @@ -778,6 +791,7 @@ class ElectrumXClient { level: LogLevel.Error); rethrow; } + */ } /// Returns the whole Lelantus anonymity set for denomination in the groupId. diff --git a/pubspec.lock b/pubspec.lock index d376b9bd0..53caba787 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -528,8 +528,8 @@ packages: dependency: "direct main" description: path: "." - ref: "1c4962bf6fa8fe639be8540f8c61e89e625c7034" - resolved-ref: "1c4962bf6fa8fe639be8540f8c61e89e625c7034" + ref: "72f5801f78b6e73165c44d349a514badf0ee0d78" + resolved-ref: "72f5801f78b6e73165c44d349a514badf0ee0d78" url: "https://github.com/cypherstack/electrum_adapter.git" source: git version: "3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 9dd0bc7d0..b8ad7f57d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -176,7 +176,7 @@ dependencies: electrum_adapter: git: url: https://github.com/cypherstack/electrum_adapter.git - ref: 1c4962bf6fa8fe639be8540f8c61e89e625c7034 + ref: 80d28a8b033af7bcf90cd6c7a3ee74160dc791a1 dev_dependencies: flutter_test: From af3e19476771d1260eed6d63cd08485b3897e0dc Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 13 Feb 2024 19:20:33 -0600 Subject: [PATCH 08/10] use electrum_adapter.getTransaction in cachedElectrumXClient, too --- lib/electrumx_rpc/cached_electrumx_client.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/electrumx_rpc/cached_electrumx_client.dart b/lib/electrumx_rpc/cached_electrumx_client.dart index 021bdf065..a92203cc4 100644 --- a/lib/electrumx_rpc/cached_electrumx_client.dart +++ b/lib/electrumx_rpc/cached_electrumx_client.dart @@ -11,6 +11,7 @@ import 'dart:convert'; import 'dart:math'; +import 'package:electrum_adapter/electrum_adapter.dart' as electrum_adapter; import 'package:stackwallet/db/hive/db.dart'; import 'package:stackwallet/electrumx_rpc/electrumx_client.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; @@ -188,8 +189,11 @@ class CachedElectrumXClient { final cachedTx = box.get(txHash) as Map?; if (cachedTx == null) { - final Map result = await electrumXClient - .getTransaction(txHash: txHash, verbose: verbose); + var channel = await electrum_adapter.connect(electrumXClient.host, + port: electrumXClient.port); // TODO pass useSLL. + var client = electrum_adapter.ElectrumClient( + channel, electrumXClient.host, electrumXClient.port); + final Map result = await client.getTransaction(txHash); result.remove("hex"); result.remove("lelantusData"); From c21af7196f736e2d383711b06b14e3ac531cd52a Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 13 Feb 2024 19:34:18 -0600 Subject: [PATCH 09/10] do not use hardcoded firo.stackwallet.com in order to support custom nodes. --- lib/electrumx_rpc/electrumx_client.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 34fc50a6d..520d7e245 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -816,7 +816,7 @@ class ElectrumXClient { // Use electrum_adapter package's getSparkAnonymitySet method. Logging.instance.log("attempting to fetch lelantus.getanonymityset...", level: LogLevel.Info); - var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var channel = await electrum_adapter.connect(host, port: port); var client = electrum_adapter.FiroElectrumClient(channel); Map anonymitySet = await client.getLelantusAnonymitySet( groupId: groupId, blockHash: blockhash); @@ -857,7 +857,7 @@ class ElectrumXClient { // Use electrum_adapter package's getLelantusMintData method. Logging.instance.log("attempting to fetch lelantus.getmintmetadata...", level: LogLevel.Info); - var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var channel = await electrum_adapter.connect(host, port: port); var client = electrum_adapter.FiroElectrumClient(channel); dynamic mintData = await client.getLelantusMintData(mints: mints); Logging.instance.log("Fetching lelantus.getmintmetadata finished", @@ -1103,7 +1103,7 @@ class ElectrumXClient { // 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 channel = await electrum_adapter.connect(host, port: port); var client = electrum_adapter.FiroElectrumClient(channel); int latestCoinId = await client.getSparkLatestCoinId(); Logging.instance.log("Fetching spark.getsparklatestcoinid finished", From 8fc2043910d132e8dd1a813ee8bed48cfdd8ce61 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Tue, 13 Feb 2024 19:47:26 -0600 Subject: [PATCH 10/10] new getFeeRate, add retry logic to usedCoinSerials, and comment cleanup --- lib/electrumx_rpc/electrumx_client.dart | 208 ++---------------- .../electrumx_interface.dart | 2 + pubspec.lock | 4 +- pubspec.yaml | 2 +- 4 files changed, 24 insertions(+), 192 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 520d7e245..dcbc47568 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -743,7 +743,6 @@ class ElectrumXClient { bool verbose = true, String? requestID, }) async { - // Use electrum_adapter package's getTransaction method. Logging.instance.log("attempting to fetch blockchain.transaction.get...", level: LogLevel.Info); var channel = @@ -752,46 +751,12 @@ class ElectrumXClient { dynamic response = await client.getTransaction(txHash); Logging.instance.log("Fetching blockchain.transaction.get finished", level: LogLevel.Info); - return Map.from(response as Map); - /* - // Original ElectrumXClient: - dynamic response; - try { - response = await request( - requestID: requestID, - command: 'blockchain.transaction.get', - args: [ - txHash, - verbose, - ], - ); - if (!verbose) { - return {"rawtx": response["result"] as String}; - } - - if (response is! Map) { - final String msg = "getTransaction($txHash) returned a non-Map response" - " of type ${response.runtimeType}.\nResponse: $response"; - Logging.instance.log(msg, level: LogLevel.Fatal); - throw Exception(msg); - } - - if (response["result"] == null) { - final String msg = "getTransaction($txHash) returned null result." - "\nResponse: $response"; - Logging.instance.log(msg, level: LogLevel.Fatal); - throw Exception(msg); - } - return Map.from(response["result"] as Map); - } catch (e, s) { - Logging.instance.log( - "getTransaction($txHash) response: $response" - "\nError: $e\nStack trace: $s", - level: LogLevel.Error); - rethrow; + if (!verbose) { + return {"rawtx": response as String}; } - */ + + return Map.from(response as Map); } /// Returns the whole Lelantus anonymity set for denomination in the groupId. @@ -813,7 +778,6 @@ class ElectrumXClient { String blockhash = "", String? requestID, }) async { - // Use electrum_adapter package's getSparkAnonymitySet method. Logging.instance.log("attempting to fetch lelantus.getanonymityset...", level: LogLevel.Info); var channel = await electrum_adapter.connect(host, port: port); @@ -823,27 +787,6 @@ class ElectrumXClient { Logging.instance.log("Fetching lelantus.getanonymityset finished", level: LogLevel.Info); return anonymitySet; - - /* - // Original ElectrumXClient: - try { - Logging.instance.log("attempting to fetch lelantus.getanonymityset...", - level: LogLevel.Info); - final response = await request( - requestID: requestID, - command: 'lelantus.getanonymityset', - args: [ - groupId, - blockhash, - ], - ); - Logging.instance.log("Fetching lelantus.getanonymityset finished", - level: LogLevel.Info); - return Map.from(response["result"] as Map); - } catch (e) { - rethrow; - } - */ } //TODO add example to docs @@ -854,7 +797,6 @@ class ElectrumXClient { dynamic mints, String? requestID, }) async { - // Use electrum_adapter package's getLelantusMintData method. Logging.instance.log("attempting to fetch lelantus.getmintmetadata...", level: LogLevel.Info); var channel = await electrum_adapter.connect(host, port: port); @@ -863,22 +805,6 @@ class ElectrumXClient { Logging.instance.log("Fetching lelantus.getmintmetadata finished", level: LogLevel.Info); return mintData; - - /* - // Original ElectrumXClient: - try { - final response = await request( - requestID: requestID, - command: 'lelantus.getmintmetadata', - args: [ - mints, - ], - ); - return response["result"]; - } catch (e) { - rethrow; - } - */ } //TODO add example to docs @@ -887,50 +813,31 @@ class ElectrumXClient { String? requestID, required int startNumber, }) async { - // Use electrum_adapter package's getLelantusUsedCoinSerials method. Logging.instance.log("attempting to fetch lelantus.getusedcoinserials...", level: LogLevel.Info); var channel = await electrum_adapter.connect('firo.stackwallet.com'); var client = electrum_adapter.FiroElectrumClient(channel); - Map usedCoinSerials = - await client.getLelantusUsedCoinSerials(startNumber: startNumber); - Logging.instance.log("Fetching lelantus.getusedcoinserials finished", - level: LogLevel.Info); - return usedCoinSerials; - /* - // Original ElectrumXClient: - try { - int retryCount = 3; - dynamic result; + int retryCount = 3; + dynamic usedCoinSerials; - while (retryCount > 0 && result is! List) { - final response = await request( - requestID: requestID, - command: 'lelantus.getusedcoinserials', - args: [ - "$startNumber", - ], - requestTimeout: const Duration(minutes: 2), - ); + while (retryCount > 0 && usedCoinSerials is! List) { + usedCoinSerials = + await client.getLelantusUsedCoinSerials(startNumber: startNumber); + // TODO add 2 minute timeout. + Logging.instance.log("Fetching lelantus.getusedcoinserials finished", + level: LogLevel.Info); - result = response["result"]; - retryCount--; - } - - return Map.from(result as Map); - } catch (e) { - Logging.instance.log(e, level: LogLevel.Error); - rethrow; + retryCount--; } - */ + + return Map.from(usedCoinSerials as Map); } /// Returns the latest Lelantus set id /// /// ex: 1 Future getLelantusLatestCoinId({String? requestID}) async { - // Use electrum_adapter package's getLelantusLatestCoinId method. Logging.instance.log("attempting to fetch lelantus.getlatestcoinid...", level: LogLevel.Info); var channel = await electrum_adapter.connect('firo.stackwallet.com'); @@ -939,20 +846,6 @@ class ElectrumXClient { Logging.instance.log("Fetching lelantus.getlatestcoinid finished", level: LogLevel.Info); return latestCoinId; - - /* - // Original ElectrumXClient: - try { - final response = await request( - requestID: requestID, - command: 'lelantus.getlatestcoinid', - ); - return response["result"] as int; - } catch (e) { - Logging.instance.log(e, level: LogLevel.Error); - rethrow; - } - */ } // ============== Spark ====================================================== @@ -976,7 +869,6 @@ 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'); @@ -986,23 +878,6 @@ class ElectrumXClient { 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( - requestID: requestID, - command: 'spark.getsparkanonymityset', - args: [ - coinGroupId, - startBlockHash, - ], - ); - Logging.instance.log("Fetching spark.getsparkanonymityset finished", - level: LogLevel.Info); - return Map.from(response["result"] as Map); - */ } catch (e) { rethrow; } @@ -1022,26 +897,12 @@ class ElectrumXClient { var client = electrum_adapter.FiroElectrumClient(channel); Map usedCoinsTags = await client.getUsedCoinsTags(startNumber: startNumber); + // TODO: Add 2 minute timeout. 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', - args: [ - "$startNumber", - ], - requestTimeout: const Duration(minutes: 2), - ); - 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; @@ -1063,7 +924,6 @@ 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'); @@ -1073,20 +933,6 @@ class ElectrumXClient { 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', - args: [ - { - "coinHashes": sparkCoinHashes, - }, - ], - ); - return List>.from(response["result"] as List); - */ } catch (e) { Logging.instance.log(e, level: LogLevel.Error); rethrow; @@ -1100,7 +946,6 @@ 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(host, port: port); @@ -1109,15 +954,6 @@ class ElectrumXClient { 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; @@ -1134,15 +970,9 @@ class ElectrumXClient { /// "rate": 1000, /// } Future> getFeeRate({String? requestID}) async { - try { - final response = await request( - requestID: requestID, - command: 'blockchain.getfeerate', - ); - return Map.from(response["result"] as Map); - } catch (e) { - rethrow; - } + var channel = await electrum_adapter.connect(host, port: port); + var client = electrum_adapter.FiroElectrumClient(channel); + return await client.getFeeRate(); } /// Return the estimated transaction fee per kilobyte for a transaction to be confirmed within a certain number of [blocks]. diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart index 6a044ff15..61fc9345b 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart @@ -1186,6 +1186,8 @@ mixin ElectrumXInterface on Bip39HDWallet { coin: cryptoCurrency.coin, ); + print("txn: $txn"); + final vout = jsonUTXO["tx_pos"] as int; final outputs = txn["vout"] as List; diff --git a/pubspec.lock b/pubspec.lock index 53caba787..b87faa62d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -528,8 +528,8 @@ packages: dependency: "direct main" description: path: "." - ref: "72f5801f78b6e73165c44d349a514badf0ee0d78" - resolved-ref: "72f5801f78b6e73165c44d349a514badf0ee0d78" + ref: dd443e293feb3b37eb494ab7c8dadef9205de14c + resolved-ref: dd443e293feb3b37eb494ab7c8dadef9205de14c url: "https://github.com/cypherstack/electrum_adapter.git" source: git version: "3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index b8ad7f57d..1534b95a8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -176,7 +176,7 @@ dependencies: electrum_adapter: git: url: https://github.com/cypherstack/electrum_adapter.git - ref: 80d28a8b033af7bcf90cd6c7a3ee74160dc791a1 + ref: dd443e293feb3b37eb494ab7c8dadef9205de14c dev_dependencies: flutter_test: