public CryptoStatus getCryptoStatus(String transactionHash) throws OutgoingIntraActorCantGetCryptoStatusException { try { DatabaseTable transactionTable = this.database.getTable( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TABLE_NAME); transactionTable.addStringFilter( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_HASH_COLUMN_NAME, transactionHash, DatabaseFilterType.EQUAL); transactionTable.loadToMemory(); List<DatabaseTableRecord> records = transactionTable.getRecords(); transactionTable.clearAllFilters(); return CryptoStatus.getByCode( records .get(0) .getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_CRYPTO_STATUS_COLUMN_NAME)); } catch (InvalidParameterException | CantLoadTableToMemoryException e) { throw new OutgoingIntraActorCantGetCryptoStatusException("An exception happened", e, "", ""); } catch (Exception e) { throw new OutgoingIntraActorCantGetCryptoStatusException( "An unexpected exception happened", FermatException.wrapException(e), "", ""); } }
/** * Saves and outgoing transaction into the database * * @param hash * @param cryptoStatus * @param blockDepth * @param addressTo * @param addressFrom * @param value * @param op_Return * @param protocolStatus * @throws CantExecuteDatabaseOperationException */ public void saveNewOutgoingTransaction( String hash, CryptoStatus cryptoStatus, int blockDepth, CryptoAddress addressTo, CryptoAddress addressFrom, long value, String op_Return, ProtocolStatus protocolStatus) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); DatabaseTableRecord record = databaseTable.getEmptyRecord(); /** generates the trx_id */ UUID trxId = UUID.randomUUID(); record.setUUIDValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TRX_ID_COLUMN_NAME, trxId); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME, hash); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME, cryptoStatus.getCode()); record.setIntegerValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_BLOCK_DEPTH_COLUMN_NAME, blockDepth); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_TO_COLUMN_NAME, addressTo.getAddress()); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_FROM_COLUMN_NAME, addressFrom.getAddress()); record.setDoubleValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_VALUE_COLUMN_NAME, value); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_OP_RETURN_COLUMN_NAME, op_Return); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, protocolStatus.getCode()); record.setStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_LAST_UPDATE_COLUMN_NAME, getCurrentDateTime()); try { databaseTable.insertRecord(record); } catch (CantInsertRecordException e) { StringBuilder outputMessage = new StringBuilder( "There was an error inserting a new transaction in the Outgoing Transactions Table. Transaction record is:"); outputMessage.append(System.lineSeparator()); outputMessage.append(XMLParser.parseObject(record)); throw new CantExecuteDatabaseOperationException( CantExecuteDatabaseOperationException.DEFAULT_MESSAGE, e, outputMessage.toString(), "database issue."); } }
public void setToCryptoStatus( OutgoingDraftTransactionWrapper transactionWrapper, CryptoStatus cryptoStatus) throws CantUpdateRecordException, CantLoadTableToMemoryException, com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai .version_1.exceptions.OutgoingIntraActorInconsistentTableStateException { try { DatabaseTable transactionTable = this.database.getTable( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TABLE_NAME); DatabaseTableRecord recordToUpdate = getByPrimaryKey(transactionWrapper.getRequestId()); recordToUpdate.setStringValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_STATUS_COLUMN_NAME, cryptoStatus.getCode()); transactionTable.addStringFilter( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_ID_COLUMN_NAME, transactionWrapper.getRequestId().toString(), DatabaseFilterType.EQUAL); transactionTable.updateRecord(recordToUpdate); } catch (CantUpdateRecordException | com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai .version_1.exceptions.OutgoingIntraActorInconsistentTableStateException | CantLoadTableToMemoryException exception) { throw exception; } catch (Exception exception) { throw new CantLoadTableToMemoryException( CantLoadTableToMemoryException.DEFAULT_MESSAGE, FermatException.wrapException(exception), null, null); } }
public boolean isPendingTransactions(CryptoStatus cryptoStatus) throws CantExecuteQueryException { try { this.database = openDatabase(); DatabaseTable databaseTable; databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_CRYPTO_STATUS_COLUMN_NAME, cryptoStatus.getCode(), DatabaseFilterType.EQUAL); databaseTable.loadToMemory(); return !databaseTable.getRecords().isEmpty(); } catch (CantLoadTableToMemoryException exception) { throw new CantExecuteQueryException( "Error executing query in DB.", exception, "Getting pending transactions.", "Cannot load table to memory."); } catch (Exception exception) { throw new CantExecuteQueryException( CantExecuteQueryException.DEFAULT_MESSAGE, FermatException.wrapException(exception), "Getting pending transactions.", "Unexpected exception"); } }
public List<String> getGenesisTransactionListByCryptoStatus(CryptoStatus cryptoStatus) throws CantCheckAssetReceptionProgressException { return getValueListFromTableByColumn( cryptoStatus.getCode(), AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME, AssetReceptionDatabaseConstants.ASSET_RECEPTION_CRYPTO_STATUS_COLUMN_NAME, AssetReceptionDatabaseConstants.ASSET_RECEPTION_GENESIS_TRANSACTION_COLUMN_NAME); }
/** * Creates a incoming or outgoing CryptoTransaction object from a database record * * @param transactionType * @param record * @return */ private CryptoTransaction getCryptoTransactionFromRecord( TransactionTypes transactionType, DatabaseTableRecord record) { String addressFromColumnName, addressToColumnName, transactionHashColumnName, valueColumnName, cryptoStatusColumnName; if (transactionType == TransactionTypes.INCOMING) { transactionHashColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME; addressFromColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_FROM_COLUMN_NAME; addressToColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_TO_COLUMN_NAME; valueColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_VALUE_COLUMN_NAME; cryptoStatusColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME; } else { transactionHashColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_HASH_COLUMN_NAME; addressFromColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_ADDRESS_FROM_COLUMN_NAME; addressToColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_ADDRESS_TO_COLUMN_NAME; valueColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_VALUE_COLUMN_NAME; cryptoStatusColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME; } CryptoTransaction cryptoTransaction = new CryptoTransaction(); cryptoTransaction.setTransactionHash(record.getStringValue(transactionHashColumnName)); cryptoTransaction.setCryptoCurrency(CryptoCurrency.BITCOIN); try { cryptoTransaction.setCryptoStatus( CryptoStatus.getByCode(record.getStringValue(cryptoStatusColumnName))); } catch (InvalidParameterException e) { e.printStackTrace(); } cryptoTransaction.setCryptoAmount(record.getLongValue(valueColumnName)); cryptoTransaction.setAddressFrom( new CryptoAddress(record.getStringValue(addressFromColumnName), CryptoCurrency.BITCOIN)); cryptoTransaction.setAddressTo( new CryptoAddress(record.getStringValue(addressToColumnName), CryptoCurrency.BITCOIN)); // todo define how to get the Op_Return value return cryptoTransaction; }
/** * Gets the crypto Status list that are in pending status from the specified table. * * @param transactionType * @return */ public Set<CryptoStatus> getPendingCryptoStatus(TransactionTypes transactionType) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable; String cryptoStatusColumnName; Set<CryptoStatus> cryptoStatuses = new HashSet<>(); /** Will set up filters and column names depending on the transaction type. */ if (transactionType == TransactionTypes.OUTGOING) { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); cryptoStatusColumnName = BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME; } else { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_PROTOCOL_STATUS_COLUMN_NAME, ProtocolStatus.TO_BE_NOTIFIED.getCode(), DatabaseFilterType.EQUAL); cryptoStatusColumnName = BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME; } try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } /** get all the CryptoStatus and remove duplicates as Im storing them in a set. */ for (DatabaseTableRecord record : databaseTable.getRecords()) { try { CryptoStatus cryptoStatus = CryptoStatus.getByCode(record.getStringValue(cryptoStatusColumnName)); cryptoStatuses.add(cryptoStatus); } catch (InvalidParameterException e) { e.printStackTrace(); } } return cryptoStatuses; }
public void updateDigitalAssetCryptoStatusByGenesisTransaction( String genesisTransaction, CryptoStatus cryptoStatus) throws CantCheckAssetReceptionProgressException, UnexpectedResultReturnedFromDatabaseException { try { this.database = openDatabase(); DatabaseTable databaseTable; databaseTable = database.getTable(AssetReceptionDatabaseConstants.ASSET_RECEPTION_TABLE_NAME); databaseTable.addStringFilter( AssetReceptionDatabaseConstants.ASSET_RECEPTION_GENESIS_TRANSACTION_COLUMN_NAME, genesisTransaction, DatabaseFilterType.EQUAL); databaseTable.loadToMemory(); List<DatabaseTableRecord> databaseTableRecords = databaseTable.getRecords(); DatabaseTableRecord databaseTableRecord; if (databaseTableRecords.size() > 1) { throw new UnexpectedResultReturnedFromDatabaseException( "Unexpected result. More than value returned.", "Genesis Transaction:" + genesisTransaction); } else { databaseTableRecord = databaseTableRecords.get(0); } databaseTableRecord.setStringValue( AssetReceptionDatabaseConstants.ASSET_RECEPTION_CRYPTO_STATUS_COLUMN_NAME, cryptoStatus.getCode()); databaseTable.updateRecord(databaseTableRecord); } catch (CantExecuteDatabaseOperationException exception) { throw new CantCheckAssetReceptionProgressException( exception, "Updating Crypto Status.", "Cannot open or find the Asset Issuing database"); } catch (CantLoadTableToMemoryException exception) { throw new CantCheckAssetReceptionProgressException( exception, "Updating Crypto Status ", "Cannot load the table into memory"); } catch (Exception exception) { throw new CantCheckAssetReceptionProgressException( FermatException.wrapException(exception), "Updating Crypto Status.", "Unexpected exception - Transaction hash:" + genesisTransaction); } }
private void decideTheEventToRaiseAndRaiseIt(Specialist specialist, CryptoStatus cryptoStatus) throws CryptoStatusNotHandledException, SpecialistNotRegisteredException { switch (specialist) { case EXTRA_USER_SPECIALIST: switch (cryptoStatus) { case ON_CRYPTO_NETWORK: raiseEvent(EventType.INCOMING_CRYPTO_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_EXTRA_USER); break; case ON_BLOCKCHAIN: raiseEvent(EventType.INCOMING_CRYPTO_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_EXTRA_USER); break; case REVERSED_ON_CRYPTO_NETWORK: raiseEvent( EventType .INCOMING_CRYPTO_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_EXTRA_USER); break; case REVERSED_ON_BLOCKCHAIN: raiseEvent( EventType.INCOMING_CRYPTO_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_EXTRA_USER); break; case IRREVERSIBLE: // define what to do. break; default: String message = "I could not find the event for this crypto status"; String context = "Specialist: " + specialist.name() + " with code: " + specialist.getCode() + FermatException.CONTEXT_CONTENT_SEPARATOR + "Crypto Status: " + cryptoStatus.name() + " with code: " + cryptoStatus.getCode(); String possibleCause = "Crypto Status not considered in switch statement"; throw new CryptoStatusNotHandledException(message, null, context, possibleCause); } break; case INTRA_USER_SPECIALIST: switch (cryptoStatus) { case ON_CRYPTO_NETWORK: System.out.println("INCOMING CRYPTO ROUTER ON CRYPTO NETWORK, LAUNCH EVENT"); raiseEvent(EventType.INCOMING_CRYPTO_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_INTRA_USER); break; case ON_BLOCKCHAIN: System.out.println("INCOMING CRYPTO ROUTER ON BLOCKCHAIN, LAUNCH EVENT"); raiseEvent(EventType.INCOMING_CRYPTO_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_INTRA_USER); break; case REVERSED_ON_CRYPTO_NETWORK: System.out.println("INCOMING CRYPTO ROUTER REVERSED ON CRYPRO NETWORK, LAUNCH EVENT"); raiseEvent( EventType .INCOMING_CRYPTO_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_INTRA_USER); break; case REVERSED_ON_BLOCKCHAIN: System.out.println("INCOMING CRYPTO ROUTER REVERSED ON BLOCKCHAIN, LAUNCH EVENT"); raiseEvent( EventType.INCOMING_CRYPTO_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_INTRA_USER); break; case IRREVERSIBLE: System.out.println("INCOMING CRYPTO ROUTER IRREVERSIBLE LAUNCH EVENT"); // define what to do. break; default: String message = "I could not find the event for this crypto status"; String context = "Specialist: " + specialist.name() + " with code: " + specialist.getCode() + FermatException.CONTEXT_CONTENT_SEPARATOR + "Crypto Status: " + cryptoStatus.name() + " with code: " + cryptoStatus.getCode(); String possibleCause = "Crypto Status not considered in switch statement"; throw new CryptoStatusNotHandledException(message, null, context, possibleCause); } break; case ASSET_ISSUER_SPECIALIST: switch (cryptoStatus) { case ON_CRYPTO_NETWORK: raiseEvent( EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER); System.out.println( "Event INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER) raised."); break; case ON_BLOCKCHAIN: raiseEvent(EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER); System.out.println( "Event INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER raised."); break; case REVERSED_ON_CRYPTO_NETWORK: raiseEvent( EventType .INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_ISSUER); break; case REVERSED_ON_BLOCKCHAIN: raiseEvent( EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_ISSUER); break; case IRREVERSIBLE: // define what to do. break; default: String message = "I could not find the event for this crypto status"; String context = "Specialist: " + specialist.name() + " with code: " + specialist.getCode() + FermatException.CONTEXT_CONTENT_SEPARATOR + "Crypto Status: " + cryptoStatus.name() + " with code: " + cryptoStatus.getCode(); String possibleCause = "Crypto Status not considered in switch statement"; throw new CryptoStatusNotHandledException(message, null, context, possibleCause); } break; case ASSET_USER_SPECIALIST: switch (cryptoStatus) { case ON_CRYPTO_NETWORK: raiseEvent(EventType.INCOMING_ASSET_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_USER); break; case ON_BLOCKCHAIN: raiseEvent(EventType.INCOMING_ASSET_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_USER); break; case REVERSED_ON_CRYPTO_NETWORK: raiseEvent( EventType .INCOMING_ASSET_REVERSED_ON_CRYPTO_NETWORK_WAITING_TRANSFERENCE_ASSET_USER); break; case REVERSED_ON_BLOCKCHAIN: raiseEvent( EventType.INCOMING_ASSET_REVERSED_ON_BLOCKCHAIN_WAITING_TRANSFERENCE_ASSET_USER); break; case IRREVERSIBLE: // define what to do. break; default: String message = "I could not find the event for this crypto status"; String context = "Specialist: " + specialist.name() + " with code: " + specialist.getCode() + FermatException.CONTEXT_CONTENT_SEPARATOR + "Crypto Status: " + cryptoStatus.name() + " with code: " + cryptoStatus.getCode(); String possibleCause = "Crypto Status not considered in switch statement"; throw new CryptoStatusNotHandledException(message, null, context, possibleCause); } break; default: String message = "I could not find the event for this specialist"; String context = "Specialist: " + specialist.name() + " with code: " + specialist.getCode() + FermatException.CONTEXT_CONTENT_SEPARATOR + "Crypto Status: " + cryptoStatus.name() + " with code: " + cryptoStatus.getCode(); String possibleCause = "Specialist not considered in switch statement"; throw new SpecialistNotRegisteredException(message, null, context, possibleCause); } }
/** * Gets the incoming transaction data and forms the CryptoTransaction object * * @param txHash * @return * @throws CantExecuteDatabaseOperationException */ public List<CryptoTransaction> getIncomingCryptoTransaction(String txHash) throws CantExecuteDatabaseOperationException { DatabaseTable databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME, txHash, DatabaseFilterType.EQUAL); try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } List<CryptoTransaction> cryptoTransactions = new ArrayList<>(); for (DatabaseTableRecord record : databaseTable.getRecords()) { /** Gets all the values */ CryptoAddress addressFrom = new CryptoAddress(); addressFrom.setAddress( record.getStringValue( BitcoinCryptoNetworkDatabaseConstants .INCOMING_TRANSACTIONS_ADDRESS_FROM_COLUMN_NAME)); addressFrom.setCryptoCurrency(CryptoCurrency.BITCOIN); CryptoAddress addressTo = new CryptoAddress(); addressFrom.setAddress( record.getStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_ADDRESS_TO_COLUMN_NAME)); addressFrom.setCryptoCurrency(CryptoCurrency.BITCOIN); long amount = record.getLongValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_VALUE_COLUMN_NAME); CryptoStatus cryptoStatus = null; try { cryptoStatus = CryptoStatus.getByCode( record.getStringValue( BitcoinCryptoNetworkDatabaseConstants .INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME)); } catch (InvalidParameterException e) { e.printStackTrace(); } String op_Return = record.getStringValue( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_OP_RETURN_COLUMN_NAME); /** Forms the CryptoTransaction object */ CryptoTransaction cryptoTransaction = new CryptoTransaction(); cryptoTransaction.setTransactionHash(txHash); cryptoTransaction.setAddressTo(addressTo); cryptoTransaction.setAddressFrom(addressFrom); cryptoTransaction.setCryptoAmount(amount); cryptoTransaction.setCryptoCurrency(CryptoCurrency.BITCOIN); cryptoTransaction.setCryptoStatus(cryptoStatus); cryptoTransaction.setOp_Return(op_Return); /** adds it to the list */ cryptoTransactions.add(cryptoTransaction); } return cryptoTransactions; }
/** * Will get the last current Crypto Status recorded from the given outgoing or incoming * transaction * * @param transactionType * @param txHash * @return */ public CryptoStatus getStoredTransactionCryptoStatus( TransactionTypes transactionType, String txHash) throws CantExecuteDatabaseOperationException { /** I will define the outgoing or incoming table, the filter and the sort order */ DatabaseTable databaseTable = null; if (transactionType == TransactionTypes.OUTGOING) { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_HASH_COLUMN_NAME, txHash, DatabaseFilterType.EQUAL); databaseTable.setFilterOrder( BitcoinCryptoNetworkDatabaseConstants.OUTGOING_TRANSACTIONS_LAST_UPDATE_COLUMN_NAME, DatabaseFilterOrder.DESCENDING); } else { databaseTable = database.getTable(BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_TABLE_NAME); databaseTable.setStringFilter( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_HASH_COLUMN_NAME, txHash, DatabaseFilterType.EQUAL); databaseTable.setFilterOrder( BitcoinCryptoNetworkDatabaseConstants.INCOMING_TRANSACTIONS_LAST_UPDATE_COLUMN_NAME, DatabaseFilterOrder.DESCENDING); } /** Wil load the table into memory */ try { databaseTable.loadToMemory(); } catch (CantLoadTableToMemoryException e) { throwLoadToMemoryException(e, databaseTable.getTableName()); } /** * Since Im ordering by update date, I will only get the fist record retrieved to form the * crypto status */ DatabaseTableRecord record = databaseTable.getRecords().get(0); CryptoStatus cryptoStatus = null; /** will get and form the crypto status */ try { if (transactionType == TransactionTypes.OUTGOING) cryptoStatus = CryptoStatus.getByCode( record.getStringValue( BitcoinCryptoNetworkDatabaseConstants .OUTGOING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME)); else cryptoStatus = CryptoStatus.getByCode( record.getStringValue( BitcoinCryptoNetworkDatabaseConstants .INCOMING_TRANSACTIONS_CRYPTO_STATUS_COLUMN_NAME)); } catch (InvalidParameterException e) { throw new CantExecuteDatabaseOperationException( CantExecuteDatabaseOperationException.DEFAULT_MESSAGE, e, "Cant load the crypto status from the database.", "database error"); } return cryptoStatus; }