Exemplo n.º 1
0
        public async Task<IActionResult> mine()
        {
            try
            {
                return StatusCode(StatusCodes.Status405MethodNotAllowed);
                using var reader = new StreamReader(Request.Body);
                var parsed_body = JsonConvert.DeserializeObject<dynamic>(await reader.ReadToEndAsync());

                var data = parsed_body.data;

                _IBlockChain.AddBlock(data);
                await _IRedis.BroadcastChain();
                return Redirect("/api/blocks");
            }
            catch (Exception ex)
            {
                _ILogger.LogError(ex, $"~/api/mine requested from {HttpContext.GetIP()}. Payload : { HttpContext.Request.Body}");

                if (IsDebugging)
                    return StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse { message = ex.Message, data = ex.ToReleventInfo() });
                else
                    return StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse { message = ex.Message });
            }

        }
Exemplo n.º 2
0
        public async Task MineTransaction()
        {
            //ToDo
            //get transaction pool's valid transactions
            //generate the miner reward
            //add a block consisting of these transactions to the blockchain
            //broadcast the updated  blockchain
            //clear the pool

            var validTransactions = _ITransactionPool.ValidTransactions();
            var minerReward       = Transaction.RewardTransaction(this._IWallet);

            validTransactions.Add(minerReward);
            _IBlockChain.AddBlock(validTransactions);
            await _IRedis.BroadcastChain();

            _ITransactionPool.ClearBlockchainTransaction(_IBlockChain.LocalChain);
        }