diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index d0a470cd1..bae7a3637 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -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 || - 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. + if (response == null || + response == -1 || + 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) { diff --git a/lib/wallets/crypto_currency/coins/bitcoin.dart b/lib/wallets/crypto_currency/coins/bitcoin.dart index ae1214e3e..dd103c794 100644 --- a/lib/wallets/crypto_currency/coins/bitcoin.dart +++ b/lib/wallets/crypto_currency/coins/bitcoin.dart @@ -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 } diff --git a/lib/wallets/crypto_currency/coins/bitcoin_frost.dart b/lib/wallets/crypto_currency/coins/bitcoin_frost.dart index 9fe8fcf69..a5f02ac08 100644 --- a/lib/wallets/crypto_currency/coins/bitcoin_frost.dart +++ b/lib/wallets/crypto_currency/coins/bitcoin_frost.dart @@ -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 } diff --git a/lib/wallets/crypto_currency/coins/bitcoincash.dart b/lib/wallets/crypto_currency/coins/bitcoincash.dart index 99724e24b..e06578ac6 100644 --- a/lib/wallets/crypto_currency/coins/bitcoincash.dart +++ b/lib/wallets/crypto_currency/coins/bitcoincash.dart @@ -367,4 +367,7 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface { @override int get transactionVersion => 2; + + @override + BigInt get defaultFeeRate => BigInt.from(1000); } diff --git a/lib/wallets/crypto_currency/coins/dogecoin.dart b/lib/wallets/crypto_currency/coins/dogecoin.dart index 2af03fab5..461d70d95 100644 --- a/lib/wallets/crypto_currency/coins/dogecoin.dart +++ b/lib/wallets/crypto_currency/coins/dogecoin.dart @@ -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 } diff --git a/lib/wallets/crypto_currency/coins/ecash.dart b/lib/wallets/crypto_currency/coins/ecash.dart index 5f420ad55..533ed3747 100644 --- a/lib/wallets/crypto_currency/coins/ecash.dart +++ b/lib/wallets/crypto_currency/coins/ecash.dart @@ -339,4 +339,7 @@ class Ecash extends Bip39HDCurrency with ElectrumXCurrencyInterface { @override int get transactionVersion => 2; + + @override + BigInt get defaultFeeRate => BigInt.from(200); } diff --git a/lib/wallets/crypto_currency/coins/firo.dart b/lib/wallets/crypto_currency/coins/firo.dart index 530bf39e7..47ee606c4 100644 --- a/lib/wallets/crypto_currency/coins/firo.dart +++ b/lib/wallets/crypto_currency/coins/firo.dart @@ -270,4 +270,7 @@ class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface { @override int get transactionVersion => 1; + + @override + BigInt get defaultFeeRate => BigInt.from(1000); } diff --git a/lib/wallets/crypto_currency/coins/litecoin.dart b/lib/wallets/crypto_currency/coins/litecoin.dart index a859f9f64..7cf53837a 100644 --- a/lib/wallets/crypto_currency/coins/litecoin.dart +++ b/lib/wallets/crypto_currency/coins/litecoin.dart @@ -283,4 +283,7 @@ class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { @override int get transactionVersion => 1; + + @override + BigInt get defaultFeeRate => BigInt.from(1000); } diff --git a/lib/wallets/crypto_currency/coins/namecoin.dart b/lib/wallets/crypto_currency/coins/namecoin.dart index 4bc2521bd..bae72281f 100644 --- a/lib/wallets/crypto_currency/coins/namecoin.dart +++ b/lib/wallets/crypto_currency/coins/namecoin.dart @@ -255,4 +255,7 @@ class Namecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { @override int get transactionVersion => 1; + + @override + BigInt get defaultFeeRate => BigInt.from(1000); } diff --git a/lib/wallets/crypto_currency/coins/particl.dart b/lib/wallets/crypto_currency/coins/particl.dart index f250792cc..fd1aa946f 100644 --- a/lib/wallets/crypto_currency/coins/particl.dart +++ b/lib/wallets/crypto_currency/coins/particl.dart @@ -233,4 +233,7 @@ class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface { @override int get transactionVersion => 1; + + @override + BigInt get defaultFeeRate => BigInt.from(20000); } diff --git a/lib/wallets/crypto_currency/coins/peercoin.dart b/lib/wallets/crypto_currency/coins/peercoin.dart index dec4ab846..a199460e7 100644 --- a/lib/wallets/crypto_currency/coins/peercoin.dart +++ b/lib/wallets/crypto_currency/coins/peercoin.dart @@ -257,4 +257,7 @@ class Peercoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { @override int get transactionVersion => 3; + + @override + BigInt get defaultFeeRate => BigInt.from(5000); } diff --git a/lib/wallets/crypto_currency/interfaces/electrumx_currency_interface.dart b/lib/wallets/crypto_currency/interfaces/electrumx_currency_interface.dart index 30ddf7c70..387bf4454 100644 --- a/lib/wallets/crypto_currency/interfaces/electrumx_currency_interface.dart +++ b/lib/wallets/crypto_currency/interfaces/electrumx_currency_interface.dart @@ -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; }