import codecs


def txidFromBroadcast (hexStr):
  """Extracts the hex txid from a broadcast in hex."""

  # The prevout txid is the first part of the broadcast data
  # in serialised form.  But we need to reverse the bytes.

  hexRev = hexStr[:64]
  bytesRev = codecs.decode (hexRev, "hex")

  return bytesRev[::-1].hex ()