mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
notification tx absurd fees error fix when estimating a tx size
This commit is contained in:
parent
55ed68a89d
commit
6bb133c552
2 changed files with 250 additions and 213 deletions
|
@ -26,6 +26,7 @@ import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
|||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||
import 'package:stackwallet/widgets/rounded_container.dart';
|
||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class PaynymDetailsPopup extends ConsumerStatefulWidget {
|
||||
|
@ -102,6 +103,20 @@ class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
|
|||
_showInsufficientFundsInfo = true;
|
||||
});
|
||||
return;
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
canPop = true;
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => StackOkDialog(
|
||||
title: "Error",
|
||||
message: e.toString(),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
|
|
|
@ -398,6 +398,7 @@ mixin PaynymWalletInterface {
|
|||
int additionalOutputs = 0,
|
||||
List<UTXO>? utxos,
|
||||
}) async {
|
||||
try {
|
||||
final amountToSend = _dustLimitP2PKH;
|
||||
final List<UTXO> availableOutputs =
|
||||
utxos ?? await _db.getUTXOs(_walletId).findAll();
|
||||
|
@ -456,14 +457,18 @@ mixin PaynymWalletInterface {
|
|||
targetPaymentCodeString: targetPaymentCodeString,
|
||||
utxosToUse: utxoObjectsToUse,
|
||||
utxoSigningData: utxoSigningData,
|
||||
change: 0))
|
||||
change: 0,
|
||||
dustLimit:
|
||||
satoshisBeingUsed, // override amount to get around absurd fees error
|
||||
))
|
||||
.item2;
|
||||
|
||||
final int vSizeForWithChange = (await _createNotificationTx(
|
||||
targetPaymentCodeString: targetPaymentCodeString,
|
||||
utxosToUse: utxoObjectsToUse,
|
||||
utxoSigningData: utxoSigningData,
|
||||
change: satoshisBeingUsed - amountToSend))
|
||||
change: satoshisBeingUsed - amountToSend,
|
||||
))
|
||||
.item2;
|
||||
|
||||
// Assume 2 outputs, for recipient and payment code script
|
||||
|
@ -494,7 +499,8 @@ mixin PaynymWalletInterface {
|
|||
|
||||
// check estimates are correct and build notification tx
|
||||
if (changeAmount >= _dustLimitP2PKH &&
|
||||
satoshisBeingUsed - amountToSend - changeAmount == feeForWithChange) {
|
||||
satoshisBeingUsed - amountToSend - changeAmount ==
|
||||
feeForWithChange) {
|
||||
var txn = await _createNotificationTx(
|
||||
targetPaymentCodeString: targetPaymentCodeString,
|
||||
utxosToUse: utxoObjectsToUse,
|
||||
|
@ -579,6 +585,9 @@ mixin PaynymWalletInterface {
|
|||
"Remaining balance does not cover the network fee.");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// return tuple with string value equal to the raw tx hex and the int value
|
||||
|
@ -588,7 +597,9 @@ mixin PaynymWalletInterface {
|
|||
required List<UTXO> utxosToUse,
|
||||
required Map<String, dynamic> utxoSigningData,
|
||||
required int change,
|
||||
int? dustLimit,
|
||||
}) async {
|
||||
try {
|
||||
final targetPaymentCode =
|
||||
PaymentCode.fromPaymentCode(targetPaymentCodeString, _network);
|
||||
final myCode = await getPaymentCode(DerivePathType.bip44);
|
||||
|
@ -602,7 +613,8 @@ mixin PaynymWalletInterface {
|
|||
final buffer = rev.buffer.asByteData();
|
||||
buffer.setUint32(txPoint.length, txPointIndex, Endian.little);
|
||||
|
||||
final myKeyPair = utxoSigningData[utxo.txid]["keyPair"] as btc_dart.ECPair;
|
||||
final myKeyPair =
|
||||
utxoSigningData[utxo.txid]["keyPair"] as btc_dart.ECPair;
|
||||
|
||||
final S = SecretPoint(
|
||||
myKeyPair.privateKey!,
|
||||
|
@ -646,7 +658,9 @@ mixin PaynymWalletInterface {
|
|||
|
||||
// todo: modify address once segwit support is in our bip47
|
||||
txb.addOutput(
|
||||
targetPaymentCode.notificationAddressP2PKH(), _dustLimitP2PKH);
|
||||
targetPaymentCode.notificationAddressP2PKH(),
|
||||
dustLimit ?? _dustLimitP2PKH,
|
||||
);
|
||||
txb.addOutput(opReturnScript, 0);
|
||||
|
||||
// TODO: add possible change output and mark output as dangerous
|
||||
|
@ -671,13 +685,21 @@ mixin PaynymWalletInterface {
|
|||
vin: i,
|
||||
keyPair: utxoSigningData[txid]["keyPair"] as btc_dart.ECPair,
|
||||
witnessValue: utxosToUse[i].value,
|
||||
witnessScript: utxoSigningData[utxo.txid]["redeemScript"] as Uint8List?,
|
||||
witnessScript:
|
||||
utxoSigningData[utxo.txid]["redeemScript"] as Uint8List?,
|
||||
);
|
||||
}
|
||||
|
||||
final builtTx = txb.build();
|
||||
|
||||
return Tuple2(builtTx.toHex(), builtTx.virtualSize());
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
"_createNotificationTx(): $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> broadcastNotificationTx(
|
||||
|
|
Loading…
Reference in a new issue