Browse Source

Added API call GET /transactions/reference/{reference} for looking up a transaction by its reference

split-DB
catbref 5 years ago
parent
commit
3470b8bf57
  1. 44
      src/main/java/org/qortal/api/resource/TransactionsResource.java

44
src/main/java/org/qortal/api/resource/TransactionsResource.java

@ -71,7 +71,7 @@ public class TransactionsResource {
@ApiErrors({
ApiError.INVALID_SIGNATURE, ApiError.TRANSACTION_NO_EXISTS, ApiError.REPOSITORY_ISSUE
})
public TransactionData getTransaction(@PathParam("signature") String signature58) {
public TransactionData getTransactionBySignature(@PathParam("signature") String signature58) {
byte[] signature;
try {
signature = Base58.decode(signature58);
@ -112,7 +112,7 @@ public class TransactionsResource {
@ApiErrors({
ApiError.INVALID_SIGNATURE, ApiError.TRANSACTION_NO_EXISTS, ApiError.REPOSITORY_ISSUE, ApiError.TRANSFORMATION_ERROR
})
public String getRawTransaction(@PathParam("signature") String signature58) {
public String getRawTransactionBySignature(@PathParam("signature") String signature58) {
byte[] signature;
try {
signature = Base58.decode(signature58);
@ -137,6 +137,46 @@ public class TransactionsResource {
}
}
@GET
@Path("/reference/{reference}")
@Operation(
summary = "Fetch transaction using transaction reference",
description = "Returns transaction",
responses = {
@ApiResponse(
description = "a transaction",
content = @Content(
schema = @Schema(
implementation = TransactionData.class
)
)
)
}
)
@ApiErrors({
ApiError.INVALID_REFERENCE, ApiError.TRANSACTION_NO_EXISTS, ApiError.REPOSITORY_ISSUE
})
public TransactionData getTransactionByReference(@PathParam("reference") String reference58) {
byte[] reference;
try {
reference = Base58.decode(reference58);
} catch (NumberFormatException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_REFERENCE, e);
}
try (final Repository repository = RepositoryManager.getRepository()) {
TransactionData transactionData = repository.getTransactionRepository().fromReference(reference);
if (transactionData == null)
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSACTION_NO_EXISTS);
return transactionData;
} catch (ApiException e) {
throw e;
} catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
}
}
@GET
@Path("/block/{signature}")
@Operation(

Loading…
Cancel
Save