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); } }
/** * 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 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); }
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); } }