コード例 #1
0
    def _deploy_cps_score(self,
                          to: str = SCORE_INSTALL_ADDRESS,
                          params=None) -> dict:
        if params is None:
            params = {}
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.CPS_SCORE_PROJECT)) \
            .params(params) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)

        # process the transaction in local
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertEqual(True, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)
        pprint(tx_result)
        return tx_result
コード例 #2
0
def _deploy_smart_wallet(wallet, token_type, contract_addr, sendLimit, dids):
    deploy_contract = gen_deploy_data_content("../smart_wallet")
    print(deploy_contract)
    account = {
        "tokenType": token_type,
        "contractAddr": contract_addr,
        "balance": 0,
        "totalUsed": 0,
        "sendLimit": int(sendLimit),
        "lastUsedDate": "2018-11-12",
        "dids": dids
    }

    transaction = DeployTransactionBuilder() \
        .from_(wallet.get_address()) \
        .to("cx0000000000000000000000000000000000000000") \
        .step_limit(2000000000000) \
        .nid(3) \
        .nonce(100) \
        .content_type("application/zip") \
        .content(deploy_contract) \
        .params({"account": json.dumps(account)}) \
        .build()
    result = _send_transaction(transaction, wallet, 10)
    IconServiceContainer.contract_addr = result['scoreAddress']
コード例 #3
0
    def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict:
        dir_path = os.path.abspath(os.path.dirname(__file__))
        score_project = os.path.abspath(os.path.join(dir_path, '..'))
        score_content_bytes = gen_deploy_data_content(score_project)

        # Generates an instance of transaction for deploying SCORE.
        transaction = DeployTransactionBuilder() \
            .from_(self._wallet.get_address()) \
            .to(to) \
            .nid(3) \
            .step_limit(10000000000) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(score_content_bytes) \
            .params({}) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, self._wallet)

        # process the transaction in local
        tx_result = self.process_transaction(signed_transaction,
                                             self._icon_service)

        self.assertEqual(True, tx_result['status'], msg=pp.pformat(tx_result))
        self.assertTrue('scoreAddress' in tx_result, msg=pp.pformat(tx_result))

        return tx_result
コード例 #4
0
ファイル: test_FISH.py プロジェクト: icon-bu-3/fishingcon
    def _deploy_score(
        self,
        to: str = SCORE_INSTALL_ADDRESS
    ) -> dict:  #SCORE 배포를위한 트랜잭션 인스턴스를 생성합니다.

        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.SCORE_PROJECT)) \
            .build()

        signed_transaction = SignedTransaction(
            transaction, self._test1)  # 서명이있는 서명 된 트랜잭션 객체를 반환합니다.

        # 로컬에서 거래 처리
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)

        return tx_result
コード例 #5
0
    def _deploy_irc2(self, project, to: str = SCORE_INSTALL_ADDRESS) -> dict:
        # Generates an instance of transaction for deploying SCORE.
        transaction = DeployTransactionBuilder() \
            .params({
                "_initialSupply": 0x100000000000,
                "_decimals": 18,
                "_name": 'StandardToken',
                "_symbol": 'ST',
            }) \
            .from_(self._operator.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(project)) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, self._operator)

        # process the transaction in local
        result = self.process_transaction(signed_transaction,
                                          self.icon_service)

        self.assertTrue('status' in result)
        self.assertEqual(1, result['status'])
        self.assertTrue('scoreAddress' in result)

        return result
コード例 #6
0
    def _deploy_score(self,
                      to: str = SCORE_INSTALL_ADDRESS,
                      params: dict = None) -> dict:
        # Generates an instance of transaction for deploying SCORE.
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.SCORE_PROJECT)) \
            .params(params) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, self._test1)

        # process the transaction
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)

        return tx_result
コード例 #7
0
    def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict:
        # publish token score contract
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100).params(self.TOKEN_SCORE_PARAM)  \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.TOKEN_SCORE_PROJECT)) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)

        # publish crowdsale score contract
        self.CROWDSALE_PARAM['_tokenScore'] = tx_result['scoreAddress']

        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100).params(self.CROWDSALE_PARAM)  \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.CROWDSALE_SCORE_PROJECT)) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)
        return {
            'crowdsale_score_address': tx_result['scoreAddress'],
            'token_score_address': self.CROWDSALE_PARAM['_tokenScore']
        }
コード例 #8
0
 def test_in_memory_zip(self):
     current_dir_path = path.abspath(path.dirname(__file__))
     score_path = path.join(current_dir_path, 'sample_token')
     tests_path = path.join(current_dir_path, 'sample_token', 'tests')
     # bytes of sample_token's content
     content_bytes = gen_deploy_data_content(score_path)
     content_bytes_as_str = str(content_bytes)
     self.assertFalse(
         'test_integrate_sample_token.py' in content_bytes_as_str)
     self.assertFalse(tests_path[1:] in content_bytes_as_str)
     self.assertTrue(score_path[1:] in content_bytes_as_str)
コード例 #9
0
    def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict:
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.SCORE_PROJECT)) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)

        tx_result = self.process_transaction(signed_transaction)

        return tx_result
