public List<StoredBlock> GetBlocksByHeight(int[] heights) { using (BlockchainRepository repo = new BlockchainRepository(conn)) { return repo.ReadHeadersWithHeight(heights); } }
public BlockLocator GetCurrentChainLocator() { List<StoredBlock> headers = new List<StoredBlock>(); using (BlockchainRepository repo = new BlockchainRepository(conn)) { StoredBlock lastBlock = repo.GetLastBlockHeader(); if (lastBlock != null) { headers = repo.ReadHeadersWithHeight(BlockLocator.GetRequiredBlockHeights(lastBlock.Height)); } } BlockLocator locator = new BlockLocator(); foreach (StoredBlock header in headers) { locator.AddHash(header.Height, header.Hash); } return locator; }
public StoredBlock FindBlockByHeight(int height) { using (BlockchainRepository repo = new BlockchainRepository(conn)) { //todo: rewrite this method List<StoredBlock> blocks = repo.ReadHeadersWithHeight(new int[] {height}); if (!blocks.Any()) { return null; } return blocks[0]; } }