Exemple #1
0
        public IActionResult GetMiningJob(string minerAddress)
        {
            if (string.IsNullOrWhiteSpace(minerAddress))
            {
                return(BadRequest(new Error("Invalid miner address.")));
            }

            Block     candidate = NodeService.CreateCandidateBlock(minerAddress);
            MiningJob job       = candidate.ToMiningJob();

            return(Ok(job));
        }
Exemple #2
0
 public static MiningJob ToMiningJob(this Block candidateBlock)
 {
     return(new MiningJob
     {
         BlockIndex = candidateBlock.Index,
         Difficulty = candidateBlock.Difficulty,
         ExpectedReward = candidateBlock.Transactions.Sum(t => t.Fee),
         RewardAddress = candidateBlock.MinedBy,
         TransactionsIncluded = candidateBlock.Transactions.Count,
         BlockDataHash = candidateBlock.DataHash.ToHex()
     });
 }
Exemple #3
0
        public IActionResult Get(int index)
        {
            if (index < 0)
            {
                return(BadRequest(new Error("Block index must be a non-negative integer.")));
            }

            Block block = NodeService.GetBlock(index);

            if (block == null)
            {
                return(NotFound());
            }

            return(Ok(block.ToContract()));
        }