Esempio n. 1
0
    def transact(
        self,
        function_name: str,
        startgas: int,
        *args,
        **kargs,
    ) -> typing.TransactionHash:
        data = ContractProxy.get_transaction_data(
            self.contract.abi,
            function_name,
            args=args,
            kwargs=kargs,
        )

        try:
            txhash = self.jsonrpc_client.send_transaction(
                to=self.contract.address,
                startgas=startgas,
                value=kargs.pop('value', 0),
                data=decode_hex(data),
            )
        except ValueError as e:
            action = inspect_client_error(e, self.jsonrpc_client.eth_node)
            if action == ClientErrorInspectResult.INSUFFICIENT_FUNDS:
                raise InsufficientFunds('Insufficient ETH for transaction')
            elif action == ClientErrorInspectResult.TRANSACTION_UNDERPRICED:
                raise ReplacementTransactionUnderpriced(
                    'Transaction was rejected. This is potentially '
                    'caused by the reuse of the previous transaction '
                    'nonce as well as paying an amount of gas less than or '
                    'equal to the previous transaction\'s gas amount', )
            elif action == ClientErrorInspectResult.TRANSACTION_PENDING:
                raise TransactionAlreadyPending(
                    'The transaction has already been submitted. Please '
                    'wait until is has been mined or increase the gas price.',
                )
            elif action == ClientErrorInspectResult.TRANSACTION_ALREADY_IMPORTED:
                # This is like TRANSACTION_PENDING is for geth but happens in parity
                # Unlike with geth this can also happen without multiple transactions
                # being sent via RPC -- due to probably some parity bug:
                # https://github.com/raiden-network/raiden/issues/3211
                # We will try to not crash by looking into the local parity
                # transaction pool to retrieve the transaction hash
                hex_address = to_checksum_address(self.jsonrpc_client.address)
                txhash = self.jsonrpc_client.parity_get_pending_transaction_hash_by_nonce(
                    address=hex_address,
                    nonce=self.jsonrpc_client._available_nonce,
                )
                if txhash:
                    raise TransactionAlreadyPending(
                        'Transaction was submitted via parity but parity saw it as'
                        ' already pending. Could not find the transaction in the '
                        'local transaction pool. Bailing ...', )
                return txhash

            raise e

        return txhash
Esempio n. 2
0
    def transact(self, function_name: str, startgas: int, *args, **kargs):
        data = ContractProxy.get_transaction_data(self.contract.abi, function_name, args)

        try:
            txhash = self.jsonrpc_client.send_transaction(
                to=self.contract.address,
                startgas=startgas,
                value=kargs.pop('value', 0),
                data=decode_hex(data),
                **kargs,
            )
        except ValueError as e:
            action = inspect_client_error(e, self.jsonrpc_client.eth_node)
            if action == ClientErrorInspectResult.INSUFFICIENT_FUNDS:
                raise InsufficientFunds('Insufficient ETH for transaction')
            elif action == ClientErrorInspectResult.TRANSACTION_UNDERPRICED:
                raise ReplacementTransactionUnderpriced(
                    'Transaction was rejected. This is potentially '
                    'caused by the reuse of the previous transaction '
                    'nonce as well as paying an amount of gas less than or '
                    'equal to the previous transaction\'s gas amount',
                )
            elif action == ClientErrorInspectResult.TRANSACTION_PENDING:
                raise TransactionAlreadyPending(
                    'The transaction has already been submitted. Please '
                    'wait until is has been mined or increase the gas price.',
                )

            raise e

        return txhash