Beispiel #1
0
    def deploy(self, conf: dict) -> dict:
        """Deploy SCORE on the server.

        :param conf: deploy command configuration
        """
        # check keystore, and get password from user's terminal input
        password = conf.get('password', None)
        password = self._check_deploy(conf, password)

        if conf['mode'] == 'install':
            score_address = f'cx{"0"*40}'
        else:
            score_address = conf['to']

        content_type = "application/zip"
        # make zip and convert to hexadecimal string data (start with 0x) and return
        content = IconJsonrpc.gen_deploy_data_content(conf['project'])

        # make IconJsonrpc instance which is used for making request (with signature)
        if conf['keyStore']:
            deploy = IconJsonrpc.from_key_store(keystore=conf['keyStore'],
                                                password=password)
        else:
            deploy = IconJsonrpc.from_string(from_=conf['from'])

        uri = conf['uri']
        step_limit = conf.get('stepLimit', None)

        # make JSON-RPC 2.0 request standard format
        request = deploy.sendTransaction(to=score_address,
                                         nid=conf['nid'],
                                         step_limit=step_limit,
                                         data_type="deploy",
                                         data=IconJsonrpc.gen_deploy_data(
                                             params=conf.get(
                                                 'scoreParams', {}),
                                             content_type=content_type,
                                             content=content))

        if step_limit is None:
            step_limit = get_enough_step(request, uri)
            request['params']['stepLimit'] = hex(step_limit)
            deploy.put_signature(request['params'])

        # send request to the rpc server
        icon_client = IconClient(uri)
        response = icon_client.send(request)

        if 'error' in response:
            print('Got an error response')
            print(json.dumps(response, indent=4))
        else:
            print('Send deploy request successfully.')
            tx_hash = response['result']
            print(
                f'If you want to check SCORE deployed successfully, execute txresult command'
            )
            print(f"transaction hash: {tx_hash}")

        return response
    def test_gen_deploy_data_content(self):
        content = IconJsonrpc.gen_deploy_data_content(TEST_UTIL_DIRECTORY)
        self.assertEqual(content[:2], '0x')

        # invalid path
        self.assertRaises(ValueError, IconJsonrpc.gen_deploy_data_content,
                          "Wrong_path")
Beispiel #3
0
    def deploy(self, conf: dict) -> dict:
        """Deploy SCORE on the server.

        :param conf: deploy command configuration
        """
        if conf['contentType'] == 'tbears' and not CommandServer.is_service_running(
        ):
            raise TBearsCommandException(f'Start tbears service first')

        # check keystore, and get password from user's terminal input
        password = conf.get('password', None)
        password = self._check_deploy(conf, password)

        step_limit = conf.get('stepLimit', "0x1234000")

        if conf['mode'] == 'install':
            score_address = f'cx{"0"*40}'
        else:
            score_address = conf['to']

        if conf['contentType'] == 'zip':
            content_type = "application/zip"
            # make zip and convert to hexadecimal string data(start with 0x) and return
            content = IconJsonrpc.gen_deploy_data_content(conf['project'])
        else:
            content_type = "application/tbears"
            content = os.path.abspath(conf['project'])

        # make IconJsonrpc instance which is used for making request(with signature)
        if conf['keyStore']:
            deploy = IconJsonrpc.from_key_store(keystore=conf['keyStore'],
                                                password=password)
        else:
            deploy = IconJsonrpc.from_string(from_=conf['from'])

        # make JSON-RPC 2.0 request standard format
        request = deploy.sendTransaction(to=score_address,
                                         nid=conf['nid'],
                                         step_limit=step_limit,
                                         data_type="deploy",
                                         data=IconJsonrpc.gen_deploy_data(
                                             params=conf.get(
                                                 'scoreParams', {}),
                                             content_type=content_type,
                                             content=content))

        # send request to rpcserver
        icon_client = IconClient(conf['uri'])
        response = icon_client.send(request)

        if 'error' in response:
            print('Got an error response')
            print(json.dumps(response, indent=4))
        else:
            print('Send deploy request successfully.')
            tx_hash = response['result']
            print(
                f'If you want to check SCORE deployed successfully, execute txresult command'
            )
            print(f"transaction hash: {tx_hash}")

        return response