Exemplo n.º 1
0
        public async Task <IBlockModel> GetBlock(string blockId)
        {
            var key = blockId;

            if (!_memoryCache.TryGetValue(key, out IBlockModel block))
            {
                block = _mapper.Map <BlockModel>(await _blockService.GetBlock(blockId));
                CacheItemKeys.Keys.Add(key);
                _memoryCache.Set(key, block);
            }

            return(block);
        }
Exemplo n.º 2
0
        public IActionResult Add(string blockId)
        {
            try
            {
                string funcId = string.Empty;
                if (!IsAddPermission(blockId, out funcId))
                {
                    return(ToPermission(funcId));
                }

                if (string.IsNullOrWhiteSpace(blockId))
                {
                    return(View(new Info_Block()));
                }
                var entity = BlockService.GetBlock(SystemID, CompanyID, blockId);
                if (entity == null)
                {
                    return(View(new Info_Block()));
                }
                return(View(entity));
            }
            catch (Exception ex)
            {
                return(ToError(ex.Message));
            }
        }
Exemplo n.º 3
0
        public IActionResult GetBlock(string uuid)
        {
            long logId = 0;

            try
            {
                logId = BaseApiManager.SaveLogs(uuid);
                if (!IsUuid(uuid))
                {
                    return(Error(logId, "verify uuid fail!"));
                }
                var    entityInterfaceAccount = GetInterfaceAccountByUuid(uuid);
                string companyId = entityInterfaceAccount.CompanyID;
                string state     = "true";
                string tags      = Accessor.HttpContext.Request.GetQueryString("tags");
                var    entity    = BlockService.GetBlock(SystemID, companyId, tags, state);
                if (entity == null)
                {
                    return(Error(logId, "tags invalid!"));
                }
                var data = new
                {
                    id      = entity.BlockID,
                    title   = entity.Title,
                    tags    = entity.Tags,
                    content = entity.Content,
                    date    = entity.CreateDate
                };
                return(Success(logId, "ok", data));
            }
            catch (Exception ex)
            {
                return(Error(logId, ex.Message));
            }
        }
Exemplo n.º 4
0
        public async Task <EntitySearchResult> SearchEntityById(string id)
        {
            try
            {
                var block = await _blockService.GetBlock(id);

                if (block != null)
                {
                    return(EntitySearchResult.Block);
                }

                var transaction = await _transactionService.GetTransaction(id);

                if (transaction != null)
                {
                    return(EntitySearchResult.Transaction);
                }

                var address = await _addressService.GetAddress(id);

                if (address != null)
                {
                    return(EntitySearchResult.Address);
                }
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
            }

            return(EntitySearchResult.NotFound);
        }
Exemplo n.º 5
0
        public async Task <SearchResult> Search(string id)
        {
            var block = await _blockService.GetBlock(id);

            if (block != null)
            {
                return(SearchResult.Block);
            }

            var transaction = await _transactionService.GetTransaction(id);

            if (transaction != null)
            {
                return(SearchResult.Transaction);
            }

            var address = await _addressService.GetAddress(id);

            if (address != null)
            {
                return(SearchResult.Address);
            }

            return(SearchResult.NotFound);
        }
