コード例 #1
0
ファイル: api.cs プロジェクト: BigbadJohn21/SimpleWallet
        public Types.ConfigureResult editComfigureFile(String status, String aliasName, String IP, String privKey, String txHash, String txIndex, String oldName, bool isNew = true)
        {
            Types.ConfigureResult result = Types.ConfigureResult.OK;
            String appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                             + "\\zero";
            String confFile = appdata + "\\zero.conf";

            try
            {
                if (!File.Exists(confFile))
                {
                    result = Types.ConfigureResult.FAIL;
                }
                else
                {
                    //config file
                    List <String> text = File.ReadAllLines(confFile).ToList();
                    text.RemoveAll(String.IsNullOrEmpty);
                    int index = text.FindIndex(x => x.StartsWith("port"));
                    if (index != -1)
                    {
                        text.RemoveAt(index);
                    }
                    text.Add("port=23801");
                    index = text.FindIndex(x => x.StartsWith("listen"));
                    if (index != -1)
                    {
                        text.RemoveAt(index);
                    }
                    text.Add("listen=1");
                    index = text.FindIndex(x => x.StartsWith("server"));
                    if (index != -1)
                    {
                        text.RemoveAt(index);
                    }
                    text.Add("server=1");
                    index = text.FindIndex(x => x.StartsWith("txindex"));
                    if (index != -1)
                    {
                        text.RemoveAt(index);
                    }
                    else
                    {
                        result = Types.ConfigureResult.REINDEX;
                    }
                    text.Add("txindex=1");

                    File.WriteAllLines(confFile, text.ToArray());
                }
            }
            catch
            {
                result = Types.ConfigureResult.FAIL;
            }
            //}
            return(result);
        }
コード例 #2
0
        void configure(bool enable = true)
        {
            if (String.IsNullOrEmpty(tbName.Text))
            {
                MessageBox.Show("Alias name could not be empty");
                return;
            }
            if (String.IsNullOrEmpty(tbIP.Text))
            {
                MessageBox.Show("IP address could not be empty");
                return;
            }
            if (String.IsNullOrEmpty(tbPrivKey.Text))
            {
                MessageBox.Show("Private key could not be empty");
                return;
            }
            if (String.IsNullOrEmpty(tbOutPuts.Text))
            {
                MessageBox.Show("Outputs could not be empty");
                return;
            }

            List <String> split = tbOutPuts.Text.Split(' ').ToList();

            split.RemoveAll(String.IsNullOrEmpty);
            if (split.Count < 2)
            {
                MessageBox.Show("Outputs is wrong");
                return;
            }

            result = api.editComfigureFile("ENABLE", tbName.Text, tbIP.Text, tbPrivKey.Text, split[0], split[1], oldName, isNew);

            if (result == Types.ConfigureResult.FAIL)
            {
                MessageBox.Show("Configure error, please check the parameters and the config files"); //this should not happen
            }
            else if (result == Types.ConfigureResult.OK)
            {
                MessageBox.Show("Configure success");
                this.Close();
            }
            else if (result == Types.ConfigureResult.REINDEX)
            {
                MessageBox.Show("Configure success. However your data need reindex to work with masternode");
                this.Close();
            }
            else if (result == Types.ConfigureResult.DUPLICATE)
            {
                MessageBox.Show("Configure error, duplicate alias name");
            }
        }
