add and use defaultFeeRate per ElectrumX coin

This commit is contained in:
sneurlax 2024-06-07 15:56:57 -05:00
parent f20005557e
commit 3b9676f40e
12 changed files with 54 additions and 11 deletions

View file

@ -10,6 +10,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
@ -28,6 +29,7 @@ import '../services/tor_service.dart';
import '../utilities/logger.dart'; import '../utilities/logger.dart';
import '../utilities/prefs.dart'; import '../utilities/prefs.dart';
import '../wallets/crypto_currency/crypto_currency.dart'; import '../wallets/crypto_currency/crypto_currency.dart';
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
import 'client_manager.dart'; import 'client_manager.dart';
class WifiOnlyException implements Exception {} class WifiOnlyException implements Exception {}
@ -1113,17 +1115,23 @@ class ElectrumXClient {
], ],
); );
try { try {
// If the response is -1 or null, return a temporary hardcoded value for // If the response is -1 or null, fall back to the defaultFeeRate.
// Dogecoin. This is a temporary fix until the fee estimation is fixed. if (response == null ||
if (cryptoCurrency is Dogecoin && response == -1 ||
(response == null || Decimal.parse(response.toString()) == Decimal.parse("-1")) {
response == -1 || if (CryptoCurrency is! BitcoinFrost) {
Decimal.parse(response.toString()) == Decimal.parse("-1"))) { // TODO [prio=low]: Take `blocks` into account.
// Return 0.05 for slow, 0.2 for average, and 1 for fast txs. return Decimal.parse(
// These numbers produce tx fees in line with txs in the wild on ((cryptoCurrency as ElectrumXCurrencyInterface).defaultFeeRate /
// https://dogechain.info/ pow(10, cryptoCurrency.fractionDigits))
return Decimal.parse((1 / blocks).toString()); .toString());
// TODO [prio=med]: Fix fee estimation. } else {
// Use Bitcoin's default fee rate for Bitcoin Frost.
return Decimal.parse(
((Bitcoin(CryptoCurrencyNetwork.main).defaultFeeRate /
pow(10, cryptoCurrency.fractionDigits))
.toString()));
}
} }
return Decimal.parse(response.toString()); return Decimal.parse(response.toString());
} catch (e, s) { } catch (e, s) {

View file

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

View file

@ -201,4 +201,7 @@ class BitcoinFrost extends FrostCurrency {
); );
} }
} }
@override
int get defaultFeeRate => 1000;
} }

View file

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

View file

@ -252,4 +252,8 @@ class Dogecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
@override @override
int get transactionVersion => 1; int get transactionVersion => 1;
@override
int get defaultFeeRate => 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 @override
int get transactionVersion => 2; int get transactionVersion => 2;
@override
int get defaultFeeRate => 200;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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