docs: def calculate_tx_fee( tx_hex, fee_per_byte ):
      """
      High-level API call (meant to be blockchain-agnostic)
      What is the fee for the transaction?
      """
      txobj = btc_tx_deserialize(tx_hex)
      tx_num_bytes = len(tx_hex) / 2
      num_virtual_bytes = None
  
      if btc_tx_is_segwit(tx_hex):
          # segwit--discount witness data 
          witness_len = 0
          for inp in txobj['ins']:
              witness_len += len(inp['witness_script']) / 2 
  
          # see https://bitcoincore.org/en/segwit_wallet_dev/#transaction-fee-estimation
          tx_num_bytes_original = tx_num_bytes - witness_len
          num_virtual_bytes = 3 * tx_num_bytes_original + tx_num_bytes
  
      else:
          # non-segwit 
          num_virtual_bytes = tx_num_bytes * 4
  
      return (fee_per_byte * num_virtual_bytes) / 4