示例#1
0
        internal static void Receive(TcpReceiveState e, PoolCommand cmd)
        {
            var msg   = new NonceDataMsg();
            int index = 0;

            msg.Deserialize(cmd.Payload, ref index);

            var miner = PoolCache.WorkingMiners.FirstOrDefault(m => m.ClientAddress == e.Address);

            if (miner == null)
            {
                RejectCommand.Send(e);
                return;
            }

            var data = POC.CalculateScoopData(miner.WalletAddress, msg.MaxNonce, miner.CheckScoopNumber);

            if (Base16.Encode(data) == Base16.Encode(msg.ScoopData))
            {
                miner.IsConnected         = true;
                miner.ConnectedTime       = Time.EpochTime;
                miner.LatestHeartbeatTime = Time.EpochTime;
                LoginCommand.SendLoginResult(e, true);
                LogHelper.Info(miner.ClientAddress + " login success");

                StartCommand.Send(e);
            }
            else
            {
                LoginCommand.SendLoginResult(e, false);
                RejectCommand.Send(e);
                LogHelper.Info(miner.ClientAddress + " login fail");
            }
        }
示例#2
0
        public static byte[] GetMiningWorkResult(BlockMsg block)
        {
            var listBytes = new List <Byte>();

            listBytes.AddRange(Base16.Decode(block.Header.PayloadHash));
            listBytes.AddRange(BitConverter.GetBytes(block.Header.Height));
            var         genHash         = Sha3Helper.Hash(listBytes.ToArray());
            var         scoopNumber     = POC.GetScoopNumber(block.Header.PayloadHash, block.Header.Height);
            var         scoopData       = POC.CalculateScoopData(block.Header.GeneratorId, block.Header.Nonce, scoopNumber);
            List <byte> targetByteLists = new List <byte>();

            targetByteLists.AddRange(scoopData);
            targetByteLists.AddRange(genHash);
            var baseTarget = Sha3Helper.Hash(targetByteLists.ToArray());

            return(baseTarget);
        }