public override Task <BlockResponse> GetBlockByHeight(CommonRequest request, ServerCallContext context) { var block = Blockchain.GetBlockByHeight(request.BlockHeight); if (block is null) { return(Task.FromResult(new BlockResponse())); } BlockModel mdl = ConvertBlock(block); return(Task.FromResult(new BlockResponse { Block = mdl })); }
public override Task <SearchResponse> Search(CommonRequest request, ServerCallContext context) { var searchText = request.SearchText.Trim(); var response = new SearchResponse { Id = 0, Title = "no data found", SarchText = searchText, Url = "/notfound", Status = "no" }; //search block by hash try { var block = Blockchain.GetBlockByHash(searchText); if (block is not null && block.Hash is not null) { response = new SearchResponse { Id = 1, Title = "search found block by hash", SarchText = searchText, Url = "/block/hash/" + searchText, Status = "ok" }; return(Task.FromResult(response)); } } catch { Console.WriteLine("no block by hash"); } // search block by height try { var height = int.Parse(searchText); var block = Blockchain.GetBlockByHeight(height); if (block is not null && block.Hash is not null) { response = new SearchResponse { Id = 2, Title = "search found block by height", SarchText = searchText, Url = "/block/height/" + searchText, Status = "ok" }; return(Task.FromResult(response)); } } catch { Console.WriteLine("no block by height"); } //search tnxs by hash try { var txn = Transaction.GetTxnByHash(searchText); if (txn is not null && txn.Hash is not null) { response = new SearchResponse { Id = 3, Title = "Found transaction", SarchText = searchText, Url = "/txn/" + searchText, Status = "ok" }; return(Task.FromResult(response)); } } catch { Console.WriteLine("no txn by hash"); } // get Account try { // 1. get one transaction by address var txn = Transaction.GetOneTxnByAddress(searchText); if (txn is not null && txn.Hash is not null) { response = new SearchResponse { Id = 4, Title = "search found one address ", SarchText = searchText, Url = "/address/" + searchText, Status = "ok" }; return(Task.FromResult(response)); } } catch { Console.WriteLine("Error when search by account"); } return(Task.FromResult(response)); }