Merge pull request #885 from cypherstack/fees

Add defaultFeeRate per ElectrumX coin and use it if fee estimates unavailable from node
This commit is contained in:
julian-CStack 2024-06-07 16:06:26 -06:00 committed by GitHub
commit b87105773c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 57 additions and 11 deletions

View file

@ -25,9 +25,11 @@ import '../services/event_bus/events/global/tor_connection_status_changed_event.
import '../services/event_bus/events/global/tor_status_changed_event.dart';
import '../services/event_bus/global_event_bus.dart';
import '../services/tor_service.dart';
import '../utilities/amount/amount.dart';
import '../utilities/logger.dart';
import '../utilities/prefs.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
import 'client_manager.dart';
class WifiOnlyException implements Exception {}
@ -1113,17 +1115,25 @@ class ElectrumXClient {
],
);
try {
// If the response is -1 or null, return a temporary hardcoded value for
// Dogecoin. This is a temporary fix until the fee estimation is fixed.
if (cryptoCurrency is Dogecoin &&
(response == null ||
if (response == null ||
response == -1 ||
Decimal.parse(response.toString()) == Decimal.parse("-1"))) {
// Return 0.05 for slow, 0.2 for average, and 1 for fast txs.
// These numbers produce tx fees in line with txs in the wild on
// https://dogechain.info/
return Decimal.parse((1 / blocks).toString());
// TODO [prio=med]: Fix fee estimation.
Decimal.parse(response.toString()) == Decimal.parse("-1")) {
if (cryptoCurrency is BitcoinFrost) {
final rate = Amount(
rawValue: (cryptoCurrency as BitcoinFrost).defaultFeeRate,
fractionDigits: cryptoCurrency.fractionDigits,
);
return rate.decimal;
} else if (cryptoCurrency is ElectrumXCurrencyInterface) {
final rate = Amount(
rawValue:
(cryptoCurrency as ElectrumXCurrencyInterface).defaultFeeRate,
fractionDigits: cryptoCurrency.fractionDigits,
);
return rate.decimal;
} else {
throw Exception("Unexpected cryptoCurrency found!");
}
}
return Decimal.parse(response.toString());
} catch (e, s) {

View file

@ -295,4 +295,8 @@ class Bitcoin extends Bip39HDCurrency
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(1000);
// https://github.com/bitcoin/bitcoin/blob/feab35189bc00bc4cf15e9dcb5cf6b34ff3a1e91/test/functional/mempool_limit.py#L259
}

View file

@ -201,4 +201,8 @@ class BitcoinFrost extends FrostCurrency {
);
}
}
// @override
BigInt get defaultFeeRate => BigInt.from(1000);
// https://github.com/bitcoin/bitcoin/blob/feab35189bc00bc4cf15e9dcb5cf6b34ff3a1e91/test/functional/mempool_limit.py#L259
}

View file

@ -367,4 +367,7 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 2;
@override
BigInt get defaultFeeRate => BigInt.from(1000);
}

View file

@ -252,4 +252,8 @@ class Dogecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(1000000);
// https://github.com/dogecoin/dogecoin/blob/master/doc/fee-recommendation.md
}

View file

@ -339,4 +339,7 @@ class Ecash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 2;
@override
BigInt get defaultFeeRate => BigInt.from(200);
}

View file

@ -270,4 +270,7 @@ class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(1000);
}

View file

@ -283,4 +283,7 @@ class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(1000);
}

View file

@ -255,4 +255,7 @@ class Namecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(1000);
}

View file

@ -233,4 +233,7 @@ class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 1;
@override
BigInt get defaultFeeRate => BigInt.from(20000);
}

View file

@ -257,4 +257,7 @@ class Peercoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override
int get transactionVersion => 3;
@override
BigInt get defaultFeeRate => BigInt.from(5000);
}

View file

@ -2,4 +2,7 @@ import '../intermediate/bip39_hd_currency.dart';
mixin ElectrumXCurrencyInterface on Bip39HDCurrency {
int get transactionVersion;
/// The default fee rate in satoshis per kilobyte.
BigInt get defaultFeeRate;
}