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)); }
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() }); }
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())); }