Added API call to view single trade's detailed info

This commit is contained in:
catbref 2021-01-17 15:31:44 +00:00
parent c8e7a00c08
commit 83f4e2f5bf

View File

@ -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 @GET
@Path("/trades") @Path("/trades")
@Operation( @Operation(