Given a NAMESPACE_PREORDER nameop, see if we can preorder it.
    It must be unqiue.

    Return True if accepted.
    Return False if not.

def check( state_engine, nameop, block_id, checked_ops ):
    """
    Given a NAMESPACE_PREORDER nameop, see if we can preorder it.
    It must be unqiue.

    Return True if accepted.
    Return False if not.
    """

    namespace_id_hash = nameop['preorder_hash']
    consensus_hash = nameop['consensus_hash']
    token_fee = nameop['token_fee']

    # cannot be preordered already
    if not state_engine.is_new_namespace_preorder( namespace_id_hash ):
        log.warning("Namespace preorder '%s' already in use" % namespace_id_hash)
        return False

    # has to have a reasonable consensus hash
    if not state_engine.is_consensus_hash_valid( block_id, consensus_hash ):
        valid_consensus_hashes = state_engine.get_valid_consensus_hashes( block_id )
        log.warning("Invalid consensus hash '%s': expected any of %s" % (consensus_hash, ",".join( valid_consensus_hashes )) )
        return False

    # has to have paid a fee
    if not 'op_fee' in nameop:
        log.warning("Missing namespace preorder fee")
        return False

    # paid to the right burn address
    if nameop['burn_address'] != BLOCKSTACK_BURN_ADDRESS:
        log.warning("Invalid burn address: expected {}, got {}".format(BLOCKSTACK_BURN_ADDRESS, nameop['burn_address']))
        return False
    
    # token burn fee must be present, if we're in the right epoch for it
    epoch_features = get_epoch_features(block_id)
    if EPOCH_FEATURE_STACKS_BUY_NAMESPACES in epoch_features:
        # must pay in STACKs
        if 'token_fee' not in nameop:
            log.warning("Missing token fee")
            return False

        token_fee = nameop['token_fee']
        token_address = nameop['address']
        token_type = TOKEN_TYPE_STACKS

        # was a token fee paid?
        if token_fee is None:
            log.warning("No tokens paid by this NAMESPACE_PREORDER")
            return False

        # does this account have enough balance?
        account_info = state_engine.get_account(token_address, token_type)
        if account_info is None:
            log.warning("No account for {} ({})".format(token_address, token_type))
            return False

        account_balance = state_engine.get_account_balance(account_info)

        assert isinstance(account_balance, (int,long)), 'BUG: account_balance of {} is {} (type {})'.format(token_address, account_balance, type(account_balance))
        assert isinstance(token_fee, (int,long)), 'BUG: token_fee is {} (type {})'.format(token_fee, type(token_fee))

        if account_balance < token_fee:
            # can't afford 
            log.warning("Account {} has balance {} {}, but needs to pay {} {}".format(token_address, account_balance, token_type, token_fee, token_type))
            return False

        # debit this account when we commit
        state_preorder_put_account_payment_info(nameop, token_address, token_type, token_fee)
        
        # NOTE: must be a string, to avoid overflow
        nameop['token_fee'] = '{}'.format(token_fee)
        nameop['token_units'] = TOKEN_TYPE_STACKS

    else:
        # must pay in BTC
        # not paying in tokens, but say so!
        state_preorder_put_account_payment_info(nameop, None, None, None)
        nameop['token_fee'] = '0'
        nameop['token_units'] = 'BTC'

    return True