public void TestGetHistoricalExchangeRateFromDatabase() throws Exception {

    double price = 0;
    cryptoCurrency = CryptoCurrency.getByCode("BTC");
    fiatCurrency = FiatCurrency.getByCode("USD");
    Date date = new Date();
    time = date.getTime() / 1000;
    price =
        cryptoIndexWorldPluginRoot.getHistoricalExchangeRateFromDatabase(
            cryptoCurrency, fiatCurrency, time);
    System.out.println(price);
  }
  private com.bitdubai.fermat_pip_plugin.layer.sub_app_module.notification.developer.bitdubai
          .version_1.structure.Notification
      createNotification(
          EventSource eventSource,
          String intraUserIdentityPublicKey,
          String walletPublicKey,
          long amount,
          CryptoCurrency cryptoCurrency,
          String actorId,
          Actors actorType)
          throws CantCreateNotification {
    try {

      Actor actor = getActor(intraUserIdentityPublicKey, actorId, actorType);

      com.bitdubai.fermat_pip_plugin.layer.sub_app_module.notification.developer.bitdubai.version_1
              .structure.Notification
          notification =
              new com.bitdubai.fermat_pip_plugin.layer.sub_app_module.notification.developer
                  .bitdubai.version_1.structure.Notification();
      notification.setAlertTitle(
          getSourceString(eventSource) + " " + WalletUtils.formatBalanceString(amount));

      notification.setImage(actor.getPhoto());

      notification.setTextTitle(getTextTitleBySource(eventSource));

      notification.setWalletPublicKey(walletPublicKey);

      notification.setTextBody(
          actor.getName()
              + makeString(eventSource)
              + WalletUtils.formatBalanceString(amount)
              + " in "
              + cryptoCurrency.getCode());

      return notification;

    } catch (CantGetExtraUserException e) {
      e.printStackTrace();
    } catch (IntraUserNotFoundException e) {
      e.printStackTrace();
    } catch (CantGetIntraUserException e) {
      e.printStackTrace();
    } catch (ExtraUserNotFoundException e) {
      e.printStackTrace();
    }
    throw new CantCreateNotification();
  }
  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);
  }
  private CryptoMoneyTransaction getCryptoMoneyRestockTransaction(
      final DatabaseTableRecord cryptoMoneyRestockTransactionRecord)
      throws CantLoadTableToMemoryException, DatabaseOperationException, InvalidParameterException {

    CryptoMoneyRestockTransactionImpl cryptoMoneyRestockTransaction =
        new CryptoMoneyRestockTransactionImpl();

    cryptoMoneyRestockTransaction.setTransactionId(
        cryptoMoneyRestockTransactionRecord.getUUIDValue(
            StockTransactionsCrpytoMoneyRestockDatabaseConstants
                .CRYPTO_MONEY_RESTOCK_TRANSACTION_ID_COLUMN_NAME));
    cryptoMoneyRestockTransaction.setActorPublicKey(
        cryptoMoneyRestockTransactionRecord.getStringValue(
            StockTransactionsCrpytoMoneyRestockDatabaseConstants
                .CRYPTO_MONEY_RESTOCK_PUBLIC_KEY_ACTOR_COLUMN_NAME));
    cryptoMoneyRestockTransaction.setCryptoCurrency(
        CryptoCurrency.getByCode(
            cryptoMoneyRestockTransactionRecord.getStringValue(
                StockTransactionsCrpytoMoneyRestockDatabaseConstants
                    .CRYPTO_MONEY_RESTOCK_CRYPTO_CURRENCY_COLUMN_NAME)));
    cryptoMoneyRestockTransaction.setCbpWalletPublicKey(
        cryptoMoneyRestockTransactionRecord.getStringValue(
            StockTransactionsCrpytoMoneyRestockDatabaseConstants
                .CRYPTO_MONEY_RESTOCK_CBP_WALLET_PUBLIC_KEY_COLUMN_NAME));
    cryptoMoneyRestockTransaction.setCryWalletPublicKey(
        cryptoMoneyRestockTransactionRecord.getStringValue(
            StockTransactionsCrpytoMoneyRestockDatabaseConstants
                .CRYPTO_MONEY_RESTOCK_CRY_WALLET_PUBLIC_KEY_COLUMN_NAME));
    cryptoMoneyRestockTransaction.setConcept(
        cryptoMoneyRestockTransactionRecord.getStringValue(
            StockTransactionsCrpytoMoneyRestockDatabaseConstants
                .CRYPTO_MONEY_RESTOCK_CONCEPT_COLUMN_NAME));
    cryptoMoneyRestockTransaction.setAmount(
        new BigDecimal(
            cryptoMoneyRestockTransactionRecord.getStringValue(
                StockTransactionsCrpytoMoneyRestockDatabaseConstants
                    .CRYPTO_MONEY_RESTOCK_AMOUNT_COLUMN_NAME)));
    cryptoMoneyRestockTransaction.setTimeStamp(
        Timestamp.valueOf(
            cryptoMoneyRestockTransactionRecord.getStringValue(
                StockTransactionsCrpytoMoneyRestockDatabaseConstants
                    .CRYPTO_MONEY_RESTOCK_TIMESTAMP_COLUMN_NAME)));
    cryptoMoneyRestockTransaction.setMemo(
        cryptoMoneyRestockTransactionRecord.getStringValue(
            StockTransactionsCrpytoMoneyRestockDatabaseConstants
                .CRYPTO_MONEY_RESTOCK_MEMO_COLUMN_NAME));
    cryptoMoneyRestockTransaction.setTransactionStatus(
        TransactionStatusRestockDestock.getByCode(
            cryptoMoneyRestockTransactionRecord.getStringValue(
                StockTransactionsCrpytoMoneyRestockDatabaseConstants
                    .CRYPTO_MONEY_RESTOCK_TRANSACTION_STATUS_COLUMN_NAME)));
    cryptoMoneyRestockTransaction.setPriceReference(
        new BigDecimal(
            cryptoMoneyRestockTransactionRecord.getStringValue(
                StockTransactionsCrpytoMoneyRestockDatabaseConstants
                    .CRYPTO_MONEY_RESTOCK_PRICE_REFERENCE_COLUMN_NAME)));
    cryptoMoneyRestockTransaction.setOriginTransaction(
        OriginTransaction.getByCode(
            cryptoMoneyRestockTransactionRecord.getStringValue(
                StockTransactionsCrpytoMoneyRestockDatabaseConstants
                    .CRYPTO_MONEY_RESTOCK_ORIGIN_TRANSACTION_COLUMN_NAME)));
    cryptoMoneyRestockTransaction.setOriginTransactionId(
        cryptoMoneyRestockTransactionRecord.getStringValue(
            StockTransactionsCrpytoMoneyRestockDatabaseConstants
                .CRYPTO_MONEY_RESTOCK_ORIGIN_TRANSACTION_ID_COLUMN_NAME));
    cryptoMoneyRestockTransaction.setBlockchainNetworkType(
        BlockchainNetworkType.getByCode(
            cryptoMoneyRestockTransactionRecord.getStringValue(
                StockTransactionsCrpytoMoneyRestockDatabaseConstants
                    .CRYPTO_MONEY_RESTOCK_BLOCK_CHAIN_NETWORK_TYPE_COLUMN_NAME)));
    return cryptoMoneyRestockTransaction;
  }
  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);
  }