コード例 #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);
        }