notification tx absurd fees error fix when estimating a tx size

This commit is contained in:
julian 2023-02-22 15:06:45 -06:00
parent 55ed68a89d
commit 6bb133c552
2 changed files with 250 additions and 213 deletions

View file

@ -26,6 +26,7 @@ import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/loading_indicator.dart'; import 'package:stackwallet/widgets/loading_indicator.dart';
import 'package:stackwallet/widgets/rounded_container.dart'; import 'package:stackwallet/widgets/rounded_container.dart';
import 'package:stackwallet/widgets/stack_dialog.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
class PaynymDetailsPopup extends ConsumerStatefulWidget { class PaynymDetailsPopup extends ConsumerStatefulWidget {
@ -102,6 +103,20 @@ class _PaynymDetailsPopupState extends ConsumerState<PaynymDetailsPopup> {
_showInsufficientFundsInfo = true; _showInsufficientFundsInfo = true;
}); });
return; 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) { if (mounted) {

View file

@ -398,6 +398,7 @@ mixin PaynymWalletInterface {
int additionalOutputs = 0, int additionalOutputs = 0,
List<UTXO>? utxos, List<UTXO>? utxos,
}) async { }) async {
try {
final amountToSend = _dustLimitP2PKH; final amountToSend = _dustLimitP2PKH;
final List<UTXO> availableOutputs = final List<UTXO> availableOutputs =
utxos ?? await _db.getUTXOs(_walletId).findAll(); utxos ?? await _db.getUTXOs(_walletId).findAll();
@ -456,14 +457,18 @@ mixin PaynymWalletInterface {
targetPaymentCodeString: targetPaymentCodeString, targetPaymentCodeString: targetPaymentCodeString,
utxosToUse: utxoObjectsToUse, utxosToUse: utxoObjectsToUse,
utxoSigningData: utxoSigningData, utxoSigningData: utxoSigningData,
change: 0)) change: 0,
dustLimit:
satoshisBeingUsed, // override amount to get around absurd fees error
))
.item2; .item2;
final int vSizeForWithChange = (await _createNotificationTx( final int vSizeForWithChange = (await _createNotificationTx(
targetPaymentCodeString: targetPaymentCodeString, targetPaymentCodeString: targetPaymentCodeString,
utxosToUse: utxoObjectsToUse, utxosToUse: utxoObjectsToUse,
utxoSigningData: utxoSigningData, utxoSigningData: utxoSigningData,
change: satoshisBeingUsed - amountToSend)) change: satoshisBeingUsed - amountToSend,
))
.item2; .item2;
// Assume 2 outputs, for recipient and payment code script // Assume 2 outputs, for recipient and payment code script
@ -494,7 +499,8 @@ mixin PaynymWalletInterface {
// check estimates are correct and build notification tx // check estimates are correct and build notification tx
if (changeAmount >= _dustLimitP2PKH && if (changeAmount >= _dustLimitP2PKH &&
satoshisBeingUsed - amountToSend - changeAmount == feeForWithChange) { satoshisBeingUsed - amountToSend - changeAmount ==
feeForWithChange) {
var txn = await _createNotificationTx( var txn = await _createNotificationTx(
targetPaymentCodeString: targetPaymentCodeString, targetPaymentCodeString: targetPaymentCodeString,
utxosToUse: utxoObjectsToUse, utxosToUse: utxoObjectsToUse,
@ -579,6 +585,9 @@ mixin PaynymWalletInterface {
"Remaining balance does not cover the network fee."); "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 // 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 List<UTXO> utxosToUse,
required Map<String, dynamic> utxoSigningData, required Map<String, dynamic> utxoSigningData,
required int change, required int change,
int? dustLimit,
}) async { }) async {
try {
final targetPaymentCode = final targetPaymentCode =
PaymentCode.fromPaymentCode(targetPaymentCodeString, _network); PaymentCode.fromPaymentCode(targetPaymentCodeString, _network);
final myCode = await getPaymentCode(DerivePathType.bip44); final myCode = await getPaymentCode(DerivePathType.bip44);
@ -602,7 +613,8 @@ mixin PaynymWalletInterface {
final buffer = rev.buffer.asByteData(); final buffer = rev.buffer.asByteData();
buffer.setUint32(txPoint.length, txPointIndex, Endian.little); 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( final S = SecretPoint(
myKeyPair.privateKey!, myKeyPair.privateKey!,
@ -646,7 +658,9 @@ mixin PaynymWalletInterface {
// todo: modify address once segwit support is in our bip47 // todo: modify address once segwit support is in our bip47
txb.addOutput( txb.addOutput(
targetPaymentCode.notificationAddressP2PKH(), _dustLimitP2PKH); targetPaymentCode.notificationAddressP2PKH(),
dustLimit ?? _dustLimitP2PKH,
);
txb.addOutput(opReturnScript, 0); txb.addOutput(opReturnScript, 0);
// TODO: add possible change output and mark output as dangerous // TODO: add possible change output and mark output as dangerous
@ -671,13 +685,21 @@ mixin PaynymWalletInterface {
vin: i, vin: i,
keyPair: utxoSigningData[txid]["keyPair"] as btc_dart.ECPair, keyPair: utxoSigningData[txid]["keyPair"] as btc_dart.ECPair,
witnessValue: utxosToUse[i].value, witnessValue: utxosToUse[i].value,
witnessScript: utxoSigningData[utxo.txid]["redeemScript"] as Uint8List?, witnessScript:
utxoSigningData[utxo.txid]["redeemScript"] as Uint8List?,
); );
} }
final builtTx = txb.build(); final builtTx = txb.build();
return Tuple2(builtTx.toHex(), builtTx.virtualSize()); return Tuple2(builtTx.toHex(), builtTx.virtualSize());
} catch (e, s) {
Logging.instance.log(
"_createNotificationTx(): $e\n$s",
level: LogLevel.Error,
);
rethrow;
}
} }
Future<String> broadcastNotificationTx( Future<String> broadcastNotificationTx(