예제 #1
0
        /// <summary>
        /// Created Address with optimistic lock
        /// </summary>
        /// <param name="repoQuery"></param>
        /// <param name="rpcClass"></param>
        /// <param name="walletId"></param>
        /// <param name="other"></param>
        /// <typeparam name="TBlockchainAddress"></typeparam>
        /// <returns></returns>
        public virtual async Task <ReturnObject> CreateAddressAsync <TBlockchainAddress>(
            IAddressRepository <TBlockchainAddress> repoQuery, IBlockchainRpc rpcClass, string walletId,
            string other = "") where TBlockchainAddress : BlockchainAddress
        {
            try
            {
                using (var walletRepository = VakapayRepositoryFactory.GetWalletRepository(DbConnection))
                {
                    var walletCheck = walletRepository.FindById(walletId);

                    if (walletCheck == null)
                    {
                        return new ReturnObject
                               {
                                   Status  = Status.STATUS_ERROR,
                                   Message = "Wallet Not Found"
                               }
                    }
                    ;
                }
                var resultsRPC = rpcClass.CreateNewAddress(other);
                if (resultsRPC.Status == Status.STATUS_ERROR)
                {
                    return(resultsRPC);
                }

                var address = resultsRPC.Data;

                //	TBlockchainAddress _newAddress = new TBlockchainAddress();

                var resultDB = await repoQuery.InsertAddress(address, walletId, other);

                //
                //if (result.Status == Status.StatusError)
                //{
                //	return new ReturnObject
                //	{
                //		Status = Status.StatusSuccess,
                //		Message = "Cannot Insert Address"
                //	};
                //}

                //update address into wallet db
                //wallet.WalletBusiness(VakapayRepositoryFactory);

                return(new ReturnObject
                {
                    Status = resultDB.Status,
                    Message = resultDB.Message
                });
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
예제 #2
0
 public void SetAccountRepositoryForRpc(VakacoinRpc rpc)
 {
     using (var rep = (VakacoinAccountRepository)VakapayRepositoryFactory.GetVakacoinAccountRepository(DbConnection))
     {
         rpc.AccountRepository = rep;
     }
 }
예제 #3
0
 public override List <BlockchainTransaction> GetDepositHistory(int offset       = -1, int limit = -1,
                                                                string[] orderBy = null)
 {
     using (var depositRepo = VakapayRepositoryFactory.GetBitcoinDepositTransactionRepository(DbConnection))
     {
         return(GetHistory <BitcoinDepositTransaction>(depositRepo, offset, limit, orderBy));
     }
 }
예제 #4
0
 public override List <BlockchainTransaction> GetWithdrawHistory(int offset       = -1, int limit = -1,
                                                                 string[] orderBy = null)
 {
     using (var withdrawRepo = VakapayRepositoryFactory.GetVakacoinWithdrawTransactionRepository(DbConnection))
     {
         return(GetHistory <VakacoinWithdrawTransaction>(withdrawRepo, offset, limit, orderBy));
     }
 }
예제 #5
0
 public override List <BlockchainTransaction> GetWithdrawHistory(int offset       = -1, int limit = -1,
                                                                 string[] orderBy = null)
 {
     using (var ethereumwithdrawRepo = VakapayRepositoryFactory.GetEthereumWithdrawTransactionRepository(DbConnection))
     {
         Console.WriteLine("Get ETH HISTORY");
         return(GetHistory <EthereumWithdrawTransaction>(ethereumwithdrawRepo, offset, limit, orderBy));
     }
 }
예제 #6
0
 /// <summary>
 /// GetEmailByAddress
 /// </summary>
 /// <param name="transaction"></param>
 /// <returns></returns>
 private string GetEmailByTransaction(BlockchainTransaction transaction)
 {
     try
     {
         using (var userRepository = VakapayRepositoryFactory.GetUserRepository(DbConnection))
         {
             var email = userRepository.FindEmailBySendTransaction(transaction);
             return(email);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #7
0
 public override List <BlockchainTransaction> GetAllHistory(out int numberData, string userId, string currency,
                                                            int offset = -1, int limit = -1, string[] orderBy = null, string search = null, long day = -1)
 {
     using (var depositRepo = VakapayRepositoryFactory.GetVakacoinDepositTransactionRepository(DbConnection))
     {
         using (var withdrawRepo = VakapayRepositoryFactory.GetVakacoinWithdrawTransactionRepository(DbConnection))
         {
             using (var inter = VakapayRepositoryFactory.GetInternalTransactionRepository(DbConnection))
             {
                 return(GetAllHistory <VakacoinWithdrawTransaction, VakacoinDepositTransaction>(out numberData, userId,
                                                                                                currency, withdrawRepo, depositRepo, inter.GetTableName(), offset, limit, orderBy, search));
             }
         }
     }
 }
예제 #8
0
        /// <summary>
        /// Created Address with optimistic lock
        /// </summary>
        /// <param name="repoQuery"></param>
        /// <param name="rpcClass"></param>
        /// <param name="walletId"></param>
        /// <param name="other"></param>
        /// <typeparam name="TBlockchainAddress"></typeparam>
        /// <returns></returns>
        public override async Task <ReturnObject> CreateAddressAsync <TBlockchainAddress>(
            IAddressRepository <TBlockchainAddress> repoQuery,
            IBlockchainRpc rpcClass, string walletId, string other = "")
        {
            //return base.CreateAddressAsync(wallet, repoQuery, rpcClass, walletId, other);

            try
            {
                using (var walletRepository = VakapayRepositoryFactory.GetWalletRepository(DbConnection))
                {
                    var walletCheck = walletRepository.FindById(walletId);

                    if (walletCheck == null)
                    {
                        return new ReturnObject
                               {
                                   Status  = Status.STATUS_ERROR,
                                   Message = "Wallet Not Found"
                               }
                    }
                    ;

                    VakacoinRpcObj = rpcClass as VakacoinRpc;

                    var results =
                        CreateNewAccount(walletId); // Create account and add account name to VakacoinAccount table

                    if (results.Status == Status.STATUS_ERROR)
                    {
                        return(results);
                    }

                    return(new ReturnObject
                    {
                        Status = Status.STATUS_SUCCESS,
                        Message = "Create vakacoin account success!"
                    });
                }
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
예제 #9
0
 public ReturnObject FakePendingTransaction(VakacoinWithdrawTransaction blockchainTransaction)
 {
     try
     {
         using (var vakacoinwithdrawRepo = VakapayRepositoryFactory.GetVakacoinWithdrawTransactionRepository(DbConnection))
         {
             blockchainTransaction.Status = Status.STATUS_PENDING;
             return(vakacoinwithdrawRepo.Insert(blockchainTransaction));
         }
     }
     catch (Exception e)
     {
         return(new ReturnObject
         {
             Status = Status.STATUS_ERROR,
             Message = e.Message
         });
     }
 }
예제 #10
0
 public ReturnObject FakeDepositTransaction(EthereumDepositTransaction blockchainTransaction)
 {
     try
     {
         using (var repo = VakapayRepositoryFactory.GetEthereumDepositeTransactionRepository(DbConnection))
         {
             blockchainTransaction.Status = Status.STATUS_COMPLETED;
             return(repo.Insert(blockchainTransaction));
         }
     }
     catch (Exception e)
     {
         return(new ReturnObject
         {
             Status = Status.STATUS_ERROR,
             Message = e.Message
         });
     }
 }
예제 #11
0
        /// <summary>
        /// call RPC Vakacoin to create a new account
        /// save account name to database
        /// </summary>
        /// <returns></returns>
        public ReturnObject CreateNewAccount(string walletId)
        {
            try
            {
                var keyPair = KeyManager.GenerateKeyPair();

                var resultRpc = VakacoinRpcObj.CreateRandomAccount(keyPair.PublicKey);

                if (resultRpc.Status == Status.STATUS_ERROR)
                {
                    return(resultRpc);
                }

                using (var repo = VakapayRepositoryFactory.GetVakacoinAccountRepository(DbConnection))
                {
                    //TODO Encrypt Password Before save
                    var returnDb = repo.Insert(new VakacoinAccount
                    {
                        Status           = Status.STATUS_ACTIVE,
                        Address          = resultRpc.Data,
                        OwnerPrivateKey  = keyPair.PrivateKey,
                        OwnerPublicKey   = keyPair.PublicKey,
                        ActivePrivateKey = keyPair.PrivateKey,
                        ActivePublicKey  = keyPair.PublicKey,
                        WalletId         = walletId,
                    });


                    return(returnDb.Status == Status.STATUS_SUCCESS ? resultRpc : returnDb);
                }
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
예제 #12
0
        /// <summary>
        /// Add existed account to database
        /// save account name to database
        /// </summary>
        /// <returns></returns>
        public ReturnObject AddAccount(string walletId, string accountName, string ownerPrivateKey,
                                       string ownerPublicKey, string activePrivateKey = "", string activePublicKey = "")
        {
            try
            {
                using (var repo = VakapayRepositoryFactory.GetVakacoinAccountRepository(DbConnection))
                {
                    if (string.IsNullOrEmpty(activePrivateKey))
                    {
                        activePrivateKey = ownerPrivateKey;
                        activePublicKey  = ownerPublicKey;
                    }

                    //TODO Encrypt Password Before save
                    var returnObject = repo.Insert(new VakacoinAccount
                    {
                        Status           = Status.STATUS_ACTIVE,
                        Address          = accountName,
                        OwnerPrivateKey  = ownerPrivateKey,
                        OwnerPublicKey   = ownerPublicKey,
                        ActivePrivateKey = activePrivateKey,
                        ActivePublicKey  = activePublicKey,
                        WalletId         = walletId
                    });

                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
예제 #13
0
 public ReturnObject CreateDepositTransaction(string trxId, int blockNumber, string networkName, decimal amount,
                                              string fromAddress, string toAddress, decimal fee, string status)
 {
     try
     {
         using (var _rep = VakapayRepositoryFactory.GetVakacoinDepositTransactionRepository(DbConnection))
         {
             if (DbConnection.State != ConnectionState.Open)
             {
                 DbConnection.Open();
             }
             var transaction = new VakacoinDepositTransaction
             {
                 TrxId        = trxId,
                 BlockNumber  = blockNumber,
                 Amount       = amount,
                 FromAddress  = fromAddress,
                 ToAddress    = toAddress,
                 Fee          = fee,
                 Status       = status,
                 IsProcessing = 0,
                 Version      = 0
             };
             var result = _rep.Insert(transaction);
             return(result);
         }
     }
     catch (Exception e)
     {
         return(new ReturnObject
         {
             Status = Status.STATUS_ERROR,
             Message = e.Message
         });
     }
 }