예제 #1
0
    def export_debug(self, output_path, data):
        """
        this method is used to generate a debug map for NEO debugger
        """

        hashstr = Digest.hash160(msg=data, is_hex=True)  # str
        a2bhashstr = bytearray(a2b_hex(hashstr))  # str ==> bytes ==>bytearray
        a2bhashstr.reverse()
        file_hash = a2bhashstr.hex()  # bytearray ==> str

        avm_name = os.path.splitext(os.path.basename(output_path))[0]
        json_data = self.generate_debug_json(avm_name, file_hash)
        mapfilename = output_path.replace('.avm', '.debug.json')
        with open(mapfilename, 'w+') as out_file:
            out_file.write(json_data)

        if self.abi != None:
            self.abi.ABI_result["hash"] = file_hash
            self.abi.ABI_result["entrypoint"] = self.main.name
            self.abi.ABI_result["functions"] = self.abi.AbiFunclist
            json_data = json.dumps(self.abi.ABI_result, indent=4)
            fullpath = os.path.realpath(self.path)
            path, filename = os.path.split(fullpath)
            newfilename = filename.replace('.py', '.abi.json')
            mapfilename = '%s/%s' % (path, newfilename)
            with open(mapfilename, 'w+') as out_file:
                out_file.write(json_data)
예제 #2
0
 def generate_abi_file(contract_path: str, save_path: str = ''):
     if save_path == '':
         split_path = os.path.split(contract_path)
         save_path = os.path.join(os.getcwd(), 'build', split_path[1])
         save_path = save_path.replace('.py', '.json')
     compiler = Compiler.load(contract_path)
     raw_avm = compiler.write()
     hex_str_hash = Digest.hash160(raw_avm, is_hex=True)
     byte_array_hash = bytearray(binascii.a2b_hex(hex_str_hash))
     byte_array_hash.reverse()
     contract_hash = byte_array_hash.hex()
     dict_abi = dict()
     dict_abi['hash'] = contract_hash
     dict_abi['entrypoint'] = compiler.entry_module.main.name
     dict_abi['functions'] = compiler.entry_module.abi.AbiFunclist
     json_data = json.dumps(dict_abi, indent=4)
     split_path = os.path.split(save_path)
     if not os.path.exists(split_path[0]):
         os.makedirs(split_path[0])
     with open(save_path, 'w') as f:
         f.write(json_data)