Esempio n. 1
0
        internal static MinerAccount Init()
        {
            // Attempt to read the GUID from the config file
            AccountIdentityFile accountIdentityFile = new AccountIdentityFile();
            var accountIdentity = accountIdentityFile.ReadJsonFromFile();

            var accountId = accountIdentity.AccountGuid;

            // Validate if a GUID was actually read
            if (accountId == Guid.Empty)
            {
                throw new Exception("Account Identity could not be found - you need to configure this node with an account id.");
            }


            AccountWalletAPI   accountWalletAPI   = new AccountWalletAPI();
            GPUSettingsAPI     gpuSettingsAPI     = new GPUSettingsAPI();
            WorkerSettingsFile workerSettingsFile = new WorkerSettingsFile();
            var workerSettings = workerSettingsFile.ReadJsonFromFile();

            return(new MinerAccount()
            {
                AccountId = accountId.ToString(),
                AccountWalletList = accountWalletAPI.GetAccountWalletList(accountId.ToString()),
                WorkerSettings = workerSettings,
                GPUSettingsList = gpuSettingsAPI.GetGPUSettings(accountId.ToString(), workerSettings.WorkerName)
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Load previous GUID from config file or get a new GUID from the API
        /// </summary>
        private void InitAccountID()
        {
            try
            {
                // Empty GUID used for validation
                Guid guidEmpty = new Guid();

                // Attempt to read the GUID from the config file
                AccountIdentityFile accountIdentityFile = new AccountIdentityFile();
                AccountIdentity = accountIdentityFile.ReadJsonFromFile();

                // Validate if a GUID was actually read
                if (AccountIdentity.AccountGuid == guidEmpty)
                {
                    try
                    {
                        // If no GUID found, then get a new GUID from the API
                        AccountIdentityAPI accountIdentityAPI = new AccountIdentityAPI();
                        AccountIdentity = accountIdentityAPI.GetAccountID();

                        // Notify UI to update
                        OnPropertyChanged("AccountGuid");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("There was an error retrieving a new account id from the web. Please create a new one manually by selecting 'new account' before mining.");
                    }
                    // Write GUID to account identity config file
                    accountIdentityFile.WriteJsonToFile(AccountIdentity);

                    // Insert new worker for account
                    InsertAccountWorkers();
                }

                // Set global variable for Account ID
                Application.Current.Properties["AccountID"] = AccountIdentity.AccountGuid;
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Error initializing account id"), e);
            }
        }