Return ArbitraryTransactionData instead of a byte array, as it is more useful if the bytes are transformed separately.

This commit is contained in:
CalDescent 2021-10-24 19:06:30 +01:00
parent 5055cfc6cb
commit c90aeba286
3 changed files with 13 additions and 10 deletions

View File

@ -262,10 +262,10 @@ public class ArbitraryResource {
publicKey58, Paths.get(path), name, Method.valueOf(methodString), Service.ARBITRARY_DATA
);
byte[] bytes = transactionBuilder.build();
return Base58.encode(bytes);
ArbitraryTransactionData transactionData = transactionBuilder.build();
return Base58.encode(ArbitraryTransactionTransformer.toBytes(transactionData));
} catch (DataException e) {
} catch (DataException | TransformationException e) {
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.INVALID_DATA, e.getMessage());
}
}

View File

@ -31,6 +31,7 @@ import org.qortal.api.ApiExceptionFactory;
import org.qortal.api.HTMLParser;
import org.qortal.api.Security;
import org.qortal.arbitrary.ArbitraryDataTransactionBuilder;
import org.qortal.data.transaction.ArbitraryTransactionData;
import org.qortal.data.transaction.ArbitraryTransactionData.*;
import org.qortal.repository.DataException;
import org.qortal.settings.Settings;
@ -38,6 +39,8 @@ import org.qortal.arbitrary.ArbitraryDataFile;
import org.qortal.arbitrary.ArbitraryDataFile.*;
import org.qortal.arbitrary.ArbitraryDataReader;
import org.qortal.arbitrary.ArbitraryDataWriter;
import org.qortal.transform.TransformationException;
import org.qortal.transform.transaction.ArbitraryTransactionTransformer;
import org.qortal.utils.Base58;
@ -93,10 +96,10 @@ public class WebsiteResource {
publicKey58, Paths.get(path), name, Method.valueOf(methodString), Service.WEBSITE
);
byte[] bytes = transactionBuilder.build();
return Base58.encode(bytes);
ArbitraryTransactionData transactionData = transactionBuilder.build();
return Base58.encode(ArbitraryTransactionTransformer.toBytes(transactionData));
} catch (DataException e) {
} catch (DataException | TransformationException e) {
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.INVALID_DATA, e.getMessage());
}
}

View File

@ -44,7 +44,7 @@ public class ArbitraryDataTransactionBuilder {
this.service = service;
}
public byte[] build() throws DataException {
public ArbitraryTransactionData build() throws DataException {
ArbitraryDataFile arbitraryDataFile = null;
try (final Repository repository = RepositoryManager.getRepository()) {
@ -109,11 +109,11 @@ public class ArbitraryDataTransactionBuilder {
throw new DataException(String.format("Arbitrary transaction invalid: %s", result));
}
return ArbitraryTransactionTransformer.toBytes(transactionData);
return transactionData;
} catch (TransformationException | DataException e) {
} catch (DataException e) {
arbitraryDataFile.deleteAll();
throw new DataException(String.format("Unable to build ARBITRARY transaction: %s", e.getMessage()));
throw(e);
}
}