Esempio n. 1
0
        public IRpcMethodResult GetBlockDataList(int skipCount, int takeCount)
        {
            try
            {
                List <BlockInfo> result = new List <BlockInfo>();
                var lastblock           = BlockDac.Default.SelectLast();
                if (lastblock == null)
                {
                    return(Ok(result));
                }

                BlockComponent component   = new BlockComponent();
                long           startHeight = lastblock.Header.Height - skipCount;
                long           height      = startHeight;
                for (long count = 1; count <= takeCount; count++)
                {
                    if (height < 0)
                    {
                        break;
                    }
                    var block = component.GetBlockInfo(height);
                    if (block != null)
                    {
                        result.Add(block);
                    }
                    height--;
                }

                //for (int i = skipCount; i < takeCount; i++)
                //{
                //    var height = lastblock.Header.Height - i;
                //    if (height < 0)
                //        break;
                //    var block = component.GetBlockInfo(height);
                //    if (block != null)
                //        result.Add(block);
                //}
                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
Esempio n. 2
0
        public IRpcMethodResult GetLatestBlock()
        {
            try
            {
                List <BlockInfo> result = new List <BlockInfo>();
                var lastblock           = BlockDac.Default.SelectLast();
                if (lastblock == null)
                {
                    return(Ok(result));
                }

                BlockComponent component = new BlockComponent();

                for (int i = 0; i < 5; i++)
                {
                    var height = lastblock.Header.Height - i;
                    if (height < 0)
                    {
                        break;
                    }
                    var block = component.GetBlockInfo(height);
                    if (block != null)
                    {
                        result.Add(block);
                    }
                }
                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }