mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-05 20:56:57 +00:00
temp fix for firo infinite fee estimate
This commit is contained in:
parent
764c66ee08
commit
3c29b9acdf
1 changed files with 53 additions and 27 deletions
|
@ -4493,6 +4493,7 @@ class FiroWallet extends CoinServiceAPI {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: investigate the bug here where chosen is null, conditions, given one mint
|
||||
spendVal += chosen!.amount;
|
||||
coinsToSpend.insert(coinsToSpend.length, chosen);
|
||||
}
|
||||
|
@ -4514,36 +4515,61 @@ class FiroWallet extends CoinServiceAPI {
|
|||
Future<int> estimateJoinSplitFee(
|
||||
int spendAmount,
|
||||
) async {
|
||||
int fee;
|
||||
int size;
|
||||
|
||||
for (fee = 0;;) {
|
||||
int currentRequired = spendAmount;
|
||||
|
||||
var map = await getCoinsToJoinSplit(currentRequired);
|
||||
if (map is bool && !map) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<DartLelantusEntry> coinsToBeSpent =
|
||||
map['coinsToSpend'] as List<DartLelantusEntry>;
|
||||
|
||||
// 1054 is constant part, mainly Schnorr and Range proofs, 2560 is for each sigma/aux data
|
||||
// 179 other parts of tx, assuming 1 utxo and 1 jmint
|
||||
size = 1054 + 2560 * coinsToBeSpent.length + 180;
|
||||
// uint64_t feeNeeded = GetMinimumFee(size, DEFAULT_TX_CONFIRM_TARGET);
|
||||
int feeNeeded =
|
||||
size; //TODO(Levon) temporary, use real estimation methods here
|
||||
|
||||
if (fee >= feeNeeded) {
|
||||
break;
|
||||
}
|
||||
|
||||
fee = feeNeeded;
|
||||
var lelantusEntry = await _getLelantusEntry();
|
||||
final balance = await availableBalance;
|
||||
int spendAmount =
|
||||
(balance * Decimal.fromInt(Constants.satsPerCoin)).toBigInt().toInt();
|
||||
if (spendAmount == 0 || lelantusEntry.isEmpty) {
|
||||
return LelantusFeeData(0, 0, []).fee;
|
||||
}
|
||||
ReceivePort receivePort = await getIsolate({
|
||||
"function": "estimateJoinSplit",
|
||||
"spendAmount": spendAmount,
|
||||
"subtractFeeFromAmount": true,
|
||||
"lelantusEntries": lelantusEntry,
|
||||
"coin": coin,
|
||||
});
|
||||
|
||||
return fee;
|
||||
final message = await receivePort.first;
|
||||
if (message is String) {
|
||||
Logging.instance.log("this is a string", level: LogLevel.Error);
|
||||
stop(receivePort);
|
||||
throw Exception("_fetchMaxFee isolate failed");
|
||||
}
|
||||
stop(receivePort);
|
||||
Logging.instance.log('Closing estimateJoinSplit!', level: LogLevel.Info);
|
||||
return (message as LelantusFeeData).fee;
|
||||
}
|
||||
// int fee;
|
||||
// int size;
|
||||
//
|
||||
// for (fee = 0;;) {
|
||||
// int currentRequired = spendAmount;
|
||||
//
|
||||
// TODO: investigate the bug here
|
||||
// var map = await getCoinsToJoinSplit(currentRequired);
|
||||
// if (map is bool && !map) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// List<DartLelantusEntry> coinsToBeSpent =
|
||||
// map['coinsToSpend'] as List<DartLelantusEntry>;
|
||||
//
|
||||
// // 1054 is constant part, mainly Schnorr and Range proofs, 2560 is for each sigma/aux data
|
||||
// // 179 other parts of tx, assuming 1 utxo and 1 jmint
|
||||
// size = 1054 + 2560 * coinsToBeSpent.length + 180;
|
||||
// // uint64_t feeNeeded = GetMinimumFee(size, DEFAULT_TX_CONFIRM_TARGET);
|
||||
// int feeNeeded =
|
||||
// size; //TODO(Levon) temporary, use real estimation methods here
|
||||
//
|
||||
// if (fee >= feeNeeded) {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// fee = feeNeeded;
|
||||
// }
|
||||
//
|
||||
// return fee;
|
||||
|
||||
@override
|
||||
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
||||
|
|
Loading…
Reference in a new issue