コード例 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            try
            {
                Mutex.OpenExisting("QURAS WALLET MUTEX");
                MessageBox.Show(StringTable.GetInstance().GetString("STR_WALLET_DUPPLICATION_ERROR", iLang), "QURAS");
                this.Close();
                return;
            }
            catch
            {
                _m = new Mutex(true, "QURAS WALLET MUTEX");
            }



            SplashTimer.Tick    += new EventHandler(NextWindow);
            SplashTimer.Interval = new TimeSpan(0, 0, 3);
            SplashTimer.Start();

            Version localVersion  = Assembly.GetExecutingAssembly().GetName().Version;
            Version serverVersion = GetNewestWalletVersionFromServer();

            if (localVersion < serverVersion)
            {
                // Show the Update Window;
            }
            else
            {
                // Check the Key file Exception.
            }

            Task.Run(() =>
            {
                try
                {
                    string vkKeyPath = SettingsConfig.Default.VkKeyPath;
                    string pkKeyPath = SettingsConfig.Default.PkKeyPath;

                    vkKeyPath = System.IO.Path.GetFullPath(vkKeyPath);
                    pkKeyPath = System.IO.Path.GetFullPath(pkKeyPath);

                    if (Constant.isLoadedVK == false)
                    {
                        int ret = SnarkDllApi.Snark_DllInit(1, vkKeyPath.ToArray(), pkKeyPath.ToArray());

                        if (ret <= 0)
                        {
                            MessageBox.Show("Verify key cannot load.", "Error", MessageBoxButton.OK);
                            this.Close();
                            return;
                        }

                        Constant.isLoadedVK = true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Verify key cannot load." + ex.ToString(), "Error", MessageBoxButton.OK);
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.Close();
                    }));
                }

                try
                {
                    Blockchain.RegisterBlockchain(new LevelDBBlockchain("chain"));
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        isLoadedBlockchain = true;
                    }));
                }
                catch (Exception ex)
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        MessageBox.Show("Cannot load blockchain db." + System.Environment.NewLine + ex.ToString(), "Error", MessageBoxButton.OK);
                        this.Close();
                    }));
                }
            });
        }
コード例 #2
0
        private void btnZKModuleLoad_Click(object sender, RoutedEventArgs e)
        {
            btnZKModuleLoad.IsEnabled = false;

            string vkKeyPath = SettingsConfig.Default.VkKeyPath;
            string pkKeyPath = SettingsConfig.Default.PkKeyPath;

            vkKeyPath = System.IO.Path.GetFullPath(vkKeyPath);
            pkKeyPath = System.IO.Path.GetFullPath(pkKeyPath);

            if (StaticUtils.CheckZKSnarksKeyStatus() == 0)
            {
                Task.Run(() => {
                    int ret;
                    if (vkKeyState == KeyState.Loaded)
                    {
                        ret = 1;

                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            zkModuleState = KeyState.Loading;
                            ShowZkModuleState(zkModuleState);
                        }));
                    }
                    else
                    {
                        try
                        {
                            this.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                StaticUtils.ShowMessageBox(StaticUtils.BlueBrush, StringTable.GetInstance().GetString("STR_SUCCESS_LOADING_VERIFYKEY", iLang));

                                vkKeyState = KeyState.Loading;
                                ShowVkKeyState(vkKeyState);

                                zkModuleState = KeyState.Loading;
                                ShowZkModuleState(zkModuleState);
                            }));
                            ret = SnarkDllApi.Snark_DllInit(1, vkKeyPath.ToArray(), pkKeyPath.ToArray());
                        }
                        catch (Exception ex)
                        {
                            ret = -1;
                        }
                    }

                    if (ret > 0)
                    {
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            StaticUtils.ShowMessageBox(StaticUtils.GreenBrush, StringTable.GetInstance().GetString("STR_SUCCESS_LOADED_VERIFYKEY", iLang));

                            vkKeyState          = KeyState.Loaded;
                            Constant.isLoadedVK = true;
                            ShowVkKeyState(vkKeyState);
                        }));

                        vkKeyPath = SettingsConfig.Default.VkKeyPath;
                        pkKeyPath = SettingsConfig.Default.PkKeyPath;

                        vkKeyPath = System.IO.Path.GetFullPath(vkKeyPath);
                        pkKeyPath = System.IO.Path.GetFullPath(pkKeyPath);

                        try
                        {
                            this.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                StaticUtils.ShowMessageBox(StaticUtils.BlueBrush, StringTable.GetInstance().GetString("STR_BEGIN_LOADING_PUBLICKEY", iLang));

                                pkKeyState = KeyState.Loading;
                                ShowPkKeyState(pkKeyState);

                                LoadKeyTaskMessage taskMessage = new LoadKeyTaskMessage(StringTable.GetInstance().GetString("STR_TASK_MESSAGE_PK_KEY_LOAD_START", iLang), DateTime.Now);
                                Constant.TaskMessages.Add(taskMessage);
                                TaskChangedEvent?.Invoke(this, taskMessage);
                            }));

                            ret = SnarkDllApi.Snark_DllInit(2, vkKeyPath.ToArray(), pkKeyPath.ToArray());
                        }
                        catch (Exception)
                        {
                            ret = -1;
                        }
                        if (ret > 0)
                        {
                            this.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                StaticUtils.ShowMessageBox(StaticUtils.GreenBrush, StringTable.GetInstance().GetString("STR_SUCCESS_LOADED_PUBLICKEY", iLang));

                                pkKeyState = KeyState.Loaded;
                                ShowPkKeyState(pkKeyState);
                                Constant.isLoadedPK = true;

                                zkModuleState = KeyState.Loaded;
                                ShowZkModuleState(zkModuleState);
                                Constant.bSnarksParamLoaded = true;

                                LoadKeyTaskMessage taskMessage = new LoadKeyTaskMessage(StringTable.GetInstance().GetString("STR_TASK_MESSAGE_PK_KEY_LOAD_FINISHED", iLang), DateTime.Now);
                                Constant.TaskMessages.Add(taskMessage);
                                TaskChangedEvent?.Invoke(this, taskMessage);
                                btnZKModuleLoad.IsEnabled = false;
                            }));
                        }
                        else
                        {
                            this.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_ERR_LOADING_PUBLICKEY", iLang));

                                pkKeyState = KeyState.Downloaded;
                                ShowPkKeyState(pkKeyState);

                                zkModuleState = KeyState.Downloaded;
                                ShowZkModuleState(zkModuleState);

                                LoadKeyTaskMessage taskMessage = new LoadKeyTaskMessage(StringTable.GetInstance().GetString("STR_TASK_MESSAGE_PK_KEY_LOAD_FAILED", iLang), DateTime.Now, TaskColor.Red);
                                Constant.TaskMessages.Add(taskMessage);
                                TaskChangedEvent?.Invoke(this, taskMessage);
                                btnZKModuleLoad.IsEnabled = true;
                            }));
                        }
                    }
                    else
                    {
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            StaticUtils.ShowMessageBox(StaticUtils.GreenBrush, StringTable.GetInstance().GetString("STR_ERR_LOADING_VERIFYKEY", iLang));

                            vkKeyState = KeyState.Downloaded;
                            ShowVkKeyState(vkKeyState);

                            zkModuleState = KeyState.Downloaded;
                            ShowZkModuleState(zkModuleState);

                            btnZKModuleLoad.IsEnabled = true;
                        }));
                    }
                });
            }
        }
