예제 #1
0
        public List <BlockApiModel> GetAllBlocks()
        {
            List <Block>         blocks = Node.BlockChain.Values.OrderByDescending(b => b.Index).ToList();
            List <BlockApiModel> result = blocks.Select(b => BlockApiModel.FromBlock(b)).ToList();

            return(result);
        }
예제 #2
0
        public BlockApiModel Get(int index)
        {
            bool success = Node.BlockChain.TryGetValue(index, out Block result);

            if (success)
            {
                return(BlockApiModel.FromBlock(result));
            }

            return(null);
        }
예제 #3
0
        public List <BlockApiModel> GetLastBlocks(int count)
        {
            int startFrom = Node.BlockChain.Count - count;

            if (startFrom < 0)
            {
                startFrom = 0;
            }

            List <Block>         blocks = Node.BlockChain.Values.OrderByDescending(b => b.Index).Take(count).ToList();
            List <BlockApiModel> result = blocks.Select(b => BlockApiModel.FromBlock(b)).ToList();

            return(result);
        }
예제 #4
0
        public List <BlockApiModel> GetBlocks(int fromIndex, int count)
        {
            int endIndex = fromIndex + count;

            if (endIndex > Node.BlockChain.Count)
            {
                endIndex = Node.BlockChain.Count - 1;
            }

            List <BlockApiModel> result = new List <BlockApiModel>();

            for (int i = fromIndex; i <= endIndex; i++)
            {
                result.Add(BlockApiModel.FromBlock(Node.BlockChain[i]));
            }

            result = result.OrderByDescending(b => b.Index).ToList();

            return(result);
        }