diff --git a/core/src/main/java/bisq/core/provider/MempoolHttpClient.java b/core/src/main/java/bisq/core/provider/MempoolHttpClient.java index 18d4001664..5a36f023da 100644 --- a/core/src/main/java/bisq/core/provider/MempoolHttpClient.java +++ b/core/src/main/java/bisq/core/provider/MempoolHttpClient.java @@ -27,6 +27,8 @@ import javax.inject.Singleton; import java.io.IOException; +import java.util.concurrent.CompletableFuture; + import javax.annotation.Nullable; @Singleton @@ -42,4 +44,18 @@ public class MempoolHttpClient extends HttpClientImpl { String api = "/" + txId; return get(api, "User-Agent", "bisq/" + Version.VERSION); } + + + public CompletableFuture requestTxAsHex(String txId) { + super.shutDown(); // close any prior incomplete request + + return CompletableFuture.supplyAsync(() -> { + String api = "/" + txId + "/hex"; + try { + return get(api, "User-Agent", "bisq/" + Version.VERSION); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } } diff --git a/core/src/main/java/bisq/core/provider/mempool/MempoolRequest.java b/core/src/main/java/bisq/core/provider/mempool/MempoolRequest.java index fcfdeb4a45..6141d2ed22 100644 --- a/core/src/main/java/bisq/core/provider/mempool/MempoolRequest.java +++ b/core/src/main/java/bisq/core/provider/mempool/MempoolRequest.java @@ -34,6 +34,7 @@ import com.google.common.util.concurrent.SettableFuture; import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.concurrent.CompletableFuture; import lombok.extern.slf4j.Slf4j; @@ -66,12 +67,19 @@ public class MempoolRequest { log.info("Received mempoolData of [{}] from provider", mempoolData); mempoolServiceCallback.set(mempoolData); } + public void onFailure(@NotNull Throwable throwable) { mempoolServiceCallback.setException(throwable); } }, MoreExecutors.directExecutor()); } + + public CompletableFuture requestTxAsHex(String txId) { + mempoolHttpClient.setBaseUrl(getRandomServiceAddress(txBroadcastServices)); + return mempoolHttpClient.requestTxAsHex(txId); + } + public boolean switchToAnotherProvider() { txBroadcastServices.remove(mempoolHttpClient.getBaseUrl()); return txBroadcastServices.size() > 0; diff --git a/core/src/main/java/bisq/core/provider/mempool/MempoolService.java b/core/src/main/java/bisq/core/provider/mempool/MempoolService.java index 02e079eba5..d0dcf806e3 100644 --- a/core/src/main/java/bisq/core/provider/mempool/MempoolService.java +++ b/core/src/main/java/bisq/core/provider/mempool/MempoolService.java @@ -43,6 +43,7 @@ import com.google.common.util.concurrent.SettableFuture; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import lombok.Getter; @@ -129,7 +130,12 @@ public class MempoolService { mempoolRequest.getTxStatus(future, txId); } - // /////////////////////////// + public CompletableFuture requestTxAsHex(String txId) { + outstandingRequests++; + return new MempoolRequest(preferences, socks5ProxyProvider) + .requestTxAsHex(txId) + .whenComplete((result, throwable) -> outstandingRequests--); + } private void validateOfferMakerTx(MempoolRequest mempoolRequest, TxValidator txValidator,