Example #1
0
    def sendtx(self, conf: dict):
        """Send transaction.

        :param conf: sendtx command configuration.
        :return: response of transfer.
        """
        with open(conf['json_file'], 'r') as jf:
            payload = json.load(jf)

        password = conf.get('password', None)
        password = self._check_sendtx(conf, password)

        if password:
            sendtx = IconJsonrpc.from_key_store(conf['keyStore'], password)
            params = payload['params']
            jsonrpc_params_to_pep_style(params)
            payload = sendtx.sendTransaction(**params)

        icon_client = IconClient(conf['uri'])
        response = icon_client.send(request=payload)

        if 'result' in response:
            print('Send transaction request successfully.')
            tx_hash = response['result']
            print(f"transaction hash: {tx_hash}")
        else:
            print('Got an error response')
            print(json.dumps(response, indent=4))

        return response
Example #2
0
    def sendtx(self, conf: dict):
        """Send transaction.

        :param conf: sendtx command configuration.
        :return: response of transfer.
        """
        with open(conf['json_file'], 'r') as jf:
            payload = json.load(jf)

        password = conf.get('password', None)
        password = self._check_sendtx(conf, password)

        if password:
            sendtx = IconJsonrpc.from_key_store(conf['keyStore'], password)
        else:
            sendtx = IconJsonrpc.from_string(payload['params']['from'])

        params = payload['params']
        params['from'] = None
        jsonrpc_params_to_pep_style(params)
        payload = sendtx.sendTransaction(**params)

        uri = conf['uri']
        step_limit = payload['params']['stepLimit']
        if step_limit is None:
            step_limit = conf.get('stepLimit', None)
            if step_limit is None:
                step_limit = get_enough_step(payload, uri)
            else:
                step_limit = int(step_limit, 16)
            payload['params']['stepLimit'] = hex(step_limit)
            sendtx.put_signature(payload['params'])

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

        if 'result' in response:
            print('Send transaction request successfully.')
            tx_hash = response['result']
            print(f"transaction hash: {tx_hash}")
        else:
            print('Got an error response')
            print(json.dumps(response, indent=4))

        return response