Skip to content

Commit

Permalink
Field id strings for FeeService extracted to Config.java
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacxx authored and ripcurlx committed Mar 1, 2021
1 parent a043e3b commit 7c80934
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
3 changes: 3 additions & 0 deletions common/src/main/java/bisq/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/bisq/core/provider/fee/FeeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ public Tuple2<Map<String, Long>, Map<String, Long>> getFees() throws IOException

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();
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/bisq/core/provider/fee/FeeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ public void onSuccess(@Nullable Tuple2<Map<String, Long>, Map<String, Long>> 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<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);
Expand Down
8 changes: 5 additions & 3 deletions pricenode/src/main/java/bisq/price/mining/FeeRateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package bisq.price.mining;

import bisq.common.config.Config;

import org.springframework.stereotype.Service;

import java.time.Instant;
Expand Down Expand Up @@ -90,11 +92,11 @@ public Map<String, Object> 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<>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,10 +101,10 @@ private void doSanityChecksForRetrievedData(Map<String, Object> 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<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));
}
}

0 comments on commit 7c80934

Please sign in to comment.