<commit_before>'use strict'

var $ = require('jquery')
var txHelper = require('../execution/txHelper')

module.exports = (contractName, contract, compiledSource) => {
  return getDetails(contractName, contract, compiledSource)
}

var getDetails = function (contractName, contract, source) {
  var detail = {}
  detail.name = contractName
  detail.metadata = contract.metadata
  if (contract.evm.bytecode.object) {
    detail.bytecode = contract.evm.bytecode.object
  }

  detail.abi = contract.abi

  if (contract.evm.bytecode.object) {
    detail.bytecode = contract.evm.bytecode
    detail.web3Deploy = gethDeploy(contractName.toLowerCase(), contract.abi, contract.evm.bytecode.object)

    detail.metadataHash = retrieveMetadataHash(contract.evm.bytecode.object)
    if (detail.metadataHash) {
      detail.swarmLocation = 'bzzr://' + detail.metadataHash
    }
  }

  detail.functionHashes = {}
  for (var fun in contract.evm.methodIdentifiers) {
    detail.functionHashes[contract.evm.methodIdentifiers[fun]] = fun
  }

  detail.gasEstimates = formatGasEstimates(contract.evm.gasEstimates)

  if (contract.evm.deployedBytecode && contract.evm.deployedBytecode.object.length > 0) {
    detail['Runtime Bytecode'] = contract.evm.deployedBytecode
  }

  if (contract.assembly !== null) {
    detail['Assembly'] = formatAssemblyText(contract.evm.legacyAssembly, '', source.content)
  }

  return detail
}

var retrieveMetadataHash = function (bytecode) {
  var match = /a165627a7a72305820([0-9a-f]{64})0029$/.exec(bytecode)
  if (match) {
    return match[1]
  }
}

var formatAssemblyText = function (asm, prefix, source) {
  if (typeof asm === typeof '' || asm === null || asm === undefined) {
    return prefix + asm + '\n'
  }
  var text = prefix + '.code\n'
  $.each(asm['.code'], function (i, item) {
    var v = item.value === undefined ? '' : item.value
    var src = ''
    if (item.begin !== undefined && item.end !== undefined) {
      src = source.slice(item.begin, item.end).replace('\n', '\\n', 'g')
    }
    if (src.length > 30) {<commit_msg>check if source is available<commit_after>'use strict'

var $ = require('jquery')
var txHelper = require('../execution/txHelper')

module.exports = (contractName, contract, compiledSource) => {
  return getDetails(contractName, contract, compiledSource)
}

var getDetails = function (contractName, contract, source) {
  var detail = {}
  detail.name = contractName
  detail.metadata = contract.metadata
  if (contract.evm.bytecode.object) {
    detail.bytecode = contract.evm.bytecode.object
  }

  detail.abi = contract.abi

  if (contract.evm.bytecode.object) {
    detail.bytecode = contract.evm.bytecode
    detail.web3Deploy = gethDeploy(contractName.toLowerCase(), contract.abi, contract.evm.bytecode.object)

    detail.metadataHash = retrieveMetadataHash(contract.evm.bytecode.object)
    if (detail.metadataHash) {
      detail.swarmLocation = 'bzzr://' + detail.metadataHash
    }
  }

  detail.functionHashes = {}
  for (var fun in contract.evm.methodIdentifiers) {
    detail.functionHashes[contract.evm.methodIdentifiers[fun]] = fun
  }

  detail.gasEstimates = formatGasEstimates(contract.evm.gasEstimates)

  if (contract.evm.deployedBytecode && contract.evm.deployedBytecode.object.length > 0) {
    detail['Runtime Bytecode'] = contract.evm.deployedBytecode
  }

  if (source && contract.assembly !== null) {
    detail['Assembly'] = formatAssemblyText(contract.evm.legacyAssembly, '', source.content)
  }

  return detail
}

var retrieveMetadataHash = function (bytecode) {
  var match = /a165627a7a72305820([0-9a-f]{64})0029$/.exec(bytecode)
  if (match) {
    return match[1]
  }
}

var formatAssemblyText = function (asm, prefix, source) {
  if (typeof asm === typeof '' || asm === null || asm === undefined) {
    return prefix + asm + '\n'
  }
  var text = prefix + '.code\n'
  $.each(asm['.code'], function (i, item) {
    var v = item.value === undefined ? '' : item.value
    var src = ''
    if (item.begin !== undefined && item.end !== undefined) {
      src = source.slice(item.begin, item.end).replace('\n', '\\n', 'g')
    }
    if (src.length > 30) {
{'fraction_non_alphanumeric': 0.14689538535878233, 'fraction_numerical': 0.013529838125151003, 'mean_word_length': 3.7972190034762456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4493569', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1338, 'n_words': 265}