Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -708,10 +726,17 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
),
);

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(),
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions scripts/app_config/templates/pubspec.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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%%
Expand Down
Loading