mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 21:26:43 +00:00
use fallback fee rate estimates if the connected server returns an error estimating fee rates
This commit is contained in:
parent
170e7c0abf
commit
74c3370277
2 changed files with 17 additions and 8 deletions
|
@ -228,7 +228,7 @@ public class BatchedElectrumServerRpc implements ElectrumServerRpc {
|
||||||
try {
|
try {
|
||||||
return batchRequest.execute();
|
return batchRequest.execute();
|
||||||
} catch(JsonRpcBatchException e) {
|
} catch(JsonRpcBatchException e) {
|
||||||
throw new ElectrumServerRpcException("Error getting fee estimates: " + e.getErrors(), e);
|
throw new ElectrumServerRpcException("Error getting fee estimates from connected server: " + e.getErrors(), e);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new ElectrumServerRpcException("Error getting fee estimates for target blocks: " + targetBlocks, e);
|
throw new ElectrumServerRpcException("Error getting fee estimates for target blocks: " + targetBlocks, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -813,6 +813,18 @@ public class ElectrumServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Double> getFeeEstimates(List<Integer> targetBlocks) throws ServerException {
|
public Map<Integer, Double> getFeeEstimates(List<Integer> targetBlocks) throws ServerException {
|
||||||
|
Map<Integer, Double> targetBlocksFeeRatesSats = getDefaultFeeEstimates(targetBlocks);
|
||||||
|
|
||||||
|
FeeRatesSource feeRatesSource = Config.get().getFeeRatesSource();
|
||||||
|
feeRatesSource = (feeRatesSource == null ? FeeRatesSource.MEMPOOL_SPACE : feeRatesSource);
|
||||||
|
if(Network.get().equals(Network.MAINNET)) {
|
||||||
|
targetBlocksFeeRatesSats.putAll(feeRatesSource.getBlockTargetFeeRates(targetBlocksFeeRatesSats));
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetBlocksFeeRatesSats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, Double> getDefaultFeeEstimates(List<Integer> targetBlocks) throws ServerException {
|
||||||
try {
|
try {
|
||||||
Map<Integer, Double> targetBlocksFeeRatesBtcKb = electrumServerRpc.getFeeEstimates(getTransport(), targetBlocks);
|
Map<Integer, Double> targetBlocksFeeRatesBtcKb = electrumServerRpc.getFeeEstimates(getTransport(), targetBlocks);
|
||||||
|
|
||||||
|
@ -825,15 +837,12 @@ public class ElectrumServer {
|
||||||
targetBlocksFeeRatesSats.put(target, minFeeRateSatsKb / 1000d);
|
targetBlocksFeeRatesSats.put(target, minFeeRateSatsKb / 1000d);
|
||||||
}
|
}
|
||||||
|
|
||||||
FeeRatesSource feeRatesSource = Config.get().getFeeRatesSource();
|
|
||||||
feeRatesSource = (feeRatesSource == null ? FeeRatesSource.MEMPOOL_SPACE : feeRatesSource);
|
|
||||||
if(Network.get().equals(Network.MAINNET)) {
|
|
||||||
targetBlocksFeeRatesSats.putAll(feeRatesSource.getBlockTargetFeeRates(targetBlocksFeeRatesSats));
|
|
||||||
}
|
|
||||||
|
|
||||||
return targetBlocksFeeRatesSats;
|
return targetBlocksFeeRatesSats;
|
||||||
} catch(ElectrumServerRpcException e) {
|
} catch(ElectrumServerRpcException e) {
|
||||||
throw new ServerException(e.getMessage(), e);
|
log.warn(e.getMessage());
|
||||||
|
return targetBlocks.stream().collect(Collectors.toMap(java.util.function.Function.identity(), v -> AppServices.getFallbackFeeRate(),
|
||||||
|
(u, v) -> { throw new IllegalStateException("Duplicate target blocks"); },
|
||||||
|
LinkedHashMap::new));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue