예제 #1
0
        public static Block FindNewBlock(IPersistenceActorRef persistenceActorRef)
        {
            var blocks = persistenceActorRef.GetActorRef()
                         .Ask <ReadOnlyCollection <Block> >(
                new Persistence.GetBlocks(),
                TimeSpan.FromSeconds(5)).Result;
            var    previousBlock = blocks.Last();
            string hash          = SHA256Encoder.EncodeString(previousBlock.toJson());

            var transactions = persistenceActorRef.GetActorRef()
                               .Ask <ReadOnlyCollection <Transaction> >(
                new Persistence.GetUnconfirmedTransactions(),
                TimeSpan.FromSeconds(5)).Result
                               .Take(5);
            var candidate = new Block(previousBlock.Index + 1, DateTime.Now.ToUnixTimestamp(), 0, transactions, hash);


            string candidateHash = SHA256Encoder.EncodeString(candidate.toJson());


            while (!candidateHash.StartsWith("0000", StringComparison.Ordinal))
            {
                candidate.IncrementProof();
                candidateHash = SHA256Encoder.EncodeString(candidate.toJson());
            }

            return(candidate);
        }
예제 #2
0
        public Task ExecuteResultAsync(ActionContext pContext)
        {
            var stream = pContext.HttpContext.Response.Body;

            pContext.HttpContext.Response.GetTypedHeaders().ContentType = new Microsoft.Net.Http.Headers.MediaTypeHeaderValue(_contentType);

            return(_connectionHolderActorRef.GetActorRef()
                   .Ask(new ConnectionHolder.NewConnection(
                            stream, pContext.HttpContext.RequestAborted,
                            _persistence.GetActorRef())));
        }
        public IActionResult NodeInfo()
        {
            var nodeInfo = new NodeInfo
            {
                NodeId = _nodeId,

                CurrentBlockHeight =
                    _persistenceActorRef
                    .GetActorRef()
                    .Ask <ReadOnlyCollection <Block> >(
                        new Persistence.GetBlocks(),
                        TimeSpan.FromSeconds(5)).Result.Last().Index
            };

            return(Content(JsonConvert.SerializeObject(nodeInfo), "application/json", Encoding.UTF8));
        }