private static void RunScan(RepositoryConfiguration repositoryConfig) { var repoFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); var business = new WalletBusiness.WalletBusiness(repoFactory); try { while (true) { try { Console.WriteLine("Start Scan wallet..."); var resultSend = business.CreateAddressAsync(); Console.WriteLine(JsonHelper.SerializeObject(resultSend.Result)); Console.WriteLine("End Create Address..."); Thread.Sleep(100); } catch (Exception e) { Console.WriteLine(e); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void AfterLogin() { Console.WriteLine("start"); var repositoryConfig = new RepositoryConfiguration { ConnectionString = AppSettingHelper.GetDbConnection() }; Console.WriteLine("New Address"); PersistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); var userBus = new UserBusiness.UserBusiness(PersistenceFactory); var walletBusiness = new WalletBusiness.WalletBusiness(PersistenceFactory); var userRepo = PersistenceFactory.GetUserRepository(PersistenceFactory.GetOldConnection()); var resultCreated = userBus.Login( new User { Email = "*****@*****.**", PhoneNumber = "+84988478266", FullName = "Ngo Ngoc Huan" }); walletBusiness.MakeAllWalletForNewUser(userRepo.FindByEmailAddress("*****@*****.**")); Console.WriteLine(JsonHelper.SerializeObject(resultCreated)); Assert.IsNotNull(resultCreated); resultCreated = userBus.Login( new User { Email = "*****@*****.**", PhoneNumber = "+84965995710", FullName = "Tieu Thanh Liem" }); walletBusiness.MakeAllWalletForNewUser(userRepo.FindByEmailAddress("*****@*****.**")); Console.WriteLine(JsonHelper.SerializeObject(resultCreated)); Assert.IsNotNull(resultCreated); }
private ReturnObject AddSendTransactionToBlockchainAddress(UserSendTransaction sendTransaction) { try { using (var walletRepository = new WalletRepository(_connectionDb)) { var walletBusiness = new WalletBusiness.WalletBusiness(_vakapayRepositoryFactory, false); var wallet = walletRepository.FindByUserAndNetwork(sendTransaction.UserId, sendTransaction.Currency); if (wallet == null) { return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = $"UserId {sendTransaction.UserId} with {sendTransaction.Currency} wallet is not found!" }); } var res = walletBusiness.Withdraw(wallet, sendTransaction.To, sendTransaction.Amount, sendTransaction.PricePerCoin, sendTransaction.Description); return(res); } } catch (Exception e) { _logger.Error(e.Message); throw; } }
public ToolsController( IVakapayRepositoryFactory persistenceFactory, IConfiguration configuration, IHostingEnvironment hostingEnvironment ) : base(persistenceFactory, configuration, hostingEnvironment) { _userBusiness = new UserBusiness.UserBusiness(persistenceFactory); _walletBusiness = new WalletBusiness.WalletBusiness(persistenceFactory); }
public static void RunPortfolioHistory() { var repositoryConfig = new RepositoryConfiguration { ConnectionString = AppSettingHelper.GetDbConnection() }; var persistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); var walletBusiness = new WalletBusiness.WalletBusiness(persistenceFactory); var portfolioHistoryBusiness = new PortfolioHistoryBusiness.PortfolioHistoryBusiness(persistenceFactory); SavePortfolioHistoryEvery(DashboardConfig.INTERVAL, walletBusiness, portfolioHistoryBusiness); }
public WithdrawsController() { var repositoryConfig = new RepositoryConfiguration { ConnectionString = AppSettingHelper.GetDbConnection() }; VakapayRepositoryFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); userBusiness = new UserBusiness.UserBusiness(VakapayRepositoryFactory); walletBusiness = new WalletBusiness.WalletBusiness(VakapayRepositoryFactory); }
public LoginController( IVakapayRepositoryFactory persistenceFactory, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { _repositoryFactory = persistenceFactory; _env = hostingEnvironment; Configuration = configuration; _userBusiness = new UserBusiness.UserBusiness(persistenceFactory); _walletBusiness = new WalletBusiness.WalletBusiness(persistenceFactory); }
public ReturnObject AddSendTransaction(UserSendTransaction sendTransaction) { try { if (!string.IsNullOrEmpty(sendTransaction.Idem)) { using (var sendTransactionRepository = new UserSendTransactionRepository(_connectionDb)) { var idem = sendTransactionRepository.FindExistedIdem(sendTransaction); if (idem != null) { return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = $"Transaction with idem = {sendTransaction.Idem} is already existed!" }); } } } var walletBusiness = new WalletBusiness.WalletBusiness(_vakapayRepositoryFactory, false); var valid = walletBusiness.ValidateWithdrawAmount(sendTransaction.UserId, sendTransaction.SendByBlockchainAddress, sendTransaction.Amount, sendTransaction.Fee, sendTransaction.Currency); if (valid.Status == Status.STATUS_ERROR) { return(valid); } if (sendTransaction.SendByBlockchainAddress) { return(AddSendTransactionToBlockchainAddress(sendTransaction)); } else { return(AddSendTransactionToEmailAddress(sendTransaction)); } } catch (Exception e) { _logger.Error(e.Message); return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = e.Message }); } }
static void Main(string[] args) { Console.WriteLine("Program Test Make new Wallet!!!!"); try { var repositoryConfig = new RepositoryConfiguration { ConnectionString = AppSettingHelper.GetDbConnection() }; var persistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); // foreach (var VARIABLE in RpcClient.GetAllTransactionsInBlock("16302351")) // { // Console.WriteLine(VARIABLE.ToString()); // } // var result = vakacoinBusiness.CreateTransactionHistory(); var walletBusiness = new WalletBusiness.WalletBusiness(persistenceFactory); var walletLst = walletBusiness.GetAllWallet(); foreach (var variable in walletLst) { Console.WriteLine(JsonHelper.SerializeObject(variable)); } // var user = new User // { // Id = CommonHelper.GenerateUuid(), // }; // var blockChainNetwork = new BlockchainNetwork // { // Name = "Ethereum", // Status = Status.StatusActive, // Sysbol = "ETH", // Id = CommonHelper.GenerateUuid() // }; // // var result = WalletBusiness.CreateNewWallet(user, blockChainNetwork); // Console.WriteLine(JsonHelper.SerializeObject(walletLst)); } catch (Exception e) { Console.WriteLine(e); } }
private static void SavePortfolioHistoryEvery(int minutes, WalletBusiness.WalletBusiness walletBusiness, PortfolioHistoryBusiness.PortfolioHistoryBusiness portfolioHistoryBusiness) { while (true) { var lsUserId = GetDistinctUserId(walletBusiness); foreach (var userId in lsUserId) { _logger.Info("Scanned UserId = " + userId + " at " + CommonHelper.GetUnixTimestamp()); portfolioHistoryBusiness.InsertWithPrice(userId); } Thread.Sleep(minutes * 60 * 1000); } }
private static void Main(string[] args) { try { var repositoryConfig = new RepositoryConfiguration { ConnectionString = AppSettingHelper.GetDbConnection() }; _persistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); var btcBusiness = new BitcoinBusiness.BitcoinBusiness(_persistenceFactory); var rpc = new BitcoinRpc(AppSettingHelper.GetBitcoinNode(), AppSettingHelper.GetBitcoinRpcAuthentication()); var transaction = rpc.FindTransactionByHash(args[0]); Logger.Debug("BitcoinNotify =>> BTCTransactionModel: " + transaction.Data); var transactionModel = BtcTransactionModel.FromJson(transaction.Data); if (transactionModel.BtcTransactionDetailsModel != null && transactionModel.BtcTransactionDetailsModel.Length > 0) { foreach (var transactionModelDetail in transactionModel.BtcTransactionDetailsModel) { _walletBusiness = new WalletBusiness.WalletBusiness(_persistenceFactory); if (transactionModelDetail.Category.Equals("receive")) { HandleNotifyDataReceiver(transactionModel, transactionModelDetail, btcBusiness); } else if (transactionModelDetail.Category.Equals("send")) { // if isExist(by address and transactionId) then update, else insert HandleNotifyDataSend(transactionModel, transactionModelDetail, btcBusiness); } } } else { Logger.Debug("BitcoinNotify BtcTransactionDetailsModel is not exist"); } } catch (Exception e) { Logger.Error(e, "BitcoinNotify exception"); } }
public void FakeWalletID() { var repositoryConfig = new RepositoryConfiguration { ConnectionString = AppSettingHelper.GetDbConnection() }; var persistenceFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); var walletBusiness = new WalletBusiness.WalletBusiness(persistenceFactory); var user = new User { Id = CommonHelper.GenerateUuid(), }; var result = walletBusiness.CreateNewWallet(user, CryptoCurrency.ETH); Console.WriteLine(JsonHelper.SerializeObject(result)); Assert.IsNotNull(result); }
private static void RunScan(RepositoryConfiguration repositoryConfig) { var repoFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); var ethereumBusiness = new EthereumBusiness.EthereumBusiness(repoFactory); var walletBusiness = new WalletBusiness.WalletBusiness(repoFactory); var connection = repoFactory.GetOldConnection() ?? repoFactory.GetDbConnection(); try { while (true) { Console.WriteLine("==========Start Scan Ethereum=========="); var rpc = new EthereumRpc(AppSettingHelper.GetEthereumNode()); using (var ethereumRepo = repoFactory.GetEthereumWithdrawTransactionRepository(connection)) { using (var ethereumDepoRepo = repoFactory.GetEthereumDepositeTransactionRepository(connection)) { var resultSend = ethereumBusiness .ScanBlockAsync <EthereumWithdrawTransaction, EthereumDepositTransaction, EthereumBlockResponse, EthereumTransactionResponse>(CryptoCurrency.ETH, walletBusiness, ethereumRepo, ethereumDepoRepo, rpc); Console.WriteLine(JsonHelper.SerializeObject(resultSend.Result)); Console.WriteLine("==========Scan Ethereum End=========="); Console.WriteLine("==========Wait for next scan=========="); Thread.Sleep(5000); } } } } catch (Exception e) { connection.Close(); Console.WriteLine(e.ToString()); } }
private static List <string> GetDistinctUserId(WalletBusiness.WalletBusiness walletBusiness) { return(walletBusiness.DistinctUserId()); }
public ActionResult <string> GetAddressInfoById(string idAddress, string currency) { try { var checkIdAddress = CheckIdAddress(idAddress); if (!string.IsNullOrEmpty(checkIdAddress)) { return(CreateDataError(checkIdAddress)); } var apiKey = (ApiKey)RouteData.Values[Requests.KEY_PASS_DATA_API_KEY_MODEL]; var checkCurrency = CheckCurrency(currency, apiKey); if (!string.IsNullOrEmpty(checkCurrency)) { return(checkCurrency); } if (!apiKey.Permissions.Contains(Permissions.READ_ADDRESSES)) { return(CreateDataError(MessageError.READ_ADDRESS_NOT_PERMISSION)); } BlockchainAddress blockChainAddress; switch (currency) { case CryptoCurrency.BTC: var bitCoinAddressRepository = new BitcoinAddressRepository(VakapayRepositoryFactory.GetOldConnection()); blockChainAddress = bitCoinAddressRepository.FindById(idAddress); break; case CryptoCurrency.ETH: var ethereumAddressRepository = new EthereumAddressRepository(VakapayRepositoryFactory.GetOldConnection()); blockChainAddress = ethereumAddressRepository.FindById(idAddress); break; case CryptoCurrency.VAKA: var vaKaCoinAccountRepository = new VakacoinAccountRepository(VakapayRepositoryFactory.GetOldConnection()); blockChainAddress = vaKaCoinAccountRepository.FindById(idAddress); break; default: return(CreateDataError(MessageError.PARAM_INVALID)); } if (blockChainAddress?.WalletId == null) { return(CreateDataError(MessageError.DATA_NOT_FOUND)); } var userModel = (User)RouteData.Values[Requests.KEY_PASS_DATA_USER_MODEL]; var walletBusiness = new WalletBusiness.WalletBusiness(VakapayRepositoryFactory); var walletModel = walletBusiness.GetWalletById(blockChainAddress.WalletId); if (walletModel != null && string.Equals(walletModel.UserId, userModel.Id)) { return(CreateDataSuccess(JsonConvert.SerializeObject(blockChainAddress))); } return(CreateDataError(MessageError.DATA_NOT_FOUND)); } catch (Exception e) { Console.WriteLine(e); return(CreateDataError(MessageError.DATA_NOT_FOUND)); } }
public async Task <ActionResult <string> > CreateAddress(string currency) { try { var apiKey = (ApiKey)RouteData.Values[Requests.KEY_PASS_DATA_API_KEY_MODEL]; var checkCurrency = CheckCurrency(currency, apiKey); if (!string.IsNullOrEmpty(checkCurrency)) { return(checkCurrency); } if (!apiKey.Permissions.Contains(Permissions.CREATED_ADDRESSES)) { return(CreateDataError(MessageError.CREATE_TRANSACION_NOT_PERMISSION)); } var userModel = (User)RouteData.Values[Requests.KEY_PASS_DATA_USER_MODEL]; var walletBusiness = new WalletBusiness.WalletBusiness(VakapayRepositoryFactory); var wallet = walletBusiness.FindByUserAndNetwork(userModel.Id, currency); if (wallet == null) { return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL)); } var result = await walletBusiness.CreateAddressAsync(wallet); if (result.Status != Status.STATUS_SUCCESS) { return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL)); } BlockchainAddress blockChainAddress; switch (currency) { case CryptoCurrency.BTC: var bitCoinAddressRepository = new BitcoinAddressRepository(VakapayRepositoryFactory.GetOldConnection()); blockChainAddress = bitCoinAddressRepository.FindByAddress(result.Data); break; case CryptoCurrency.ETH: var ethereumAddressRepository = new EthereumAddressRepository(VakapayRepositoryFactory.GetOldConnection()); blockChainAddress = ethereumAddressRepository.FindById(result.Data); break; case CryptoCurrency.VAKA: var vaKaCoinAccountRepository = new VakacoinAccountRepository(VakapayRepositoryFactory.GetOldConnection()); blockChainAddress = vaKaCoinAccountRepository.FindById(result.Data); break; default: return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL)); } return(blockChainAddress != null ? CreateDataSuccess(JsonConvert.SerializeObject(blockChainAddress)) : CreateDataError(MessageError.CREATE_ADDRESS_FAIL)); } catch (Exception) { return(CreateDataError(MessageError.CREATE_ADDRESS_FAIL)); } }