Check for null last references at the beginning of the process when creating an arbitrary tx.

This commit is contained in:
CalDescent 2021-08-19 09:10:13 +01:00
parent 59ef66f46d
commit 1d62ef357d
2 changed files with 70 additions and 62 deletions

View File

@ -261,10 +261,19 @@ public class ArbitraryResource {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NON_PRODUCTION);
}
ArbitraryDataFile arbitraryDataFile = null;
try (final Repository repository = RepositoryManager.getRepository()) {
if (creatorPublicKeyBase58 == null || path == null) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
}
byte[] creatorPublicKey = Base58.decode(creatorPublicKeyBase58);
final String creatorAddress = Crypto.toAddress(creatorPublicKey);
final byte[] lastReference = repository.getAccountRepository().getLastReference(creatorAddress);
if (lastReference == null) {
LOGGER.info(String.format("Qortal account %s has no last reference", creatorAddress));
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
}
String name = null;
byte[] secret = null;
@ -283,13 +292,11 @@ public class ArbitraryResource {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
}
ArbitraryDataFile arbitraryDataFile = arbitraryDataWriter.getArbitraryDataFile();
arbitraryDataFile = arbitraryDataWriter.getArbitraryDataFile();
if (arbitraryDataFile == null) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
}
try (final Repository repository = RepositoryManager.getRepository()) {
ArbitraryDataFile.ValidationResult validationResult = arbitraryDataFile.isValid();
if (validationResult != ArbitraryDataFile.ValidationResult.OK) {
LOGGER.error("Invalid file: {}", validationResult);
@ -310,9 +317,6 @@ public class ArbitraryResource {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
}
final String creatorAddress = Crypto.toAddress(creatorPublicKey);
final byte[] lastReference = repository.getAccountRepository().getLastReference(creatorAddress);
final BaseTransactionData baseTransactionData = new BaseTransactionData(NTP.getTime(), Group.NO_GROUP,
lastReference, creatorPublicKey, BlockChain.getInstance().getUnitFee(), null);
final int size = (int) arbitraryDataFile.size();

View File

@ -96,13 +96,22 @@ public class WebsiteResource {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NON_PRODUCTION);
}
ArbitraryDataFile arbitraryDataFile = null;
try (final Repository repository = RepositoryManager.getRepository()) {
if (creatorPublicKeyBase58 == null || path == null) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
}
byte[] creatorPublicKey = Base58.decode(creatorPublicKeyBase58);
final String creatorAddress = Crypto.toAddress(creatorPublicKey);
final byte[] lastReference = repository.getAccountRepository().getLastReference(creatorAddress);
if (lastReference == null) {
LOGGER.info(String.format("Qortal account %s has no last reference", creatorAddress));
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
}
String name = "CalDescentTest1"; // TODO: dynamic
ArbitraryTransactionData.Method method = ArbitraryTransactionData.Method.PATCH;
ArbitraryTransactionData.Method method = ArbitraryTransactionData.Method.PUT; // TODO: dynamic
ArbitraryTransactionData.Service service = ArbitraryTransactionData.Service.WEBSITE;
ArbitraryTransactionData.Compression compression = ArbitraryTransactionData.Compression.ZIP;
@ -117,7 +126,7 @@ public class WebsiteResource {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
}
ArbitraryDataFile arbitraryDataFile = arbitraryDataWriter.getArbitraryDataFile();
arbitraryDataFile = arbitraryDataWriter.getArbitraryDataFile();
if (arbitraryDataFile == null) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
}
@ -128,11 +137,6 @@ public class WebsiteResource {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
}
try (final Repository repository = RepositoryManager.getRepository()) {
final String creatorAddress = Crypto.toAddress(creatorPublicKey);
final byte[] lastReference = repository.getAccountRepository().getLastReference(creatorAddress);
final BaseTransactionData baseTransactionData = new BaseTransactionData(NTP.getTime(), Group.NO_GROUP,
lastReference, creatorPublicKey, BlockChain.getInstance().getUnitFee(), null);
final int size = (int) arbitraryDataFile.size();