/** * @param record with values from the table * @return FermatMessage setters the values from table */ private FermatMessage constructFrom(DatabaseTableRecord record) { FermatMessageCommunication incomingTemplateNetworkServiceMessage = new FermatMessageCommunication(); try { incomingTemplateNetworkServiceMessage.setId( UUID.fromString( record.getStringValue( CommunicationNetworkServiceDatabaseConstants.INCOMING_MESSAGES_ID_COLUMN_NAME))); incomingTemplateNetworkServiceMessage.setSender( record.getStringValue( CommunicationNetworkServiceDatabaseConstants .INCOMING_MESSAGES_SENDER_ID_COLUMN_NAME)); incomingTemplateNetworkServiceMessage.setReceiver( record.getStringValue( CommunicationNetworkServiceDatabaseConstants .INCOMING_MESSAGES_RECEIVER_ID_COLUMN_NAME)); incomingTemplateNetworkServiceMessage.setContent( record.getStringValue( CommunicationNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TEXT_CONTENT_COLUMN_NAME)); incomingTemplateNetworkServiceMessage.setFermatMessageContentType( (FermatMessageContentType.getByCode( record.getStringValue( CommunicationNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TYPE_COLUMN_NAME)))); incomingTemplateNetworkServiceMessage.setShippingTimestamp( new Timestamp( record.getLongValue( CommunicationNetworkServiceDatabaseConstants .INCOMING_MESSAGES_SHIPPING_TIMESTAMP_COLUMN_NAME))); incomingTemplateNetworkServiceMessage.setDeliveryTimestamp( new Timestamp( record.getLongValue( CommunicationNetworkServiceDatabaseConstants .INCOMING_MESSAGES_DELIVERY_TIMESTAMP_COLUMN_NAME))); incomingTemplateNetworkServiceMessage.setFermatMessagesStatus( FermatMessagesStatus.getByCode( record.getStringValue( CommunicationNetworkServiceDatabaseConstants .INCOMING_MESSAGES_STATUS_COLUMN_NAME))); } catch (InvalidParameterException e) { // TODO METODO CON RETURN NULL - OJO: solo INFORMATIVO de ayuda VISUAL para DEBUG - Eliminar // si molesta // this should not happen, but if it happens return null e.printStackTrace(); return null; } return incomingTemplateNetworkServiceMessage; }
/** * @param record with values from the table * @return WalletStoreNetworkServiceMessage setters the values from table */ private WalletStoreNetworkServiceMessage constructFrom(DatabaseTableRecord record) { WalletStoreNetworkServiceMessage walletStoreNetworkServiceMessage = new WalletStoreNetworkServiceMessage(); try { walletStoreNetworkServiceMessage.setId( record.getLongValue( WalletStoreNetworkServiceDatabaseConstants.INCOMING_MESSAGES_TABLE_ID_COLUMN_NAME)); walletStoreNetworkServiceMessage.setSender( UUID.fromString( record.getStringValue( WalletStoreNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TABLE_SENDER_ID_COLUMN_NAME))); walletStoreNetworkServiceMessage.setReceiver( UUID.fromString( record.getStringValue( WalletStoreNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TABLE_RECEIVER_ID_COLUMN_NAME))); walletStoreNetworkServiceMessage.setTextContent( record.getStringValue( WalletStoreNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TABLE_TEXT_CONTENT_COLUMN_NAME)); walletStoreNetworkServiceMessage.setMessageType( MessagesTypes.getByCode( record.getStringValue( WalletStoreNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TABLE_TYPE_COLUMN_NAME))); walletStoreNetworkServiceMessage.setShippingTimestamp( new Timestamp( record.getLongValue( WalletStoreNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TABLE_SHIPPING_TIMESTAMP_COLUMN_NAME))); walletStoreNetworkServiceMessage.setDeliveryTimestamp( new Timestamp( record.getLongValue( WalletStoreNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TABLE_DELIVERY_TIMESTAMP_COLUMN_NAME))); walletStoreNetworkServiceMessage.setStatus( MessagesStatus.getByCode( record.getStringValue( WalletStoreNetworkServiceDatabaseConstants .INCOMING_MESSAGES_TABLE_STATUS_COLUMN_NAME))); } catch (InvalidParameterException e) { // TODO METODO CON RETURN NULL - OJO: solo INFORMATIVO de ayuda VISUAL para DEBUG - Eliminar // si molesta // this should not happen, but if it happens return null return null; } return walletStoreNetworkServiceMessage; }
@Before public void setUpMockitoRules() { when(mockDatabase.getTable(BitcoinWalletDatabaseConstants.BITCOIN_WALLET_BALANCE_TABLE_NAME)) .thenReturn(mockTable); when(mockTable.getRecords()).thenReturn(mockRecords); when(mockRecords.get(0)).thenReturn(mockRecord); when(mockRecord.getLongValue( BitcoinWalletDatabaseConstants.BITCOIN_WALLET_BALANCE_TABLE_BOOK_BALANCE_COLUMN_NAME)) .thenReturn(mockBookBalance); }
@Override public int compare( DatabaseTableRecord databaseTableRecord1, DatabaseTableRecord databaseTableRecord2) { long chunkFiatAmount1 = databaseTableRecord1.getLongValue( BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_FIAT_AMOUNT_COLUMN_NAME); long chunkCryptoAmount1 = databaseTableRecord1.getLongValue( BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_CRYPTO_AMOUNT_COLUMN_NAME); long chunkFiatAmount2 = databaseTableRecord2.getLongValue( BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_FIAT_AMOUNT_COLUMN_NAME); long chunkCryptoAmount2 = databaseTableRecord2.getLongValue( BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_CRYPTO_AMOUNT_COLUMN_NAME); double rate1 = ((double) chunkFiatAmount1) / chunkCryptoAmount1; double rate2 = ((double) chunkFiatAmount2) / chunkCryptoAmount2; return Double.compare(rate1, rate2); }
/** * 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; }
private CustomerBrokerClose getCustomerBrokerCloseFromRecord(DatabaseTableRecord record) throws InvalidParameterException { UUID transactionId = record.getUUIDValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_TRANSACTION_ID_COLUMN_NAME); UUID negotiationId = record.getUUIDValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_NEGOTIATION_ID_COLUMN_NAME); String publicKeyBroker = record.getStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_PUBLIC_KEY_BROKER_COLUMN_NAME); String publicKeyCustomer = record.getStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_PUBLIC_KEY_CUSTOMER_COLUMN_NAME); NegotiationTransactionStatus status = NegotiationTransactionStatus.getByCode( record.getStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_STATUS_COLUMN_NAME)); NegotiationType negotiationType = NegotiationType.getByCode( record.getStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_NEGOTIATION_TYPE_COLUMN_NAME)); String negotiationXML = record.getStringValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_NEGOTIATION_XML_COLUMN_NAME); long timestamp = record.getLongValue( CustomerBrokerCloseNegotiationTransactionDatabaseConstants .CUSTOMER_BROKER_CLOSE_TIMESTAMP_COLUMN_NAME); return new CustomerBrokerCloseImpl( transactionId, negotiationId, publicKeyBroker, publicKeyCustomer, status, negotiationType, negotiationXML, timestamp); }
/** * (non-javadoc) * * @see AbstractBaseDao#getEntityFromDatabaseTableRecord(DatabaseTableRecord) */ @Override protected NodeConnectionHistory getEntityFromDatabaseTableRecord(DatabaseTableRecord record) throws InvalidParameterException { NodeConnectionHistory entity = new NodeConnectionHistory(); entity.setUuid( record.getUUIDValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_UUID_COLUMN_NAME)); entity.setConnectionTimestamp( new Timestamp( record.getLongValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_CONNECTION_TIMESTAMP_COLUMN_NAME))); entity.setDefaultPort( record.getIntegerValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_DEFAULT_PORT_COLUMN_NAME)); entity.setIdentityPublicKey( record.getStringValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_IDENTITY_PUBLIC_KEY_COLUMN_NAME)); entity.setIp( record.getStringValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_IP_COLUMN_NAME)); entity.setLastLatitude( record.getDoubleValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_LAST_LATITUDE_COLUMN_NAME)); entity.setLastLongitude( record.getDoubleValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_LAST_LONGITUDE_COLUMN_NAME)); entity.setStatus( record.getStringValue( CommunicationsNetworkNodeP2PDatabaseConstants .NODES_CONNECTIONS_HISTORY_STATUS_COLUMN_NAME)); return entity; }
/* * Given a fiat amount and its equivalent crypto amount this methods calculates the * discount that would be produced if the user debit the same amounts. * The return value represents fiat currency. */ long calculateDiscount(long fiatAmount, long cryptoAmount) throws CalculateDiscountFailedException { long spent = 0; BasicWalletAvailable basicWalletAvailable = new BasicWalletAvailable(this.fiatCurrency, this.cryptoCurrency); basicWalletAvailable.setCryptoIndexManager(this.cryptoIndexManager); basicWalletAvailable.setErrorManager(this.errorManager); basicWalletAvailable.setDatabase(this.database); long available; try { available = basicWalletAvailable.getAvailableAmount(); } catch (CantCalculateAvailableAmountException e) { System.err.println("AvailableFailedException" + e.getMessage()); e.printStackTrace(); throw new CalculateDiscountFailedException(); } if (available < fiatAmount) { System.err.println("Not enough funds"); throw new CalculateDiscountFailedException(); } DatabaseTable valueChunksTable = database.getTable(BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_NAME); // We set the filter to get the UNSPENT chunks valueChunksTable.setStringFilter( BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_STATUS_COLUMN_NAME, CryptoValueChunkStatus.UNSPENT.getCode(), DatabaseFilterType.EQUAL); // now we apply the filter try { valueChunksTable.loadToMemory(); } catch (CantLoadTableToMemoryException cantLoadTableToMemory) { /** I can not solve this situation. */ System.err.println("CantLoadTableToMemoryException: " + cantLoadTableToMemory.getMessage()); cantLoadTableToMemory.printStackTrace(); throw new CalculateDiscountFailedException(); } /* We first sort the chunks of the list putting the chunks generated * at lower exchange rate at the beginning of the list. The exchange * rate of a chunk (fa,ca,state) is equal to the quotient fa/ca. (see documentation) */ List<DatabaseTableRecord> recordList = valueChunksTable.getRecords(); Collections.sort(recordList, new ChunksComparator()); /* Let's calculate the discount as explained in the * documentation. we will add up the fiat amounts stored * in the chunks that would be used to pay the extraction * equivalent to cryptoAmount */ for (DatabaseTableRecord d : recordList) { long fa = d.getLongValue(BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_FIAT_AMOUNT_COLUMN_NAME); long ca = d.getLongValue(BasicWalletDatabaseConstants.VALUE_CHUNKS_TABLE_CRYPTO_AMOUNT_COLUMN_NAME); if (cryptoAmount == 0) break; if (cryptoAmount >= ca) { cryptoAmount = cryptoAmount - ca; spent = spent + fa; } else { long fa1 = Converter.getProportionalFiatAmountRoundedDown(ca, fa, cryptoAmount); cryptoAmount = 0; spent = spent + fa1; } } return fiatAmount - spent; }
private NegotiationTransmission buildNegotiationTransmission(DatabaseTableRecord record) throws InvalidParameterException { try { UUID transmissionId = record.getUUIDValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_TRANSMISSION_ID_COLUMN_NAME); UUID transactionId = record.getUUIDValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_TRANSACTION_ID_COLUMN_NAME); UUID negotiationId = record.getUUIDValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_NEGOTIATION_ID_COLUMN_NAME); String negotiationTransactionType = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_NEGOTIATION_TRANSACTION_TYPE_COLUMN_NAME); String publicKeyActorSend = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_PUBLIC_KEY_ACTOR_SEND_COLUMN_NAME); String actorSendType = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_ACTOR_SEND_TYPE_COLUMN_NAME); String publicKeyActorReceive = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_PUBLIC_KEY_ACTOR_RECEIVE_COLUMN_NAME); String actorReceiveType = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_ACTOR_RECEIVE_TYPE_COLUMN_NAME); String transmissionType = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_TRANSMISSION_TYPE_COLUMN_NAME); String transmissionState = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_TRANSMISSION_STATE_COLUMN_NAME); String negotiationType = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_NEGOTIATION_TYPE_COLUMN_NAME); String negotiationXML = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_NEGOTIATION_XML_COLUMN_NAME); long timestamp = record.getLongValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_TIMESTAMP_COLUMN_NAME); String pendingFlag = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_NETWORK_SERVICE_PENDING_FLAG_COLUMN_NAME); String flagRead = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_READ_MARK_COLUMN_NAME); String protocolState = record.getStringValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_PROTOCOL_STATE_COLUMN_NAME); int sentCount = 0; UUID responseToNotificationId = record.getUUIDValue( com.bitdubai .fermat_cbp_plugin .layer .network_service .negotiation_transmission .developer .bitdubai .version_1 .newDatabase .NegotiationTransmissionNetworkServiceDatabaseConstants .OUTGOING_NOTIFICATION_RESPONSE_TO_NOTIFICATION_ID_COLUMN_NAME); ActorProtocolState actorProtocolState = null; if (protocolState != null) { actorProtocolState = ActorProtocolState.getByCode(protocolState); } return new NegotiationTransmissionImpl( transmissionId, transactionId, negotiationId, NegotiationTransactionType.getByCode(negotiationTransactionType), publicKeyActorSend, PlatformComponentType.getByCode(actorSendType), publicKeyActorReceive, PlatformComponentType.getByCode(actorReceiveType), NegotiationTransmissionType.getByCode(transmissionType), NegotiationTransmissionState.getByCode(transmissionState), NegotiationType.getByCode(negotiationType), negotiationXML, timestamp, Boolean.valueOf(pendingFlag), Boolean.valueOf(flagRead), actorProtocolState, sentCount, responseToNotificationId); } catch (Exception e) { throw new InvalidParameterException(); } }
private OutgoingDraftTransactionWrapper convertToBT(DatabaseTableRecord record) throws InvalidParameterException { // boolean sameDevice = // Boolean.valueOf(record.getStringValue(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_SAME_DEVICE_COLUMN_NAME)); String walletPublicKey = record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_WALLET_ID_TO_DEBIT_FROM_COLUMN_NAME); UUID transactionId = record.getUUIDValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_ID_COLUMN_NAME); String transactionHash = record.getStringValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TRANSACTION_HASH_COLUMN_NAME); long amount = record.getLongValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_AMOUNT_COLUMN_NAME); // String op_Return = // record.getStringValue(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_OP_RETURN_COLUMN_NAME); com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer.bitdubai .version_1.enums.TransactionState state = com.bitdubai.fermat_ccp_plugin.layer.crypto_transaction.outgoing_draft.developer .bitdubai.version_1.enums.TransactionState.getByCode( record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_TRANSACTION_STATUS_COLUMN_NAME)); long timestamp = record.getLongValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_TIMESTAMP_COLUMN_NAME); String memo = record.getStringValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_DESCRIPTION_COLUMN_NAME); // CryptoStatus cryptoStatus = // CryptoStatus.getByCode(record.getStringValue(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_STATUS_COLUMN_NAME)); Actors actorFromType = Actors.getByCode( record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_ACTOR_FROM_TYPE_COLUMN_NAME)); Actors actorToType = Actors.getByCode( record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_ACTOR_TO_TYPE_COLUMN_NAME)); String actorFromPublicKey = record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_ACTOR_FROM_PUBLIC_KEY_COLUMN_NAME); String actorToPublicKey = record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_ACTOR_TO_PUBLIC_KEY_COLUMN_NAME); ReferenceWallet referenceWallet = ReferenceWallet.getByCode( record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_WALLET_REFERENCE_TYPE_COLUMN_NAME)); String addressFrom = record.getStringValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ADDRESS_FROM_COLUMN_NAME); String addressTo = record.getStringValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_ADDRESS_TO_COLUMN_NAME); // CryptoAddress cryptoAddressFrom = null; // if (addressFrom != null) { // cryptoAddressFrom = new CryptoAddress( // addressFrom, // // CryptoCurrency.getByCode(OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_CRYPTO_CURRENCY_COLUMN_NAME)); // } CryptoAddress cryptoAddressTo = null; if (addressFrom != null) { cryptoAddressTo = new CryptoAddress( addressTo, CryptoCurrency.getByCode( record.getStringValue( OutgoingDraftTransactionDatabaseConstants .OUTGOING_DRAFT_CRYPTO_CURRENCY_COLUMN_NAME))); } BlockchainNetworkType blockchainNetworkType = BlockchainNetworkType.getByCode( record.getStringValue( OutgoingDraftTransactionDatabaseConstants.OUTGOING_DRAFT_RUNNING_NETWORK_TYPE)); return new OutgoingDraftTransactionWrapper( transactionId, walletPublicKey, amount, cryptoAddressTo, referenceWallet, blockchainNetworkType, actorFromPublicKey, actorToPublicKey, actorFromType, actorToType, memo, timestamp, transactionHash); }
/** * 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; }
private ExchangeRate constructExchangeRateFromRecord(DatabaseTableRecord record) throws CantCreateExchangeRateException { UUID id = record.getUUIDValue( BitcoinVenezuelaProviderDatabaseConstants.DAILY_EXCHANGE_RATES_ID_COLUMN_NAME); double salePrice = record.getDoubleValue( BitcoinVenezuelaProviderDatabaseConstants.DAILY_EXCHANGE_RATES_SALE_PRICE_COLUMN_NAME); double purchasePrice = record.getDoubleValue( BitcoinVenezuelaProviderDatabaseConstants .DAILY_EXCHANGE_RATES_PURCHASE_PRICE_COLUMN_NAME); long timestamp = record.getLongValue( BitcoinVenezuelaProviderDatabaseConstants.DAILY_EXCHANGE_RATES_TIMESTAMP_COLUMN_NAME); Currency fromCurrency; try { String fromCurrencyStr = record.getStringValue( BitcoinVenezuelaProviderDatabaseConstants .DAILY_EXCHANGE_RATES_FROM_CURRENCY_COLUMN_NAME); if (FiatCurrency.codeExists(fromCurrencyStr)) fromCurrency = FiatCurrency.getByCode(fromCurrencyStr); else if (CryptoCurrency.codeExists(fromCurrencyStr)) fromCurrency = CryptoCurrency.getByCode(fromCurrencyStr); else throw new InvalidParameterException(); } catch (InvalidParameterException e) { throw new CantCreateExchangeRateException( e.getMessage(), e, "BitcoinVenezuela provider plugin", "Invalid From Currency value stored in table" + BitcoinVenezuelaProviderDatabaseConstants.DAILY_EXCHANGE_RATES_TABLE_NAME + " for id " + id); } Currency toCurrency; try { String toCurrencyStr = record.getStringValue( BitcoinVenezuelaProviderDatabaseConstants .DAILY_EXCHANGE_RATES_TO_CURRENCY_COLUMN_NAME); if (FiatCurrency.codeExists(toCurrencyStr)) toCurrency = FiatCurrency.getByCode(toCurrencyStr); else if (CryptoCurrency.codeExists(toCurrencyStr)) toCurrency = CryptoCurrency.getByCode(toCurrencyStr); else throw new InvalidParameterException(); } catch (InvalidParameterException e) { throw new CantCreateExchangeRateException( e.getMessage(), e, "BitcoinVenezuela provider plugin", "Invalid To Currency value stored in table" + BitcoinVenezuelaProviderDatabaseConstants.DAILY_EXCHANGE_RATES_TABLE_NAME + " for id " + id); } return new ExchangeRateImpl(fromCurrency, toCurrency, salePrice, purchasePrice, timestamp); }
private CashMoneyWalletTransaction constructCashMoneyWalletTransactionFromRecord( DatabaseTableRecord record) throws CantCreateCashMoneyWalletTransactionException { UUID transactionId = record.getUUIDValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_TRANSACTION_ID_COLUMN_NAME); String publicKeyWallet = record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_WALLET_PUBLIC_KEY_COLUMN_NAME); String publicKeyActor = record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_ACTOR_PUBLIC_KEY_COLUMN_NAME); String publicKeyPlugin = record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_PLUGIN_PUBLIC_KEY_COLUMN_NAME); BigDecimal amount = new BigDecimal( record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_AMOUNT_COLUMN_NAME)); String memo = record.getStringValue(CashMoneyWalletDatabaseConstants.TRANSACTIONS_MEMO_COLUMN_NAME); long timestamp = record.getLongValue(CashMoneyWalletDatabaseConstants.TRANSACTIONS_TIMESTAMP_COLUMN_NAME); TransactionType transactionType; try { transactionType = TransactionType.getByCode( record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_TRANSACTION_TYPE_COLUMN_NAME)); } catch (InvalidParameterException e) { throw new CantCreateCashMoneyWalletTransactionException( e.getMessage(), e, "Cash Money Wallet", "Invalid TransactionType value stored in table" + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TABLE_NAME + " for id " + transactionId); } BalanceType balanceType; try { balanceType = BalanceType.getByCode( record.getStringValue( CashMoneyWalletDatabaseConstants.TRANSACTIONS_BALANCE_TYPE_COLUMN_NAME)); } catch (InvalidParameterException e) { throw new CantCreateCashMoneyWalletTransactionException( e.getMessage(), e, "Cash Money Wallet", "Invalid BalanceType value stored in table" + CashMoneyWalletDatabaseConstants.TRANSACTIONS_TABLE_NAME + " for id " + transactionId); } return new CashMoneyWalletTransactionImpl( transactionId, publicKeyWallet, publicKeyActor, publicKeyPlugin, transactionType, balanceType, amount, memo, timestamp); }
private ActorAssetNetworkServiceRecord buildAssetUserNetworkServiceRecord( DatabaseTableRecord record) throws InvalidParameterException { try { BlockchainNetworkType blockchainNetworkType; UUID notificationId = record.getUUIDValue( AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_ID_COLUMN_NAME); String senderAlias = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_SENDER_ALIAS_COLUMN_NAME); String descriptor = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_DESCRIPTOR_COLUMN_NAME); String destinationType = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_RECEIVER_TYPE_COLUMN_NAME); String senderType = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_SENDER_TYPE_COLUMN_NAME); String senderPublicKey = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_SENDER_PUBLIC_KEY_COLUMN_NAME); String destinationPublicKey = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_RECEIVER_PUBLIC_KEY_COLUMN_NAME); long timestamp = record.getLongValue( AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_TIMESTAMP_COLUMN_NAME); String protocolState = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_PROTOCOL_STATE_COLUMN_NAME); String flagRead = record.getStringValue( AssetUserNetworkServiceDatabaseConstants.INCOMING_NOTIFICATION_READ_MARK_COLUMN_NAME); String blockChainNetwork = record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_BLOCKCHAIN_NETWORK_TYPE_COLUMN_NAME); UUID responseToNotificationId = record.getUUIDValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_RESPONSE_TO_NOTIFICATION_ID_COLUMN_NAME); ActorAssetProtocolState actorAssetProtocolState = ActorAssetProtocolState.getByCode(protocolState); Boolean read = Boolean.valueOf(flagRead); AssetNotificationDescriptor assetNotificationDescriptor = AssetNotificationDescriptor.getByCode(descriptor); if (blockChainNetwork != null) blockchainNetworkType = BlockchainNetworkType.getByCode(blockChainNetwork); else blockchainNetworkType = BlockchainNetworkType.getDefaultBlockchainNetworkType(); Actors actorDestinationType = Actors.getByCode(destinationType); Actors actorSenderType = Actors.getByCode(senderType); byte[] profileImage; try { profileImage = getActorUserProfileImagePrivateKey( record.getStringValue( AssetUserNetworkServiceDatabaseConstants .INCOMING_NOTIFICATION_SENDER_PUBLIC_KEY_COLUMN_NAME)); } catch (FileNotFoundException e) { profileImage = new byte[0]; } return new ActorAssetNetworkServiceRecord( notificationId, senderAlias, // senderPhrase, profileImage, assetNotificationDescriptor, actorDestinationType, actorSenderType, senderPublicKey, destinationPublicKey, timestamp, actorAssetProtocolState, read, 0, blockchainNetworkType, responseToNotificationId, null); } catch (Exception e) { throw new InvalidParameterException(); } }