private void generateButton_Click(object sender, EventArgs e) { MyFile myFile = new MyFile(); WalletDotDat walletDotDat = new WalletDotDat(); string text = myFile.ReadFile(path); string[] splitted = text.Split(' '); string seed; int i; if (splitted.Length != 12) { Aes aes = new Aes(); walletDotDat.FromString(aes.Decrypt(text, password)); seed = walletDotDat.mnemonics; i = walletDotDat.bitcoinSecrets.Count; } else { walletDotDat.FromString(myFile.ReadFile(path)); seed = walletDotDat.mnemonics; i = walletDotDat.bitcoinSecrets.Count; } ExtKey extKey = Wallet.generateMasterAdress(seed); bitcoinSecret = Wallet.generateDerivedAdress(extKey, walletDotDat.bitcoinSecrets.Count()); inputReceiving.Text = bitcoinSecret.PubKey.GetAddress(Network.TestNet).ToString(); // generateQRCode(); }
private void saveButton_Click(object sender, EventArgs e) { if (inputReceiving.Text != "") { MyFile myFile = new MyFile(); string text = myFile.ReadFile(path); string[] splitted = text.Split(' '); if (splitted.Length != 12) { Aes aes = new Aes(); WalletDotDat walletDotDat = new WalletDotDat(); //aes.Decrypt(f.ReadFile(ucChooseYourWallet.FilePath), ucChooseYourWallet.Password) walletDotDat.FromString(aes.Decrypt(text, password)); walletDotDat.addPrivateKey(bitcoinSecret); MessageBox.Show(walletDotDat.ToString()); myFile.SaveEncryptedFile(walletDotDat.ToString(), password, path); } else { WalletDotDat walletDotDat = new WalletDotDat(); walletDotDat.FromString(myFile.ReadFile(path)); walletDotDat.addPrivateKey(bitcoinSecret); myFile.SaveUnecryptedFile(walletDotDat.ToString(), path); } } else { MessageBox.Show("Generate adress and input needed info!"); } }
private void UserControlAdresses_VisibleChanged(object sender, EventArgs e) { MyFile myFile = new MyFile(); string text = myFile.ReadFile(path); WalletDotDat walletDotDat = new WalletDotDat(); if (text.Split(' ').Length < 12) { Aes aes = new Aes(); walletDotDat.FromString(aes.Decrypt(text, password)); } else { walletDotDat.FromString(text); } dataGridView1.DataSource = walletDotDat.getAddresses(); }
private void inputAllAvailable_Click(object sender, EventArgs e) { MyFile myFile = new MyFile(); string text = myFile.ReadFile(path); WalletDotDat walletDotDat = new WalletDotDat(); if (text.Split(' ').Length < 12) { Aes aes = new Aes(); walletDotDat.FromString(aes.Decrypt(text, password)); } else { walletDotDat.FromString(text); } inputAmount.Text = ((Wallet.GetConfirmedWalletBalance(walletDotDat.getSecrets(), true) * 1000m).ToString()); }
private void GetBalance() { MyFile myFile = new MyFile(); string text = myFile.ReadFile(path); WalletDotDat walletDotDat = new WalletDotDat(); if (text.Split(' ').Length < 12) { Aes aes = new Aes(); walletDotDat.FromString(aes.Decrypt(text, password)); } else { walletDotDat.FromString(text); } outputBalance.Text = ((Wallet.GetConfirmedWalletBalance(walletDotDat.getSecrets(), true)).ToString()) + " BTC"; if (((Wallet.GetUnconfirmedWalletBalance(walletDotDat.getSecrets(), true)) > 0)) { outputBalance.Text += " [" + ((Wallet.GetUnconfirmedWalletBalance(walletDotDat.getSecrets(), true)).ToString()) + " unconfirmed]"; } }
private void ShowHistory() { outputTranstactionHistory.Rows.Clear(); MyFile myFile = new MyFile(); WalletDotDat walletDotDat = new WalletDotDat(); string text = myFile.ReadFile(path); string[] splitted = text.Split(' '); string seed; int i; if (splitted.Length != 12) { Aes aes = new Aes(); walletDotDat.FromString(aes.Decrypt(text, password)); seed = walletDotDat.mnemonics; i = walletDotDat.bitcoinSecrets.Count; } else { walletDotDat.FromString(myFile.ReadFile(path)); seed = walletDotDat.mnemonics; i = walletDotDat.bitcoinSecrets.Count; } ExtKey extKey = Wallet.generateMasterAdress(seed); int n = 0; string address = ""; for (int j = 0; j < i; j++) { bitcoinSecret = Wallet.generateDerivedAdress(extKey, j); address = bitcoinSecret.PubKey.GetAddress(Network.TestNet).ToString(); using (var client = new HttpClient()) { var result = client.GetAsync("http://tapi.qbit.ninja/balances/" + address).Result; if (result.IsSuccessStatusCode) { var content = result.Content; string transactions = content.ReadAsStringAsync().Result; JObject json = JObject.Parse(transactions); foreach (var transaction in json["operations"]) { outputTranstactionHistory.Rows.Add(); if (int.Parse(transaction["confirmations"].ToString()) > 6) { outputTranstactionHistory.Rows[n].Cells[0].Value = "6+"; } else { outputTranstactionHistory.Rows[n].Cells[0].Value = transaction["confirmations"]; } outputTranstactionHistory.Rows[n].Cells[1].Value = transaction["firstSeen"]; if (int.Parse(transaction["confirmations"].ToString()) < 6) { outputTranstactionHistory.Rows[n].Cells[2].Value = "Unconfirmed transaction"; } else { outputTranstactionHistory.Rows[n].Cells[2].Value = "Confirmed transaction"; } outputTranstactionHistory.Rows[n].Cells[3].Value = decimal.Parse(transaction["amount"].ToString()) * 0.00000001m; n++; } } } } if (outputTranstactionHistory.Rows.Count != 0) { outputTranstactionHistory.Sort(outputTranstactionHistory.Columns[1], ListSortDirection.Descending); outputTranstactionHistory.Rows[outputTranstactionHistory.Rows.Count - 1].Cells[4].Value = outputTranstactionHistory.Rows[outputTranstactionHistory.Rows.Count - 1].Cells[3].Value; for (int j = outputTranstactionHistory.Rows.Count - 2; j >= 0; j--) { outputTranstactionHistory.Rows[j].Cells[4].Value = decimal.Parse(outputTranstactionHistory.Rows[j + 1].Cells[4].Value.ToString()) + decimal.Parse(outputTranstactionHistory.Rows[j].Cells[3].Value.ToString()); } } }
private void inputSend_Click(object sender, EventArgs e) { decimal amount, fee; string destination = inputPayTo.Text; bool adressValid, amountValid, feeValid; DialogResult dialogResult = DialogResult.Yes; adressValid = Wallet.checkAdress(destination); amountValid = decimal.TryParse(inputAmount.Text, out amount); feeValid = decimal.TryParse(inputFee.Text, out fee); if (feeValid) { fee = fee / 1000m; } //MessageBox.Show(fee.ToString()); if (feeValid && fee < 0.0005m) { dialogResult = MessageBox.Show("Fee is too low. Confirming transaction will take very long time.", "Continue?", MessageBoxButtons.YesNo); } if (adressValid && amountValid && feeValid && dialogResult == DialogResult.Yes) { MyFile myFile = new MyFile(); string text = myFile.ReadFile(path); WalletDotDat walletDotDat = new WalletDotDat(); if (text.Split(' ').Length < 12) { Aes aes = new Aes(); walletDotDat.FromString(aes.Decrypt(text, password)); } else { walletDotDat.FromString(text); } BitcoinWallet.Class.Transaction transaction = new BitcoinWallet.Class.Transaction(walletDotDat.getSecrets(), fee, amount, inputPayTo.Text); transaction.getInputs(); try { transaction.Send(); } catch (NBitcoin.NotEnoughFundsException exc) { decimal missing = decimal.Parse(exc.Missing.ToString()) * 1000m; MessageBox.Show("Not enough funds. Missing: " + missing + "mBTC", "BitcoinWallet", MessageBoxButtons.OK, MessageBoxIcon.Error); } //System.Windows.Forms.Clipboard.SetText(transaction.getHexTransaction()); } else if (dialogResult == DialogResult.No) { inputFee.Text = "0.5"; } else { string errors = ""; if (!adressValid) { errors += "Adress is not in correct format!" + Environment.NewLine; } if (!amountValid) { errors += "Amount is not in correct format!" + Environment.NewLine; } if (!feeValid) { errors += "Fee is not in correct format!" + Environment.NewLine; } MessageBox.Show(errors, "BitcoinWallet", MessageBoxButtons.OK, MessageBoxIcon.Error); } }