def on_persist_completed(self, block):
        """
        Called when a block has been persisted to disk.  Used as a hook to persist notification data.
        Args:
            block (neo.Core.Block): the currently persisting block
        """
        if len(self._events_to_write):

            addr_db = self.db.prefixed_db(NotificationPrefix.PREFIX_ADDR)
            block_db = self.db.prefixed_db(NotificationPrefix.PREFIX_BLOCK)
            contract_db = self.db.prefixed_db(NotificationPrefix.PREFIX_CONTRACT)

            block_write_batch = block_db.write_batch()
            contract_write_batch = contract_db.write_batch()

            block_count = 0
            block_bytes = self._events_to_write[0].block_number.to_bytes(4, 'little')

            for evt in self._events_to_write:  # type:NotifyEvent

                # write the event for both or one of the addresses involved in the transfer
                write_both = True
                hash_data = evt.ToByteArray()

                bytes_to = bytes(evt.addr_to.Data)
                bytes_from = bytes(evt.addr_from.Data)

                if bytes_to == bytes_from:
                    write_both = False

                total_bytes_to = addr_db.get(bytes_to + NotificationPrefix.PREFIX_COUNT)
                total_bytes_from = addr_db.get(bytes_from + NotificationPrefix.PREFIX_COUNT)

                if not total_bytes_to:
                    total_bytes_to = b'\x00'

                if not total_bytes_from:
                    total_bytes_from = b'x\00'

                addr_to_key = bytes_to + total_bytes_to
                addr_from_key = bytes_from + total_bytes_from

                with addr_db.write_batch() as b:
                    b.put(addr_to_key, hash_data)
                    if write_both:
                        b.put(addr_from_key, hash_data)
                    total_bytes_to = int.from_bytes(total_bytes_to, 'little') + 1
                    total_bytes_from = int.from_bytes(total_bytes_from, 'little') + 1
                    new_bytes_to = total_bytes_to.to_bytes(4, 'little')
                    new_bytes_from = total_bytes_from.to_bytes(4, 'little')
                    b.put(bytes_to + NotificationPrefix.PREFIX_COUNT, new_bytes_to)
                    if write_both:
                        b.put(bytes_from + NotificationPrefix.PREFIX_COUNT, new_bytes_from)

                # write the event to the per-block database
                per_block_key = block_bytes + block_count.to_bytes(4, 'little')
                block_write_batch.put(per_block_key, hash_data)
                block_count += 1

                # write the event to the per-contract database
                contract_bytes = bytes(evt.contract_hash.Data)
                count_for_contract = contract_db.get(contract_bytes + NotificationPrefix.PREFIX_COUNT)
                if not count_for_contract:
                    count_for_contract = b'\x00'
                contract_event_key = contract_bytes + count_for_contract
                contract_count_int = int.from_bytes(count_for_contract, 'little') + 1
                new_contract_count = contract_count_int.to_bytes(4, 'little')
                contract_write_batch.put(contract_bytes + NotificationPrefix.PREFIX_COUNT, new_contract_count)
                contract_write_batch.put(contract_event_key, hash_data)

            # finish off the per-block write batch and contract write batch
            block_write_batch.write()
            contract_write_batch.write()

        self._events_to_write = []

        if len(self._new_contracts_to_write):

            token_db = self.db.prefixed_db(NotificationPrefix.PREFIX_TOKEN)

            token_write_batch = token_db.write_batch()

            for token_event in self._new_contracts_to_write:
                try:
                    hash_data = token_event.ToByteArray()  # used to fail here
                    hash_key = token_event.contract.Code.ScriptHash().ToBytes()
                    token_write_batch.put(hash_key, hash_data)
                except Exception as e:
                    logger.debug(f"Failed to write new contract, reason: {e}")

            token_write_batch.write()

        self._new_contracts_to_write = []
Called when a block has been persisted to disk.  Used as a hook to persist notification data.
        Args:
            block (neo.Core.Block): the currently persisting block