mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Add block explorer tx as hex request using completeable future api
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
7f5675f054
commit
0388c7c88a
@ -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<String> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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<String> requestTxAsHex(String txId) {
|
||||
mempoolHttpClient.setBaseUrl(getRandomServiceAddress(txBroadcastServices));
|
||||
return mempoolHttpClient.requestTxAsHex(txId);
|
||||
}
|
||||
|
||||
public boolean switchToAnotherProvider() {
|
||||
txBroadcastServices.remove(mempoolHttpClient.getBaseUrl());
|
||||
return txBroadcastServices.size() > 0;
|
||||
|
@ -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<String> requestTxAsHex(String txId) {
|
||||
outstandingRequests++;
|
||||
return new MempoolRequest(preferences, socks5ProxyProvider)
|
||||
.requestTxAsHex(txId)
|
||||
.whenComplete((result, throwable) -> outstandingRequests--);
|
||||
}
|
||||
|
||||
private void validateOfferMakerTx(MempoolRequest mempoolRequest,
|
||||
TxValidator txValidator,
|
||||
|
Loading…
Reference in New Issue
Block a user