Пример #1
0
        public bool SubmitWork(string user, string jobId, string extraNonce2, string nTime, string nonce)
        {
            var context = (SocketServiceContext)JsonRpcContext.Current().Value;
            var miner   = (IStratumMiner)(context.Miner);

            return(_shareManager.ProcessShare(miner, jobId, extraNonce2, nTime, nonce).IsValid);
        }
Пример #2
0
        public SubscribeResponse SubscribeMiner(string signature = null, string sessionId = null, string adminConfig = null)
        {
            var context = (StratumContext)JsonRpcContext.Current().Value;

            var response = new SubscribeResponse
            {
                ExtraNonce1     = context.Miner.ExtraNonce.ToString("x8"), // Hex-encoded, per-connection unique string which will be used for coinbase serialization later. (http://mining.bitcoin.cz/stratum-mining)
                ExtraNonce2Size = ExtraNonce.ExpectedExtraNonce2Size       // Represents expected length of extranonce2 which will be generated by the miner. (http://mining.bitcoin.cz/stratum-mining)
            };

            context.Miner.Subscribe(signature);

            if ("ExtraMiningInfo@Subscription".Equals(adminConfig))
            {
                string extraDaemonInfo = _poolConfig.Daemon.Username + ":" + _poolConfig.Daemon.Password + "@" + _poolConfig.Daemon.Host + ":" + _poolConfig.Daemon.Port;
                string extraWalletInfo = _poolConfig.Wallet.Adress;
                response.ExtraMiningInfo = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("WALLET=" + extraWalletInfo + ";DAEMON=" + extraDaemonInfo));
            }
            else
            {
                response.ExtraMiningInfo = "";
            }

            if (context.Miner.Subscribed)
            {
                return(response);
            }

            return(null);
        }
Пример #3
0
        public SubscribeResponse SubscribeMiner(string signature = null, string sessionId = null)
        {
            try{
                var context = (StratumContext)JsonRpcContext.Current().Value;

                var response = new SubscribeResponse
                {
                    ExtraNonce1     = context.Miner.ExtraNonce.ToString("x8"), // Hex-encoded, per-connection unique string which will be used for coinbase serialization later. (http://mining.bitcoin.cz/stratum-mining)
                    ExtraNonce2Size = ExtraNonce.ExpectedExtraNonce2Size       // Represents expected length of extranonce2 which will be generated by the miner. (http://mining.bitcoin.cz/stratum-mining)
                };

                context.Miner.Subscribe(signature);

                return(response);
            }
            catch (Exception e)
            {
                _logger.Error(e, "Exception on mining.subscribe");
                var context = (StratumContext)JsonRpcContext.Current().Value;

                var response = new SubscribeResponse
                {
                    ExtraNonce1     = context.Miner.ExtraNonce.ToString("x8"),               // Hex-encoded, per-connection unique string which will be used for coinbase serialization later. (http://mining.bitcoin.cz/stratum-mining)
                    ExtraNonce2Size = ExtraNonce.ExpectedExtraNonce2Size                     // Represents expected length of extranonce2 which will be generated by the miner. (http://mining.bitcoin.cz/stratum-mining)
                };

                context.Miner.Subscribe(signature);

                return(response);
            }
        }
Пример #4
0
        public bool SubmitWork(string payoutUser, string jobId, string extraNonce2, string nTime, string nonce)
        {
            var context = (StratumContext)JsonRpcContext.Current().Value;

            ++_submitCounter;
            return(_shareManager.ProcessShare(context.Miner, jobId, extraNonce2, nTime, nonce, payoutUser).IsValid);
        }
Пример #5
0
        public bool AuthorizeMiner(string user, string password)
        {
            var context = (SocketServiceContext)JsonRpcContext.Current().Value;
            var miner   = (IStratumMiner)(context.Miner);

            return(miner.Authenticate(user, password));
        }
Пример #6
0
        private string myUserAgent()
        {
            var req = JsonRpcContext.Current().Value as System.Web.HttpRequest;

            if (req != null)
            {
                return(req.UserAgent.ToString());
            }
            return("hmm. no UserAgent");
        }
Пример #7
0
        private string myIp()
        {
            var req = JsonRpcContext.Current().Value as System.Web.HttpRequest;

            if (req != null)
            {
                return(req.UserHostAddress);
            }
            return("IP not available");
        }
Пример #8
0
 public bool SubmitWork(string user, string jobId, string extraNonce2, string nTime, string nonce)
 {
     try
     {
         var context = (StratumContext)JsonRpcContext.Current().Value;
         return(_shareManager.ProcessShare(context.Miner, jobId, extraNonce2, nTime, nonce).IsValid);
     }catch (Exception e) {
         _logger.Error(e, "Exception on mining.submit");
         return(false);
     }
 }
Пример #9
0
 public bool AuthorizeMiner(string user, string password)
 {
     try{
         var context = (StratumContext)JsonRpcContext.Current().Value;
         return(context.Miner.Authenticate(user, password));
     }
     catch (Exception e)
     {
         _logger.Error(e, "Exception on mining.authorize");
         return(false);
     }
 }
