(required by virtualchain state engine)

    Advance the state of the state engine: get a list of all
    externally visible state transitions.
   
    Given a block ID and checked opcode, record it as 
    part of the database.  This does *not* need to write 
    the data to persistent storage, since save() will be 
    called once per block processed.
  
    Returns one or more new name operations on success, which will 
    be fed into virtualchain to translate into a string
    to be used to generate this block's consensus hash.

def db_commit( block_id, op, op_data, txid, vtxindex, db_state=None ):
    """
    (required by virtualchain state engine)

    Advance the state of the state engine: get a list of all
    externally visible state transitions.
   
    Given a block ID and checked opcode, record it as 
    part of the database.  This does *not* need to write 
    the data to persistent storage, since save() will be 
    called once per block processed.
  
    Returns one or more new name operations on success, which will 
    be fed into virtualchain to translate into a string
    to be used to generate this block's consensus hash.
    """
    try:
        assert db_state is not None
    except:
        log.error("FATAL: no state given")
        os.abort()

    if op != 'virtualchain_final':
        # ongoing processing.
        # do sanity checks
        try:
            assert '__original_op_data__' in op_data, 'BUG: no __original_op_data__'
            assert 'txid' in op_data, "BUG: No txid given"
            assert 'vtxindex' in op_data, "BUG: No vtxindex given"
            assert op_data['txid'] == txid, "BUG: txid mismatch"
            assert op_data['vtxindex'] == vtxindex, "BUG: vtxindex mismatch"
            
            opcode = op_data.get('opcode', None)
            assert opcode in OPCODE_PREORDER_OPS + OPCODE_CREATION_OPS + OPCODE_TRANSITION_OPS + OPCODE_STATELESS_OPS + OPCODE_TOKEN_OPS, \
                            "BUG: uncategorized opcode '%s'" % opcode

        except Exception, e:
            log.exception(e)
            log.error("FATAL: failed to commit operation")
            os.abort()

        # from db_parse
        original_op_data = op_data['__original_op_data__']
        del op_data['__original_op_data__']

        # save, and get the sequence of committed operations
        consensus_ops = []
        if opcode in OPCODE_STATELESS_OPS:
            # state-less operation 
            consensus_ops = []

        else:
            consensus_op = db_state.commit_operation(original_op_data, op_data, block_id)
            
            # make sure compatibility quirks are preserved
            check_quirks(block_id, consensus_op, db_state)

            consensus_ops = [consensus_op]
        
        return consensus_ops

    else:
        return None