예제 #1
0
        private void btnArchive_Click(object sender, EventArgs e)
        {
            DialogResult prompt = MessageBox.Show("You are about to permanently etch a profile onto " + Main.CoinType + "." + Environment.NewLine + "            !!! Apertus may lock up during this process !!!" + Environment.NewLine + "       Please be patient.  We will thread it better next time.", "Confirmation", MessageBoxButtons.YesNoCancel);

            if (prompt == DialogResult.Yes)
            {
                Main.ProfileID    = "";
                Main.ProfileLabel = "";
                var    mainForm      = Application.OpenForms.OfType <Main>().Single();
                string tempSignature = Main.SignatureLabel;
                Main.SignatureLabel = "~~" + cmbProfileAddress.Text;
                Match  match            = Regex.Match(openFileDialog1.FileName, @"([a-fA-F0-9]{64})");
                string profileImagePath = "";
                if (openFileDialog1.FileName != "openFileDialog1" && !match.Success)

                {
                    mainForm.PerformArchive(Main.CoinType, openFileDialog1.FileName, "");
                    var b            = new CoinRPC(new Uri(GetURL(Main.coinIP[Main.CoinType]) + ":" + Main.coinPort[Main.CoinType]), new NetworkCredential(Main.coinUser[Main.CoinType], Main.coinPassword[Main.CoinType]));
                    var transactions = b.ListTransactions("~~~~" + cmbProfileAddress.Text, 100, 0);

                    foreach (var transaction in transactions.Reverse())
                    {
                        if (transaction.category == "receive")
                        {
                            if (mainForm.CreateArchive(transaction.txid, Main.CoinType, false, true, null, null, false))
                            {
                                if (System.IO.File.Exists("root//" + transaction.txid + "//" + Path.GetFileName(openFileDialog1.FileName)))
                                {
                                    profileImagePath = "../" + transaction.txid + "/" + Path.GetFileName(openFileDialog1.FileName);
                                    break;
                                }
                            }
                        }
                    }
                }

                if (match.Success)
                {
                    profileImagePath = "../" + match.Value + "/" + Path.GetFileName(openFileDialog1.FileName);
                }


                String processId = Guid.NewGuid().ToString();
                System.IO.Directory.CreateDirectory("process//" + processId);
                System.IO.StreamWriter proFile = new System.IO.StreamWriter("process//" + processId + "//PRO");
                proFile.WriteLine("IMG=" + profileImagePath);
                proFile.WriteLine("NIK=" + txtNickName.Text);
                proFile.WriteLine("PRE=" + txtPrefix.Text);
                proFile.WriteLine("FNM=" + txtFirstName.Text);
                proFile.WriteLine("MNM=" + txtMiddleName.Text);
                proFile.WriteLine("LNM=" + txtLastName.Text);
                proFile.WriteLine("SUF=" + txtSuffix.Text);
                proFile.WriteLine("AD1=" + txtAddress1.Text);
                proFile.WriteLine("AD2=" + txtAddress2.Text);
                proFile.WriteLine("AD3=" + txtAddress3.Text);
                CoinRPC a = new CoinRPC(new Uri(GetURL(Main.coinIP[Main.CoinType]) + ":" + Main.coinPort[Main.CoinType]), new NetworkCredential(Main.coinUser[Main.CoinType], Main.coinPassword[Main.CoinType]));
                IEnumerable <string> Address = null;
                if (cmbTipAddress.SelectedIndex > 0)
                {
                    Address = a.GetAddressesByAccount("~~~~~" + cmbTipAddress.Text);
                    proFile.WriteLine("TIP=" + Address.First());
                }
                Address = a.GetAddressesByAccount("~~~~" + cmbProfileAddress.Text);
                var privKeyHex = BitConverter.ToString(Base58.Decode(a.DumpPrivateKey(Address.First()))).Replace("-", "");
                privKeyHex = privKeyHex.Substring(2, 64);
                BigInteger privateKey = Hex.HexToBigInteger(privKeyHex);
                ECPoint    publicKey  = Secp256k1.Secp256k1.G.Multiply(privateKey);

                proFile.WriteLine("MSG=" + Address.First());
                proFile.WriteLine("PKX=" + publicKey.X.ToHex());
                proFile.WriteLine("PKY=" + publicKey.Y.ToHex());
                proFile.Close();

                mainForm.PerformArchive(Main.CoinType, Application.StartupPath + "//process//" + processId + "//PRO", "");
                Main.SignatureLabel = tempSignature;
                BuildSelectedProfile();
                Main.ProfileID    = txtTransID.Text;
                Main.ProfileLabel = cmbProfileAddress.Text;
                mainForm.AddProfile(cmbProfileAddress.Text);
            }
        }
