From 83f4e2f5bf651fc05b4bcd31136912db42ec0c89 Mon Sep 17 00:00:00 2001 From: catbref Date: Sun, 17 Jan 2021 15:31:44 +0000 Subject: [PATCH] Added API call to view single trade's detailed info --- .../api/resource/CrossChainResource.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/org/qortal/api/resource/CrossChainResource.java b/src/main/java/org/qortal/api/resource/CrossChainResource.java index 005b1ff1..7a6c2c96 100644 --- a/src/main/java/org/qortal/api/resource/CrossChainResource.java +++ b/src/main/java/org/qortal/api/resource/CrossChainResource.java @@ -118,6 +118,37 @@ public class CrossChainResource { } } + @GET + @Path("/trade/{ataddress}") + @Operation( + summary = "Show detailed trade info", + responses = { + @ApiResponse( + content = @Content( + schema = @Schema( + implementation = CrossChainTradeData.class + ) + ) + ) + } + ) + @ApiErrors({ApiError.ADDRESS_UNKNOWN, ApiError.INVALID_CRITERIA, ApiError.REPOSITORY_ISSUE}) + public CrossChainTradeData getTrade(@PathParam("ataddress") String atAddress) { + try (final Repository repository = RepositoryManager.getRepository()) { + ATData atData = repository.getATRepository().fromATAddress(atAddress); + if (atData == null) + throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN); + + ACCT acct = SupportedBlockchain.getAcctByCodeHash(atData.getCodeHash()); + if (acct == null) + throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA); + + return acct.populateTradeData(repository, atData); + } catch (DataException e) { + throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); + } + } + @GET @Path("/trades") @Operation(