diff --git a/src/main/java/org/qortal/api/resource/ArbitraryResource.java b/src/main/java/org/qortal/api/resource/ArbitraryResource.java index c4c19652..8dbf467d 100644 --- a/src/main/java/org/qortal/api/resource/ArbitraryResource.java +++ b/src/main/java/org/qortal/api/resource/ArbitraryResource.java @@ -540,6 +540,9 @@ public class ArbitraryResource { } for (ArbitraryTransactionData transactionData : transactionDataList) { + if (transactionData.getService() == null) { + continue; + } ArbitraryResourceInfo arbitraryResourceInfo = new ArbitraryResourceInfo(); arbitraryResourceInfo.name = transactionData.getName(); arbitraryResourceInfo.service = transactionData.getService(); diff --git a/src/main/java/org/qortal/controller/PirateChainWalletController.java b/src/main/java/org/qortal/controller/PirateChainWalletController.java index 333c2cda..90e65329 100644 --- a/src/main/java/org/qortal/controller/PirateChainWalletController.java +++ b/src/main/java/org/qortal/controller/PirateChainWalletController.java @@ -163,7 +163,7 @@ public class PirateChainWalletController extends Thread { // Library not found, so check if we've fetched the resource from QDN ArbitraryTransactionData t = this.getTransactionData(repository); - if (t == null) { + if (t == null || t.getService() == null) { // Can't find the transaction - maybe on a different chain? return; } diff --git a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataCleanupManager.java b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataCleanupManager.java index 34acf0cb..f3d9d8cd 100644 --- a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataCleanupManager.java +++ b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataCleanupManager.java @@ -137,7 +137,7 @@ public class ArbitraryDataCleanupManager extends Thread { // Fetch the transaction data ArbitraryTransactionData arbitraryTransactionData = ArbitraryTransactionUtils.fetchTransactionData(repository, signature); - if (arbitraryTransactionData == null) { + if (arbitraryTransactionData == null || arbitraryTransactionData.getService() == null) { continue; } diff --git a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java index 6b3f0160..99e490b6 100644 --- a/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java +++ b/src/main/java/org/qortal/controller/arbitrary/ArbitraryDataManager.java @@ -398,6 +398,11 @@ public class ArbitraryDataManager extends Thread { // Entrypoint to request new metadata from peers public ArbitraryDataTransactionMetadata fetchMetadata(ArbitraryTransactionData arbitraryTransactionData) { + if (arbitraryTransactionData.getService() == null) { + // Can't fetch metadata without a valid service + return null; + } + ArbitraryDataResource resource = new ArbitraryDataResource( arbitraryTransactionData.getName(), ArbitraryDataFile.ResourceIdType.NAME, @@ -489,7 +494,7 @@ public class ArbitraryDataManager extends Thread { public void invalidateCache(ArbitraryTransactionData arbitraryTransactionData) { String signature58 = Base58.encode(arbitraryTransactionData.getSignature()); - if (arbitraryTransactionData.getName() != null) { + if (arbitraryTransactionData.getName() != null && arbitraryTransactionData.getService() != null) { String resourceId = arbitraryTransactionData.getName().toLowerCase(); Service service = arbitraryTransactionData.getService(); String identifier = arbitraryTransactionData.getIdentifier(); diff --git a/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBArbitraryTransactionRepository.java b/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBArbitraryTransactionRepository.java index 345338c7..57b75a29 100644 --- a/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBArbitraryTransactionRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBArbitraryTransactionRepository.java @@ -66,7 +66,7 @@ public class HSQLDBArbitraryTransactionRepository extends HSQLDBTransactionRepos HSQLDBSaver saveHelper = new HSQLDBSaver("ArbitraryTransactions"); saveHelper.bind("signature", arbitraryTransactionData.getSignature()).bind("sender", arbitraryTransactionData.getSenderPublicKey()) - .bind("version", arbitraryTransactionData.getVersion()).bind("service", arbitraryTransactionData.getService().value) + .bind("version", arbitraryTransactionData.getVersion()).bind("service", arbitraryTransactionData.getServiceInt()) .bind("nonce", arbitraryTransactionData.getNonce()).bind("size", arbitraryTransactionData.getSize()) .bind("is_data_raw", arbitraryTransactionData.getDataType() == DataType.RAW_DATA).bind("data", arbitraryTransactionData.getData()) .bind("metadata_hash", arbitraryTransactionData.getMetadataHash()).bind("name", arbitraryTransactionData.getName()) diff --git a/src/test/java/org/qortal/test/arbitrary/ArbitraryTransactionTests.java b/src/test/java/org/qortal/test/arbitrary/ArbitraryTransactionTests.java index 2c2d52b2..01c1f0f3 100644 --- a/src/test/java/org/qortal/test/arbitrary/ArbitraryTransactionTests.java +++ b/src/test/java/org/qortal/test/arbitrary/ArbitraryTransactionTests.java @@ -6,12 +6,14 @@ import org.junit.Test; import org.qortal.account.PrivateKeyAccount; import org.qortal.arbitrary.ArbitraryDataFile; import org.qortal.arbitrary.ArbitraryDataTransactionBuilder; -import org.qortal.arbitrary.exception.MissingDataException; import org.qortal.arbitrary.misc.Service; import org.qortal.controller.arbitrary.ArbitraryDataManager; +import org.qortal.data.PaymentData; import org.qortal.data.transaction.ArbitraryTransactionData; +import org.qortal.data.transaction.BaseTransactionData; import org.qortal.data.transaction.RegisterNameTransactionData; import org.qortal.data.transaction.TransactionData; +import org.qortal.group.Group; import org.qortal.repository.DataException; import org.qortal.repository.Repository; import org.qortal.repository.RepositoryManager; @@ -25,9 +27,11 @@ import org.qortal.transaction.Transaction; import org.qortal.utils.Base58; import org.qortal.utils.NTP; -import javax.xml.crypto.Data; import java.io.IOException; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; import static org.junit.Assert.*; @@ -423,4 +427,44 @@ public class ArbitraryTransactionTests extends Common { assertTrue(transaction.isSignatureValid()); } } + + @Test + public void testInvalidService() { + byte[] randomHash = new byte[32]; + new Random().nextBytes(randomHash); + + byte[] lastReference = new byte[64]; + new Random().nextBytes(lastReference); + + Long now = NTP.getTime(); + + final BaseTransactionData baseTransactionData = new BaseTransactionData(now, Group.NO_GROUP, + lastReference, randomHash, 0L, null); + final String name = "test"; + final String identifier = "test"; + final ArbitraryTransactionData.Method method = ArbitraryTransactionData.Method.PUT; + final ArbitraryTransactionData.Compression compression = ArbitraryTransactionData.Compression.ZIP; + final int size = 999; + final int version = 5; + final int nonce = 0; + final byte[] secret = randomHash; + final ArbitraryTransactionData.DataType dataType = ArbitraryTransactionData.DataType.DATA_HASH; + final byte[] digest = randomHash; + final byte[] metadataHash = null; + final List payments = new ArrayList<>(); + final int validService = Service.IMAGE.value; + final int invalidService = 99999999; + + // Try with valid service + ArbitraryTransactionData transactionData = new ArbitraryTransactionData(baseTransactionData, + version, validService, nonce, size, name, identifier, method, + secret, compression, digest, dataType, metadataHash, payments); + assertEquals(Service.IMAGE, transactionData.getService()); + + // Try with invalid service + transactionData = new ArbitraryTransactionData(baseTransactionData, + version, invalidService, nonce, size, name, identifier, method, + secret, compression, digest, dataType, metadataHash, payments); + assertNull(transactionData.getService()); + } }