diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 4bf3bb1a..c41376c2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -293,7 +293,7 @@ public class AppServices { FeeRatesSource feeRatesSource = Config.get().getFeeRatesSource(); feeRatesSource = (feeRatesSource == null ? FeeRatesSource.MEMPOOL_SPACE : feeRatesSource); - if(event instanceof ConnectionEvent && Network.get().equals(Network.MAINNET) && feeRatesSource.isExternal()) { + if(event instanceof ConnectionEvent && feeRatesSource.supportsNetwork(Network.get()) && feeRatesSource.isExternal()) { EventManager.get().post(new FeeRatesSourceChangedEvent(feeRatesSource)); } }); diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index 888bbd77..32696de1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -823,7 +823,7 @@ public class ElectrumServer { if(AppServices.getTargetBlockFeeRates() != null) { targetBlocksFeeRatesSats.putAll(AppServices.getTargetBlockFeeRates()); } - } else if(Network.get().equals(Network.MAINNET)) { + } else if(feeRatesSource.supportsNetwork(Network.get())) { targetBlocksFeeRatesSats.putAll(feeRatesSource.getBlockTargetFeeRates(targetBlocksFeeRatesSats)); } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java b/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java index 0a2fb5df..3466f3db 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java @@ -1,5 +1,6 @@ package com.sparrowwallet.sparrow.net; +import com.sparrowwallet.drongo.Network; import com.sparrowwallet.sparrow.AppServices; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,13 +15,26 @@ public enum FeeRatesSource { public Map getBlockTargetFeeRates(Map defaultblockTargetFeeRates) { return Collections.emptyMap(); } + + @Override + public boolean supportsNetwork(Network network) { + return true; + } }, MEMPOOL_SPACE("mempool.space", true) { @Override public Map getBlockTargetFeeRates(Map defaultblockTargetFeeRates) { String url = AppServices.isUsingProxy() ? "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/api/v1/fees/recommended" : "https://mempool.space/api/v1/fees/recommended"; + if(Network.get() != Network.MAINNET && supportsNetwork(Network.get())) { + url = url.replace("/api/", "/" + Network.get().getName() + "/api/"); + } return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url); } + + @Override + public boolean supportsNetwork(Network network) { + return network == Network.MAINNET || network == Network.TESTNET || network == Network.TESTNET4 || network == Network.SIGNET; + } }, BITCOINFEES_EARN_COM("bitcoinfees.earn.com", true) { @Override @@ -28,6 +42,11 @@ public enum FeeRatesSource { String url = "https://bitcoinfees.earn.com/api/v1/fees/recommended"; return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url); } + + @Override + public boolean supportsNetwork(Network network) { + return network == Network.MAINNET; + } }, MINIMUM("Minimum (1 sat/vB)", false) { @Override @@ -39,6 +58,11 @@ public enum FeeRatesSource { return blockTargetFeeRates; } + + @Override + public boolean supportsNetwork(Network network) { + return true; + } }, OXT_ME("oxt.me", true) { @Override @@ -47,6 +71,11 @@ public enum FeeRatesSource { return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url); } + @Override + public boolean supportsNetwork(Network network) { + return network == Network.MAINNET; + } + @Override protected ThreeTierRates getThreeTierRates(String url, HttpClientService httpClientService) throws Exception { OxtRates oxtRates = httpClientService.requestJson(url, OxtRates.class, null); @@ -72,6 +101,8 @@ public enum FeeRatesSource { public abstract Map getBlockTargetFeeRates(Map defaultblockTargetFeeRates); + public abstract boolean supportsNetwork(Network network); + public String getName() { return name; } @@ -132,7 +163,7 @@ public enum FeeRatesSource { return name; } - private record ThreeTierRates(Double fastestFee, Double halfHourFee, Double hourFee, Double minimumFee) {} + protected record ThreeTierRates(Double fastestFee, Double halfHourFee, Double hourFee, Double minimumFee) {} private record OxtRates(OxtRatesData[] data) {}