def parse_tx(arg, parser, tx_db, network):
    tx = None
    if TX_ID_RE.match(arg):
        if (tx_db is None):
            tx_db = create_tx_db(network)
        tx = tx_db.get(h2b_rev(arg))
        if (not tx):
            parser.error(("can't find Tx with id %s" % arg))
        return (tx, tx_db)
    try:
        return (Tx.from_hex(arg), tx_db)
    except Exception:
        pass
    if os.path.exists(arg):
        try:
            with open(arg, 'rb') as f:
                if f.name.endswith('hex'):
                    f = io.BytesIO(codecs.getreader('hex_codec')(f).read())
                tx = Tx.parse(f)
                tx.parse_unspents(f)
        except Exception:
            pass
    return (tx, tx_db)
def parse_tx(arg, parser, tx_db, network):
    tx = None
    if TX_ID_RE.match(arg):
        if (tx_db is None):
            tx_db = create_tx_db(network)
        tx = tx_db.get(h2b_rev(arg))
        if (not tx):
            parser.error(("can't find Tx with id %s" % arg))
        return (tx, tx_db)
    try:
        return (Tx.from_hex(arg), tx_db)
    except Exception:
        pass
    if os.path.exists(arg):
        try:
            with open(arg, 'rb') as f:
                if f.name.endswith('hex'):
                    f = io.BytesIO(codecs.getreader('hex_codec')(f).read())
                tx = Tx.parse(f)
                tx.parse_unspents(f)
        except Exception:
            pass
    return (tx, tx_db)