diff --git a/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java b/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java index 30963053..e3f112b8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/FeeRatesSource.java @@ -19,14 +19,14 @@ public enum FeeRatesSource { @Override public Map getBlockTargetFeeRates(Map defaultblockTargetFeeRates) { String url = AppServices.isUsingProxy() ? "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/api/v1/fees/recommended" : "https://mempool.space/api/v1/fees/recommended"; - return getThreeTierFeeRates(defaultblockTargetFeeRates, url); + return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url); } }, BITCOINFEES_EARN_COM("bitcoinfees.earn.com") { @Override public Map getBlockTargetFeeRates(Map defaultblockTargetFeeRates) { String url = "https://bitcoinfees.earn.com/api/v1/fees/recommended"; - return getThreeTierFeeRates(defaultblockTargetFeeRates, url); + return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url); } }, MINIMUM("Minimum (1 sat/vB)") { @@ -39,6 +39,22 @@ public enum FeeRatesSource { return blockTargetFeeRates; } + }, + OXT_ME("oxt.me") { + @Override + public Map getBlockTargetFeeRates(Map defaultblockTargetFeeRates) { + String url = AppServices.isUsingProxy() ? "http://oxtwshnfyktikbflierkwcxxksbonl6v73l5so5zky7ur72w52tktkid.onion/stats/global/mempool" : "https://api.oxt.me/stats/global/mempool"; + return getThreeTierFeeRates(this, defaultblockTargetFeeRates, url); + } + + @Override + protected ThreeTierRates getThreeTierRates(String url, HttpClientService httpClientService) throws Exception { + OxtRates oxtRates = httpClientService.requestJson(url, OxtRates.class, null); + if(oxtRates.data == null || oxtRates.data.length < 1) { + throw new Exception("Invalid response from " + url); + } + return oxtRates.data[0].getThreeTierRates(); + } }; private static final Logger log = LoggerFactory.getLogger(FeeRatesSource.class); @@ -58,7 +74,7 @@ public enum FeeRatesSource { return name; } - private static Map getThreeTierFeeRates(Map defaultblockTargetFeeRates, String url) { + private static Map getThreeTierFeeRates(FeeRatesSource feeRatesSource, Map defaultblockTargetFeeRates, String url) { if(log.isInfoEnabled()) { log.info("Requesting fee rates from " + url); } @@ -66,7 +82,7 @@ public enum FeeRatesSource { Map blockTargetFeeRates = new LinkedHashMap<>(); HttpClientService httpClientService = AppServices.getHttpClientService(); try { - ThreeTierRates threeTierRates = httpClientService.requestJson(url, ThreeTierRates.class, null); + ThreeTierRates threeTierRates = feeRatesSource.getThreeTierRates(url, httpClientService); Double lastRate = null; for(Integer blockTarget : defaultblockTargetFeeRates.keySet()) { if(blockTarget < BLOCKS_IN_HALF_HOUR) { @@ -101,15 +117,22 @@ public enum FeeRatesSource { return blockTargetFeeRates; } + protected ThreeTierRates getThreeTierRates(String url, HttpClientService httpClientService) throws Exception { + return httpClientService.requestJson(url, ThreeTierRates.class, null); + } + @Override public String toString() { return name; } - private static class ThreeTierRates { - public Double fastestFee; - public Double halfHourFee; - public Double hourFee; - public Double minimumFee; + private record ThreeTierRates(Double fastestFee, Double halfHourFee, Double hourFee, Double minimumFee) {} + + private record OxtRates(OxtRatesData[] data) {} + + private record OxtRatesData(Double recommended_fee_099, Double recommended_fee_090, Double recommended_fee_050) { + public ThreeTierRates getThreeTierRates() { + return new ThreeTierRates(recommended_fee_099/1000, recommended_fee_090/1000, recommended_fee_050/1000, null); + } } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml index 33ba8238..65788e20 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/preferences/general.fxml @@ -36,6 +36,7 @@ +