code: def btc_tx_get_hash( tx_serialized, hashcode=None ):
      
      if btc_tx_is_segwit(tx_serialized):
          raise ValueError('Segwit transaction: {}'.format(tx_serialized))
  
      tx_bin = binascii.unhexlify(tx_serialized)
      if hashcode:
          return binascii.hexlify( hashing.bin_double_sha256(tx_bin + encoding.encode(int(hashcode), 256, 4)[::-1]) )
  
      else:
          return binascii.hexlify( hashing.bin_double_sha256(tx_bin)[::-1] )
docs: Make a transaction hash (txid) from a hex tx, optionally along with a sighash.
      This DOES NOT WORK for segwit transactions