mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +00:00
retrieve fee rates from configured source on non-mainnet networks where available
This commit is contained in:
parent
e50fe4c68c
commit
7e68ecffd3
3 changed files with 34 additions and 3 deletions
|
@ -293,7 +293,7 @@ public class AppServices {
|
||||||
|
|
||||||
FeeRatesSource feeRatesSource = Config.get().getFeeRatesSource();
|
FeeRatesSource feeRatesSource = Config.get().getFeeRatesSource();
|
||||||
feeRatesSource = (feeRatesSource == null ? FeeRatesSource.MEMPOOL_SPACE : feeRatesSource);
|
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));
|
EventManager.get().post(new FeeRatesSourceChangedEvent(feeRatesSource));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -823,7 +823,7 @@ public class ElectrumServer {
|
||||||
if(AppServices.getTargetBlockFeeRates() != null) {
|
if(AppServices.getTargetBlockFeeRates() != null) {
|
||||||
targetBlocksFeeRatesSats.putAll(AppServices.getTargetBlockFeeRates());
|
targetBlocksFeeRatesSats.putAll(AppServices.getTargetBlockFeeRates());
|
||||||
}
|
}
|
||||||
} else if(Network.get().equals(Network.MAINNET)) {
|
} else if(feeRatesSource.supportsNetwork(Network.get())) {
|
||||||
targetBlocksFeeRatesSats.putAll(feeRatesSource.getBlockTargetFeeRates(targetBlocksFeeRatesSats));
|
targetBlocksFeeRatesSats.putAll(feeRatesSource.getBlockTargetFeeRates(targetBlocksFeeRatesSats));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.sparrowwallet.sparrow.net;
|
package com.sparrowwallet.sparrow.net;
|
||||||
|
|
||||||
|
import com.sparrowwallet.drongo.Network;
|
||||||
import com.sparrowwallet.sparrow.AppServices;
|
import com.sparrowwallet.sparrow.AppServices;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -14,13 +15,26 @@ public enum FeeRatesSource {
|
||||||
public Map<Integer, Double> getBlockTargetFeeRates(Map<Integer, Double> defaultblockTargetFeeRates) {
|
public Map<Integer, Double> getBlockTargetFeeRates(Map<Integer, Double> defaultblockTargetFeeRates) {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsNetwork(Network network) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
MEMPOOL_SPACE("mempool.space", true) {
|
MEMPOOL_SPACE("mempool.space", true) {
|
||||||
@Override
|
@Override
|
||||||
public Map<Integer, Double> getBlockTargetFeeRates(Map<Integer, Double> defaultblockTargetFeeRates) {
|
public Map<Integer, Double> getBlockTargetFeeRates(Map<Integer, Double> defaultblockTargetFeeRates) {
|
||||||
String url = AppServices.isUsingProxy() ? "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/api/v1/fees/recommended" : "https://mempool.space/api/v1/fees/recommended";
|
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);
|
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) {
|
BITCOINFEES_EARN_COM("bitcoinfees.earn.com", true) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,6 +42,11 @@ public enum FeeRatesSource {
|
||||||
String url = "https://bitcoinfees.earn.com/api/v1/fees/recommended";
|
String url = "https://bitcoinfees.earn.com/api/v1/fees/recommended";
|
||||||
return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url);
|
return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsNetwork(Network network) {
|
||||||
|
return network == Network.MAINNET;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
MINIMUM("Minimum (1 sat/vB)", false) {
|
MINIMUM("Minimum (1 sat/vB)", false) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,6 +58,11 @@ public enum FeeRatesSource {
|
||||||
|
|
||||||
return blockTargetFeeRates;
|
return blockTargetFeeRates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsNetwork(Network network) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
OXT_ME("oxt.me", true) {
|
OXT_ME("oxt.me", true) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,6 +71,11 @@ public enum FeeRatesSource {
|
||||||
return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url);
|
return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsNetwork(Network network) {
|
||||||
|
return network == Network.MAINNET;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThreeTierRates getThreeTierRates(String url, HttpClientService httpClientService) throws Exception {
|
protected ThreeTierRates getThreeTierRates(String url, HttpClientService httpClientService) throws Exception {
|
||||||
OxtRates oxtRates = httpClientService.requestJson(url, OxtRates.class, null);
|
OxtRates oxtRates = httpClientService.requestJson(url, OxtRates.class, null);
|
||||||
|
@ -72,6 +101,8 @@ public enum FeeRatesSource {
|
||||||
|
|
||||||
public abstract Map<Integer, Double> getBlockTargetFeeRates(Map<Integer, Double> defaultblockTargetFeeRates);
|
public abstract Map<Integer, Double> getBlockTargetFeeRates(Map<Integer, Double> defaultblockTargetFeeRates);
|
||||||
|
|
||||||
|
public abstract boolean supportsNetwork(Network network);
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +163,7 @@ public enum FeeRatesSource {
|
||||||
return name;
|
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) {}
|
private record OxtRates(OxtRatesData[] data) {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue