Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor & simplify fee service. #6931

Merged
merged 3 commits into from Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,12 @@ public boolean verifyBsqSentToAddress(String address, String amount) {
return walletsService.verifyBsqSentToAddress(address, amount);
}

public void getTxFeeRate(ResultHandler resultHandler) {
walletsService.getTxFeeRate(resultHandler);
public void setTxFeeRatePreference(long txFeeRate) {
walletsService.setTxFeeRatePreference(txFeeRate);
}

public void setTxFeeRatePreference(long txFeeRate,
ResultHandler resultHandler) {
walletsService.setTxFeeRatePreference(txFeeRate, resultHandler);
}

public void unsetTxFeeRatePreference(ResultHandler resultHandler) {
walletsService.unsetTxFeeRatePreference(resultHandler);
public void unsetTxFeeRatePreference() {
walletsService.unsetTxFeeRatePreference();
}

public TxFeeRateInfo getMostRecentTxFeeRateInfo() {
Expand Down
32 changes: 2 additions & 30 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,33 +362,7 @@ boolean verifyBsqSentToAddress(String address, String amount) {
return numMatches > 0;
}

void getTxFeeRate(ResultHandler resultHandler) {
try {
@SuppressWarnings({"unchecked", "Convert2MethodRef"})
ListenableFuture<Void> future =
(ListenableFuture<Void>) executor.submit(() -> feeService.requestFees());
//noinspection NullableProblems
Futures.addCallback(future, new FutureCallback<>() {
@Override
public void onSuccess(@Nullable Void ignored) {
resultHandler.handleResult();
}

@Override
public void onFailure(Throwable t) {
log.error("", t);
throw new IllegalStateException("could not request fees from fee service", t);
}
}, MoreExecutors.directExecutor());

} catch (Exception ex) {
log.error(ex.toString());
throw new IllegalStateException("could not request fees from fee service", ex);
}
}

void setTxFeeRatePreference(long txFeeRate,
ResultHandler resultHandler) {
void setTxFeeRatePreference(long txFeeRate) {
long minFeePerVbyte = feeService.getMinFeePerVByte();
if (txFeeRate < minFeePerVbyte)
throw new IllegalArgumentException(
Expand All @@ -397,12 +371,10 @@ void setTxFeeRatePreference(long txFeeRate,
preferences.setUseCustomWithdrawalTxFee(true);
Coin satsPerByte = Coin.valueOf(txFeeRate);
preferences.setWithdrawalTxFeeInVbytes(satsPerByte.value);
getTxFeeRate(resultHandler);
}

void unsetTxFeeRatePreference(ResultHandler resultHandler) {
void unsetTxFeeRatePreference() {
preferences.setUseCustomWithdrawalTxFee(false);
getTxFeeRate(resultHandler);
}

TxFeeRateInfo getMostRecentTxFeeRateInfo() {
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/bisq/core/btc/BitcoinModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import bisq.core.btc.wallet.NonBsqCoinSelector;
import bisq.core.btc.wallet.TradeWalletService;
import bisq.core.provider.ProvidersRepository;
import bisq.core.provider.fee.FeeProvider;
import bisq.core.provider.fee.FeeService;
import bisq.core.provider.price.PriceFeedService;

Expand Down Expand Up @@ -95,7 +94,6 @@ protected void configure() {
bind(Balances.class).in(Singleton.class);

bind(ProvidersRepository.class).in(Singleton.class);
bind(FeeProvider.class).in(Singleton.class);
bind(PriceFeedService.class).in(Singleton.class);
bind(FeeService.class).in(Singleton.class);
bind(TxFeeEstimationService.class).in(Singleton.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,7 @@ private void calculateTxFees() {
}

private Coin getTxFeePerVbyte() {
try {
CompletableFuture<Void> feeRequestFuture = CompletableFuture.runAsync(feeService::requestFees);
feeRequestFuture.get(); // Block until async fee request is complete.
return feeService.getTxFeePerVbyte();
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException("Could not request fees from fee service.", e);
}
return feeService.getTxFeePerVbyte();
}

private void calculateTotalToPay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,9 @@ private void applyTxFeePerVbyte() {
// We only set the txFeePerVbyte at start, otherwise we might get diff. required amounts while user has view open
txFeePerVbyte = feeService.getTxFeePerVbyte().getValue();
resetTxFeeAndMissingFunds();
feeService.requestFees(() -> {
txFeePerVbyte = feeService.getTxFeePerVbyte().getValue();
calculateInputAndPayout();
resetTxFeeAndMissingFunds();
});
txFeePerVbyte = feeService.getTxFeePerVbyte().getValue();
calculateInputAndPayout();
resetTxFeeAndMissingFunds();
}

private void resetTxFeeAndMissingFunds() {
Expand Down
77 changes: 0 additions & 77 deletions core/src/main/java/bisq/core/provider/fee/FeeProvider.java

This file was deleted.

68 changes: 0 additions & 68 deletions core/src/main/java/bisq/core/provider/fee/FeeRequest.java

This file was deleted.

Loading