Exemplo n.º 6
0
        public async Task CheckIncomingTransactions()
        {
            var lastBlockId = await wallet.GetLastBlockId();

            int lastBlockHeight = 0;

            try
            {
                var block = await blockService.GetBlock(BlockLocator.ByBlockId(lastBlockId));

                lastBlockHeight = block.Height;
                Console.WriteLine($"Last known block id {lastBlockId} is on height {lastBlockHeight}");
            }
            catch (NxtException e)
            {
                if (e.Message == "Unknown block")
                {
                    Console.WriteLine($"Fork detected, unable to find block with id: {lastBlockId}. Manual rollback is needed!");
                    Environment.Exit(-1);
                }
                else
                {
                    throw;
                }
            }

            var blockchainStatus = await serverInfoService.GetBlockchainStatus();

            var currentBlockHeight = blockchainStatus.NumberOfBlocks - 1;
            var blocksToProcess    = Math.Max(0, currentBlockHeight - lastBlockHeight - confirmations);

            Console.WriteLine($"Current block height is: {currentBlockHeight} ({blocksToProcess} block(s) to process)");
            var depositAccounts = await wallet.GetAllDepositAccounts();

            var depositAddresses = new HashSet <string>(depositAccounts.Select(a => a.Address));

            while (currentBlockHeight > lastBlockHeight + confirmations)
            {
                lastBlockHeight++;
                Console.WriteLine($"Processing block @ height {lastBlockHeight}");

                var block = await blockService.GetBlockIncludeTransactions(BlockLocator.ByHeight(lastBlockHeight), true);

                var nxtTransactions = block.Transactions.Where(t => depositAddresses.Contains(t.RecipientRs) && !t.Phased)
                                      .Union(block.ExecutedPhasedTransactions.Where(t => depositAddresses.Contains(t.RecipientRs)))
                                      .Where(t => t.Amount.Nqt > 0);

                foreach (var transaction in nxtTransactions)
                {
                    Console.WriteLine($"Incoming {transaction.Amount.Nxt} NXT to {transaction.RecipientRs}");
                    var account = depositAccounts.Single(d => d.Address == transaction.RecipientRs);
                    account.BalanceNqt += transaction.Amount.Nqt;
                    await wallet.UpdateAccountBalance(account.Id, account.BalanceNqt);
                }
                await wallet.UpdateLastBlockId(block.BlockId);
            }
        }
Exemplo n.º 7
0
        public async Task <BlockchainStatus> GetBlockchainStatus()
        {
            var status = new BlockchainStatus();

            var blockchainStatusReply = await _serverInfoService.GetBlockchainStatus();

            var lastBlock = await _blockService.GetBlock(BlockLocator.ByBlockId(blockchainStatusReply.LastBlockId));

            var confirmedBlock = await _blockService.GetBlock(BlockLocator.ByHeight(blockchainStatusReply.NumberOfBlocks - 11));

            var secureBlock = await _blockService.GetBlock(BlockLocator.ByHeight(blockchainStatusReply.NumberOfBlocks - 721));

            status.LastKnownBlockId        = blockchainStatusReply.LastBlockId.ToSigned();
            status.LastKnownBlockTimestamp = lastBlock.Timestamp;

            status.LastConfirmedBlockId        = confirmedBlock.BlockId.ToSigned();
            status.LastConfirmedBlockTimestamp = confirmedBlock.Timestamp;

            status.LastSecureBlockId        = secureBlock.BlockId.ToSigned();
            status.LastSecureBlockTimestamp = secureBlock.Timestamp;

            return(status);
        }
Exemplo n.º 8
0
        private List <TimeSpan> GetBlockTimespans(int startHeight, int stopHeight, IBlockService service)
        {
            var previousTimestamp = DateTime.MinValue;
            var timeSpans         = new List <TimeSpan>();

            for (var i = startHeight; i <= stopHeight; i++)
            {
                var block = service.GetBlock(BlockLocator.ByHeight(i)).Result;
                if (i != startHeight)
                {
                    timeSpans.Add(block.Timestamp.Subtract(previousTimestamp));
                }
                previousTimestamp = block.Timestamp;
            }
            return(timeSpans);
        }
