Verify the validity of a name's transferrance to another private key.
    The name must exist, not be revoked, and be owned by the sender.
    The recipient must not exceed the maximum allowed number of names per keypair,
    and the recipient cannot own an equivalent name.

    NAME_TRANSFER isn't allowed during an import, so the name's namespace must be ready.

    Return True if accepted
    Return False if not

def check( state_engine, nameop, block_id, checked_ops ):
    """
    Verify the validity of a name's transferrance to another private key.
    The name must exist, not be revoked, and be owned by the sender.
    The recipient must not exceed the maximum allowed number of names per keypair,
    and the recipient cannot own an equivalent name.

    NAME_TRANSFER isn't allowed during an import, so the name's namespace must be ready.

    Return True if accepted
    Return False if not
    """

    name_hash = nameop['name_hash128']
    name = state_engine.get_name_from_name_hash128( name_hash )

    consensus_hash = nameop['consensus_hash']
    sender = nameop['sender']
    recipient_address = nameop['recipient_address']
    recipient = nameop['recipient']

    if name is None:
        # invalid
        log.warning("No name found for '%s'" % name_hash )
        return False

    namespace_id = get_namespace_from_name( name )
    name_rec = state_engine.get_name( name )
    
    if name_rec is None:
        log.warning("Name '%s' does not exist" % name)
        return False

    # namespace must be ready
    if not state_engine.is_namespace_ready( namespace_id ):
        # non-existent namespace
        log.warning("Namespace '%s' is not ready" % (namespace_id))
        return False

    # name must not be revoked
    if state_engine.is_name_revoked( name ):
        log.warning("Name '%s' is revoked" % name)
        return False

    # name must not be expired as of the *last block processed*
    if state_engine.is_name_expired( name, state_engine.lastblock ):
        log.warning("Name '%s' is expired" % name)
        return False

    # name must not be in grace period in this block
    if state_engine.is_name_in_grace_period(name, block_id):
        log.warning("Name '{}' is in the renewal grace period.  It can only be renewed at this time.".format(name))
        return False

    if not state_engine.is_consensus_hash_valid( block_id, consensus_hash ):
        # invalid concensus hash
        log.warning("Invalid consensus hash '%s'" % consensus_hash )
        return False

    if sender == recipient:
        # nonsensical transfer
        log.warning("Sender is the same as the Recipient (%s)" % sender )
        return False

    if not state_engine.is_name_registered( name ):
        # name is not registered
        log.warning("Name '%s' is not registered" % name)
        return False

    if not state_engine.is_name_owner( name, sender ):
        # sender doesn't own the name
        log.warning("Name '%s' is not owned by %s (but %s)" % (name, sender, state_engine.get_name_owner(name)))
        return False

    names_owned = state_engine.get_names_owned_by_sender( recipient )
    if name in names_owned:
        # recipient already owns it 
        log.warning("Recipient %s already owns '%s'" % (recipient, name))
        return False

    if len(names_owned) >= MAX_NAMES_PER_SENDER:
        # exceeds quota 
        log.warning("Recipient %s has exceeded name quota" % recipient)
        return False

    # sender cannot be a p2sh script until we're in an epoch that supports multisig.
    # this is to preserve compatibility with 0.13.
    if virtualchain.is_multisig_script( sender ) and not epoch_has_multisig( block_id ):
        log.warning("Sender %s is a p2sh script, but multisig is not enabled in epoch %s" % (sender, get_epoch_number(block_id)))
        return False

    # the given consensus hash must be valid
    nameop_consensus_hash = nameop['consensus_hash']
    transfer_send_block_id = state_engine.get_block_from_consensus(nameop_consensus_hash)
    if transfer_send_block_id is None:
        # wrong/invalid consensus hash 
        log.warning("Unrecognized consensus hash '%s'" % nameop_consensus_hash)
        return False
    
    # QUIRK: we hash either the consensus hash from the last non-NAME_TRANSFER
    # operation, or if there are no such consensus hashes, we hash on the one from the NAME_TRANSFER itself.
    transfer_consensus_hash = find_transfer_consensus_hash(name_rec, block_id, nameop['vtxindex'], nameop['consensus_hash'])

    # remember the name, so we don't have to look it up later
    nameop['name'] = name

    # carry out transition, putting the operation into the state to be committed
    nameop['sender'] = recipient
    nameop['address'] = recipient_address
    nameop['sender_pubkey'] = None

    if not nameop['keep_data']:
        nameop['value_hash'] = None
        nameop['op'] = "%s%s" % (NAME_TRANSFER, TRANSFER_REMOVE_DATA)
    else:
        # preserve 
        nameop['value_hash'] = name_rec['value_hash']
        nameop['op'] = "%s%s" % (NAME_TRANSFER, TRANSFER_KEEP_DATA)

    del nameop['recipient']
    del nameop['recipient_address']
    del nameop['keep_data']
    del nameop['name_hash128']
    
    # QUIRK examples
    # example 1: doog.id underwent a NAME_PREORDER, NAME_REGISTRATION, and NAME_TRANSFER (>~).
    # In the NAME_TRANSFER (>~) at 405088, it should have consensus_hash == CONSNSUS(405079) hashed when the consensus hash is calculated
    # (i.e. there is no prior non-NAME_TRANSFER stored consensus hash, so the consensus hash comes from the one given in this NAME_TRANSFER).
    # example 2: doog.id underwent a NAME_PREORDER, NAME_REGISTRATION, NAME_TRANSFER (>~), and NAME_TRANSFER (>~)
    # In the NAME_TRANSFER (>~) at 405175, it should have consensus_hash == CONSNSUS(405165) hashed when the consensus hash is calculated
    # (i.e. there is no prior non-NAME_TRANSFER stored consensus hash, so the consensus hash comes from the one given in this NAME_TRANSFER).
    # example 3: eth3r3um.id underwent a NAME_PREORDER, NAME_REGISTRATION, NAME_UPDATE, and NAME_TRANSFER (>>)
    # in the NAME_TRANSFER (>>) at 385652, it should have consensus_hash == CONSENSUS(385610) hashed when the consensus hash is calculated
    # (i.e. this was the prior stored consensus hash at 385610 from a non-NAME_TRANSFER---the one from the earlier NAME_UPDATE)
    log.debug("QUIRK: Hash NAME_TRANSFER consensus hash {} instead of {}".format(transfer_consensus_hash, nameop_consensus_hash))
    nameop['consensus_hash'] = transfer_consensus_hash

    return True