コード例 #10
0
    def test_update_scores(self):
        score_list = ['cps_score', 'cpf_treasury', 'cps_treasury']
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(self.contracts[score_list[0]]) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.CPS_SCORE_PROJECT)) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)

        tx_hash = self.process_transaction(signed_transaction,
                                           self.icon_service)
        pprint(tx_hash)
コード例 #11
0
    def create_deploy_score_tx(
            score_path: str,
            from_: 'KeyWallet',
            to: str = SCORE_INSTALL_ADDRESS) -> 'SignedTransaction':
        transaction = DeployTransactionBuilder() \
            .from_(from_.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(DEFAULT_NID) \
            .nonce(0) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(score_path)) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, from_)
        return signed_transaction
コード例 #12
0
    def _deploy_std_basic(self, to: str = SCORE_INSTALL_ADDRESS) -> dict:
        # Generates an instance of transaction for deploying SCORE.
        transaction = (DeployTransactionBuilder().from_(
            self._test1.get_address()).to(to).step_limit(100_000_000_000).nid(
                3).nonce(100).content_type("application/zip").content(
                    gen_deploy_data_content(self.STD_BASIC_PROJECT)).build())

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, self._test1)

        # process the transaction in local
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertEqual(True, tx_result["status"])
        self.assertTrue("scoreAddress" in tx_result)

        return tx_result
コード例 #13
0
    def update(self, score_path: str, step_limit: int, estimate: bool) -> str:
        """Update governance SCORE

        :return: tx_hash
        """
        path: str = os.path.join(score_path, "package.json")
        if not os.path.isfile(path):
            raise Exception(f"Invalid score path: {score_path}")

        content: bytes = gen_deploy_data_content(score_path)

        tx_handler = self._create_tx_handler()
        ret = tx_handler.update(self._owner,
                                GOVERNANCE_ADDRESS,
                                content,
                                step_limit=step_limit,
                                estimate=estimate)

        return ret
コード例 #14
0
    def update_contracts(self, contract_path: str, contract_address: str):
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(contract_address) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(contract_path)) \
            .build()
        signed_transaction = SignedTransaction(transaction, self._test1)

        # process the transaction in local
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertEqual(True, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)
        return tx_result
コード例 #15
0
    def _deploy_score(
        self,
        key_wallet: 'KeyWallet',
        path: str,
        score_address: str = SYSTEM_ADDRESS,
    ) -> dict:
        # Generates an instance of transaction for deploying SCORE.
        transaction = DeployTransactionBuilder() \
            .from_(key_wallet.get_address()) \
            .to(score_address) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(path)) \
            .build()

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(transaction, key_wallet)

        # send transaction
        return self.icon_service.send_transaction(signed_transaction)
コード例 #16
0
    def test_deploy_sICX_score(self, to=SCORE_INSTALL_ADDRESS):
        params = {'_admin': self.contracts['staking_score']}
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.sICX_SCORE)) \
            .params(params) \
            .build()
        signed_transaction = SignedTransaction(transaction, self._test1)

        # process the transaction in local
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertEqual(True, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)
        pprint(tx_result)
        return tx_result
コード例 #17
0
    def deploy_contract(self, contract_info, account_info):
        wallet = KeyWallet.load(bytes.fromhex(account_info['wallet_key']))
        contract_content_bytes = gen_deploy_data_content(
            contract_info['contract_file'])

        deploy_transaction = DeployTransactionBuilder() \
          .from_(wallet.get_address()) \
          .to(SCORE_INSTALL_ADDRESS) \
          .step_limit(self.get_max_step_limit(wallet.get_address())) \
          .nid(self.network_id) \
          .nonce(self.network_id) \
          .content_type('application/zip') \
          .content(contract_content_bytes) \
          .params(contract_info['params']) \
          .version(self.network_id) \
          .build()

        signed_transaction = SignedTransaction(deploy_transaction, wallet)
        tx_hash = self.icon_service.send_transaction(signed_transaction)
        # print('tx_hash:', tx_hash)

        tx_result = self.get_transaction_result(tx_hash)
        return tx_result
コード例 #18
0
    def _deploy_score(self, to: str = SCORE_INSTALL_ADDRESS) -> dict:
        # SCORE deploy하기 위한 transaction instance를 만든다 
        transaction = DeployTransactionBuilder() \
            .from_(self._test.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .nonce(100) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(self.SCORE_PROJECT)) \
            .build()

        # signature 를 가진 signed transaction 리턴한다
        signed_transaction = SignedTransaction(transaction, self._test)

        # 로컬에서 transaction process 한다 
        tx_result = self.process_transaction(signed_transaction)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)

        return tx_result
コード例 #19
0
    def _deploy_score(self,
                      scorepath: str,
                      to: str = SCORE_INSTALL_ADDRESS,
                      _params: dict = None) -> dict:
        transaction = DeployTransactionBuilder() \
            .from_(self._test1.get_address()) \
            .to(to) \
            .step_limit(100_000_000_000) \
            .nid(3) \
            .content_type("application/zip") \
            .content(gen_deploy_data_content(scorepath)) \
            .params(_params) \
            .build()

        signed_transaction = SignedTransaction(transaction, self._test1)
        tx_result = self.process_transaction(signed_transaction,
                                             self.icon_service)

        self.assertTrue('status' in tx_result)
        self.assertEqual(1, tx_result['status'])
        self.assertTrue('scoreAddress' in tx_result)

        return tx_result
