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

Remove unused dependency on Pricenode metadata strings. #6822

Merged
merged 1 commit into from Aug 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -394,21 +394,17 @@ private void requestAllPrices(PriceProvider provider, Runnable resultHandler, Fa
}

priceRequest = new PriceRequest();
SettableFuture<Tuple2<Map<String, Long>, Map<String, MarketPrice>>> future = priceRequest.requestAllPrices(provider);
SettableFuture<Map<String, MarketPrice>> future = priceRequest.requestAllPrices(provider);
Futures.addCallback(future, new FutureCallback<>() {
@Override
public void onSuccess(@Nullable Tuple2<Map<String, Long>, Map<String, MarketPrice>> result) {
public void onSuccess(@Nullable Map<String, MarketPrice> result) {
UserThread.execute(() -> {
checkNotNull(result, "Result must not be null at requestAllPrices");
// Each currency rate has a different timestamp, depending on when
// the priceNode aggregate rate was calculated
// However, the request timestamp is when the pricenode was queried
epochInMillisAtLastRequest = System.currentTimeMillis();

Map<String, MarketPrice> priceMap = result.second;

cache.putAll(priceMap);

cache.putAll(result);
resultHandler.run();
});
}
Expand Down
12 changes: 3 additions & 9 deletions core/src/main/java/bisq/core/provider/price/PriceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public PriceProvider(HttpClient httpClient, String baseUrl) {
super(httpClient, baseUrl, false);
}

public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOException {
public Map<String, MarketPrice> getAll() throws IOException {
if (shutDownRequested) {
return new Tuple2<>(new HashMap<>(), new HashMap<>());
return new HashMap<>();
}

Map<String, MarketPrice> marketPriceMap = new HashMap<>();
Expand All @@ -61,13 +61,7 @@ public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOExc
String json = httpClient.get("getAllMarketPrices", "User-Agent", "bisq/"
+ Version.VERSION + hsVersion);


LinkedTreeMap<?, ?> map = new Gson().fromJson(json, LinkedTreeMap.class);
Map<String, Long> tsMap = new HashMap<>();
tsMap.put("btcAverageTs", ((Double) map.get("btcAverageTs")).longValue());
tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue());
tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue());

List<?> list = (ArrayList<?>) map.get("data");
list.forEach(obj -> {
try {
Expand All @@ -83,7 +77,7 @@ public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOExc
}

});
return new Tuple2<>(tsMap, marketPriceMap);
return marketPriceMap;
}

public String getBaseUrl() {
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/bisq/core/provider/price/PriceRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public class PriceRequest {
public PriceRequest() {
}

public SettableFuture<Tuple2<Map<String, Long>, Map<String, MarketPrice>>> requestAllPrices(PriceProvider provider) {
public SettableFuture<Map<String, MarketPrice>> requestAllPrices(PriceProvider provider) {
this.provider = provider;
String baseUrl = provider.getBaseUrl();
SettableFuture<Tuple2<Map<String, Long>, Map<String, MarketPrice>>> resultFuture = SettableFuture.create();
ListenableFuture<Tuple2<Map<String, Long>, Map<String, MarketPrice>>> future = executorService.submit(() -> {
SettableFuture<Map<String, MarketPrice>> resultFuture = SettableFuture.create();
ListenableFuture<Map<String, MarketPrice>> future = executorService.submit(() -> {
Thread.currentThread().setName(Thread.currentThread().getName() + "@" + baseUrl);
return provider.getAll();
});

Futures.addCallback(future, new FutureCallback<>() {
public void onSuccess(Tuple2<Map<String, Long>, Map<String, MarketPrice>> marketPriceTuple) {
public void onSuccess(Map<String, MarketPrice> marketPriceTuple) {
log.trace("Received marketPriceTuple of {}\nfrom provider {}", marketPriceTuple, provider);
if (!shutDownRequested) {
resultFuture.set(marketPriceTuple);
Expand Down