コード例 #3
0
        private void MainWalletForm_Load(object sender, EventArgs e)
        {
            string vkKeyPath = Settings.Default.VkKeyPath;
            string pkKeyPath = Settings.Default.PkKeyPath;

            vkKeyPath = Path.GetFullPath(vkKeyPath);
            pkKeyPath = Path.GetFullPath(pkKeyPath);

            if (Utils.CheckZKSnarksKeyStatus() == 0)
            {
                int ret;
                try
                {
                    ret = SnarkDllApi.Snark_DllInit(1, vkKeyPath.ToArray(), pkKeyPath.ToArray());
                }
                catch (Exception)
                {
                    ret = -1;
                }
                if (ret > 0)
                {
                    Invoke(new Action(() =>
                    {
                        lbl_status.Text = StringTable.DATA[iLang, 37];
                    }));

                    Task.Run(() =>
                    {
                        Invoke(new Action(() =>
                        {
                            lbl_status.Text = StringTable.DATA[iLang, 38];
                        }));

                        vkKeyPath = Settings.Default.VkKeyPath;
                        pkKeyPath = Settings.Default.PkKeyPath;

                        vkKeyPath = Path.GetFullPath(vkKeyPath);
                        pkKeyPath = Path.GetFullPath(pkKeyPath);

                        ret = SnarkDllApi.Snark_DllInit(2, vkKeyPath.ToArray(), pkKeyPath.ToArray());
                        if (ret > 0)
                        {
                            Invoke(new Action(() =>
                            {
                                lbl_status.Text             = StringTable.DATA[iLang, 39];
                                Constant.bSnarksParamLoaded = true;
                            }));
                        }
                        else
                        {
                            Invoke(new Action(() =>
                            {
                                lbl_status.Text = StringTable.DATA[iLang, 40] + ret.ToString();
                            }));
                        }
                    });
                }
                else
                {
                    Invoke(new Action(() =>
                    {
                        lbl_status.Text = StringTable.DATA[iLang, 41] + ret.ToString();
                    }));
                }
            }
            else
            {
                Invoke(new Action(() =>
                {
                    lbl_status.Text = StringTable.DATA[iLang, 41];
                }));
            }

            Task.Run(() =>
            {
                const string acc_path     = "chain.acc";
                const string acc_zip_path = acc_path + ".zip";
                if (File.Exists(acc_path))
                {
                    using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                    File.Delete(acc_path);
                }
                else if (File.Exists(acc_zip_path))
                {
                    using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(acc_path).Open())
                            {
                                ImportBlocks(zs);
                            }
                    File.Delete(acc_zip_path);
                }
                Blockchain.PersistCompleted += Blockchain_PersistCompleted;
                Constant.LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
            });
        }
