mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-03 17:29:23 +00:00
add and use defaultFeeRate per ElectrumX coin
This commit is contained in:
parent
f20005557e
commit
3b9676f40e
12 changed files with 54 additions and 11 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:decimal/decimal.dart';
|
||||
|
@ -28,6 +29,7 @@ import '../services/tor_service.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,23 @@ 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 the response is -1 or null, fall back to the defaultFeeRate.
|
||||
if (response == null ||
|
||||
response == -1 ||
|
||||
Decimal.parse(response.toString()) == Decimal.parse("-1")) {
|
||||
if (CryptoCurrency is! BitcoinFrost) {
|
||||
// TODO [prio=low]: Take `blocks` into account.
|
||||
return Decimal.parse(
|
||||
((cryptoCurrency as ElectrumXCurrencyInterface).defaultFeeRate /
|
||||
pow(10, cryptoCurrency.fractionDigits))
|
||||
.toString());
|
||||
} 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());
|
||||
} catch (e, s) {
|
||||
|
|
|
@ -295,4 +295,8 @@ class Bitcoin extends Bip39HDCurrency
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 1000;
|
||||
// https://github.com/bitcoin/bitcoin/blob/feab35189bc00bc4cf15e9dcb5cf6b34ff3a1e91/test/functional/mempool_limit.py#L259
|
||||
}
|
||||
|
|
|
@ -201,4 +201,7 @@ class BitcoinFrost extends FrostCurrency {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 1000;
|
||||
}
|
||||
|
|
|
@ -367,4 +367,7 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 2;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 1000;
|
||||
}
|
||||
|
|
|
@ -252,4 +252,8 @@ class Dogecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 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
|
||||
int get defaultFeeRate => 200;
|
||||
}
|
||||
|
|
|
@ -270,4 +270,7 @@ class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 1000;
|
||||
}
|
||||
|
|
|
@ -283,4 +283,7 @@ class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 1000;
|
||||
}
|
||||
|
|
|
@ -255,4 +255,7 @@ class Namecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 1000;
|
||||
}
|
||||
|
|
|
@ -233,4 +233,7 @@ class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 1;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 20000;
|
||||
}
|
||||
|
|
|
@ -257,4 +257,7 @@ class Peercoin extends Bip39HDCurrency with ElectrumXCurrencyInterface {
|
|||
|
||||
@override
|
||||
int get transactionVersion => 3;
|
||||
|
||||
@override
|
||||
int get defaultFeeRate => 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.
|
||||
int get defaultFeeRate;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue