From 0469141fee97a553e4627065d17db9accbec7250 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 31 Mar 2022 09:20:57 +0200 Subject: [PATCH] use paynym.is onion address when proxy is set --- .../sparrow/control/PayNymAvatar.java | 3 ++- .../sparrow/paynym/PayNymService.java | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/PayNymAvatar.java b/src/main/java/com/sparrowwallet/sparrow/control/PayNymAvatar.java index 0d48dbde..bcb1edec 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/PayNymAvatar.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/PayNymAvatar.java @@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.control; import com.sparrowwallet.drongo.bip47.PaymentCode; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.io.Config; +import com.sparrowwallet.sparrow.paynym.PayNymService; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.concurrent.Service; @@ -117,8 +118,8 @@ public class PayNymAvatar extends StackPane { } synchronized(lock) { - String url = "https://paynym.is/" + paymentCodeStr + "/avatar"; Proxy proxy = AppServices.getProxy(); + String url = PayNymService.getHostUrl(proxy != null) + "/" + paymentCodeStr + "/avatar"; try(InputStream is = (proxy == null ? new URL(url).openStream() : new URL(url).openConnection(proxy).getInputStream())) { Image image = new Image(is, 150, 150, true, false); diff --git a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymService.java b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymService.java index 23826660..9a39ba0c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymService.java +++ b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymService.java @@ -52,7 +52,7 @@ public class PayNymService { body.put("code", paymentCode.toString()); IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST); - return httpClient.postJson("https://paynym.is/api/v1/create", Map.class, headers, body) + return httpClient.postJson(getHostUrl() + "/api/v1/create", Map.class, headers, body) .subscribeOn(Schedulers.io()) .observeOn(JavaFxScheduler.platform()) .map(Optional::get); @@ -70,7 +70,7 @@ public class PayNymService { body.put("code", paymentCode.toString()); IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST); - return httpClient.postJson("https://paynym.is/api/v1/token", Map.class, headers, body) + return httpClient.postJson(getHostUrl() + "/api/v1/token", Map.class, headers, body) .subscribeOn(Schedulers.io()) .observeOn(JavaFxScheduler.platform()) .map(Optional::get); @@ -115,7 +115,7 @@ public class PayNymService { body.put("signature", signature); IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST); - return httpClient.postJson("https://paynym.is/api/v1/claim", Map.class, headers, body) + return httpClient.postJson(getHostUrl() + "/api/v1/claim", Map.class, headers, body) .subscribeOn(Schedulers.io()) .observeOn(JavaFxScheduler.platform()) .map(Optional::get); @@ -140,7 +140,7 @@ public class PayNymService { body.put("signature", signature); IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST); - return httpClient.postJson("https://paynym.is/api/v1/nym/add", Map.class, headers, body) + return httpClient.postJson(getHostUrl() + "/api/v1/nym/add", Map.class, headers, body) .subscribeOn(Schedulers.io()) .observeOn(JavaFxScheduler.platform()) .map(Optional::get); @@ -160,7 +160,7 @@ public class PayNymService { body.put("target", paymentCode.toString()); IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST); - return httpClient.postJson("https://paynym.is/api/v1/follow", Map.class, headers, body) + return httpClient.postJson(getHostUrl() + "/api/v1/follow", Map.class, headers, body) .subscribeOn(Schedulers.io()) .observeOn(JavaFxScheduler.platform()) .map(Optional::get); @@ -174,7 +174,7 @@ public class PayNymService { body.put("nym", nymIdentifier); IHttpClient httpClient = httpClientService.getHttpClient(HttpUsage.COORDINATOR_REST); - return httpClient.postJson("https://paynym.is/api/v1/nym", Map.class, headers, body) + return httpClient.postJson(getHostUrl() + "/api/v1/nym", Map.class, headers, body) .subscribeOn(Schedulers.io()) .observeOn(JavaFxScheduler.platform()) .map(Optional::get); @@ -235,6 +235,14 @@ public class PayNymService { httpClientService.setTorProxy(torProxy); } + private String getHostUrl() { + return getHostUrl(getTorProxy() != null); + } + + public static String getHostUrl(boolean tor) { + return tor ? "http://paynym7bwekdtb2hzgkpl6y2waqcrs2dii7lwincvxme7mdpcpxzfsad.onion" : "https://paynym.is"; + } + public void shutdown() { httpClientService.shutdown(); }