public string SendBitcoins(String FromCardId, String FromCardPublicAddress, String encryptedPrivateKey, String DestinationCardId, Decimal BitcoinAmount, Decimal FiatAmount, String Currency) { // For the FromCardId, Obtain the password. String Password = "******"; // Check that the FromCardPublicAddress = what is in the cards table for this cardID String DBCardPublicAddress = FromCardPublicAddress; Boolean AutoTopUp = true; // For the DesintationCardId, obtain the DestinationAddress from the Cards Table String DestinationAddress = "1QJQMFhgyoiLLUZXpr913T2TaEaX7pNFaF"; if (DBCardPublicAddress == DestinationAddress) { Card.CardClient card = new Card.CardClient(); ATM.AtmClient atm = new ATM.AtmClient(); Decimal CardBalance = atm.GetBalance(FromCardPublicAddress, 1); Decimal MinersFee = 0.0001M; if (CardBalance >= (BitcoinAmount + MinersFee)) { String result = atm.SendBitcoins(encryptedPrivateKey, Password, DestinationAddress, BitcoinAmount); return(result); } else { if (AutoTopUp) { // Purchase more coins to cover the difference DCExchange.ExchangeClient ExchangeClient = new DCExchange.ExchangeClient(); DCExchange.Margin margin = ExchangeClient.GetMargin(Currency, 0); Decimal PurchaseBitcoinsAmount = FiatAmount * margin.Buy; // PurchaseFiatAmount = PurchaseBitcoinsAmount; PurchaseBitcoins(FromCardId, DestinationAddress, FiatAmount, Currency); // Empty the wallet String result = atm.SendBitcoins(encryptedPrivateKey, Password, DestinationAddress, CardBalance); return(""); } else { return("Refer to DD/CC Issuer"); } } } else { return("Invalid Card - Public Address does not match entry in Database. Card may have been tampered with"); } }
private void readCard() { nfc = DCPOS.Factory.GetNFC(); if (nfc.InitReader()) { if (nfc.ConnectReader()) { String CardId = ""; if (nfc.ReadTagID(ref CardId)) { String PublicKey = ""; if (nfc.readPublicKey(ref PublicKey)) { // Get Balance ATM.AtmClient atm = new ATM.AtmClient(); decimal value = atm.GetBalance(PublicKey, 1); lblBTCBalance.Text = value.ToString("0.000000 BTC"); } else { lblStatus.Text = "Cannot read Public Key"; } } else { lblStatus.Text = "Cannot read CardId"; } } else { lblStatus.Text = "Card not Present on Reader"; } } else { lblStatus.Text = "Cannot Initalise Reader"; } }