示例#1
0
        public override Task <ResponseCommit> Commit(RequestCommit request, ServerCallContext context)
        {
            hashCount += 1;

            if (txCount == 0)
            {
                return(Task.FromResult(new ResponseCommit
                {
                    Code = CodeType.Ok
                }));
            }
            else
            {
                using (MemoryStream data = new MemoryStream())
                {
                    var bd = Encoding.UTF8.GetBytes(txCount.ToString());
                    data.Write(bd, 0, bd.Length - 1);

                    return(Task.FromResult(new ResponseCommit
                    {
                        Code = CodeType.Ok,
                        Data = ByteString.FromStream(data)
                    }));
                }
            }
        }
示例#2
0
        public virtual Task <ResponseCommit> RequestCommit(RequestCommit req)
        {
            hashCount += 1;

            if (txCount == 0)
            {
                return(Task.FromResult(new ResponseCommit
                {
                    Code = CodeType.Ok
                }));
            }
            else
            {
                using (System.IO.MemoryStream data = new System.IO.MemoryStream())
                {
                    var bd = System.Text.Encoding.UTF8.GetBytes(txCount.ToString());
                    data.Write(bd, 0, bd.Length - 1);

                    return(Task.FromResult(new ResponseCommit
                    {
                        Code = CodeType.Ok,
                        Data = Google.Protobuf.ByteString.FromStream(data)
                    }));
                }
            }
        }
示例#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 }));
        }
 public override Task <ResponseCommit> Commit(RequestCommit request, ServerCallContext context)
 {
     Console.WriteLine("Commit has been called.");
     return(_blockHandler.Commit(request, context));
 }
示例#5
0
 public override ResponseCommit Commit(RequestCommit request, CallOptions options)
 {
     return(base.Commit(request, options));
 }