Skip to content

Commit b871057

Browse files
Merge pull request #885 from cypherstack/fees
Add defaultFeeRate per ElectrumX coin and use it if fee estimates unavailable from node
2 parents f200055 + 713d8b0 commit b871057

File tree

12 files changed

+57
-11
lines changed

12 files changed

+57
-11
lines changed

lib/electrumx_rpc/electrumx_client.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import '../services/event_bus/events/global/tor_connection_status_changed_event.
2525
import '../services/event_bus/events/global/tor_status_changed_event.dart';
2626
import '../services/event_bus/global_event_bus.dart';
2727
import '../services/tor_service.dart';
28+
import '../utilities/amount/amount.dart';
2829
import '../utilities/logger.dart';
2930
import '../utilities/prefs.dart';
3031
import '../wallets/crypto_currency/crypto_currency.dart';
32+
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
3133
import 'client_manager.dart';
3234

3335
class WifiOnlyException implements Exception {}
@@ -1113,17 +1115,25 @@ class ElectrumXClient {
11131115
],
11141116
);
11151117
try {
1116-
// If the response is -1 or null, return a temporary hardcoded value for
1117-
// Dogecoin. This is a temporary fix until the fee estimation is fixed.
1118-
if (cryptoCurrency is Dogecoin &&
1119-
(response == null ||
1120-
response == -1 ||
1121-
Decimal.parse(response.toString()) == Decimal.parse("-1"))) {
1122-
// Return 0.05 for slow, 0.2 for average, and 1 for fast txs.
1123-
// These numbers produce tx fees in line with txs in the wild on
1124-
// https://dogechain.info/
1125-
return Decimal.parse((1 / blocks).toString());
1126-
// TODO [prio=med]: Fix fee estimation.
1118+
if (response == null ||
1119+
response == -1 ||
1120+
Decimal.parse(response.toString()) == Decimal.parse("-1")) {
1121+
if (cryptoCurrency is BitcoinFrost) {
1122+
final rate = Amount(
1123+
rawValue: (cryptoCurrency as BitcoinFrost).defaultFeeRate,
1124+
fractionDigits: cryptoCurrency.fractionDigits,
1125+
);
1126+
return rate.decimal;
1127+
} else if (cryptoCurrency is ElectrumXCurrencyInterface) {
1128+
final rate = Amount(
1129+
rawValue:
1130+
(cryptoCurrency as ElectrumXCurrencyInterface).defaultFeeRate,
1131+
fractionDigits: cryptoCurrency.fractionDigits,
1132+
);
1133+
return rate.decimal;
1134+
} else {
1135+
throw Exception("Unexpected cryptoCurrency found!");
1136+
}
11271137
}
11281138
return Decimal.parse(response.toString());
11291139
} catch (e, s) {

lib/wallets/crypto_currency/coins/bitcoin.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,8 @@ class Bitcoin extends Bip39HDCurrency
295295

296296
@override
297297
int get transactionVersion => 1;
298+
299+
@override
300+
BigInt get defaultFeeRate => BigInt.from(1000);
301+
// https://github.com/bitcoin/bitcoin/blob/feab35189bc00bc4cf15e9dcb5cf6b34ff3a1e91/test/functional/mempool_limit.py#L259
298302
}

lib/wallets/crypto_currency/coins/bitcoin_frost.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,8 @@ class BitcoinFrost extends FrostCurrency {
201201
);
202202
}
203203
}
204+
205+
// @override
206+
BigInt get defaultFeeRate => BigInt.from(1000);
207+
// https://github.com/bitcoin/bitcoin/blob/feab35189bc00bc4cf15e9dcb5cf6b34ff3a1e91/test/functional/mempool_limit.py#L259
204208
}

lib/wallets/crypto_currency/coins/bitcoincash.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,7 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
367367

368368
@override
369369
int get transactionVersion => 2;
370+
371+
@override
372+
BigInt get defaultFeeRate => BigInt.from(1000);
370373
}

lib/wallets/crypto_currency/coins/dogecoin.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,8 @@ class Dogecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
252252

253253
@override
254254
int get transactionVersion => 1;
255+
256+
@override
257+
BigInt get defaultFeeRate => BigInt.from(1000000);
258+
// https://github.com/dogecoin/dogecoin/blob/master/doc/fee-recommendation.md
255259
}

lib/wallets/crypto_currency/coins/ecash.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,7 @@ class Ecash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
339339

340340
@override
341341
int get transactionVersion => 2;
342+
343+
@override
344+
BigInt get defaultFeeRate => BigInt.from(200);
342345
}

lib/wallets/crypto_currency/coins/firo.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,7 @@ class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface {
270270

271271
@override
272272
int get transactionVersion => 1;
273+
274+
@override
275+
BigInt get defaultFeeRate => BigInt.from(1000);
273276
}

lib/wallets/crypto_currency/coins/litecoin.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,7 @@ class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
283283

284284
@override
285285
int get transactionVersion => 1;
286+
287+
@override
288+
BigInt get defaultFeeRate => BigInt.from(1000);
286289
}

lib/wallets/crypto_currency/coins/namecoin.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,7 @@ class Namecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
255255

256256
@override
257257
int get transactionVersion => 1;
258+
259+
@override
260+
BigInt get defaultFeeRate => BigInt.from(1000);
258261
}

lib/wallets/crypto_currency/coins/particl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,7 @@ class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface {
233233

234234
@override
235235
int get transactionVersion => 1;
236+
237+
@override
238+
BigInt get defaultFeeRate => BigInt.from(20000);
236239
}

0 commit comments

Comments
 (0)