public async Task <ResponseQuery> Handle(RequestQuery query, ServerCallContext context)
        {
            var list         = new List <CallNumber>(_callNumberRepository.List().OrderBy(p => p.PhoneNumber));
            var resultString = JsonConvert.SerializeObject(list);

            return(ResponseHelper.Query.Ok(resultString.ToByteString()));
        }
示例#2
0
        public async Task <ResponseQuery> Handle(RequestQuery query, ServerCallContext context)
        {
            var party = query.Data.ToStringUtf8();

            if (string.IsNullOrWhiteSpace(party))
            {
                return(new ResponseQuery());
            }

            var openRequests = _callNumberRepository.List().Where(number => number.Owner == party && number.TransferRequestStarted.HasValue).OrderBy(p => p.PhoneNumber);
            var jsonString   = JsonConvert.SerializeObject(openRequests);

            return(ResponseHelper.Query.Ok(jsonString.ToByteString()));
        }
示例#3
0
        public async Task <ResponseCommit> Commit(RequestCommit commit, ServerCallContext context)
        {
            if (!_callNumberRepository.List().Any())
            {
                return(new ResponseCommit()
                {
                    Log = "Zero tx. Hash is empty."
                });
            }

            var allData        = _callNumberRepository.List().OrderBy(p => p.PhoneNumber).ToList();
            var serializedData = JsonConvert.SerializeObject(allData);
            var byteData       = Encoding.UTF8.GetBytes(serializedData);
            var hashBytes      = _hashCalculation.Calculate(byteData);
            var hashByteString = hashBytes.ToByteString();

            _logger.LogInformation($"Calculated hash: {hashByteString.ToStringUtf8()}");

            _blockchainMetadata.Hash = hashByteString;
            _blockchainMetadata.Height++;

            return(await Task.FromResult(new ResponseCommit { Data = hashByteString }));
        }