Fix fee estimation for send all

This commit is contained in:
Hector Chu 2024-04-26 01:07:58 +01:00
parent b1caf79c1b
commit fea7e7a097
2 changed files with 12 additions and 18 deletions

View file

@ -245,24 +245,13 @@ abstract class ElectrumWalletBase
throw BitcoinTransactionNoInputsException();
}
int estimatedSize;
if (network is BitcoinCashNetwork) {
estimatedSize = ForkedTransactionBuilder.estimateTransactionSize(
utxos: utxos,
outputs: outputs,
network: network as BitcoinCashNetwork,
memo: memo,
);
} else {
estimatedSize = BitcoinTransactionBuilder.estimateTransactionSize(
utxos: utxos,
outputs: outputs,
network: network,
memo: memo,
);
}
int fee = feeAmountWithFeeRate(feeRate, 0, 0, size: estimatedSize);
int fee = await calcFee(
utxos: utxos,
outputs: outputs,
network: network,
memo: memo,
feeRate: feeRate,
);
if (fee == 0) {
throw BitcoinTransactionNoFeeException();

View file

@ -298,6 +298,11 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
return await super.calcFee(utxos: utxos, outputs: outputs,
network: network, memo: memo, feeRate: feeRate);
}
if (outputs.length == 1 && outputs[0].toOutput.amount == BigInt.zero) {
outputs = [BitcoinScriptOutput(
script: outputs[0].toOutput.scriptPubKey,
value: utxos.sumOfUtxosValue())];
}
final txb = BitcoinTransactionBuilder(utxos: utxos,
outputs: outputs, fee: BigInt.zero, network: network);
final scanSecret = mwebHd.derive(0x80000000).privKey!;