async def get_block_generator(self, block: Union[(FullBlock, UnfinishedBlock)], additional_blocks=None) -> Optional[BlockGenerator]:
    if (additional_blocks is None):
        additional_blocks = {}
    ref_list = block.transactions_generator_ref_list
    if (block.transactions_generator is None):
        assert (len(ref_list) == 0)
        return None
    if (len(ref_list) == 0):
        return BlockGenerator(block.transactions_generator, [])
    result: List[GeneratorArg] = []
    previous_block_hash = block.prev_header_hash
    if (self.try_block_record(previous_block_hash) and (self.height_to_hash(self.block_record(previous_block_hash).height) == previous_block_hash)):
        for ref_height in block.transactions_generator_ref_list:
            header_hash = self.height_to_hash(ref_height)
            ref_block = (await self.get_full_block(header_hash))
            assert (ref_block is not None)
            if (ref_block.transactions_generator is None):
                raise ValueError(Err.GENERATOR_REF_HAS_NO_GENERATOR)
            result.append(GeneratorArg(ref_block.height, ref_block.transactions_generator))
    else:
        reorg_chain: Dict[(uint32, FullBlock)] = {}
        curr: Union[(FullBlock, UnfinishedBlock)] = block
        additional_height_dict = {}
        while (curr.prev_header_hash in additional_blocks):
            prev: FullBlock = additional_blocks[curr.prev_header_hash]
            additional_height_dict[prev.height] = prev
            if isinstance(curr, FullBlock):
                assert (curr.height == (prev.height + 1))
            reorg_chain[prev.height] = prev
            curr = prev
        peak: Optional[BlockRecord] = self.get_peak()
        if (self.contains_block(curr.prev_header_hash) and (peak is not None)):
            previous_block_hash = curr.prev_header_hash
            prev_block_record = (await self.block_store.get_block_record(previous_block_hash))
            prev_block = (await self.block_store.get_full_block(previous_block_hash))
            assert (prev_block is not None)
            assert (prev_block_record is not None)
            fork = find_fork_point_in_chain(self, peak, prev_block_record)
            curr_2: Optional[FullBlock] = prev_block
            assert ((curr_2 is not None) and isinstance(curr_2, FullBlock))
            reorg_chain[curr_2.height] = curr_2
            while ((curr_2.height > fork) and (curr_2.height > 0)):
                curr_2 = (await self.block_store.get_full_block(curr_2.prev_header_hash))
                assert (curr_2 is not None)
                reorg_chain[curr_2.height] = curr_2
        for ref_height in block.transactions_generator_ref_list:
            if (ref_height in reorg_chain):
                ref_block = reorg_chain[ref_height]
                assert (ref_block is not None)
                if (ref_block.transactions_generator is None):
                    raise ValueError(Err.GENERATOR_REF_HAS_NO_GENERATOR)
                result.append(GeneratorArg(ref_block.height, ref_block.transactions_generator))
            else:
                if (ref_height in additional_height_dict):
                    ref_block = additional_height_dict[ref_height]
                else:
                    header_hash = self.height_to_hash(ref_height)
                    ref_block = (await self.get_full_block(header_hash))
                assert (ref_block is not None)
                if (ref_block.transactions_generator is None):
                    raise ValueError(Err.GENERATOR_REF_HAS_NO_GENERATOR)
                result.append(GeneratorArg(ref_block.height, ref_block.transactions_generator))
    assert (len(result) == len(ref_list))
    return BlockGenerator(block.transactions_generator, result)
async def get_block_generator(self, block: Union[(FullBlock, UnfinishedBlock)], additional_blocks=None) -> Optional[BlockGenerator]:
    if (additional_blocks is None):
        additional_blocks = {}
    ref_list = block.transactions_generator_ref_list
    if (block.transactions_generator is None):
        assert (len(ref_list) == 0)
        return None
    if (len(ref_list) == 0):
        return BlockGenerator(block.transactions_generator, [])
    result: List[GeneratorArg] = []
    previous_block_hash = block.prev_header_hash
    if (self.try_block_record(previous_block_hash) and (self.height_to_hash(self.block_record(previous_block_hash).height) == previous_block_hash)):
        for ref_height in block.transactions_generator_ref_list:
            header_hash = self.height_to_hash(ref_height)
            ref_block = (await self.get_full_block(header_hash))
            assert (ref_block is not None)
            if (ref_block.transactions_generator is None):
                raise ValueError(Err.GENERATOR_REF_HAS_NO_GENERATOR)
            result.append(GeneratorArg(ref_block.height, ref_block.transactions_generator))
    else:
        reorg_chain: Dict[(uint32, FullBlock)] = {}
        curr: Union[(FullBlock, UnfinishedBlock)] = block
        additional_height_dict = {}
        while (curr.prev_header_hash in additional_blocks):
            prev: FullBlock = additional_blocks[curr.prev_header_hash]
            additional_height_dict[prev.height] = prev
            if isinstance(curr, FullBlock):
                assert (curr.height == (prev.height + 1))
            reorg_chain[prev.height] = prev
            curr = prev
        peak: Optional[BlockRecord] = self.get_peak()
        if (self.contains_block(curr.prev_header_hash) and (peak is not None)):
            previous_block_hash = curr.prev_header_hash
            prev_block_record = (await self.block_store.get_block_record(previous_block_hash))
            prev_block = (await self.block_store.get_full_block(previous_block_hash))
            assert (prev_block is not None)
            assert (prev_block_record is not None)
            fork = find_fork_point_in_chain(self, peak, prev_block_record)
            curr_2: Optional[FullBlock] = prev_block
            assert ((curr_2 is not None) and isinstance(curr_2, FullBlock))
            reorg_chain[curr_2.height] = curr_2
            while ((curr_2.height > fork) and (curr_2.height > 0)):
                curr_2 = (await self.block_store.get_full_block(curr_2.prev_header_hash))
                assert (curr_2 is not None)
                reorg_chain[curr_2.height] = curr_2
        for ref_height in block.transactions_generator_ref_list:
            if (ref_height in reorg_chain):
                ref_block = reorg_chain[ref_height]
                assert (ref_block is not None)
                if (ref_block.transactions_generator is None):
                    raise ValueError(Err.GENERATOR_REF_HAS_NO_GENERATOR)
                result.append(GeneratorArg(ref_block.height, ref_block.transactions_generator))
            else:
                if (ref_height in additional_height_dict):
                    ref_block = additional_height_dict[ref_height]
                else:
                    header_hash = self.height_to_hash(ref_height)
                    ref_block = (await self.get_full_block(header_hash))
                assert (ref_block is not None)
                if (ref_block.transactions_generator is None):
                    raise ValueError(Err.GENERATOR_REF_HAS_NO_GENERATOR)
                result.append(GeneratorArg(ref_block.height, ref_block.transactions_generator))
    assert (len(result) == len(ref_list))
    return BlockGenerator(block.transactions_generator, result)