mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +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.io.IOException;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@ -42,4 +44,18 @@ public class MempoolHttpClient extends HttpClientImpl {
|
|||||||
String api = "/" + txId;
|
String api = "/" + txId;
|
||||||
return get(api, "User-Agent", "bisq/" + Version.VERSION);
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@ -66,12 +67,19 @@ public class MempoolRequest {
|
|||||||
log.info("Received mempoolData of [{}] from provider", mempoolData);
|
log.info("Received mempoolData of [{}] from provider", mempoolData);
|
||||||
mempoolServiceCallback.set(mempoolData);
|
mempoolServiceCallback.set(mempoolData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFailure(@NotNull Throwable throwable) {
|
public void onFailure(@NotNull Throwable throwable) {
|
||||||
mempoolServiceCallback.setException(throwable);
|
mempoolServiceCallback.setException(throwable);
|
||||||
}
|
}
|
||||||
}, MoreExecutors.directExecutor());
|
}, MoreExecutors.directExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public CompletableFuture<String> requestTxAsHex(String txId) {
|
||||||
|
mempoolHttpClient.setBaseUrl(getRandomServiceAddress(txBroadcastServices));
|
||||||
|
return mempoolHttpClient.requestTxAsHex(txId);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean switchToAnotherProvider() {
|
public boolean switchToAnotherProvider() {
|
||||||
txBroadcastServices.remove(mempoolHttpClient.getBaseUrl());
|
txBroadcastServices.remove(mempoolHttpClient.getBaseUrl());
|
||||||
return txBroadcastServices.size() > 0;
|
return txBroadcastServices.size() > 0;
|
||||||
|
@ -43,6 +43,7 @@ import com.google.common.util.concurrent.SettableFuture;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -129,7 +130,12 @@ public class MempoolService {
|
|||||||
mempoolRequest.getTxStatus(future, txId);
|
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,
|
private void validateOfferMakerTx(MempoolRequest mempoolRequest,
|
||||||
TxValidator txValidator,
|
TxValidator txValidator,
|
||||||
|
Loading…
Reference in New Issue
Block a user