mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-09 12:19:24 +00:00
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:
commit
b87105773c
12 changed files with 57 additions and 11 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -367,4 +367,7 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 2;
|
||||
|
||||
@override
|
||||
BigInt get defaultFeeRate => BigInt.from(1000);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -339,4 +339,7 @@ class Ecash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 2;
|
||||
|
||||
@override
|
||||
BigInt get defaultFeeRate => BigInt.from(200);
|
||||
}
|
||||
|
|
|
@ -270,4 +270,7 @@ class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
BigInt get defaultFeeRate => BigInt.from(1000);
|
||||
}
|
||||
|
|
|
@ -283,4 +283,7 @@ class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
BigInt get defaultFeeRate => BigInt.from(1000);
|
||||
}
|
||||
|
|
|
@ -255,4 +255,7 @@ class Namecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
BigInt get defaultFeeRate => BigInt.from(1000);
|
||||
}
|
||||
|
|
|
@ -233,4 +233,7 @@ class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
BigInt get defaultFeeRate => BigInt.from(20000);
|
||||
}
|
||||
|
|
|
@ -257,4 +257,7 @@ class Peercoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 3;
|
||||
|
||||
@override
|
||||
BigInt get defaultFeeRate => BigInt.from(5000);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue