From 7c80934a171497139e0fce292fe3078d97a45b19 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Thu, 25 Feb 2021 11:51:40 -0600 Subject: [PATCH] Field id strings for FeeService extracted to Config.java --- common/src/main/java/bisq/common/config/Config.java | 3 +++ .../java/bisq/core/provider/fee/FeeProvider.java | 12 ++++++------ .../main/java/bisq/core/provider/fee/FeeService.java | 6 +++--- .../main/java/bisq/price/mining/FeeRateService.java | 8 +++++--- .../java/bisq/price/mining/FeeRateServiceTest.java | 6 ++++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/bisq/common/config/Config.java b/common/src/main/java/bisq/common/config/Config.java index 34b7ab5727c..f824d8ff79f 100644 --- a/common/src/main/java/bisq/common/config/Config.java +++ b/common/src/main/java/bisq/common/config/Config.java @@ -121,6 +121,9 @@ public class Config { public static final String API_PORT = "apiPort"; public static final String PREVENT_PERIODIC_SHUTDOWN_AT_SEED_NODE = "preventPeriodicShutdownAtSeedNode"; public static final String REPUBLISH_MAILBOX_ENTRIES = "republishMailboxEntries"; + public static final String BTC_TX_FEE = "btcTxFee"; + public static final String BTC_MIN_TX_FEE = "btcMinTxFee"; + public static final String BTC_FEES_TS = "bitcoinFeesTs"; // Default values for certain options public static final int UNSPECIFIED_PORT = -1; diff --git a/core/src/main/java/bisq/core/provider/fee/FeeProvider.java b/core/src/main/java/bisq/core/provider/fee/FeeProvider.java index b998402b383..0e410204b83 100644 --- a/core/src/main/java/bisq/core/provider/fee/FeeProvider.java +++ b/core/src/main/java/bisq/core/provider/fee/FeeProvider.java @@ -52,18 +52,18 @@ public Tuple2, Map> getFees() throws IOException LinkedTreeMap linkedTreeMap = new Gson().fromJson(json, LinkedTreeMap.class); Map tsMap = new HashMap<>(); - tsMap.put("bitcoinFeesTs", ((Double) linkedTreeMap.get("bitcoinFeesTs")).longValue()); + tsMap.put(Config.BTC_FEES_TS, ((Double) linkedTreeMap.get(Config.BTC_FEES_TS)).longValue()); Map map = new HashMap<>(); try { LinkedTreeMap dataMap = (LinkedTreeMap) linkedTreeMap.get("dataMap"); - Long btcTxFee = ((Double) dataMap.get("btcTxFee")).longValue(); - Long btcMinTxFee = dataMap.get("btcMinTxFee") != null ? - ((Double) dataMap.get("btcMinTxFee")).longValue() : Config.baseCurrencyNetwork().getDefaultMinFeePerVbyte(); + Long btcTxFee = ((Double) dataMap.get(Config.BTC_TX_FEE)).longValue(); + Long btcMinTxFee = dataMap.get(Config.BTC_MIN_TX_FEE) != null ? + ((Double) dataMap.get(Config.BTC_MIN_TX_FEE)).longValue() : Config.baseCurrencyNetwork().getDefaultMinFeePerVbyte(); - map.put("BTC", btcTxFee); - map.put("btcMinTxFee", btcMinTxFee); + map.put(Config.BTC_TX_FEE, btcTxFee); + map.put(Config.BTC_MIN_TX_FEE, btcMinTxFee); } catch (Throwable t) { log.error(t.toString()); t.printStackTrace(); diff --git a/core/src/main/java/bisq/core/provider/fee/FeeService.java b/core/src/main/java/bisq/core/provider/fee/FeeService.java index 0f1fc0eba74..0c68293565c 100644 --- a/core/src/main/java/bisq/core/provider/fee/FeeService.java +++ b/core/src/main/java/bisq/core/provider/fee/FeeService.java @@ -155,10 +155,10 @@ public void onSuccess(@Nullable Tuple2, Map> res UserThread.execute(() -> { checkNotNull(result, "Result must not be null at getFees"); timeStampMap = result.first; - epochInSecondAtLastRequest = timeStampMap.get("bitcoinFeesTs"); + epochInSecondAtLastRequest = timeStampMap.get(Config.BTC_FEES_TS); final Map map = result.second; - txFeePerVbyte = map.get("BTC"); - minFeePerVByte = map.get("btcMinTxFee"); + txFeePerVbyte = map.get(Config.BTC_TX_FEE); + minFeePerVByte = map.get(Config.BTC_MIN_TX_FEE); if (txFeePerVbyte < minFeePerVByte) { log.warn("The delivered fee of {} sat/vbyte is smaller than the min. default fee of {} sat/vbyte", txFeePerVbyte, minFeePerVByte); diff --git a/pricenode/src/main/java/bisq/price/mining/FeeRateService.java b/pricenode/src/main/java/bisq/price/mining/FeeRateService.java index ea7f9669185..e723efad457 100644 --- a/pricenode/src/main/java/bisq/price/mining/FeeRateService.java +++ b/pricenode/src/main/java/bisq/price/mining/FeeRateService.java @@ -17,6 +17,8 @@ package bisq.price.mining; +import bisq.common.config.Config; + import org.springframework.stereotype.Service; import java.time.Instant; @@ -90,11 +92,11 @@ public Map getFees() { // Prepare response: Add timestamp of now // Since this is an average, the timestamp is associated with when the moment in // time when the avg was computed - metadata.put("bitcoinFeesTs", Instant.now().getEpochSecond()); + metadata.put(Config.BTC_FEES_TS, Instant.now().getEpochSecond()); // Prepare response: Add the fee average - allFeeRates.put("btcTxFee", averageFeeRate); - allFeeRates.put("btcMinTxFee", averageMinFeeRate); + allFeeRates.put(Config.BTC_TX_FEE, averageFeeRate); + allFeeRates.put(Config.BTC_MIN_TX_FEE, averageMinFeeRate); // Build response return new HashMap<>() {{ diff --git a/pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java b/pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java index dd21a8c1339..7298d7143e2 100644 --- a/pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java +++ b/pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java @@ -2,6 +2,8 @@ import bisq.price.mining.providers.MempoolFeeRateProviderTest; +import bisq.common.config.Config; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -99,10 +101,10 @@ private void doSanityChecksForRetrievedData(Map retrievedData, l // Check if the response has the expected format. Since the timestamp is that of // the average (not that of the individual fee rates reported by the individual // providers), we always expect a non-zero timestamp - assertNotEquals(0L, retrievedData.get("bitcoinFeesTs")); + assertNotEquals(0L, retrievedData.get(Config.BTC_FEES_TS)); Map retrievedDataMap = (Map) retrievedData.get("dataMap"); assertEquals(2, retrievedDataMap.size()); - assertEquals(expectedFeeRate, retrievedDataMap.get("btcTxFee")); + assertEquals(expectedFeeRate, retrievedDataMap.get(Config.BTC_TX_FEE)); } }