Merge pull request #450 from cypherstack/fix-epiccash-send-all

Fix Epiccash sendAll not enough funds error
This commit is contained in:
julian-CStack 2023-03-31 15:44:00 -06:00 committed by GitHub
commit f77043b8a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -862,6 +862,9 @@ class EpicCashWallet extends CoinServiceAPI
Map<String, dynamic>? args}) async { Map<String, dynamic>? args}) async {
try { try {
int realfee = await nativeFee(satoshiAmount); int realfee = await nativeFee(satoshiAmount);
if (balance.spendable == satoshiAmount) {
satoshiAmount = balance.spendable - realfee;
}
Map<String, dynamic> txData = { Map<String, dynamic> txData = {
"fee": realfee, "fee": realfee,
@ -906,33 +909,81 @@ class EpicCashWallet extends CoinServiceAPI
}); });
debugPrint(transactionFees); debugPrint(transactionFees);
dynamic decodeData; dynamic decodeData;
try {
decodeData = json.decode(transactionFees!); final available = balance.spendable;
} catch (e) {
if (ifErrorEstimateFee) { if (available == satoshiAmount) {
//Error Not enough funds. Required: 0.56500000, Available: 0.56200000 if (transactionFees!.contains("Required")) {
if (transactionFees!.contains("Required")) { var splits = transactionFees!.split(" ");
var splits = transactionFees!.split(" "); Decimal required = Decimal.zero;
Decimal required = Decimal.zero; Decimal available = Decimal.zero;
Decimal available = Decimal.zero; for (int i = 0; i < splits.length; i++) {
for (int i = 0; i < splits.length; i++) { var word = splits[i];
var word = splits[i]; if (word == "Required:") {
if (word == "Required:") { required = Decimal.parse(splits[i + 1].replaceAll(",", ""));
required = Decimal.parse(splits[i + 1].replaceAll(",", "")); } else if (word == "Available:") {
} else if (word == "Available:") { available = Decimal.parse(splits[i + 1].replaceAll(",", ""));
available = Decimal.parse(splits[i + 1].replaceAll(",", ""));
}
} }
int largestSatoshiFee =
((required - available) * Decimal.fromInt(100000000))
.toBigInt()
.toInt();
Logging.instance.log("largestSatoshiFee $largestSatoshiFee",
level: LogLevel.Info);
return largestSatoshiFee;
} }
int largestSatoshiFee =
((required - available) * Decimal.fromInt(100000000))
.toBigInt()
.toInt();
var amountSending = satoshiAmount - largestSatoshiFee;
//Get fees for this new amount
await m.protect(() async {
ReceivePort receivePort = await getIsolate({
"function": "getTransactionFees",
"wallet": wallet!,
"amount": amountSending,
"minimumConfirmations": MINIMUM_CONFIRMATIONS,
}, name: walletName);
var message = await receivePort.first;
if (message is String) {
Logging.instance
.log("this is a string $message", level: LogLevel.Error);
stop(receivePort);
throw Exception("getTransactionFees isolate failed");
}
stop(receivePort);
Logging.instance.log('Closing getTransactionFees!\n $message',
level: LogLevel.Info);
// return message;
transactionFees = message['result'] as String;
});
}
decodeData = json.decode(transactionFees!);
} else {
try {
decodeData = json.decode(transactionFees!);
} catch (e) {
if (ifErrorEstimateFee) {
//Error Not enough funds. Required: 0.56500000, Available: 0.56200000
if (transactionFees!.contains("Required")) {
var splits = transactionFees!.split(" ");
Decimal required = Decimal.zero;
Decimal available = Decimal.zero;
for (int i = 0; i < splits.length; i++) {
var word = splits[i];
if (word == "Required:") {
required = Decimal.parse(splits[i + 1].replaceAll(",", ""));
} else if (word == "Available:") {
available = Decimal.parse(splits[i + 1].replaceAll(",", ""));
}
}
int largestSatoshiFee =
((required - available) * Decimal.fromInt(100000000))
.toBigInt()
.toInt();
Logging.instance.log("largestSatoshiFee $largestSatoshiFee",
level: LogLevel.Info);
return largestSatoshiFee;
}
}
rethrow;
} }
rethrow;
} }
//TODO: first problem //TODO: first problem
@ -1799,7 +1850,7 @@ class EpicCashWallet extends CoinServiceAPI
// final chunk = { // final chunk = {
// "timestamp": txTimeArray[0], // "timestamp": txTimeArray[0],
// "transactions": [txObject], // "transactions": [txObject],
// }; // };sendAll
// //
// // result["dateTimeChunks"]. // // result["dateTimeChunks"].
// result["dateTimeChunks"].add(chunk); // result["dateTimeChunks"].add(chunk);