コード例 #3
0
ファイル: api.cs プロジェクト: 0x6b656e/SimpleWallet
        public Types.ConfigureResult changeStatus(String status, String aliasName, String IP, String privKey, String txHash, String txIndex, bool isDisableAll)
        {
            Types.ConfigureResult result = Types.ConfigureResult.OK;
            String appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                             + "\\Anon";
            String confFile = appdata + "\\anon.conf";
            String mnFile   = appdata + "\\masternode.conf";

            if (aliasName.StartsWith("#"))
            {
                aliasName = aliasName.Substring(1, aliasName.Length - 1);
            }
            List <Types.Masternode> mns = getMasternodes();

            try
            {
                if (!File.Exists(confFile))
                {
                    result = Types.ConfigureResult.FAIL;
                }
                else
                {
                    int index = 0;
                    if (status == "ENABLE" || isDisableAll)
                    {
                        //config file
                        List <String> text = File.ReadAllLines(confFile).ToList();
                        text.RemoveAll(String.IsNullOrEmpty);
                        index = text.FindIndex(x => x.StartsWith("port"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("port=33130");
                        index = text.FindIndex(x => x.StartsWith("listen"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("listen=1");
                        index = text.FindIndex(x => x.StartsWith("server"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("server=1");
                        index = text.FindIndex(x => x.StartsWith("txindex"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("txindex=1");
                        index = text.FindIndex(x => x.StartsWith("daemon"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("daemon=1");
                        index = text.FindIndex(x => x.StartsWith("masternode="));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        index = text.FindIndex(x => x.StartsWith("masternodeaddr"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        index = text.FindIndex(x => x.StartsWith("externalip"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        index = text.FindIndex(x => x.StartsWith("masternodeprivkey"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }

                        File.WriteAllLines(confFile, text.ToArray());
                    }

                    index = mns.FindIndex(f => f.alias == aliasName);
                    if (index > -1)
                    {
                        mns.RemoveAt(index);
                    }

                    mns.Add(new Types.Masternode(status, aliasName, IP, privKey, txHash, txIndex));

                    List <String> data = new List <string>();
                    foreach (Types.Masternode m in mns)
                    {
                        data.Add(m.ToString());
                    }

                    File.WriteAllLines(mnFile, data);
                }
            }
            catch (Exception ex)
            {
                result = Types.ConfigureResult.FAIL;
            }
            return(result);
        }
コード例 #4
0
        public Types.ConfigureResult editComfigureFile(String status, String aliasName, String IP, String privKey, String txHash, String txIndex, String oldName, bool isNew = true)
        {
            Types.ConfigureResult result = Types.ConfigureResult.OK;
            String appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                             + "\\Snowgem";
            String confFile = appdata + "\\snowgem.conf";
            String mnFile   = appdata + "\\masternode.conf";

            if (aliasName.StartsWith("#"))
            {
                aliasName = aliasName.Substring(1, aliasName.Length - 1);
            }

            List <Types.Masternode> mns = getMasternodes();

            if (oldName != aliasName && mns.FindIndex(f => f.alias == aliasName) != -1)
            {
                result = Types.ConfigureResult.DUPLICATE;
            }
            else
            {
                try
                {
                    if (!File.Exists(confFile))
                    {
                        result = Types.ConfigureResult.FAIL;
                    }
                    else
                    {
                        //config file
                        List <String> text = File.ReadAllLines(confFile).ToList();
                        text.RemoveAll(String.IsNullOrEmpty);
                        int index = text.FindIndex(x => x.StartsWith("port"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("port=16113");
                        index = text.FindIndex(x => x.StartsWith("listen"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("listen=1");
                        index = text.FindIndex(x => x.StartsWith("server"));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }
                        text.Add("server=1");
                        index = text.FindIndex(x => x.StartsWith("masternode="));
                        if (index != -1)
                        {
                            text.RemoveAt(index);
                        }

                        File.WriteAllLines(confFile, text.ToArray());

                        if (!isNew)
                        {
                            index = mns.FindIndex(f => f.alias == oldName);
                            if (index > -1)
                            {
                                mns.RemoveAt(index);
                            }
                        }
                        mns.Add(new Types.Masternode(status, aliasName, IP + ":16113", privKey, txHash, txIndex));

                        List <String> data = new List <string>();
                        foreach (Types.Masternode m in mns)
                        {
                            data.Add(m.ToString());
                        }

                        File.WriteAllLines(mnFile, data);
                    }
                }
                catch (Exception ex)
                {
                    result = Types.ConfigureResult.FAIL;
                }
            }
            return(result);
        }