@Test void unknownTransactionType() throws Exception { int unknownType = 9999; byte[] transactionBodyBytes = Hex.decodeHex( "0a120a0c08eb88d6ee0510e8eff7ab01120218021202180318c280de1922020878321043727970746f2074657374206d656d6ffaf004050a03666f6f"); Transaction transaction = Transaction.newBuilder() .setBodyBytes(ByteString.copyFrom(transactionBodyBytes)) .build(); RecordItem recordItem = new RecordItem(transaction, TRANSACTION_RECORD); assertThat(recordItem.getTransactionType()).isEqualTo(unknownType); }
private static int getTransactionType(TransactionBody body) { TransactionBody.DataCase dataCase = body.getDataCase(); if (dataCase == null || dataCase == TransactionBody.DataCase.DATA_NOT_SET) { Set<Integer> unknownFields = body.getUnknownFields().asMap().keySet(); if (unknownFields.size() != 1) { throw new IllegalStateException("Unable to guess correct transaction type since there's not " + "exactly one: " + unknownFields); } int transactionType = unknownFields.iterator().next(); log.warn("Encountered unknown transaction type: {}", transactionType); return transactionType; } return dataCase.getNumber(); }
RecordItem implements StreamItem { private static int getTransactionType(TransactionBody body) { TransactionBody.DataCase dataCase = body.getDataCase(); if (dataCase == null || dataCase == TransactionBody.DataCase.DATA_NOT_SET) { Set<Integer> unknownFields = body.getUnknownFields().asMap().keySet(); if (unknownFields.size() != 1) { throw new IllegalStateException("Unable to guess correct transaction type since there's not " + "exactly one: " + unknownFields); } int transactionType = unknownFields.iterator().next(); log.warn("Encountered unknown transaction type: {}", transactionType); return transactionType; } return dataCase.getNumber(); } }
RecordItem implements StreamItem { private static int getTransactionType(TransactionBody body) { TransactionBody.DataCase dataCase = body.getDataCase(); if (dataCase == null || dataCase == TransactionBody.DataCase.DATA_NOT_SET) { Set<Integer> unknownFields = body.getUnknownFields().asMap().keySet(); if (unknownFields.size() != 1) { throw new IllegalStateException("Unable to guess correct transaction type since there's not " + "exactly one: " + unknownFields); } int transactionType = unknownFields.iterator().next(); log.warn("Encountered unknown transaction type: {}", transactionType); return transactionType; } return dataCase.getNumber(); } RecordItem(byte[] transactionBytes, byte[] recordBytes);  RecordItem(Transaction transaction, TransactionRecord record); }
RecordItem implements StreamItem { private static int getTransactionType(TransactionBody body) { TransactionBody.DataCase dataCase = body.getDataCase(); if (dataCase == null || dataCase == TransactionBody.DataCase.DATA_NOT_SET) { Set<Integer> unknownFields = body.getUnknownFields().asMap().keySet(); if (unknownFields.size() != 1) { throw new IllegalStateException("Unable to guess correct transaction type since there's not " + "exactly one: " + unknownFields); } int transactionType = unknownFields.iterator().next(); log.warn("Encountered unknown transaction type: {}", transactionType); return transactionType; } return dataCase.getNumber(); } RecordItem(byte[] transactionBytes, byte[] recordBytes);  RecordItem(Transaction transaction, TransactionRecord record); TransactionBody getTransactionBody(); SignatureMap getSignatureMap(); }
RecordItem implements StreamItem { private static int getTransactionType(TransactionBody body) { TransactionBody.DataCase dataCase = body.getDataCase(); if (dataCase == null || dataCase == TransactionBody.DataCase.DATA_NOT_SET) { Set<Integer> unknownFields = body.getUnknownFields().asMap().keySet(); if (unknownFields.size() != 1) { throw new IllegalStateException("Unable to guess correct transaction type since there's not " + "exactly one: " + unknownFields); } int transactionType = unknownFields.iterator().next(); log.warn("Encountered unknown transaction type: {}", transactionType); return transactionType; } return dataCase.getNumber(); } RecordItem(byte[] transactionBytes, byte[] recordBytes);  RecordItem(Transaction transaction, TransactionRecord record); TransactionBody getTransactionBody(); SignatureMap getSignatureMap();  }