Example #1
0
        public void Authenticate(IMiner miner)
        {
            // if username validation is not on just authenticate the miner, else ask the current storage layer to do so.
            miner.Authenticated = !_poolConfig.Miner.ValidateUsername || _storageLayer.Authenticate(miner);

            _logger.Debug(
                miner.Authenticated ? "Authenticated miner: {0:l} [{1:l}]" : "Miner authentication failed: {0:l} [{1:l}]",
                miner.Username, ((IClient)miner).Connection.RemoteEndPoint);

            if (!miner.Authenticated)
            {
                return;
            }

            if (miner is IStratumMiner) // if we are handling a stratum-miner, apply stratum specific stuff.
            {
                var stratumMiner = (IStratumMiner)miner;
                stratumMiner.SetDifficulty(_poolConfig.Stratum.Diff); // set the initial difficulty for the miner and send it.
                stratumMiner.SendMessage(_poolConfig.Meta.MOTD);      // send the motd.
            }

            miner.Account = _accountManager.GetAccountByUsername(miner.Username);     // query the user.
            if (miner.Account == null)                                                // if the user doesn't exists.
            {
                _accountManager.AddAccount(new Account(miner));                       // create a new one.
                miner.Account = _accountManager.GetAccountByUsername(miner.Username); // re-query the newly created record.
            }

            OnMinerAuthenticated(new MinerEventArgs(miner)); // notify listeners about the new authenticated miner.
        }
Example #2
0
        private void CalculatePayments()
        {
            // find total shares within the round.
            var totalShares = _shares.Sum(pair => pair.Value);

            // loop through user shares and calculate the payouts.
            foreach (var pair in _shares)
            {
                var percent = pair.Value / totalShares;
                var amount  = (decimal)percent * Block.Reward;

                // get the user id for the payment.
                var user = _accountManager.GetAccountByUsername(pair.Key);

                if (user == null)
                {
                    _accountManager.AddAccount(new Account(-1, pair.Key, pair.Key));
                    user = _accountManager.GetAccountByUsername(pair.Key);
                }

                // if we can't find a user for the given username, just skip.
                if (user == null)
                {
                    continue;
                }

                Payments.Add(new Payment(Block, user.Id, amount));
            }

            // mark the block as accounted
            Block.Accounted = true;
        }
Example #3
0
        public IActionResult UpdateAccounts([FromBody] List <AccountForm> forms)
        {
            foreach (var form in forms)
            {
                if (form.AccountId.HasValue)
                {
                    _accountManager.UpdateAccount(form.MapToCore());
                }
                else
                {
                    _accountManager.AddAccount(form.MapToCore(), form.ParentId.Value);
                }
            }

            return(Overview());
        }
Example #4
0
        public string Authenticate(IMiner miner)
        {
            var username = miner.Username;

            miner.Account = _accountManager.GetAccountByUsernameOrAddress(username); // query the user.
            if (miner.Account == null)                                               // if the user doesn't exists check the blockchain
            {
                var addressInfo = _daemonClient.ValidateAddress(miner.Username);

                // if username validation is not on just authenticate the miner, else ask the current storage layer to do so.
                if (!addressInfo.IsValid || !addressInfo.IsConfirmed)
                {
                    _logger.Debug("Miner authentication failed: {0:l} [{1:l}]", username, ((IClient)miner).Connection.RemoteEndPoint);
                    return(username);
                }

                var address = addressInfo.Address;
                username = string.IsNullOrEmpty(addressInfo.Alias) ? address : addressInfo.Alias;
                _accountManager.AddAccount(new Account(-1, username, address)); // create a new one.

                miner.Account = _accountManager.GetAccountByUsername(username); // re-query the newly created record.
            }

            miner.Authenticated = true;

            if (miner is IStratumMiner) // if we are handling a stratum-miner, apply stratum specific stuff.
            {
                var stratumMiner = (IStratumMiner)miner;
                stratumMiner.SetDifficulty(_poolConfig.Stratum.Diff); // set the initial difficulty for the miner and send it.
                stratumMiner.SendMessage(_poolConfig.Meta.MOTD);      // send the motd.
            }

            username = miner.Account.Username;

            _logger.Debug("Authenticated miner: {0:l} [{1:l}]", username, ((IClient)miner).Connection.RemoteEndPoint);

            OnMinerAuthenticated(new MinerEventArgs(miner)); // notify listeners about the new authenticated miner.

            return(username);
        }