Example #1
0
    def send_raw_transaction(self, tx: Transaction) -> str:
        """
        This interface is used to send the transaction into the network.

        Args:
         tx (Transaction):
            Transaction object in ontology Python SDK.

        Return:
            a hexadecimal transaction hash value.
        """

        buf = tx.serialize()
        tx_data = buf.hex()
        payload = RpcClient.set_json_rpc_version(RPC_SEND_TRANSACTION, [tx_data])
        try:
            response = HttpRequest.request("post", self.addr, payload)
        except requests.exceptions.ConnectTimeout:
            raise SDKException(ErrorCode.other_error(''.join(['ConnectTimeout: ', self.addr])))
        except requests.exceptions.ConnectionError:
            raise SDKException(ErrorCode.other_error(''.join(['ConnectionError: ', self.addr])))
        data = json.loads(response.content.decode())
        res = data["result"]
        if data["error"] != 0:
            raise SDKException(ErrorCode.other_error(res))
        return res
Example #2
0
    def send_raw_transaction_pre_exec(self, tx: Transaction):
        """
        This interface is used to send the transaction that is prepare to execute.

        Args:
         tx (Transaction):
            Transaction object in ontology Python SDK.

        Return:
            the execution result of transaction that is prepare to execute.
        """

        buf = tx.serialize()
        tx_data = buf.hex()
        payload = RpcClient.set_json_rpc_version(RPC_SEND_TRANSACTION, [tx_data, 1])
        try:
            response = HttpRequest.request("post", self.addr, payload)
        except requests.exceptions.ConnectTimeout:
            raise SDKException(ErrorCode.other_error(''.join(['ConnectTimeout: ', self.addr])))
        except requests.exceptions.ConnectionError:
            raise SDKException(ErrorCode.other_error(''.join(['ConnectionError: ', self.addr])))
        res = json.loads(response.content.decode())
        err = res["error"]
        if err > 0:
            try:
                result = res['result']
                raise RuntimeError(result)
            except KeyError:
                raise RuntimeError('send raw transaction pre-execute error')
        if res["result"]["State"] == 0:
            raise RuntimeError("State = 0")
        return res["result"]["Result"]
Example #3
0
 def send_raw_transaction(self, tx: Transaction):
     buf = tx.serialize()
     tx_data = buf.hex()
     rpc_struct = self.set_json_rpc_version(RPC_SEND_TRANSACTION, [tx_data])
     r = HttpRequest.request("post", self.addr, rpc_struct)
     res = json.loads(r.content.decode())["result"]
     return res
Example #4
0
 def send_raw_transaction(self, tx: Transaction, is_full: bool = False):
     hex_tx_data = tx.serialize(is_hex=True)
     data = f'{{"Action":"sendrawtransaction", "Version":"1.0.0","Data":"{hex_tx_data}"}}'
     url = RestfulMethod.send_transaction(self._url)
     response = self.__post(url, data)
     if is_full:
         return response
     return response['Result']
Example #5
0
 async def send_raw_transaction_pre_exec(self,
                                         tx: Transaction,
                                         is_full: bool = False):
     tx_data = tx.serialize(is_hex=True)
     msg = dict(Action='sendrawtransaction',
                Version='1.0.0',
                Id=self.__id,
                PreExec='1',
                Data=tx_data)
     return await self.__send_recv(msg, is_full)
Example #6
0
 async def send_raw_transaction_pre_exec(self, tx: Transaction, is_full: bool = False):
     """
     This interface is used to send the transaction that is prepare to execute.
     """
     tx_data = tx.serialize(is_hex=True)
     payload = self.generate_json_rpc_payload(RpcMethod.SEND_TRANSACTION, [tx_data, 1])
     response = await self.__post(payload)
     if is_full:
         return response
     return response['result']
Example #7
0
 async def send_raw_transaction(self, tx: Transaction, is_full: bool = False) -> str:
     """
     This interface is used to send the transaction into the network.
     """
     tx_data = tx.serialize(is_hex=True)
     payload = self.generate_json_rpc_payload(RpcMethod.SEND_TRANSACTION, [tx_data])
     response = await self.__post(payload)
     if is_full:
         return response
     result = response['result']
     return dict() if result is None else result
Example #8
0
 def send_raw_transaction(self, tx: Transaction, is_full: bool = False) -> str:
     """
     This interface is used to send the transaction into the network.
     :param tx: Transaction object in ontology Python SDK.
     :param is_full:
     :return: a hexadecimal transaction hash value.
     """
     tx_data = tx.serialize(is_hex=True)
     payload = self.generate_json_rpc_payload(RpcMethod.SEND_TRANSACTION, [tx_data])
     response = self.__post(self.__url, payload)
     if is_full:
         return response
     return response['result']
Example #9
0
    def send_raw_transaction_pre_exec(self, tx: Transaction, is_full: bool = False):
        """
        This interface is used to send the transaction that is prepare to execute.

        :param tx: Transaction object in ontology Python SDK.
        :param is_full: Whether to return all information.
        :return: the execution result of transaction that is prepare to execute.
        """
        tx_data = tx.serialize(is_hex=True)
        payload = self.generate_json_rpc_payload(RpcMethod.SEND_TRANSACTION, [tx_data, 1])
        response = self.__post(self.__url, payload)
        if is_full:
            return response
        return response['result']
Example #10
0
 def send_raw_transaction_preexec(self, tx: Transaction):
     buf = tx.serialize()
     tx_data = buf.hex()
     rpc_struct = self.set_json_rpc_version(RPC_SEND_TRANSACTION,
                                            [tx_data, 1])
     r = HttpRequest.request("post", self.addr, rpc_struct)
     res = json.loads(r.content.decode())
     #print(res)
     err = res["error"]
     if err > 0:
         raise RuntimeError("error > 0")
     if res["result"]["State"] == 0:
         raise RuntimeError("State = 0")
     return res["result"]["Result"]
Example #11
0
    def send_raw_transaction_pre_exec(self, tx: Transaction):
        """
        This interface is used to send the transaction that is prepare to execute.

        Args:
         tx (Transaction):
            Transaction object in ontology Python SDK.

        Return:
            the execution result of transaction that is prepare to execute.
        """

        buf = tx.serialize()
        tx_data = buf.hex()
        rpc_struct = RpcClient.set_json_rpc_version(RPC_SEND_TRANSACTION,
                                                    [tx_data, 1])
        r = HttpRequest.request("post", self.addr, rpc_struct)
        res = json.loads(r.content.decode())
        return res
Example #12
0
    def send_raw_transaction(self, tx: Transaction) -> str:
        """
        This interface is used to send the transaction into the network.

        Args:
         tx (Transaction):
            Transaction object in ontology Python SDK.

        Return:
            a hexadecimal transaction hash value.
        """

        buf = tx.serialize()
        tx_data = buf.hex()
        rpc_struct = RpcClient.set_json_rpc_version(RPC_SEND_TRANSACTION, [tx_data])
        r = HttpRequest.request("post", self.addr, rpc_struct)
        data = json.loads(r.content.decode())
        res = data["result"]
        if data["error"] != 0:
            raise SDKException(ErrorCode.other_error(res))
        return res