Skip to content

Commit 9bfdd2f

Browse files
committed
fix ElectrumEstimateFee
1 parent d42a8be commit 9bfdd2f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Diff for: example/lib/global/transfer_from_7_account_to_6_accout_example.dart

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ void main() async {
123123
/// get network fee esmtimate (fee per kilobyte)
124124
final networkEstimate = await provider.request(ElectrumEstimateFee());
125125

126+
/// the daemon does not have enough information to make an estimate
127+
if (networkEstimate == null) {
128+
return;
129+
}
130+
126131
/// Convert kilobytes to bytes, multiply by the transaction size, and the result yields the transaction fees.
127132
final fee =
128133
BigInt.from(transactionSize) * (networkEstimate ~/ BigInt.from(1000));

Diff for: example/lib/global/transfer_to_8_account_example.dart

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ void main() async {
102102
/// get network fee esmtimate (kb/s)
103103
final networkEstimate = await provider.request(ElectrumEstimateFee());
104104

105+
/// the daemon does not have enough information to make an estimate
106+
if (networkEstimate == null) {
107+
return;
108+
}
109+
105110
/// kb to bytes and mul with transaction size and now we have fee
106111
final fee =
107112
BigInt.from(estimateSize) * (networkEstimate ~/ BigInt.from(1000));

Diff for: lib/src/provider/electrum_methods/methods/estimate_fee.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:bitcoin_base/src/utils/btc_utils.dart';
33

44
/// Return the estimated transaction fee per kilobyte for a transaction to be confirmed within a certain number of blocks.
55
/// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html
6-
class ElectrumEstimateFee extends ElectrumRequest<BigInt, dynamic> {
6+
class ElectrumEstimateFee extends ElectrumRequest<BigInt?, dynamic> {
77
ElectrumEstimateFee({this.numberOfBlock = 2});
88

99
/// The number of blocks to target for confirmation.
@@ -20,7 +20,9 @@ class ElectrumEstimateFee extends ElectrumRequest<BigInt, dynamic> {
2020

2121
/// The estimated transaction fee in Bigint(satoshi)
2222
@override
23-
BigInt onResonse(result) {
24-
return BtcUtils.toSatoshi(result.toString()).abs();
23+
BigInt? onResonse(result) {
24+
final fee = BtcUtils.toSatoshi(result.toString());
25+
if (fee.isNegative) return null;
26+
return fee;
2527
}
2628
}

0 commit comments

Comments
 (0)