private static void RunSend(RepositoryConfiguration repositoryConfig) { var repoFactory = new VakapayRepositoryMysqlPersistenceFactory(repositoryConfig); var bitcoinBusiness = new BitcoinBusiness.BitcoinBusiness(repoFactory); var connection = repoFactory.GetOldConnection() ?? repoFactory.GetDbConnection(); try { while (true) { Console.WriteLine("Start Send Bitcoin...."); var rpc = new BitcoinRpc(AppSettingHelper.GetBitcoinNode(), AppSettingHelper.GetBitcoinRpcAuthentication()); using (var bitcoinRepo = repoFactory.GetBitcoinWithdrawTransactionRepository(connection)) { var resultSend = bitcoinBusiness.SendTransactionAsync(bitcoinRepo, rpc); Console.WriteLine(JsonHelper.SerializeObject(resultSend.Result)); Console.WriteLine("Send Bitcoin End..."); Thread.Sleep(1000); } } } catch (Exception e) { connection.Close(); _logger.Error(e, "Send Bitcoin"); Console.WriteLine(e.ToString()); } }
public async Task <ReturnObject> CreateAddressForWallet(Wallet pendingWallet) { try { var pass = CommonHelper.RandomString(15); ReturnObject res = new ReturnObject() { Status = Status.STATUS_ERROR, Message = "No currency " + pendingWallet.Currency }; ; switch (pendingWallet.Currency) { case CryptoCurrency.ETH: Console.WriteLine("make eth"); // var ethereumBusiness = new EthereumBusiness.EthereumBusiness(_vakapayRepositoryFactory, false); res = ethereumBussiness.CreateAddressAsync( new EthereumAddressRepository(_connectionDb), new EthereumRpc(AppSettingHelper.GetEthereumNode()), pendingWallet.Id, pass).Result; break; case CryptoCurrency.BTC: Console.WriteLine("make btc"); // var bitcoinBusiness = new BitcoinBusiness.BitcoinBusiness(_vakapayRepositoryFactory, false); res = bitcoinBussiness.CreateAddressAsync( new BitcoinAddressRepository(_connectionDb), new BitcoinRpc(AppSettingHelper.GetBitcoinNode(), AppSettingHelper.GetBitcoinRpcAuthentication()), pendingWallet.Id, pass).Result; break; case CryptoCurrency.VAKA: Console.WriteLine("make vaka"); // var vakaBusiness = new VakacoinBusiness.VakacoinBusiness(_vakapayRepositoryFactory, false); res = vakacoinBussiness.CreateAddressAsync( new VakacoinAccountRepository(_connectionDb), new VakacoinRpc(AppSettingHelper.GetVakacoinNode()), pendingWallet.Id, pass).Result; break; } return(res); } catch (Exception e) { Console.WriteLine(e.ToString()); return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = e.Message }); } }
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 Setup() { _btcRpc = new BitcoinRpc(AppSettingHelper.GetBitcoinNode(), AppSettingHelper.GetBitcoinRpcAuthentication()); }
private ReturnObject ValidateNetworkStatus(string walletNetworkName) { // throw new NotImplementedException(); /* * 1. Validate Bitcoin Network Status * 2. Validate Ethereum Network Status * 3. Validate Vakacoin Network Status * * Return network error in result.Message */ // 3. Validate Vakacoin Network Status try { ReturnObject getInfoResult; switch (walletNetworkName) { case CryptoCurrency.BTC: var bitcoinRpc = new BitcoinRpc(AppSettingHelper.GetBitcoinNode(), AppSettingHelper.GetBitcoinRpcAuthentication()); getInfoResult = bitcoinRpc.GetInfo(); if (getInfoResult.Status == Status.STATUS_ERROR) { return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = "Bitcoin network error: " + getInfoResult.Message }); } break; case CryptoCurrency.ETH: var ethRpc = new EthereumRpc(AppSettingHelper.GetEthereumNode()); var blockNumber = ethRpc.GetBlockNumber(); if (blockNumber.Status == Status.STATUS_ERROR) { return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = "Ethereum network error: " + blockNumber.Message }); } break; case CryptoCurrency.VAKA: var vakacoinRpc = new VakacoinRpc(AppSettingHelper.GetVakacoinNode()); getInfoResult = vakacoinRpc.GetInfo(); if (getInfoResult.Status == Status.STATUS_ERROR) { return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = "Vakacoin network error: " + getInfoResult.Message }); } break; default: return(new ReturnObject() { Status = Status.STATUS_ERROR, Message = "Undefined network name!" }); } } catch (Exception e) { Console.WriteLine(e); throw; } return(new ReturnObject() { Status = Status.STATUS_SUCCESS }); }