Example #1
0
        public void LoadEveryNewBlock()
        {
            var chainPath = $"{Configurations.CurrentPath}\\BlockChain\\Chain\\";
            var blocks    = Directory.GetFiles(chainPath);

            foreach (var block in blocks)
            {
                var pathTokens = block.Split('\\');
                var id         = pathTokens[pathTokens.Length - 1].Split('.')[0];
                var bb         = _blockChainService.LookUpBlock(id);

                if (!IsLoadedIn(bb.Body.Id))
                {
                    _logger.Log($"Backloaded :{bb.Body.Id}-block");
                    LoadBlockToUnspentDb(bb);
                }
            }
        }
Example #2
0
        public bool GetTransactionMessage(WebServer server, HttpListenerContext context, string id)
        {
            try
            {
                Console.WriteLine("[HTTPInfo]Got asked to Transaction message {0}", id);
                var vout = _transactionVerifier.GetUnspeTransactionVOut(id, out bool spent);
                if (vout == null)
                {
                    return(context.JsonResponse(new { message = "" }));
                }

                var block = _blockChainService.LookUpBlock(vout.FromBlock);
                var tt    = block.Body.Tx.FindAll(r => r.Body.VOuts.FindAll(l => l.Id == id).Count > 0)[0];
                return(context.JsonResponse(new { message = tt.Body.Message }));
            }
            catch (Exception ex)
            {
                return(HandleError(context, ex, (int)HttpStatusCode.InternalServerError));
            }
        }
Example #3
0
        private void LoadDataInOrder()
        {
            _logger.Log("Caught up ! Starting ..");
            var files = Directory.GetFiles(_catchDataFullPath);

            foreach (var file in files)
            {
                var tokens = file.Split('\\');
                var name   = tokens[tokens.Length - 1];
                _logger.Log("Copied new block from catch : " + name);
                File.Copy(file, $"{Configurations.CurrentPath}\\BlockChain\\Chain\\{name}");
                File.Delete(file);
            }
            //process blocks in order
            var order = bufferedBlockInfos.OrderBy(r => r.Height).ToList();

            foreach (var blockInfo in order)
            {
                var bb = _blockChainService.LookUpBlock(blockInfo.Id);
                _eventManager.PassNewTrigger(bb, EventTypes.EventType.NewBlock);
            }
            _blockChainService.TryLoadSavedInfo();
            _minerService.TryRestartingWorkers();
        }