Exemplo n.º 9
0
        public async Task <EntitySearchResult> SearchEntityById(string id)
        {
            try
            {
                id = id.Trim();

                int blockHeight;
                if (int.TryParse(id, out blockHeight) || id.Length == 64)
                {
                    Core.Domain.Block block = await _blockService.GetBlock(id);

                    if (block != null)
                    {
                        return(EntitySearchResult.Block);
                    }
                }

                if (id.Length == 64)
                {
                    var transaction = await _transactionService.GetTransaction(id);

                    if (transaction != null)
                    {
                        return(EntitySearchResult.Transaction);
                    }
                }

                if (id.Length == 34 || id.Equals("OP_RETURN", StringComparison.OrdinalIgnoreCase))
                {
                    var address = await _addressService.GetAddress(id);

                    if (address != null)
                    {
                        return(EntitySearchResult.Address);
                    }
                }
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
            }

            return(EntitySearchResult.NotFound);
        }
        public async Task <Stream> GetTransactionsReport(string blockId)
        {
            var getBlock = _blockService.GetBlock(BlockFeature.Parse(blockId));
            var getAssetDefDictionary = _assetDefinitionService.GetAssetDefinitionsAsync();

            await Task.WhenAll(getBlock, getAssetDefDictionary);

            if (getBlock.Result == null)
            {
                throw new Exception($"Block {blockId} not found");
            }

            var transactionIds = getBlock.Result.Block.Transactions.Select(p => p.GetHash());

            var txResps = await _transactionService.GetTransactions(transactionIds);

            var xlsxData = XlsxTransactionsReportData.Create(
                txResps,
                getAssetDefDictionary.Result,
                _network);

            return(await _transactionXlsxRenderer.RenderTransactionReport(xlsxData));
        }
Exemplo n.º 11
0
        public async Task <ActionResult> ChangeBookingAsync([FromBody] BookingCM model)
        {
            if (CanBook(model.CustomerId))
            {
                return(Ok(false));
            }
            try
            {
                var customer = _customerService.GetCustomer(model.CustomerId);
                if (customer != null)
                {
                    string currentUserName = (await _userManager.GetUserAsync(User)).UserName;

                    //BlockId da duoc check isFull va time lon hon time hien tai
                    var tickets = _ticketService.GetTickets(t => t.BlockId == model.BlockId).ToList();

                    List <Ticket> newTickets = new List <Ticket>();
                    //Check xem Khach hang này đã đặt trong block nay chưa
                    foreach (var item in tickets)
                    {
                        if (item.CustomerId == null)
                        {
                            newTickets.Add(item);
                        }
                        else if (item.CustomerId.Equals(model.CustomerId.ToString()))
                        {
                            return(Ok(false));
                        }
                    }

                    if (newTickets.Count != 0)
                    {
                        //Xoa customer tu Ticket cu va check xem isFull=true thi set isFull = false
                        var currentTicket = _ticketService.GetTickets(t => t.CustomerId == model.CustomerId.ToString() &&
                                                                      t.Block.Date.Date >= DateTime.Now.Date &&
                                                                      t.Status == 0).FirstOrDefault();
                        currentTicket.CustomerId = null;
                        currentTicket.Note       = null;
                        if (currentTicket.Block.IsFull)
                        {
                            currentTicket.Block.IsFull = false;
                        }
                        _ticketService.UpdateTicket(currentTicket, currentUserName);

                        //Gan customer vao ticket va check xem neu con 1 ticket thi set block isFull = true
                        newTickets[0].CustomerId  = model.CustomerId.ToString();
                        newTickets[0].BookingDate = DateTime.Now;
                        newTickets[0].Note        = model.Note;
                        _ticketService.UpdateTicket(newTickets[0], currentUserName);
                        if (newTickets.Count == 1) // Chỉ còn 1 ticket thì update isFull
                        {
                            var block = _blockService.GetBlock(model.BlockId);
                            block.IsFull = true;
                            _blockService.UpdateBlock(block, currentUserName);
                        }
                        _blockService.Save();
                        return(Ok(true));
                    }
                    else
                    {
                        return(Ok(false));
                    }
                }
                else
                {
                    return(BadRequest("Customer does not existed!"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
 public Task <string> GetBlock(string hash)
 {
     return(_blockService.GetBlock(hash));
 }
Exemplo n.º 13
0
        public ActionResult ViewBlock(int id)
        {
            var block = _blockService.GetBlock(id);

            return(PartialView(block));
        }
Exemplo n.º 14
0
 public async Task <Response> Get([FromQuery] GetBlockViewModel model)
 {
     return(await _blockService.GetBlock(model));
 }