Commit a state-creation operation (works for name_registration,
        namespace_reveal, name_import).

        Returns the sequence of dicts of fields to serialize.

        DO NOT CALL THIS DIRECTLY

def commit_state_create( self, nameop, current_block_number ):
        """
        Commit a state-creation operation (works for name_registration,
        namespace_reveal, name_import).

        Returns the sequence of dicts of fields to serialize.

        DO NOT CALL THIS DIRECTLY
        """

        # have to have read-write disposition 
        if self.disposition != DISPOSITION_RW:
            log.error("FATAL: borrowing violation: not a read-write connection")
            traceback.print_stack()
            os.abort()

        cur = self.db.cursor()
        opcode = nameop.get('opcode', None)

        try:
            assert state_create_is_valid( nameop ), "Invalid state-creation"
            assert opcode is not None, "BUG: did not set opcode"
            
            preorder = state_create_get_preorder( nameop )
        except Exception, e:
            log.exception(e)
            log.error("FATAL: missing preorder and/or prior history and/or opcode")
            os.abort()

        initial_state = self.sanitize_op( nameop )
        table = state_create_get_table( nameop )
        history_id_key = state_create_get_history_id_key( nameop )
        history_id = nameop[history_id_key]
        constraints_ignored = state_create_get_always_set( nameop )

        # cannot have collided 
        if BlockstackDB.nameop_is_collided( nameop ):
            # TODO: is this reachable?
            log.debug("Not commiting '%s' since we're collided" % history_id)
            self.log_reject( current_block_number, nameop['vtxindex'], nameop['op'], nameop )
            return {}

        self.log_accept( current_block_number, nameop['vtxindex'], nameop['op'], nameop )
        
        canonical_opdata = None

        if preorder is not None:
            # preordered a name or a namespace, possibly not for the first time even.
            try:
                assert 'preorder_hash' in preorder, 'BUG: missing preorder-hash'
            except Exception as e:
                log.exception(e)
                log.error("FATAL: invalid preorder")
                os.abort()

            canonical_opdata = namedb_state_create(cur, opcode, initial_state, current_block_number,
                                                   initial_state['vtxindex'], initial_state['txid'],
                                                   history_id, preorder, table, constraints_ignored=constraints_ignored)

            if not canonical_opdata:
                log.error("FATAL: failed to create '{}'".format(history_id))
                self.db.rollback()
                os.abort()

            self.db.commit()
        
        else:
            # importing a name
            try:
                assert opcode in OPCODE_NAME_STATE_IMPORTS, "BUG: not an import operation"
            except Exception, e:
                log.exception(e)
                log.error("FATAL: invalid import operation")
                os.abort()

            canonical_opdata = namedb_state_create_as_import(self.db, opcode, initial_state, 
                                                             current_block_number, initial_state['vtxindex'], initial_state['txid'],
                                                             history_id, table, constraints_ignored=constraints_ignored)

            if not canonical_opdata:
                log.error("FATAL: failed to create '{}' as import".format(history_id))
                self.db.rollback()
                os.abort()

            self.db.commit()
        
        return canonical_opdata