Skip to content

Commit

Permalink
Rename BitcoinFeeRateProvider to MempoolFeeRateProvider
Browse files Browse the repository at this point in the history
The BitcoinFeeRateProvider name was never great; it should technically
have been something like EarnDotComFeeRateProvider. This change renames
the class to reflect that it (and its new subclasses) are specifically
designed to query the Mempool API as found at https://mempool.space.
  • Loading branch information
cbeams committed May 11, 2020
1 parent d160d9e commit 714e494
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
import java.util.stream.Stream;

/**
* Provider that specifically interprets the mempool.space API format to retrieve a mining
* fee estimate. Other {@link FeeRateProvider}s can be created for other APIs.
* {@link FeeRateProvider} that interprets the Mempool API format to retrieve a mining
* fee estimate. See https://mempool.space.
*/
abstract class BitcoinFeeRateProvider extends FeeRateProvider {
abstract class MempoolFeeRateProvider extends FeeRateProvider {

private static final int DEFAULT_MAX_BLOCKS = 2;
private static final int DEFAULT_REFRESH_INTERVAL = 2;
Expand All @@ -68,7 +68,7 @@ abstract class BitcoinFeeRateProvider extends FeeRateProvider {

protected Environment env;

public BitcoinFeeRateProvider(Environment env) {
public MempoolFeeRateProvider(Environment env) {
super(Duration.ofMinutes(refreshInterval(env)));
this.env = env;
this.maxBlocks = maxBlocks(env);
Expand Down Expand Up @@ -143,7 +143,7 @@ private static long refreshInterval(Environment env) {
@Primary
@Component
@Order(1)
public static class First extends BitcoinFeeRateProvider {
public static class First extends MempoolFeeRateProvider {

public First(Environment env) {
super(env);
Expand All @@ -161,7 +161,7 @@ protected String getMempoolApiHostname() {
@Component
@Order(2)
@ConditionalOnProperty(name = API_ENDPOINT_HOSTNAME_KEY_2)
public static class Second extends BitcoinFeeRateProvider {
public static class Second extends MempoolFeeRateProvider {

public Second(Environment env) {
super(env);
Expand All @@ -175,7 +175,7 @@ protected String getMempoolApiHostname() {
@Component
@Order(3)
@ConditionalOnProperty(name = API_ENDPOINT_HOSTNAME_KEY_3)
public static class Third extends BitcoinFeeRateProvider {
public static class Third extends MempoolFeeRateProvider {

public Third(Environment env) {
super(env);
Expand All @@ -189,7 +189,7 @@ protected String getMempoolApiHostname() {
@Component
@Order(4)
@ConditionalOnProperty(name = API_ENDPOINT_HOSTNAME_KEY_4)
public static class Fourth extends BitcoinFeeRateProvider {
public static class Fourth extends MempoolFeeRateProvider {

public Fourth(Environment env) {
super(env);
Expand All @@ -203,7 +203,7 @@ protected String getMempoolApiHostname() {
@Component
@Order(5)
@ConditionalOnProperty(name = API_ENDPOINT_HOSTNAME_KEY_5)
public static class Fifth extends BitcoinFeeRateProvider {
public static class Fifth extends MempoolFeeRateProvider {

public Fifth(Environment env) {
super(env);
Expand Down
20 changes: 11 additions & 9 deletions pricenode/src/test/java/bisq/price/mining/FeeRateServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bisq.price.mining;

import bisq.price.mining.providers.MempoolFeeRateProviderTest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -10,16 +12,16 @@

import org.junit.jupiter.api.Test;

import static bisq.price.mining.providers.BitcoinFeeRateProviderTest.buildDummyReachableBitcoinFeeRateProvider;
import static bisq.price.mining.providers.BitcoinFeeRateProviderTest.buildDummyUnreachableBitcoinFeeRateProvider;
import static bisq.price.mining.providers.MempoolFeeRateProviderTest.buildDummyReachableMempoolFeeRateProvider;
import static bisq.price.mining.providers.MempoolFeeRateProviderTest.buildDummyUnreachableMempoolFeeRateProvider;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

/**
* Tests the {@link bisq.price.mining.FeeRateService}, which can aggregate data from
* several {@link FeeRateProvider}s.
* @see bisq.price.mining.providers.BitcoinFeeRateProviderTest
* @see MempoolFeeRateProviderTest
*/
public class FeeRateServiceTest {

Expand All @@ -31,7 +33,7 @@ public void getFees_noWorkingProvider() {
List<FeeRateProvider> listOfProviders = new ArrayList<>();
for (int i = 0; i < 3; i++) {
try {
listOfProviders.add(buildDummyUnreachableBitcoinFeeRateProvider());
listOfProviders.add(buildDummyUnreachableMempoolFeeRateProvider());
} catch (Exception e) {
// Expected
log.info("We encountered an expected exception: " + e.getMessage());
Expand All @@ -52,7 +54,7 @@ public void getFees_singleProvider_feeBelowMin() {
long providerFee = FeeRateProvider.MIN_FEE_RATE - 3;
FeeRateService service = new FeeRateService(
Collections.singletonList(
buildDummyReachableBitcoinFeeRateProvider(providerFee)));
buildDummyReachableMempoolFeeRateProvider(providerFee)));

Map<String, Object> retrievedData = service.getFees();

Expand All @@ -67,7 +69,7 @@ public void getFees_singleProvider_feeAboveMax() {
long providerFee = FeeRateProvider.MAX_FEE_RATE + 13;
FeeRateService service = new FeeRateService(
Collections.singletonList(
buildDummyReachableBitcoinFeeRateProvider(providerFee)));
buildDummyReachableMempoolFeeRateProvider(providerFee)));

Map<String, Object> retrievedData = service.getFees();

Expand All @@ -80,9 +82,9 @@ public void getFees_singleProvider_feeAboveMax() {
public void getFees_multipleProviders() {
// 3 providers, returning 1xMIN, 2xMIN, 3xMIN
FeeRateService service = new FeeRateService(asList(
buildDummyReachableBitcoinFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 1),
buildDummyReachableBitcoinFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 2),
buildDummyReachableBitcoinFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 3)));
buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 1),
buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 2),
buildDummyReachableMempoolFeeRateProvider(FeeRateProvider.MIN_FEE_RATE * 3)));

Map<String, Object> retrievedData = service.getFees();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
import static org.junit.Assert.assertTrue;

/**
* Tests specific to a {@link BitcoinFeeRateProvider} which queries one API endpoint. For
* Tests specific to a {@link MempoolFeeRateProvider} which queries one API endpoint. For
* tests related to managing parallel fee API endpoints, see
* {@link bisq.price.mining.FeeRateServiceTest}
*/
public class BitcoinFeeRateProviderTest {
public class MempoolFeeRateProviderTest {

@Test
public void doGet_successfulCall() {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
BitcoinFeeRateProvider feeRateProvider = new BitcoinFeeRateProvider.First(ctx.getEnvironment());
MempoolFeeRateProvider feeRateProvider = new MempoolFeeRateProvider.First(ctx.getEnvironment());

// Make a call to the API, retrieve the recommended fee rate
// If the API call fails, or the response body cannot be parsed, the test will
Expand All @@ -54,9 +54,9 @@ public void doGet_successfulCall() {
/**
* Simulates a reachable provider, which successfully returns an API response
*/
public static FeeRateProvider buildDummyReachableBitcoinFeeRateProvider(long feeRate) {
public static FeeRateProvider buildDummyReachableMempoolFeeRateProvider(long feeRate) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
BitcoinFeeRateProvider dummyProvider = new BitcoinFeeRateProvider.First(ctx.getEnvironment()) {
MempoolFeeRateProvider dummyProvider = new MempoolFeeRateProvider.First(ctx.getEnvironment()) {
@Override
protected FeeRate doGet() {
return new FeeRate("BTC", feeRate, Instant.now().getEpochSecond());
Expand All @@ -75,9 +75,9 @@ protected FeeRate doGet() {
* response to the API. Reasons for that could be: host went offline, connection
* timeout, connection cannot be established (expired certificate), etc.
*/
public static FeeRateProvider buildDummyUnreachableBitcoinFeeRateProvider() throws RestClientException {
public static FeeRateProvider buildDummyUnreachableMempoolFeeRateProvider() throws RestClientException {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
BitcoinFeeRateProvider dummyProvider = new BitcoinFeeRateProvider.First(ctx.getEnvironment()) {
MempoolFeeRateProvider dummyProvider = new MempoolFeeRateProvider.First(ctx.getEnvironment()) {
@Override
protected FeeRate doGet() {
throw new RestClientException("Simulating connection error when trying to reach API endpoint");
Expand Down

0 comments on commit 714e494

Please sign in to comment.