コード例 #1
0
        public List <TransferCardViewModel> GetCustomerCards()
        {
            var cards = new List <TransferCardViewModel>();

            using (var db = new DiamondCircle_dbEntities())
            {
                var customerId = Helpers.GetLoggedInCustomerId(db);

                cards = db.Cards.Where(c => c.CustomerID == customerId && (c.Status == CardStatus.ACTIVE || c.Status == CardStatus.PENDING))
                        .Select(c => new TransferCardViewModel()
                {
                    CardId = c.CardId, DateIssued = c.DateIssued, PublicKey = c.PublicKey, Status = c.Status, BalanceAUD = 0, BalanceBTC = 0
                }).ToList();

                using (var atmClient = new DC.AtmService.AtmClient())
                {
                    foreach (var card in cards)
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(card.PublicKey))
                            {
                                //card.BalanceBTC = atmClient.GetBalance(card.PublicKey, 6);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }

            return(cards);
        }
コード例 #2
0
        public ActionResult TransferBalance(string cardId)
        {
            var model = new TransferModel();

            model.CardId = cardId;
            string publicKey;

            using (var atmClient = new DC.AtmService.AtmClient())
            {
                using (var db = new DiamondCircle_dbEntities())
                {
                    var card = db.Cards.Where(c => c.CardId == model.CardId).First();
                    publicKey = card.PublicKey;
                }

                try
                {
                    //Check that they have sufficient funds
                    var balance = atmClient.GetBalance(publicKey, 0);
                    if (balance < model.AmountToTransferInBtc + 0.0001M)
                    {
                        ModelState.AddModelError(string.Empty, "You do not have sufficient funds to transfer bitcoins");
                        return(View(model));
                    }
                    model.Balance = balance;
                }
                catch
                {
                    //TODO: This is a temporary fix. The GetBalance needs to return a value to distinguish what the error is.
                    ModelState.AddModelError(string.Empty, "You do not have sufficient funds to do a transfer, or a previous transaction has not yet been finalised");
                    return(View(model));
                }
            }
            return(View(model));
        }
コード例 #3
0
 public void DoTransfer()
 {
     using (var atmClient = new DC.AtmService.AtmClient())
     {
         var result = atmClient.ReceiveCoins(_sender.PrivateKey, _sender.Password, _receiver.PublicKey, _receiver.Amount);
     }
 }
コード例 #4
0
        public void CreateCard()
        {
            using (var atmClient = new DC.AtmService.AtmClient())
            {
                using (var cardClient = new DC.CardService.CardClient())
                {
                    var keys = atmClient.CreatePublicEncryptedPrivateKey();

                    var card = new Card();
                    card.CardId = "eeeee111";
                    var privateKey = Convert.ToBase64String(keys.EncryptedWIFPrivateKey);
                    //card.Password = Convert.ToBase64String(keys.Password);
                    card.TempPublicKey = keys.PublicKey;
                    card.DateIssued    = DateTime.Now;

                    using (var db = new DiamondCircle_dbEntities())
                    {
                        var userId = WebSecurity.CurrentUserId.ToString();
                        //card.CustomerID = db.Customers.Where(s => s.UserId == userId).SingleOrDefault().CustomerId;

                        db.Cards.Add(card);
                        db.SaveChanges();
                    }
                }
            }
        }
コード例 #5
0
        public ActionResult Transfer(string encryptedPrivateKey, string toAddress, Decimal amount)
        {
            DC.AtmService.AtmClient client = new DC.AtmService.AtmClient();
            //client.SendBitcoins(encryptedPrivateKey)
            //var atm = new AtmService.AtmClient();
            //var result = atm.Sell(privateKey, fromAddress, toAddress, amount);

            return(View(GetCards()));
        }
コード例 #6
0
 public void Commit()
 {
     var atmClient = new DC.AtmService.AtmClient();
     {
         //TODO: Find out the method for sending bitcoin to a public key
         //var order = atmClient.(PublicKey, Amount);
         //order.
         //Should we wait for confirmation of receipt of amount?
         var result = atmClient.GetBalance(PublicKey, 6);
     }
 }
コード例 #7
0
ファイル: CardController.cs プロジェクト: srowlison/bbiller
        private string CreateRandomToken()
        {
            string token;

            using (var atmClient = new DC.AtmService.AtmClient())
            {
                var keys = atmClient.CreatePublicEncryptedPrivateKey();
                token = keys.PublicKey;
            }

            return(token);
        }
コード例 #8
0
        public ActionResult TransferBalance(TransferModel model)
        {
            if (ModelState.IsValid)
            {
                using (var atmClient = new DC.AtmService.AtmClient())
                {
                    try
                    {
                        string password;
                        Card   card;

                        using (var db = new DiamondCircle_dbEntities())
                        {
                            card     = db.Cards.Where(c => c.CardId == model.CardId).First();
                            password = card.Password;
                        }

                        var transactionHash = atmClient.SendBitcoins(model.PrivateKey.Trim(), password.Trim(), model.DestinationAddress, model.AmountToTransferInBtc);
                        //var atmObj = new atm();
                        //var transactionHash = atmObj.SendBitcoins(model.PrivateKey.Trim(), password.Trim(), model.DestinationAddress, model.AmountToTransferInBtc);

                        //Store the transaction
                        //using (var db = new DiamondCircle_dbEntities())
                        //{
                        //    var sendAction = new SendBitcoin();
                        //    sendAction.CardId = model.CardId;
                        //    sendAction.Sender = card.PublicKey;
                        //    sendAction.Receiver = model.DestinationAddress;
                        //    sendAction.BTCAmount = model.AmountToTransferInBtc;
                        //    sendAction.Created = DateTime.UtcNow;
                        //    db.SendBitcoins.Add(sendAction);
                        //    db.SaveChanges();
                        //}

                        return(RedirectToAction("TransferSuccessful", new { receipt = transactionHash }));
                    }
                    catch (ArgumentException argEx)
                    {
                        ModelState.AddModelError(string.Empty, argEx.Message);
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(string.Empty, "An unknown error occurred");
                    }
                }
            }

            return(View(model));
        }
コード例 #9
0
ファイル: CardController.cs プロジェクト: srowlison/bbiller
        /// <summary>
        /// Generates the keys necessary to create an active card
        /// </summary>
        /// <returns></returns>
        public TransferCardViewModel GetKeys()
        {
            TransferCardViewModel viewModelCard = new TransferCardViewModel();

            using (var atmClient = new DC.AtmService.AtmClient())
            {
                var cardClient = new DC.CardService.CardClient();
                var keys       = atmClient.CreatePublicEncryptedPrivateKey();

                viewModelCard.Password   = Convert.ToBase64String(keys.Password);
                viewModelCard.PublicKey  = keys.PublicKey;
                viewModelCard.DateIssued = DateTime.Now;
                viewModelCard.PrivateKey = Convert.ToBase64String(keys.EncryptedWIFPrivateKey);

                return(viewModelCard);
            }
        }
コード例 #10
0
        public ActionResult BuyBitcoin(BuyBitcoinViewModel model)
        {
            string     publicKey;
            CreditCard creditCard;

            using (var db = new DiamondCircle_dbEntities())
            {
                //Get the card
                var card = db.Cards.Where(c => c.CardId == model.CardId).First();
                publicKey = card.PublicKey;

                //Get the creditCard for this card
                creditCard = db.CreditCards.Where(c => c.CreditCardId == card.CreditCardId).First();
            }
            using (var atmClient = new DC.AtmService.AtmClient())
            {
                //TODO: Deduct credit card by converted fiat amount
                // var result = PinPaymentsCharge(creditCard)
                atmClient.CreateOrder(publicKey, model.Price);
            }
            return(View());
        }
コード例 #11
0
        public ActionResult TransferBalance(TransferModel model)
        {
            if (ModelState.IsValid)
            {
                using (var atmClient = new DC.AtmService.AtmClient())
                {
                    //var atmClient = new DCNode.atm();
                    try
                    {
                        string password;
                        Card   card;

                        using (var db = new DiamondCircle_dbEntities())
                        {
                            card     = db.Cards.Where(c => c.CardId == model.CardId).First();
                            password = card.Password;
                        }

                        //Check that the private key they entered resolves to the public key on their card
                        if (card.PublicKey != atmClient.ResolvePrivateKey(model.PrivateKey.Trim(), card.Password.Trim()))
                        {
                            ModelState.AddModelError(string.Empty, "The private key you entered does not relate to the public key on this card");
                            return(View(model));
                        }

                        //Check that there are 6 confirmations
                        int confirmations = atmClient.GetConfirmations(card.PublicKey.Trim());
                        if (confirmations < 1)
                        {
                            ModelState.AddModelError(string.Empty, "Your current balance is still being verified. Your last transaction is unconfirmed. Please try again later");
                            return(View(model));
                        }
                        else if (confirmations < 6)
                        {
                            ModelState.AddModelError(string.Empty, "Your current balance has been confirmed with " + confirmations.ToString() + " out of the minimum 6 blockchain confirmations. Please try again later");
                            return(View(model));
                        }


                        //try
                        //{
                        //    //Check that they have sufficient funds
                        //    var balance = atmClient.GetBalance(card.PublicKey, 0);
                        //    if (balance < model.AmountToTransferInBtc + 0.0001M)
                        //    {
                        //        ModelState.AddModelError(string.Empty, "You do not have sufficient funds to transfer this amount");
                        //        return View(model);
                        //    }
                        //}
                        //catch
                        //{
                        //    //TODO: This is a temporary fix. The GetBalance needs to return a value to distinguish what the error is.
                        //    ModelState.AddModelError(string.Empty, "You do not have sufficient funds to transfer this amount");
                        //    return View(model);
                        //}

                        var transactionHash = atmClient.SendBitcoins(model.PrivateKey.Trim(), password.Trim(), model.DestinationAddress, model.AmountToTransferInBtc);

                        //Store the transaction
                        //using (var db = new DiamondCircle_dbEntities())
                        //{
                        //    var sendAction = new SendBitcoin();
                        //    sendAction.CardId = model.CardId;
                        //    sendAction.Sender = card.PublicKey;
                        //    sendAction.Receiver = model.DestinationAddress;
                        //    sendAction.BTCAmount = model.AmountToTransferInBtc;
                        //    sendAction.Created = DateTime.UtcNow;
                        //    db.SendBitcoins.Add(sendAction);
                        //    db.SaveChanges();
                        //}

                        return(RedirectToAction("TransferSuccessful", new { receipt = transactionHash }));
                    }
                    catch (ArgumentException argEx)
                    {
                        ModelState.AddModelError(string.Empty, argEx.Message);
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            return(View(model));
        }