public override Task <BlockResponse> LastBlock(EmptyRequest request, ServerCallContext context) { var block = Blockchain.GetLastBlock(); if (block is null) { return(Task.FromResult(new BlockResponse())); } BlockModel mdl = ConvertBlock(block); return(Task.FromResult(new BlockResponse { Block = mdl })); }
public static void BuildReport() { BuildChart(); var localBcInfo = new BcInfoResponse(); Console.WriteLine("make report"); var lastBlock = Blockchain.GetLastBlock(); var blocks = Blockchain.GetBlocks(); var amountTnxs = 0d; var numTnxs = 0L; var amountReward = 0d; var transactions = new List <Transaction>(); if (bcInfo.NumBloks == 0) { // calculate from begining foreach (var block in blocks.FindAll()) { amountTnxs += block.TotalAmount; numTnxs += block.NumOfTx; amountReward += block.TotalReward; } localBcInfo.AmountTxns = amountTnxs; localBcInfo.NumTxns = numTnxs; localBcInfo.AmountReward = amountReward; localBcInfo.NumBloks = lastBlock.Height; localBcInfo.Tps = (double)lastBlock.NumOfTx / (double)30; // add 10 txns var trans1 = Transaction.GetTransactions(1, 10); if (trans1 is not null) { foreach (Transaction txn in trans1) { TxnModel mdl = ConvertTxnModel(txn); localBcInfo.Txns.Add(mdl); } } // add 10 blocks var blocks1 = Blockchain.GetBlocks(1, 10); if (blocks1 is not null) { foreach (Block block in blocks1) { BlockModel mdl = ConvertBlockForList(block); localBcInfo.Blocks.Add(mdl); } } bcInfo = localBcInfo; Console.WriteLine("== TPS {0}", localBcInfo.Tps); return; } amountTnxs = (bcInfo.AmountTxns + lastBlock.TotalAmount); numTnxs = (bcInfo.NumTxns + lastBlock.NumOfTx); amountReward = (bcInfo.AmountReward + lastBlock.TotalReward); localBcInfo.AmountTxns = amountTnxs; localBcInfo.NumTxns = numTnxs; localBcInfo.Tps = (double)lastBlock.NumOfTx / (double)30; localBcInfo.AmountReward = amountReward; localBcInfo.NumBloks = lastBlock.Height; // add 10 txns var trans = Transaction.GetTransactions(1, 10); if (trans is not null) { foreach (Transaction txn in trans) { TxnModel mdl = ConvertTxnModel(txn); localBcInfo.Txns.Add(mdl); } } // add 10 blocks var blcks = Blockchain.GetBlocks(1, 10); if (blocks is not null) { foreach (Block block in blcks) { BlockModel mdl = ConvertBlockForList(block); localBcInfo.Blocks.Add(mdl); } } bcInfo = localBcInfo; Console.WriteLine("== TPS {0}", localBcInfo.Tps); }