Ejemplo n.º 1
0
        /*
         * Mining Thread
         */
        private async void MinerThread()
        {
            MinerUtils minUtils = new MinerUtils();
            await Task.Run(() =>
            {
                while (true)
                {
                    //always update client list
                    RestRequest req    = new RestRequest("api/Client/ip/" + encodeClient.ip + "/port/" + encodeClient.port + "/GetPeers");
                    IRestResponse resp = webPool.Get(req);
                    this.clientList    = JsonConvert.DeserializeObject <List <ClientDataStruct> >(resp.Content);

                    //perform operations
                    BroadcastTransaction();
                    DoMining(minUtils);
                    SynchroniseChain();
                    GetResults();
                }
            });
        }
Ejemplo n.º 2
0
        /*
         * creating blocks
         */
        private void DoMining(MinerUtils minUtils)
        {
            string recvTransaction = ourRemoteThread.ReceiveTransaction(null);

            if (!string.IsNullOrEmpty(recvTransaction))
            {
                //insert transaction details
                APIClass.Block newBlock = new APIClass.Block();
                newBlock.ID          = ourBlockchain.Last().ID + 1;
                newBlock.JsonStrList = DoPython(recvTransaction);
                newBlock.Hash        = "";

                newBlock.PrevHash = ourRemoteThread.GetLatestBlock().Hash;

                newBlock = minUtils.GenerateHash(newBlock);    //create valid hash and add it to new block

                ourRemoteThread.AddBlock(newBlock);
                ourBlockchain = ourRemoteThread.GetCurrentChain();
            }
        }