From 57eacbdd59ac28822474bb6de2d144a382700b6d Mon Sep 17 00:00:00 2001 From: CalDescent Date: Thu, 19 Jan 2023 20:47:06 +0000 Subject: [PATCH] Added "GET_PRICE" action. --- Q-Apps.md | 11 +++++++++++ .../org/qortal/api/apps/resource/AppsResource.java | 9 +++++++++ src/main/resources/q-apps/q-apps.js | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/Q-Apps.md b/Q-Apps.md index 72b4f34b..12a49e3d 100644 --- a/Q-Apps.md +++ b/Q-Apps.md @@ -76,6 +76,7 @@ Here is a list of currently supported actions: - FETCH_BLOCK - FETCH_BLOCK_RANGE - SEARCH_TRANSACTIONS +- GET_PRICE More functionality will be added in the future. @@ -392,6 +393,16 @@ let res = await qortalRequest({ }); ``` +### Get an estimate of the QORT price +``` +let res = await qortalRequest({ + action: "GET_PRICE", + blockchain: "LITECOIN", + // maxtrades: 10, + inverse: true +}); +``` + ## Sample App diff --git a/src/main/java/org/qortal/api/apps/resource/AppsResource.java b/src/main/java/org/qortal/api/apps/resource/AppsResource.java index 32b364b2..db72a13c 100644 --- a/src/main/java/org/qortal/api/apps/resource/AppsResource.java +++ b/src/main/java/org/qortal/api/apps/resource/AppsResource.java @@ -12,6 +12,7 @@ import org.qortal.api.*; import org.qortal.api.model.NameSummary; import org.qortal.api.resource.*; import org.qortal.arbitrary.misc.Service; +import org.qortal.crosschain.SupportedBlockchain; import org.qortal.data.account.AccountData; import org.qortal.data.arbitrary.ArbitraryResourceInfo; import org.qortal.data.arbitrary.ArbitraryResourceStatus; @@ -214,6 +215,14 @@ public class AppsResource { return transactionsResource.searchTransactions(startBlock, blockLimit, txGroupId, txTypes, address, confirmationStatus, limit, offset, reverse); } + @GET + @Path("/price") + @Hidden // For internal Q-App API use only + public long getPrice(@QueryParam("blockchain") SupportedBlockchain foreignBlockchain, @QueryParam("maxtrades") Integer maxtrades, @QueryParam("inverse") Boolean inverse) { + CrossChainResource crossChainResource = (CrossChainResource) buildResource(CrossChainResource.class, request, response, context); + return crossChainResource.getTradePriceEstimate(foreignBlockchain, maxtrades, inverse); + } + public static Object buildResource(Class resourceClass, HttpServletRequest request, HttpServletResponse response, ServletContext context) { try { diff --git a/src/main/resources/q-apps/q-apps.js b/src/main/resources/q-apps/q-apps.js index b6e75404..2a2c04a5 100644 --- a/src/main/resources/q-apps/q-apps.js +++ b/src/main/resources/q-apps/q-apps.js @@ -190,6 +190,14 @@ window.addEventListener("message", (event) => { response = httpGet(url); break; + case "GET_PRICE": + url = "/apps/price?"; + if (data.blockchain != null) url = url.concat("&blockchain=" + data.blockchain); + if (data.maxtrades != null) url = url.concat("&maxtrades=" + data.maxtrades); + if (data.inverse != null) url = url.concat("&inverse=" + data.inverse); + response = httpGet(url); + break; + default: // Pass to parent (UI), in case they can fulfil this request event.data.requestedHandler = "UI";