Field id strings for FeeService extracted to Config.java

This commit is contained in:
jmacxx 2021-02-25 11:51:40 -06:00 committed by Christoph Atteneder
parent a043e3bdf1
commit 7c80934a17
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
5 changed files with 21 additions and 14 deletions

View File

@ -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;

View File

@ -52,18 +52,18 @@ public class FeeProvider extends HttpClientProvider {
LinkedTreeMap<?, ?> linkedTreeMap = new Gson().fromJson(json, LinkedTreeMap.class);
Map<String, Long> 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<String, Long> 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();

View File

@ -155,10 +155,10 @@ public class FeeService {
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<String, Long> 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);

View File

@ -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 @@ class FeeRateService {
// 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<>() {{

View File

@ -2,6 +2,8 @@ package bisq.price.mining;
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 @@ public class FeeRateServiceTest {
// 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<String, String> retrievedDataMap = (Map<String, String>) retrievedData.get("dataMap");
assertEquals(2, retrievedDataMap.size());
assertEquals(expectedFeeRate, retrievedDataMap.get("btcTxFee"));
assertEquals(expectedFeeRate, retrievedDataMap.get(Config.BTC_TX_FEE));
}
}