예제 #2
0
        private void BuildSelectedProfile()
        {
            if (cmbProfileAddress.SelectedIndex > 0)
            {
                txtNickName.Enabled     = true;
                txtPrefix.Enabled       = true;
                txtFirstName.Enabled    = true;
                txtMiddleName.Enabled   = true;
                txtLastName.Enabled     = true;
                txtSuffix.Enabled       = true;
                txtAddress1.Enabled     = true;
                txtAddress2.Enabled     = true;
                txtAddress3.Enabled     = true;
                txtTransID.Enabled      = true;
                cmbTipAddress.Enabled   = true;
                btnArchive.Enabled      = true;
                btnTipAddress.Enabled   = true;
                imgProfilePhoto.Enabled = true;

                txtNickName.Text            = "";
                txtPrefix.Text              = "";
                txtFirstName.Text           = "";
                txtMiddleName.Text          = "";
                txtLastName.Text            = "";
                txtSuffix.Text              = "";
                txtAddress1.Text            = "";
                txtAddress2.Text            = "";
                txtAddress3.Text            = "";
                txtTransID.Text             = "";
                imgProfilePhoto.Image       = Properties.Resources.Profile;
                cmbTipAddress.SelectedIndex = 0;
                btnArchive.Enabled          = true;
                btnTipAddress.Enabled       = true;

                var b            = new CoinRPC(new Uri(GetURL(Main.coinIP[Main.CoinType]) + ":" + Main.coinPort[Main.CoinType]), new NetworkCredential(Main.coinUser[Main.CoinType], Main.coinPassword[Main.CoinType]));
                var transactions = b.ListTransactions("~~~~" + cmbProfileAddress.Text, 10000, 0);

                foreach (var transaction in transactions.Reverse())
                {
                    if (transaction.category == "receive")
                    {
                        var mainForm = Application.OpenForms.OfType <Main>().Single();
                        if (mainForm.CreateArchive(transaction.txid, Main.CoinType, false, true, null, null, false))
                        {
                            if (System.IO.File.Exists("root//" + transaction.txid + "//PRO"))
                            {
                                var doc = new HtmlAgilityPack.HtmlDocument();
                                doc.Load("root\\" + transaction.txid + "\\index.htm");
                                if (doc.GetElementbyId("signature") != null)
                                {
                                    var signature = doc.GetElementbyId("signature").InnerText;
                                    if (transaction.address == signature)
                                    {
                                        txtTransID.Text = transaction.txid;
                                        string readFile = System.IO.File.ReadAllText("root//" + transaction.txid + "//PRO");
                                        int    start    = readFile.IndexOf("NIK=") + 4;
                                        int    length   = readFile.IndexOf(Environment.NewLine, start);
                                        txtNickName.Text   = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("PRE=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtPrefix.Text     = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("FNM=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtFirstName.Text  = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("MNM=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtMiddleName.Text = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("LNM=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtLastName.Text   = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("SUF=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtSuffix.Text     = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("AD1=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtAddress1.Text   = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("AD2=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtAddress2.Text   = readFile.Substring(start, length - start);
                                        start              = readFile.IndexOf("AD3=") + 4;
                                        length             = readFile.IndexOf(Environment.NewLine, start);
                                        txtAddress3.Text   = readFile.Substring(start, length - start);

                                        try
                                        {
                                            start  = readFile.IndexOf("TIP=") + 4;
                                            length = readFile.IndexOf(Environment.NewLine, start);
                                            var    addData = b.ValidateAddress(readFile.Substring(start, length - start));
                                            string accData = addData.account.Substring(5);
                                            cmbTipAddress.Text = accData;
                                        }
                                        catch { }



                                        try
                                        {
                                            start  = readFile.IndexOf("IMG=") + 4;
                                            length = readFile.IndexOf(Environment.NewLine, start);
                                            string strProfileImage = readFile.Substring(start, length - start);

                                            imgProfilePhoto.Image    = Image.FromFile(Application.StartupPath + "//root//" + strProfileImage.Substring(3).Replace('/', '\\'));
                                            openFileDialog1.FileName = Application.StartupPath + "//root//" + strProfileImage.Substring(3).Replace('/', '\\');
                                        }
                                        catch { }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                txtNickName.Enabled   = false;
                txtPrefix.Enabled     = false;
                txtFirstName.Enabled  = false;
                txtMiddleName.Enabled = false;
                txtLastName.Enabled   = false;
                txtSuffix.Enabled     = false;
                txtAddress1.Enabled   = false;
                txtAddress2.Enabled   = false;
                txtAddress3.Enabled   = false;
                txtTransID.Enabled    = false;
                cmbTipAddress.Enabled = false;
                btnArchive.Enabled    = false;
                btnTipAddress.Enabled = false;
                txtNickName.Text      = "";
                txtPrefix.Text        = "";
                txtFirstName.Text     = "";
                txtMiddleName.Text    = "";
                txtLastName.Text      = "";
                txtSuffix.Text        = "";
                txtAddress1.Text      = "";
                txtAddress2.Text      = "";
                txtAddress3.Text      = "";
                txtTransID.Text       = "";
                imgProfilePhoto.Image = Properties.Resources.Profile;
            }
        }