コード例 #1
0
        /// <summary>
        /// CreateDataEmail
        /// </summary>
        /// <param name="btcBusiness"></param>
        /// <param name="transactionModelDetail"></param>
        private static void CreateDataEmail(AbsBlockchainBusiness btcBusiness,
                                            BtcTransactionDetailModel transactionModelDetail)
        {
            try
            {
                using (var userRepository = btcBusiness.VakapayRepositoryFactory.GetUserRepository(btcBusiness.DbConnection))
                {
                    var email = userRepository.FindEmailByBitcoinAddress(transactionModelDetail.Address);

                    if (email != null)
                    {
                        const string title = "Notify receiver BitCoin";
                        //                    btcBusiness.CreateDataEmail(title, email, transactionModelDetail.Amount,
                        //                        Constants.TEMPLATE_EMAIL_SENT, Constants.NETWORK_NAME_BITCOIN, Constants.TYPE_RECEIVER);
                        var res = SendMailBusiness.SendMailBusiness.CreateDataEmail(title, email,
                                                                                    transactionModelDetail.Amount, "", //TODO add transaction Id
                                                                                    EmailTemplate.Received, CryptoCurrency.BTC, btcBusiness.VakapayRepositoryFactory, false);
                    }
                    else
                    {
                        Logger.Debug("CreateDataEmail =>> error because email fail");
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("CreateDataEmail error: ", e.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// HandleNotifyDataSend
        /// </summary>
        /// <param name="transactionModel"></param>
        /// <param name="transactionModelDetail"></param>
        /// <param name="btcBusiness"></param>
        private static void HandleNotifyDataSend(BtcTransactionModel transactionModel,
                                                 BtcTransactionDetailModel transactionModelDetail, AbsBlockchainBusiness btcBusiness)
        {
            try
            {
                Logger.Debug("HandleNotifyDataSend start");
                if (transactionModel.Confirmations > 0)
                {
                    using (var bitCoinRawTransactionRepository = btcBusiness
                                                                 .VakapayRepositoryFactory.GetBitcoinWithdrawTransactionRepository(btcBusiness.DbConnection))
                    {
                        var currentBtcWithdrawTransaction =
                            GetBtcWithdrawTransaction(bitCoinRawTransactionRepository, transactionModelDetail.Address,
                                                      transactionModel.Txid);

                        Logger.Debug(
                            "HandleNotifyDataSend =>> btcWithdrawTransaction: " + currentBtcWithdrawTransaction);
                        if (currentBtcWithdrawTransaction == null)
                        {
                            return;
                        }
                        Logger.Debug("HandleNotifyDataSend ==>> Update hash and time update ");
                        var currentTime = CommonHelper.GetUnixTimestamp();
                        if (currentBtcWithdrawTransaction.UserId == null)
                        {
                            currentBtcWithdrawTransaction.UserId = GetUserIdByAddress(transactionModelDetail.Address);
                        }

                        currentBtcWithdrawTransaction.BlockHash = transactionModel.BlockHash;
                        currentBtcWithdrawTransaction.UpdatedAt = currentTime;
                        bitCoinRawTransactionRepository.Update(currentBtcWithdrawTransaction);
                    }
                }
                else
                {
                    Logger.Debug("HandleNotifyDataSend =>> confirm == 0");
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, "HandleNotifyDataSend exception");
            }
        }
コード例 #3
0
 /// <summary>
 /// CreateNewBtcDepositTransaction
 /// </summary>
 /// <param name="transactionModel"></param>
 /// <param name="transactionModelDetail"></param>
 /// <param name="btcDepositTransactionRepository"></param>
 /// <param name="currentTime"></param>
 private static void CreateNewBtcDepositTransaction(BtcTransactionModel transactionModel,
                                                    BtcTransactionDetailModel transactionModelDetail,
                                                    IBitcoinDepositTransactionRepository btcDepositTransactionRepository, long currentTime
                                                    )
 {
     try
     {
         Logger.Debug("cretateNewBtcDepositTransaction ");
         var btcDepositTransaction = new BitcoinDepositTransaction
         {
             Hash        = transactionModel.Txid,
             BlockNumber = 0,
             BlockHash   = transactionModel.BlockHash,
             Amount      = transactionModel.Amount,
             FromAddress = "",
             ToAddress   = transactionModelDetail.Address,
             Fee         = 0,
             Status      = Status.STATUS_PENDING,
             CreatedAt   = currentTime,
             UpdatedAt   = currentTime
         };
         var userId = GetUserIdByAddress(transactionModelDetail.Address);
         if (userId == null)
         {
             return;
         }
         var portfolioHistoryBusiness =
             new PortfolioHistoryBusiness.PortfolioHistoryBusiness(_persistenceFactory, false);
         portfolioHistoryBusiness.InsertWithPrice(userId);
         btcDepositTransaction.UserId = userId;
         Logger.Debug("cretateNewBtcDepositTransaction =>> btcDepositTransaction: " +
                      btcDepositTransaction.ToJson());
         btcDepositTransactionRepository.Insert(btcDepositTransaction);
     }
     catch (Exception e)
     {
         Logger.Error(e, "cretateNewBtcDepositTransaction ");
     }
 }
コード例 #4
0
        /// <summary>
        /// handle notify transaction receiver
        /// </summary>
        /// <param name="transactionModel"></param>
        /// <param name="transactionModelDetail"></param>
        /// <param name="btcBusiness"></param>
        private static void HandleNotifyDataReceiver(BtcTransactionModel transactionModel,
                                                     BtcTransactionDetailModel transactionModelDetail, AbsBlockchainBusiness btcBusiness)
        {
            try
            {
                Logger.Debug("HandleNotifiDataReceiver start");

                using (var btcDepositTransactionRepository = btcBusiness.VakapayRepositoryFactory.GetBitcoinDepositTransactionRepository(btcBusiness.DbConnection))
                {
                    Logger.Debug("HandleNotifiDataReceiver start1");
                    var currentBtcDepositTransaction = GetDepositTransaction(btcDepositTransactionRepository,
                                                                             transactionModelDetail.Address, transactionModel.Txid);
                    Logger.Debug("HandleNotifiDataReceiver =>> currentBtcDepositTransaction: " +
                                 currentBtcDepositTransaction);
                    var currentTime = CommonHelper.GetUnixTimestamp();
                    if (transactionModel.Confirmations == 0)
                    {
                        Logger.Debug("HandleNotifiDataReceiver with confirm = 0");
                        if (currentBtcDepositTransaction == null)
                        {
                            CreateNewBtcDepositTransaction(transactionModel, transactionModelDetail,
                                                           btcDepositTransactionRepository, currentTime);
                        }
                        else
                        {
                            // transaction is exist
                            Logger.Debug(
                                "HandleNotifiDataReceiver =>> BitcoinDepositTransaction is exist, don't create new data");
                        }
                    }
                    else
                    {
                        Logger.Debug("HandleNotifiDataReceiver with confirm > 0");
                        if (currentBtcDepositTransaction != null)
                        {
                            currentBtcDepositTransaction.BlockHash = transactionModel.BlockHash;
                            currentBtcDepositTransaction.Amount    = transactionModel.Amount;
                            currentBtcDepositTransaction.Status    = Status.STATUS_COMPLETED;
                            currentBtcDepositTransaction.UpdatedAt = currentTime;
                            btcDepositTransactionRepository.Update(currentBtcDepositTransaction);
                        }
                        else
                        {
                            CreateNewBtcDepositTransaction(transactionModel, transactionModelDetail,
                                                           btcDepositTransactionRepository, currentTime);
                        }

                        // update balance
                        _walletBusiness?.UpdateBalanceDeposit(transactionModelDetail.Address,
                                                              transactionModelDetail.Amount,
                                                              CryptoCurrency.BTC);

                        //insert new email data
                        CreateDataEmail(btcBusiness, transactionModelDetail);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, "HandleNotifiDataReceiver exception");
            }
        }