Пример #1
0
 public static MinedBlock ToDomainModel(
     this MinedBlockContract block,
     string minerAddress)
 {
     return(new MinedBlock
     {
         MinerAddress = minerAddress,
         BlockDataHash = block.BlockDataHash,
         DateCreated = DateTime.Parse(block.DateCreated).ToUniversalTime(),
         Nonce = ulong.Parse(block.Nonce),
         BlockHash = block.BlockHash
     });
 }
Пример #2
0
        public IActionResult SubmitMinedBlock(string minerAddress, [FromBody] MinedBlockContract block)
        {
            MinedBlock minedBlock = block.ToDomainModel(minerAddress);

            BlockValidationResult validationResult = NodeService.TryAddBlock(
                minedBlock,
                out Block candidateBlock);

            if (validationResult != BlockValidationResult.Ok)
            {
                return(BadRequest(new Error(validationResult.GetEnumDescription())));
            }

            return(CreatedAtRoute(
                       "GetBlock", new
            {
                controller = "Blocks",
                index = candidateBlock.Index
            },
                       candidateBlock.ToContract()));
        }