mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 12:44:31 +00:00
WIP spark spend progress
This commit is contained in:
parent
f61acd90b7
commit
d132116282
3 changed files with 28 additions and 23 deletions
|
@ -625,7 +625,9 @@ class _ConfirmTransactionViewState
|
|||
),
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final amount = widget.txData.amount!;
|
||||
// TODO: [prio=high] spark transaction specifics - better handling
|
||||
final amount = widget.txData.amount ??
|
||||
widget.txData.amountSpark!;
|
||||
final externalCalls = ref.watch(
|
||||
prefsChangeNotifierProvider.select(
|
||||
(value) => value.externalCalls));
|
||||
|
@ -723,9 +725,12 @@ class _ConfirmTransactionViewState
|
|||
height: 2,
|
||||
),
|
||||
SelectableText(
|
||||
// TODO: [prio=high] spark transaction specifics - better handling
|
||||
widget.isPaynymTransaction
|
||||
? widget.txData.paynymAccountLite!.nymName
|
||||
: widget.txData.recipients!.first.address,
|
||||
: widget.txData.recipients?.first.address ??
|
||||
widget.txData.sparkRecipients!.first
|
||||
.address,
|
||||
style: STextStyles.desktopTextExtraExtraSmall(
|
||||
context)
|
||||
.copyWith(
|
||||
|
@ -1072,7 +1077,9 @@ class _ConfirmTransactionViewState
|
|||
Builder(builder: (context) {
|
||||
final fee = widget.txData.fee!;
|
||||
|
||||
final amount = widget.txData.amount!;
|
||||
// TODO: [prio=high] spark transaction specifics - better handling
|
||||
final amount =
|
||||
widget.txData.amount ?? widget.txData.amountSpark!;
|
||||
return SelectableText(
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
|
|
|
@ -103,6 +103,13 @@ class TxData {
|
|||
.reduce((total, amount) => total += amount)
|
||||
: null;
|
||||
|
||||
Amount? get amountSpark =>
|
||||
sparkRecipients != null && sparkRecipients!.isNotEmpty
|
||||
? sparkRecipients!
|
||||
.map((e) => e.amount)
|
||||
.reduce((total, amount) => total += amount)
|
||||
: null;
|
||||
|
||||
int? get estimatedSatsPerVByte => fee != null && vSize != null
|
||||
? (fee!.raw ~/ BigInt.from(vSize!)).toInt()
|
||||
: null;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:bitcoindart/bitcoindart.dart' as btc;
|
||||
import 'package:bitcoindart/src/utils/script.dart' as bscript;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_libsparkmobile/flutter_libsparkmobile.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
|
@ -118,6 +117,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
|
|||
Future<TxData> prepareSendSpark({
|
||||
required TxData txData,
|
||||
}) async {
|
||||
// fetch spendable spark coins
|
||||
final coins = await mainDB.isar.sparkCoins
|
||||
.where()
|
||||
.walletIdEqualToAnyLTagHash(walletId)
|
||||
|
@ -127,6 +127,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
|
|||
.heightIsNotNull()
|
||||
.findAll();
|
||||
|
||||
// prepare coin data for ffi
|
||||
final serializedCoins = coins
|
||||
.map((e) => (
|
||||
serializedCoin: e.serializedCoinB64!,
|
||||
|
@ -366,18 +367,6 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
|
|||
|
||||
// inputs
|
||||
|
||||
final opReturnScript = bscript.compile([
|
||||
0xd3, // OP_SPARKSPEND
|
||||
Uint8List(0),
|
||||
]);
|
||||
|
||||
txb.addInput(
|
||||
'0000000000000000000000000000000000000000000000000000000000000000',
|
||||
0xffffffff,
|
||||
0xffffffff,
|
||||
opReturnScript,
|
||||
);
|
||||
|
||||
// final sig = extractedTx.getId();
|
||||
|
||||
// for (final coin in estimated.coins) {
|
||||
|
@ -404,18 +393,20 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
|
|||
.toList(),
|
||||
);
|
||||
|
||||
print("SPARK SPEND ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
print("fee: ${spend.fee}");
|
||||
print("spend: ${spend.serializedSpendPayload}");
|
||||
print("scripts:");
|
||||
spend.outputScripts.forEach(print);
|
||||
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
|
||||
for (final outputScript in spend.outputScripts) {
|
||||
txb.addOutput(outputScript, 0);
|
||||
}
|
||||
|
||||
final extractedTx = txb.buildIncomplete();
|
||||
|
||||
extractedTx.addInput(
|
||||
'0000000000000000000000000000000000000000000000000000000000000000'
|
||||
.toUint8ListFromHex,
|
||||
0xffffffff,
|
||||
0xffffffff,
|
||||
"d3".toUint8ListFromHex, // OP_SPARKSPEND
|
||||
);
|
||||
|
||||
extractedTx.setPayload(spend.serializedSpendPayload);
|
||||
final rawTxHex = extractedTx.toHex();
|
||||
|
||||
|
|
Loading…
Reference in a new issue