From ca52f39cc2166465fa4718c2c21a9ccd53aaffa8 Mon Sep 17 00:00:00 2001 From: Reuben Yap Date: Sat, 4 Jul 2026 00:24:03 +0800 Subject: [PATCH] Fix Spark Name registration format --- .../spark_interface.dart | 27 ++++++++++++++++++- pubspec.lock | 6 ++--- .../templates/pubspec.template.yaml | 4 +-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart index fcf753fd6a..eaf82f4d25 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart @@ -4,6 +4,7 @@ import 'dart:isolate'; import 'dart:math'; import 'package:bitcoindart/bitcoindart.dart' as btc; +import 'package:bitcoindart/src/utils/script.dart' as bscript; import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib; import 'package:decimal/decimal.dart'; import 'package:flutter/foundation.dart'; @@ -50,6 +51,8 @@ const SPARK_OUT_LIMIT_PER_TX = 16; const OP_SPARKMINT = 0xd1; const OP_SPARKSMINT = 0xd2; const OP_SPARKSPEND = 0xd3; +const OP_SPARKNAMEID = 0xe1; +const OP_DROP = 0x75; /// top level function for use with [compute] String _hashTag(String tag) { @@ -61,6 +64,21 @@ String _hashTag(String tag) { return hash; } +Uint8List _sparkNameFeeScript({ + required Uint8List baseScript, + required String name, + required String sparkAddress, +}) => Uint8List.fromList([ + ...baseScript, + ...bscript.compile([ + OP_SPARKNAMEID, + Uint8List.fromList(utf8.encode(name)), + OP_DROP, + Uint8List.fromList(utf8.encode(sparkAddress)), + OP_DROP, + ]), +]); + void initSparkLogging(Level level) => libSpark.initSparkLogging(level); abstract class _SparkIsolate { @@ -708,10 +726,17 @@ mixin SparkInterface ), ); - final scriptPubKey = btc.Address.addressToOutputScript( + var scriptPubKey = btc.Address.addressToOutputScript( txData.recipients![i].address, _bitcoinDartNetwork, ); + if (txData.sparkNameInfo != null) { + scriptPubKey = _sparkNameFeeScript( + baseScript: scriptPubKey, + name: txData.sparkNameInfo!.name, + sparkAddress: txData.sparkNameInfo!.sparkAddress.value, + ); + } txb.addOutput( scriptPubKey, recipientsWithFeeSubtracted[i].amount.raw.toInt(), diff --git a/pubspec.lock b/pubspec.lock index 091d58a6f0..1baec63d48 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1028,9 +1028,9 @@ packages: dependency: "direct main" description: path: "." - ref: "4bd84c88e1b2a817a2604ec53030634cc3304bc7" - resolved-ref: "4bd84c88e1b2a817a2604ec53030634cc3304bc7" - url: "https://github.com/cypherstack/flutter_libsparkmobile.git" + ref: "171bc186663e3c7a573a6240f28f430e8d6b7d50" + resolved-ref: "171bc186663e3c7a573a6240f28f430e8d6b7d50" + url: "https://github.com/firoorg/flutter_libsparkmobile.git" source: git version: "0.1.0" flutter_lints: diff --git a/scripts/app_config/templates/pubspec.template.yaml b/scripts/app_config/templates/pubspec.template.yaml index 6764428fac..7ebc0b24c0 100644 --- a/scripts/app_config/templates/pubspec.template.yaml +++ b/scripts/app_config/templates/pubspec.template.yaml @@ -43,8 +43,8 @@ dependencies: # %%ENABLE_FIRO%% # flutter_libsparkmobile: # git: -# url: https://github.com/cypherstack/flutter_libsparkmobile.git -# ref: 4bd84c88e1b2a817a2604ec53030634cc3304bc7 +# url: https://github.com/firoorg/flutter_libsparkmobile.git +# ref: 171bc186663e3c7a573a6240f28f430e8d6b7d50 # %%END_ENABLE_FIRO%% # %%ENABLE_EPIC%%