wrap hashTag in compute

This commit is contained in:
julian 2024-06-05 16:23:58 -06:00
parent df5988b48e
commit 04a24edaec
2 changed files with 19 additions and 6 deletions
lib/wallets/wallet
impl
wallet_mixin_interfaces

View file

@ -3,7 +3,6 @@ import 'dart:convert';
import 'dart:math';
import 'package:decimal/decimal.dart';
import 'package:flutter_libsparkmobile/flutter_libsparkmobile.dart';
import 'package:isar/isar.dart';
import '../../../db/sqlite/firo_cache.dart';
@ -429,11 +428,7 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
if (lTags?.isNotEmpty == true) {
final List<SparkCoin> usedCoins = [];
for (final tag in lTags!) {
final components = (tag as String).split(",");
final x = components[0].substring(1);
final y = components[1].substring(0, components[1].length - 1);
final hash = LibSpark.hashTag(x, y);
final hash = await hashTag(tag as String);
usedCoins.addAll(sparkCoins.where((e) => e.lTagHash == hash));
}

View file

@ -38,6 +38,16 @@ const OP_SPARKMINT = 0xd1;
const OP_SPARKSMINT = 0xd2;
const OP_SPARKSPEND = 0xd3;
/// top level function for use with [compute]
String _hashTag(String tag) {
final components = tag.split(",");
final x = components[0].substring(1);
final y = components[1].substring(0, components[1].length - 1);
final hash = LibSpark.hashTag(x, y);
return hash;
}
mixin SparkInterface<T extends ElectrumXCurrencyInterface>
on Bip39HDWallet<T>, ElectrumXInterface<T> {
String? _sparkChangeAddressCached;
@ -56,6 +66,14 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
}) =>
LibSpark.validateAddress(address: address, isTestNet: isTestNet);
Future<String> hashTag(String tag) async {
try {
return await compute(_hashTag, tag);
} catch (_) {
throw ArgumentError("Invalid tag string format", "tag");
}
}
@override
Future<void> init() async {
try {