mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Translation fixes
Translator class no longer logs warnings for every failed translation. Commented out unused ApiError enum entries. Renamed some ApiError names like "_NO_EXISTS" to "_UNKNOWN". Removed old src/main/resources/globalization/* files. Added CheckTranslations test app. Fixed some extraneous/missing ApiError aspects in some API-related classes. e.g. added NAME_UNKNOWN to GET /names/{name}
This commit is contained in:
@@ -7,10 +7,10 @@ import java.util.Map;
|
||||
|
||||
public enum ApiError {
|
||||
// COMMON
|
||||
UNKNOWN(0, 500),
|
||||
// UNKNOWN(0, 500),
|
||||
JSON(1, 400),
|
||||
NO_BALANCE(2, 422),
|
||||
NOT_YET_RELEASED(3, 422),
|
||||
// NO_BALANCE(2, 422),
|
||||
// NOT_YET_RELEASED(3, 422),
|
||||
UNAUTHORIZED(4, 403),
|
||||
REPOSITORY_ISSUE(5, 500),
|
||||
NON_PRODUCTION(6, 403),
|
||||
@@ -19,28 +19,28 @@ public enum ApiError {
|
||||
// VALIDATION
|
||||
INVALID_SIGNATURE(101, 400),
|
||||
INVALID_ADDRESS(102, 400),
|
||||
INVALID_SEED(103, 400),
|
||||
INVALID_AMOUNT(104, 400),
|
||||
INVALID_FEE(105, 400),
|
||||
INVALID_SENDER(106, 400),
|
||||
INVALID_RECIPIENT(107, 400),
|
||||
INVALID_NAME_LENGTH(108, 400),
|
||||
INVALID_VALUE_LENGTH(109, 400),
|
||||
INVALID_NAME_OWNER(110, 400),
|
||||
INVALID_BUYER(111, 400),
|
||||
// INVALID_SEED(103, 400),
|
||||
// INVALID_AMOUNT(104, 400),
|
||||
// INVALID_FEE(105, 400),
|
||||
// INVALID_SENDER(106, 400),
|
||||
// INVALID_RECIPIENT(107, 400),
|
||||
// INVALID_NAME_LENGTH(108, 400),
|
||||
// INVALID_VALUE_LENGTH(109, 400),
|
||||
// INVALID_NAME_OWNER(110, 400),
|
||||
// INVALID_BUYER(111, 400),
|
||||
INVALID_PUBLIC_KEY(112, 400),
|
||||
INVALID_OPTIONS_LENGTH(113, 400),
|
||||
INVALID_OPTION_LENGTH(114, 400),
|
||||
// INVALID_OPTIONS_LENGTH(113, 400),
|
||||
// INVALID_OPTION_LENGTH(114, 400),
|
||||
INVALID_DATA(115, 400),
|
||||
INVALID_DATA_LENGTH(116, 400),
|
||||
INVALID_UPDATE_VALUE(117, 400),
|
||||
KEY_ALREADY_EXISTS(118, 422),
|
||||
KEY_NOT_EXISTS(119, 404),
|
||||
LAST_KEY_IS_DEFAULT_KEY_ERROR(120, 422),
|
||||
FEE_LESS_REQUIRED(121, 422),
|
||||
WALLET_NOT_IN_SYNC(122, 422),
|
||||
// INVALID_DATA_LENGTH(116, 400),
|
||||
// INVALID_UPDATE_VALUE(117, 400),
|
||||
// KEY_ALREADY_EXISTS(118, 422),
|
||||
// KEY_NOT_EXISTS(119, 404),
|
||||
// LAST_KEY_IS_DEFAULT_KEY_ERROR(120, 422),
|
||||
// FEE_LESS_REQUIRED(121, 422),
|
||||
// WALLET_NOT_IN_SYNC(122, 422),
|
||||
INVALID_NETWORK_ADDRESS(123, 404),
|
||||
ADDRESS_NO_EXISTS(124, 404),
|
||||
ADDRESS_UNKNOWN(124, 404),
|
||||
INVALID_CRITERIA(125, 400),
|
||||
INVALID_REFERENCE(126, 400),
|
||||
TRANSFORMATION_ERROR(127, 400),
|
||||
@@ -49,72 +49,72 @@ public enum ApiError {
|
||||
CANNOT_MINT(130, 400),
|
||||
|
||||
// WALLET
|
||||
WALLET_NO_EXISTS(201, 404),
|
||||
WALLET_ADDRESS_NO_EXISTS(202, 404),
|
||||
WALLET_LOCKED(203, 422),
|
||||
WALLET_ALREADY_EXISTS(204, 422),
|
||||
WALLET_API_CALL_FORBIDDEN_BY_USER(205, 403),
|
||||
// WALLET_NO_EXISTS(201, 404),
|
||||
// WALLET_ADDRESS_NO_EXISTS(202, 404),
|
||||
// WALLET_LOCKED(203, 422),
|
||||
// WALLET_ALREADY_EXISTS(204, 422),
|
||||
// WALLET_API_CALL_FORBIDDEN_BY_USER(205, 403),
|
||||
|
||||
// BLOCKS
|
||||
BLOCK_NO_EXISTS(301, 404),
|
||||
BLOCK_UNKNOWN(301, 404),
|
||||
|
||||
// TRANSACTIONS
|
||||
TRANSACTION_NO_EXISTS(311, 404),
|
||||
TRANSACTION_UNKNOWN(311, 404),
|
||||
PUBLIC_KEY_NOT_FOUND(304, 404),
|
||||
TRANSACTION_INVALID(312, 400),
|
||||
|
||||
// NAMING
|
||||
NAME_NO_EXISTS(401, 404),
|
||||
NAME_ALREADY_EXISTS(402, 422),
|
||||
NAME_ALREADY_FOR_SALE(403, 422),
|
||||
NAME_NOT_LOWER_CASE(404, 422),
|
||||
NAME_SALE_NO_EXISTS(410, 404),
|
||||
BUYER_ALREADY_OWNER(411, 422),
|
||||
NAME_UNKNOWN(401, 404),
|
||||
// NAME_ALREADY_EXISTS(402, 422),
|
||||
// NAME_ALREADY_FOR_SALE(403, 422),
|
||||
// NAME_NOT_LOWER_CASE(404, 422),
|
||||
// NAME_SALE_NO_EXISTS(410, 404),
|
||||
// BUYER_ALREADY_OWNER(411, 422),
|
||||
|
||||
// POLLS
|
||||
POLL_NO_EXISTS(501, 404),
|
||||
POLL_ALREADY_EXISTS(502, 422),
|
||||
DUPLICATE_OPTION(503, 422),
|
||||
POLL_OPTION_NO_EXISTS(504, 404),
|
||||
ALREADY_VOTED_FOR_THAT_OPTION(505, 422),
|
||||
// POLL_NO_EXISTS(501, 404),
|
||||
// POLL_ALREADY_EXISTS(502, 422),
|
||||
// DUPLICATE_OPTION(503, 422),
|
||||
// POLL_OPTION_NO_EXISTS(504, 404),
|
||||
// ALREADY_VOTED_FOR_THAT_OPTION(505, 422),
|
||||
|
||||
// ASSET
|
||||
INVALID_ASSET_ID(601, 400),
|
||||
INVALID_ORDER_ID(602, 400),
|
||||
ORDER_NO_EXISTS(603, 404),
|
||||
ORDER_UNKNOWN(603, 404),
|
||||
|
||||
// NAME PAYMENTS
|
||||
NAME_NOT_REGISTERED(701, 422),
|
||||
NAME_FOR_SALE(702, 422),
|
||||
NAME_WITH_SPACE(703, 422),
|
||||
// NAME_NOT_REGISTERED(701, 422),
|
||||
// NAME_FOR_SALE(702, 422),
|
||||
// NAME_WITH_SPACE(703, 422),
|
||||
|
||||
// ATs
|
||||
INVALID_DESC_LENGTH(801, 400),
|
||||
EMPTY_CODE(802, 400),
|
||||
DATA_SIZE(803, 400),
|
||||
NULL_PAGES(804, 400),
|
||||
INVALID_TYPE_LENGTH(805, 400),
|
||||
INVALID_TAGS_LENGTH(806, 400),
|
||||
INVALID_CREATION_BYTES(809, 400),
|
||||
// INVALID_DESC_LENGTH(801, 400),
|
||||
// EMPTY_CODE(802, 400),
|
||||
// DATA_SIZE(803, 400),
|
||||
// NULL_PAGES(804, 400),
|
||||
// INVALID_TYPE_LENGTH(805, 400),
|
||||
// INVALID_TAGS_LENGTH(806, 400),
|
||||
// INVALID_CREATION_BYTES(809, 400),
|
||||
|
||||
// BLOG/Namestorage
|
||||
BODY_EMPTY(901, 400),
|
||||
BLOG_DISABLED(902, 403),
|
||||
NAME_NOT_OWNER(903, 422),
|
||||
TX_AMOUNT(904, 400),
|
||||
BLOG_ENTRY_NO_EXISTS(905, 404),
|
||||
BLOG_EMPTY(906, 404),
|
||||
POSTID_EMPTY(907, 400),
|
||||
POST_NOT_EXISTING(908, 404),
|
||||
COMMENTING_DISABLED(909, 403),
|
||||
COMMENT_NOT_EXISTING(910, 404),
|
||||
INVALID_COMMENT_OWNER(911, 422),
|
||||
// BODY_EMPTY(901, 400),
|
||||
// BLOG_DISABLED(902, 403),
|
||||
// NAME_NOT_OWNER(903, 422),
|
||||
// TX_AMOUNT(904, 400),
|
||||
// BLOG_ENTRY_NO_EXISTS(905, 404),
|
||||
// BLOG_EMPTY(906, 404),
|
||||
// POSTID_EMPTY(907, 400),
|
||||
// POST_NOT_EXISTING(908, 404),
|
||||
// COMMENTING_DISABLED(909, 403),
|
||||
// COMMENT_NOT_EXISTING(910, 404),
|
||||
// INVALID_COMMENT_OWNER(911, 422),
|
||||
|
||||
// Messages
|
||||
MESSAGE_FORMAT_NOT_HEX(1001, 400),
|
||||
MESSAGE_BLANK(1002, 400),
|
||||
NO_PUBLIC_KEY(1003, 422),
|
||||
MESSAGESIZE_EXCEEDED(1004, 400),
|
||||
// MESSAGE_FORMAT_NOT_HEX(1001, 400),
|
||||
// MESSAGE_BLANK(1002, 400),
|
||||
// NO_PUBLIC_KEY(1003, 422),
|
||||
// MESSAGESIZE_EXCEEDED(1004, 400),
|
||||
|
||||
// Groups
|
||||
GROUP_UNKNOWN(1101, 404);
|
||||
|
@@ -410,7 +410,7 @@ public class AssetsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_ORDER_ID, ApiError.ORDER_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_ORDER_ID, ApiError.ORDER_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public OrderData getAssetOrder(@PathParam("orderid") String orderId58) {
|
||||
// Decode orderID
|
||||
@@ -424,7 +424,7 @@ public class AssetsResource {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
OrderData orderData = repository.getAssetRepository().fromOrderId(orderId);
|
||||
if (orderData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ORDER_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ORDER_UNKNOWN);
|
||||
|
||||
return orderData;
|
||||
} catch (DataException e) {
|
||||
@@ -451,7 +451,7 @@ public class AssetsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_ORDER_ID, ApiError.ORDER_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_ORDER_ID, ApiError.ORDER_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public List<TradeData> getAssetOrderTrades(@PathParam("orderid") String orderId58, @Parameter(
|
||||
ref = "limit"
|
||||
@@ -471,7 +471,7 @@ public class AssetsResource {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
OrderData orderData = repository.getAssetRepository().fromOrderId(orderId);
|
||||
if (orderData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ORDER_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ORDER_UNKNOWN);
|
||||
|
||||
return repository.getAssetRepository().getOrdersTrades(orderId, limit, offset, reverse);
|
||||
} catch (DataException e) {
|
||||
@@ -497,7 +497,7 @@ public class AssetsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_ADDRESS, ApiError.ADDRESS_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public List<OrderData> getAccountOrders(@PathParam("address") String address, @QueryParam("includeClosed") boolean includeClosed,
|
||||
@QueryParam("includeFulfilled") boolean includeFulfilled, @Parameter(
|
||||
@@ -514,11 +514,11 @@ public class AssetsResource {
|
||||
AccountData accountData = repository.getAccountRepository().getAccount(address);
|
||||
|
||||
if (accountData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
byte[] publicKey = accountData.getPublicKey();
|
||||
if (publicKey == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
return repository.getAssetRepository().getAccountsOrders(publicKey, includeClosed, includeFulfilled, limit, offset, reverse);
|
||||
} catch (ApiException e) {
|
||||
@@ -546,7 +546,7 @@ public class AssetsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_ADDRESS, ApiError.ADDRESS_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public List<OrderData> getAccountAssetPairOrders(@PathParam("address") String address, @PathParam("assetid") int assetId,
|
||||
@PathParam("otherassetid") int otherAssetId, @QueryParam("isClosed") Boolean isClosed, @QueryParam("isFulfilled") Boolean isFulfilled, @Parameter(
|
||||
@@ -563,11 +563,11 @@ public class AssetsResource {
|
||||
AccountData accountData = repository.getAccountRepository().getAccount(address);
|
||||
|
||||
if (accountData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
byte[] publicKey = accountData.getPublicKey();
|
||||
if (publicKey == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
if (!repository.getAssetRepository().assetExists(assetId))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ASSET_ID);
|
||||
|
@@ -59,7 +59,7 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public BlockData getBlock(@PathParam("signature") String signature58) {
|
||||
// Decode signature
|
||||
@@ -98,7 +98,7 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public List<TransactionData> getBlockTransactions(@PathParam("signature") String signature58, @Parameter(
|
||||
ref = "limit"
|
||||
@@ -117,7 +117,7 @@ public class BlocksResource {
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
if (repository.getBlockRepository().getHeightFromSignature(signature) == 0)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
return repository.getBlockRepository().getTransactionsFromSignature(signature, limit, offset, reverse);
|
||||
} catch (ApiException e) {
|
||||
@@ -144,13 +144,11 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public BlockData getFirstBlock() {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return repository.getBlockRepository().fromHeight(1);
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
@@ -173,13 +171,11 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public BlockData getLastBlock() {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return repository.getBlockRepository().getLastBlock();
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
@@ -202,7 +198,7 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public BlockData getChild(@PathParam("signature") String signature58) {
|
||||
// Decode signature
|
||||
@@ -218,13 +214,13 @@ public class BlocksResource {
|
||||
|
||||
// Check block exists
|
||||
if (blockData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
BlockData childBlockData = repository.getBlockRepository().fromReference(signature);
|
||||
|
||||
// Check child block exists
|
||||
if (childBlockData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
return childBlockData;
|
||||
} catch (ApiException e) {
|
||||
@@ -282,7 +278,7 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public int getHeight(@PathParam("signature") String signature58) {
|
||||
// Decode signature
|
||||
@@ -298,7 +294,7 @@ public class BlocksResource {
|
||||
|
||||
// Check block exists
|
||||
if (blockData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
return blockData.getHeight();
|
||||
} catch (ApiException e) {
|
||||
@@ -325,13 +321,13 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public BlockData getByHeight(@PathParam("height") int height) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
BlockData blockData = repository.getBlockRepository().fromHeight(height);
|
||||
if (blockData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
return blockData;
|
||||
} catch (ApiException e) {
|
||||
@@ -357,17 +353,17 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public BlockData getByTimestamp(@PathParam("timestamp") long timestamp) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
int height = repository.getBlockRepository().getHeightFromTimestamp(timestamp);
|
||||
if (height == 0)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
BlockData blockData = repository.getBlockRepository().fromHeight(height);
|
||||
if (blockData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
return blockData;
|
||||
} catch (ApiException e) {
|
||||
@@ -396,7 +392,7 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public List<BlockData> getBlockRange(@PathParam("height") int height, @Parameter(
|
||||
ref = "count"
|
||||
@@ -414,8 +410,6 @@ public class BlocksResource {
|
||||
}
|
||||
|
||||
return blocks;
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.qortal.api.ApiError;
|
||||
import org.qortal.api.ApiErrors;
|
||||
import org.qortal.api.ApiException;
|
||||
import org.qortal.api.ApiExceptionFactory;
|
||||
import org.qortal.api.model.NameSummary;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@@ -122,10 +123,17 @@ public class NamesResource {
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.REPOSITORY_ISSUE})
|
||||
@ApiErrors({ApiError.NAME_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public NameData getName(@PathParam("name") String name) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return repository.getNameRepository().fromName(name);
|
||||
NameData nameData = repository.getNameRepository().fromName(name);
|
||||
|
||||
if (nameData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NAME_UNKNOWN);
|
||||
|
||||
return nameData;
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
|
@@ -137,7 +137,7 @@ public class PeersResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_DATA, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_NETWORK_ADDRESS, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public String addPeer(String address) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
@@ -151,7 +151,7 @@ public class PeersResource {
|
||||
|
||||
return "true";
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_NETWORK_ADDRESS);
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
@@ -188,7 +188,7 @@ public class PeersResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_DATA, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_NETWORK_ADDRESS, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public String removePeer(String address) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
@@ -199,7 +199,7 @@ public class PeersResource {
|
||||
boolean wasKnown = Network.getInstance().forgetPeer(peerAddress);
|
||||
return wasKnown ? "true" : "false";
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_NETWORK_ADDRESS);
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
@@ -223,7 +223,7 @@ public class PeersResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_DATA, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public String removeKnownPeers(String address) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
@@ -232,8 +232,6 @@ public class PeersResource {
|
||||
int numDeleted = Network.getInstance().forgetAllPeers();
|
||||
|
||||
return numDeleted != 0 ? "true" : "false";
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ public class TransactionsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_SIGNATURE, ApiError.TRANSACTION_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_SIGNATURE, ApiError.TRANSACTION_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public TransactionData getTransactionBySignature(@PathParam("signature") String signature58) {
|
||||
byte[] signature;
|
||||
@@ -82,7 +82,7 @@ public class TransactionsResource {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature);
|
||||
if (transactionData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSACTION_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSACTION_UNKNOWN);
|
||||
|
||||
return transactionData;
|
||||
} catch (ApiException e) {
|
||||
@@ -110,7 +110,7 @@ public class TransactionsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_SIGNATURE, ApiError.TRANSACTION_NO_EXISTS, ApiError.REPOSITORY_ISSUE, ApiError.TRANSFORMATION_ERROR
|
||||
ApiError.INVALID_SIGNATURE, ApiError.TRANSACTION_UNKNOWN, ApiError.REPOSITORY_ISSUE, ApiError.TRANSFORMATION_ERROR
|
||||
})
|
||||
public String getRawTransactionBySignature(@PathParam("signature") String signature58) {
|
||||
byte[] signature;
|
||||
@@ -123,7 +123,7 @@ public class TransactionsResource {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature);
|
||||
if (transactionData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSACTION_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSACTION_UNKNOWN);
|
||||
|
||||
byte[] transactionBytes = TransactionTransformer.toBytes(transactionData);
|
||||
|
||||
@@ -154,7 +154,7 @@ public class TransactionsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_REFERENCE, ApiError.TRANSACTION_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_REFERENCE, ApiError.TRANSACTION_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public TransactionData getTransactionByReference(@PathParam("reference") String reference58) {
|
||||
byte[] reference;
|
||||
@@ -167,7 +167,7 @@ public class TransactionsResource {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TransactionData transactionData = repository.getTransactionRepository().fromReference(reference);
|
||||
if (transactionData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSACTION_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.TRANSACTION_UNKNOWN);
|
||||
|
||||
return transactionData;
|
||||
} catch (ApiException e) {
|
||||
@@ -196,7 +196,7 @@ public class TransactionsResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
|
||||
ApiError.INVALID_SIGNATURE, ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public List<TransactionData> getBlockTransactions(@PathParam("signature") String signature58, @Parameter(
|
||||
ref = "limit"
|
||||
@@ -215,7 +215,7 @@ public class TransactionsResource {
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
if (repository.getBlockRepository().getHeightFromSignature(signature) == 0)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||
|
||||
return repository.getBlockRepository().getTransactionsFromSignature(signature, limit, offset, reverse);
|
||||
} catch (ApiException e) {
|
||||
|
@@ -17,36 +17,32 @@ import org.apache.logging.log4j.Logger;
|
||||
public enum BIP39WordList {
|
||||
INSTANCE;
|
||||
|
||||
private Logger LOGGER = LogManager.getLogger(BIP39WordList.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(BIP39WordList.class);
|
||||
|
||||
private Map<String, List<String>> wordListsByLang;
|
||||
|
||||
private BIP39WordList() {
|
||||
wordListsByLang = new HashMap<>();
|
||||
}
|
||||
private static final Map<String, List<String>> wordListsByLang = new HashMap<>();
|
||||
|
||||
public synchronized List<String> getByLang(String lang) {
|
||||
List<String> wordList = wordListsByLang.get(lang);
|
||||
|
||||
if (wordList == null) {
|
||||
if (wordList == null && !wordListsByLang.containsKey(lang)) {
|
||||
ClassLoader loader = this.getClass().getClassLoader();
|
||||
|
||||
try (InputStream inputStream = loader.getResourceAsStream("BIP39/wordlist_" + lang + ".txt")) {
|
||||
if (inputStream == null) {
|
||||
if (inputStream == null)
|
||||
LOGGER.warn(String.format("Can't locate '%s' BIP39 wordlist", lang));
|
||||
return null;
|
||||
}
|
||||
|
||||
wordList = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn(String.format("Error reading '%s' BIP39 wordlist", lang), e);
|
||||
return null;
|
||||
LOGGER.warn(String.format("Error reading '%s' BIP39 wordlist: %s", lang, e.getMessage()));
|
||||
}
|
||||
|
||||
wordListsByLang.put(lang, wordList);
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(wordList);
|
||||
if (wordList != null)
|
||||
return Collections.unmodifiableList(wordList);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import java.util.MissingFormatArgumentException;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -13,35 +14,12 @@ import org.apache.logging.log4j.Logger;
|
||||
public enum Translator {
|
||||
INSTANCE;
|
||||
|
||||
private final Logger LOGGER = LogManager.getLogger(Translator.class);
|
||||
private final String DEFAULT_LANG = Locale.getDefault().getLanguage();
|
||||
private static final Logger LOGGER = LogManager.getLogger(Translator.class);
|
||||
private static final String DEFAULT_LANG = Locale.getDefault().getLanguage();
|
||||
|
||||
private final Map<String, ResourceBundle> resourceBundles = new HashMap<>();
|
||||
private static final Map<String, ResourceBundle> resourceBundles = new HashMap<>();
|
||||
|
||||
private synchronized ResourceBundle getOrLoadResourceBundle(String className, String lang) {
|
||||
final String bundleKey = className + ":" + lang;
|
||||
|
||||
ResourceBundle resourceBundle = resourceBundles.get(bundleKey);
|
||||
if (resourceBundle != null)
|
||||
return resourceBundle;
|
||||
|
||||
try {
|
||||
resourceBundle = ResourceBundle.getBundle("i18n." + className, Locale.forLanguageTag(lang));
|
||||
} catch (MissingResourceException e) {
|
||||
LOGGER.warn("Can't locate '" + lang + "' translation resource bundle for " + className, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
resourceBundles.put(bundleKey, resourceBundle);
|
||||
|
||||
return resourceBundle;
|
||||
}
|
||||
|
||||
public String translate(final String className, final String key) {
|
||||
return this.translate(className, DEFAULT_LANG, key);
|
||||
}
|
||||
|
||||
public String translate(final String className, final String lang, final String key, final Object... args) {
|
||||
public String translate(String className, String lang, String key, Object... args) {
|
||||
ResourceBundle resourceBundle = getOrLoadResourceBundle(className, lang);
|
||||
|
||||
if (resourceBundle == null || !resourceBundle.containsKey(key))
|
||||
@@ -55,4 +33,37 @@ public enum Translator {
|
||||
}
|
||||
}
|
||||
|
||||
public String translate(String className, String key) {
|
||||
return this.translate(className, DEFAULT_LANG, key);
|
||||
}
|
||||
|
||||
public Set<String> keySet(String className, String lang) {
|
||||
ResourceBundle resourceBundle = getOrLoadResourceBundle(className, lang);
|
||||
|
||||
if (resourceBundle == null)
|
||||
return null;
|
||||
|
||||
return resourceBundle.keySet();
|
||||
}
|
||||
|
||||
private synchronized ResourceBundle getOrLoadResourceBundle(String className, String lang) {
|
||||
String bundleKey = className + ":" + lang;
|
||||
|
||||
ResourceBundle resourceBundle = resourceBundles.get(bundleKey);
|
||||
if (resourceBundle != null || resourceBundles.containsKey(bundleKey))
|
||||
return resourceBundle;
|
||||
|
||||
try {
|
||||
resourceBundle = ResourceBundle.getBundle("i18n." + className, Locale.forLanguageTag(lang));
|
||||
} catch (MissingResourceException e) {
|
||||
LOGGER.warn(String.format("Can't locate '%s' translation resource bundle for %s", lang, className));
|
||||
// Set to null then fall-through to storing in map so we don't emit warning more than once
|
||||
resourceBundle = null;
|
||||
}
|
||||
|
||||
resourceBundles.put(bundleKey, resourceBundle);
|
||||
|
||||
return resourceBundle;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user