'Validate a transaction.
Also checks if the transaction already exists in the blockchain. If it
does, or it\'s invalid, it\'s deleted from the backlog immediately.
Args:
tx (dict): the transaction to validate.
Returns:
:class:`~bigchaindb.models.Transaction`: The transaction if valid,
``None`` otherwise.'

def validate_tx(self, tx):

    try:
        tx = Transaction.from_dict(tx)
    except ValidationError:
        return None
    if (not self.bigchain.is_new_transaction(tx.id)):
        self.bigchain.delete_transaction(tx.id)
        return None
    try:
        if (tx.operation == Transaction.GENESIS):
            raise GenesisBlockAlreadyExistsError('Duplicate    GENESIS    transaction')
        tx.validate(self.bigchain)
        return tx
    except ValidationError as e:
        logger.warning('Invalid    tx:    %s', e)
        self.bigchain.delete_transaction(tx.id)
        return None