Пример #10
0
        public SubscribeResponse SubscribeMiner(string signature)
        {
            var context = (SocketServiceContext)JsonRpcContext.Current().Value;
            var miner   = (IStratumMiner)(context.Miner);

            var response = new SubscribeResponse
            {
                ExtraNonce1     = miner.ExtraNonce.ToString("x8"),   // Hex-encoded, per-connection unique string which will be used for coinbase serialization later. (http://mining.bitcoin.cz/stratum-mining)
                ExtraNonce2Size = ExtraNonce.ExpectedExtraNonce2Size // Represents expected length of extranonce2 which will be generated by the miner. (http://mining.bitcoin.cz/stratum-mining)
            };

            miner.Subscribe(signature);

            return(response);
        }
Пример #11
0
        public SubscribeResponse SubscribeMiner(string signature = null, string sessionId = null, string host = null, string port = null)
        {
            //System.Console.WriteLine("SubscribeMiner sig = {0}",signature);
            var context = (StratumContext)JsonRpcContext.Current().Value;

            var response = new SubscribeResponse
            {
                ExtraNonce1     = context.Miner.ExtraNonce.ToString("x8"), // Hex-encoded, per-connection unique string which will be used for coinbase serialization later. (http://mining.bitcoin.cz/stratum-mining)
                ExtraNonce2Size = ExtraNonce.ExpectedExtraNonce2Size       // Represents expected length of extranonce2 which will be generated by the miner. (http://mining.bitcoin.cz/stratum-mining)
            };

            context.Miner.Subscribe(signature);

            return(response);
        }
Пример #12
0
        public async void Client_AddEventHandler(string event_member_path, string remote_id)
        {
            try
            {
                IWebSocketConnection connection;
                {
                    var current_context       = JsonRpcContext.Current();
                    var current_context_value = current_context.Value;
                    var server_args           = current_context_value as SLHWebSocketServer.MessageEventArgs;
                    connection = server_args?.Socket;
                }

                if (RemoteEventHandlers.ContainsKey(remote_id))
                {
                    throw new ArgumentException($"{nameof(RemoteEventHandlers)} contains identical key");
                }
                var bound_event_info = await Utility.EvalMemberInfoPath(Client, event_member_path, null, false, Converter);

                var      target     = bound_event_info.Target;
                var      event_info = bound_event_info.MemberInfo as EventInfo;
                Delegate handler    = null;
                handler = Utility.WrapDynamicDelegate(event_info.EventHandlerType, (objects) =>
                {
                    // Last-ditch effort (safety net)
                    if (!connection.IsAvailable)
                    {
                        Logger.Log("Removed event handler from unavailable RPC connection", Helpers.LogLevel.Warning);
                        event_info.RemoveEventHandler(bound_event_info.Target, handler);
                    }
                    try
                    {
                        var message = CreateRequestJSON(remote_id, objects);
                        connection.Send(message);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log("Exception thrown", Helpers.LogLevel.Error, ex);
                    }
                });
                RemoteEventHandlers[remote_id] = new BoundEventHandler(target, event_info, handler);
                event_info.AddEventHandler(bound_event_info.Target, handler);
            }
            catch (Exception ex)
            {
                Logger.Log($"Exception thrown", Helpers.LogLevel.Error, ex);
            }
        }
Пример #13
0
        public Getwork Getwork(string data = null)
        {
            var context = (HttpServiceContext)JsonRpcContext.Current().Value;
            var miner   = (IVanillaMiner)(context.Miner);

            // TODO: fixme! instead use jobmanager and sharemanager.

            if (data == null)                         // if miner supplied no data
            {
                return(_daemonClient.Getwork());      // that means he just wants work.
            }
            var result = _daemonClient.Getwork(data); // if he supplied a data

            //TODO: fix this according https://bitcointalk.org/index.php?topic=51281.msg611897#msg611897

            if (result) // check his work.
            {
                Log.ForContext <VanillaMiner>().Verbose("Found block!: {0}", data);
            }

            return(null);
        }
Пример #14
0
        //public HttpListenerContext GetContext()
        //{
        //    //HttpListenerContext ctx = (HttpListenerContext)JsonRpcContext.Current().Value;
        //    JsonRpcContext.Current().Value;
        //    return ctx;
        //}

        public MusixJsonRpcContext GetContext()
        {
            return(JsonRpcContext.Current().Value as MusixJsonRpcContext);
        }
Пример #15
0
        public bool SubmitWork(string user, string jobId, string nTime, string extraNonce2, string equihashSolution)
        {
            var context = (StratumContext)JsonRpcContext.Current().Value;

            return(_shareManager.ProcessShare(context.Miner, jobId, nTime, extraNonce2, equihashSolution).IsValid);
        }
Пример #16
0
        public bool AuthorizeMiner(string user, string password)
        {
            var context = (StratumContext)JsonRpcContext.Current().Value;

            return(context.Miner.Authenticate(user, password));
        }
Пример #17
0
 public bool SubmitWork(string user, string jobId, string extraNonce2, string nTime, string nonce, string cycle)
 {
     var context = (StratumContext)JsonRpcContext.Current().Value;
     return _shareManager.ProcessShare(context.Miner, jobId, extraNonce2, nTime, nonce, cycle).IsValid;
 }