コード例 #20
0
def deployJoinScore(wallet: KeyWallet, icon_service: IconService,
                    proccess_tx_fn) -> dict:
    dir_path = os.path.abspath(os.path.dirname(__file__))
    score_project = os.path.abspath(os.path.join(dir_path, '..'))
    score_content_bytes = gen_deploy_data_content(score_project)

    # Generates an instance of transaction for deploying SCORE.
    transaction = DeployTransactionBuilder() \
        .from_(wallet.get_address()) \
        .to(SCORE_INSTALL_ADDRESS) \
        .nid(3) \
        .step_limit(10000000000) \
        .nonce(100) \
        .content_type("application/zip") \
        .content(score_content_bytes) \
        .params({}) \
        .build()

    # Returns the signed transaction object having a signature
    signed_transaction = SignedTransaction(transaction, wallet)

    # process the transaction in local
    tx_result = proccess_tx_fn(signed_transaction, icon_service)
    return tx_result
コード例 #21
0
def get_score_content(target: str):
    score_path = f"./contracts/{target}"
    return gen_deploy_data_content(score_path)
コード例 #22
0
ファイル: command_score.py プロジェクト: xgenvn/t-bears
    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']

        uri, version = uri_parser(conf['uri'])
        icon_service = IconService(HTTPProvider(uri, version))

        if password:
            try:
                wallet = KeyWallet.load(conf['keyStore'], password)
                from_ = wallet.get_address()

            except KeyStoreException as e:
                print(e.args[0])
                return None
        else:
            # make dummy wallet
            wallet = KeyWallet.create()
            from_ = conf['from']

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

        deploy_transaction = DeployTransactionBuilder() \
            .from_(from_) \
            .to(score_address) \
            .nid(convert_hex_str_to_int(conf['nid'])) \
            .content_type("application/zip") \
            .content(content) \
            .params(conf.get('scoreParams', {})) \
            .build()

        if 'stepLimit' not in conf:
            step_limit = icon_service.estimate_step(deploy_transaction) + 10000
        else:
            step_limit = convert_hex_str_to_int(conf['stepLimit'])

        deploy_transaction.step_limit = step_limit

        # Returns the signed transaction object having a signature
        signed_transaction = SignedTransaction(deploy_transaction, wallet)

        if not password:
            signed_transaction.signed_transaction_dict['signature'] = 'sig'

        # Sends transaction and return response
        response = send_transaction_with_logger(icon_service,
                                                signed_transaction, uri)

        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
コード例 #23
0
# Returns the max step limit
def get_max_step_limit():
    _param = {"context_type": "invoke"}
    _call = CallBuilder()\
        .from_(wallet1.get_address())\
        .to(GOVERNANCE_ADDRESS)\
        .method("getMaxStepLimit")\
        .params(_param)\
        .build()
    _result = icon_service.call(_call)
    return convert_hex_str_to_int(_result)


for score_path in score_paths:
    # Reads the zip file 'standard_token.zip' and returns bytes of the file
    install_content_bytes = gen_deploy_data_content(score_path)
    # Loads a wallet from a key store file
    wallet1 = KeyWallet.load(TEST_PRIVATE_KEY)
    print("=" * 100)
    print("[wallet1] address: ", wallet1.get_address(), " private key: ",
          wallet1.get_private_key())

    # Enters transaction information
    deploy_transaction = DeployTransactionBuilder()\
        .from_(wallet1.get_address())\
        .to(SCORE_INSTALL_ADDRESS) \
        .step_limit(get_max_step_limit())\
        .nid(3)\
        .nonce(3)\
        .content_type("application/zip")\
        .content(install_content_bytes)\
コード例 #24
0
def get_token_content():
    token_score_path = path.join("./score", "sampleToken.zip")
    return gen_deploy_data_content(token_score_path)
コード例 #25
0
        .nonce(4) \
        .method("scrooge")\
        .params(params)\
        .build()
    signed_transaction = SignedTransaction(call_transaction, wallet)
    tx_hash = icon_service.send_transaction(signed_transaction)
    print(tx_hash)
    print(get_tx(tx_hash))


# 1. DeployTransactionBuilder
transaction = DeployTransactionBuilder()\
    .from_(wallet.get_address())\
    .step_limit(100_000_000_000)\
    .to("cx0000000000000000000000000000000000000000")\
    .nid(3)\
    .nonce(100)\
    .content_type("application/zip")\
    .content(gen_deploy_data_content(SCORE_PROJECT)) \
    .params("")\
    .build()

signed_transaction = SignedTransaction(transaction, wallet)
tx_hash = icon_service.send_transaction(signed_transaction)
print(tx_hash)

score_address = get_tx_result()
# 2. CallBuilder
call_score_method_welcome(score_address)
# 3. CallTransactionBuilder
transaction_scrooge(score_address)