コード例 #4
0
        protected internal override void OnStart(string[] args)
        {
            Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.DataDirectoryPath));
            if (File.Exists(PeerStatePath))
            {
                using (FileStream fs = new FileStream(PeerStatePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    LocalNode.LoadState(fs);
                }
            }

            // Load Verify Key
            string vk_path = ".//crypto//vk.key";
            string pk_path = ".//crypto//pk.key";

            int ret = SnarkDllApi.Snark_DllInit(1, vk_path.ToArray(), pk_path.ToArray());

            if (ret > 0)
            {
                Console.WriteLine($"Verify key loading success");
            }
            else
            {
                Console.WriteLine($"Verify key loading unseccess");
            }

            LocalNode = new LocalNode();
            Task.Run(() =>
            {
                const string acc_path     = "chain.acc";
                const string acc_zip_path = acc_path + ".zip";
                if (File.Exists(acc_path))
                {
                    using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                    File.Delete(acc_path);
                }
                else if (File.Exists(acc_zip_path))
                {
                    using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(acc_path).Open())
                            {
                                ImportBlocks(zs);
                            }
                    File.Delete(acc_zip_path);
                }
                LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
                bool recordNotifications = false;
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "/rpc":
                    case "--rpc":
                    case "-r":
                        if (rpc == null)
                        {
                            rpc = new RpcServerWithWallet(LocalNode);
                            rpc.Start(Settings.Default.UriPrefix.OfType <string>().ToArray(), Settings.Default.SslCert, Settings.Default.SslCertPassword);
                        }
                        break;

                    case "--record-notifications":
                        recordNotifications = true;
                        break;
                    }
                }
                if (recordNotifications)
                {
                    Blockchain.Notify += Blockchain_Notify;
                }
            });
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: cryptian2019/QURAS_CORE
        private void MainForm_Load(object sender, EventArgs e)
        {
            string vkKeyPath = Settings.Default.VkKeyPath;
            string pkKeyPath = Settings.Default.PkKeyPath;

            vkKeyPath = Path.GetFullPath(vkKeyPath);
            pkKeyPath = Path.GetFullPath(pkKeyPath);
            int ret = SnarkDllApi.Snark_DllInit(1, vkKeyPath.ToArray(), pkKeyPath.ToArray());

            if (ret > 0)
            {
                Invoke(new Action(() =>
                {
                    lbl_status.Text = "Verify key was loaded.";
                }));

                Task.Run(() =>
                {
                    Invoke(new Action(() =>
                    {
                        lbl_status.Text = "Loading PK...";
                    }));

                    vkKeyPath = Settings.Default.VkKeyPath;
                    pkKeyPath = Settings.Default.PkKeyPath;

                    vkKeyPath = Path.GetFullPath(vkKeyPath);
                    pkKeyPath = Path.GetFullPath(pkKeyPath);

                    ret = SnarkDllApi.Snark_DllInit(2, vkKeyPath.ToArray(), pkKeyPath.ToArray());
                    if (ret > 0)
                    {
                        Invoke(new Action(() =>
                        {
                            lbl_status.Text = "Loading PK Successed!";
                        }));
                    }
                    else
                    {
                        Invoke(new Action(() =>
                        {
                            lbl_status.Text = "Loading PK Failed!" + ret.ToString();
                        }));
                    }
                });
            }
            else
            {
                Invoke(new Action(() =>
                {
                    lbl_status.Text = "Loading verify key was failed" + ret.ToString();
                }));
            }

            Task.Run(() =>
            {
                const string acc_path     = "chain.acc";
                const string acc_zip_path = acc_path + ".zip";
                if (File.Exists(acc_path))
                {
                    using (FileStream fs = new FileStream(acc_path, FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        ImportBlocks(fs);
                    }
                    File.Delete(acc_path);
                }
                else if (File.Exists(acc_zip_path))
                {
                    using (FileStream fs = new FileStream(acc_zip_path, FileMode.Open, FileAccess.Read, FileShare.None))
                        using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
                            using (Stream zs = zip.GetEntry(acc_path).Open())
                            {
                                ImportBlocks(zs);
                            }
                    File.Delete(acc_zip_path);
                }

                Blockchain.PersistCompleted += Blockchain_PersistCompleted;
                Constant.LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
            });

            LoadAddrbook();
            LoadAssets();
        }