Exemple #1
0
 def _get_script_hash(self) -> bytes:
     file_path = self._nef_path
     if file_path.endswith('.nef') and os.path.isfile(file_path):
         with open(file_path, mode='rb') as nef:
             file = nef.read()
         from boa3.neo.contracts.neffile import NefFile
         return NefFile.deserialize(file).script_hash
Exemple #2
0
    def get_output(self,
                   path: str,
                   root_folder: str = None) -> Tuple[bytes, Dict[str, Any]]:
        nef_output = path.replace('.py', '.nef')
        if not os.path.isfile(nef_output):
            return self.compile_and_save(path, root_folder=root_folder)

        manifest_output = path.replace('.py', '.manifest.json')

        from boa3.neo.contracts.neffile import NefFile

        if not os.path.isfile(nef_output):
            output = bytes()
        else:
            with open(nef_output, mode='rb') as nef:
                file = nef.read()
                output = NefFile.deserialize(file).script

        if not os.path.isfile(manifest_output):
            manifest = {}
        else:
            with open(manifest_output) as manifest_output:
                import json
                manifest = json.loads(manifest_output.read())

        return output, manifest
Exemple #3
0
    def __init__(self, file_path: str):
        self._nef_path: str = file_path

        script_hash = None
        if file_path.endswith('.nef') and os.path.isfile(file_path):
            with open(file_path, mode='rb') as nef:
                file = nef.read()
            from boa3.neo.contracts.neffile import NefFile
            script_hash = NefFile.deserialize(file).script_hash

        self._script_hash: Optional[bytes] = script_hash
Exemple #4
0
    def _get_contract_id(self, contract_path: str) -> int:
        if path.isfile(contract_path):
            with open(contract_path, mode='rb') as nef:
                from boa3.neo.contracts.neffile import NefFile
                script_hash = NefFile.deserialize(nef.read()).script_hash

            return self._storage.get_contract_id(script_hash)

        contracts = self.contracts
        if contract_path in contracts:
            return contracts.index(contract_path)
        return -1
Exemple #5
0
    def compile_and_save(self, path: str, log: bool = True) -> Tuple[bytes, Dict[str, Any]]:
        nef_output = path.replace('.py', '.nef')
        manifest_output = path.replace('.py', '.manifest.json')

        from boa3.boa3 import Boa3
        from boa3.neo.contracts.neffile import NefFile
        Boa3.compile_and_save(path, show_errors=log)

        with open(nef_output, mode='rb') as nef:
            file = nef.read()
            output = NefFile.deserialize(file).script

        with open(manifest_output) as manifest_output:
            import json
            manifest = json.loads(manifest_output.read())

        return output, manifest