gnosis/eth/ethereum_client.py
def send_unsigned_transaction(self, tx: Dict[str, any], private_key: Optional[str] = None,
                                  public_key: Optional[str] = None, retry: bool = False,
                                  block_identifier: Optional[str] = None) -> bytes:
        """
        Send a tx using an unlocked public key in the node or a private key. Both `public_key` and
        `private_key` cannot be `None`
        :param tx:
        :param private_key:
        :param public_key:
        :param retry: Retry if a problem with nonce is found
        :param block_identifier:
        :return: tx hash
        """
        if private_key:
            address = self.private_key_to_address(private_key)
        elif public_key:
            address = public_key
        else:
            logger.error('No ethereum account provided. Need a public_key or private_key')
            raise ValueError("Ethereum account was not configured or unlocked in the node")

        if tx.get('nonce') is None:
            tx['nonce'] = self.get_nonce_for_account(address, block_identifier=block_identifier)

        number_errors = 5
        while number_errors >= 0:
            try:
                if private_key:
                    signed_tx = self.w3.eth.account.signTransaction(tx, private_key=private_key)
                    logger.debug('Sending %d wei from %s to %s', tx['value'], address, tx['to'])
                    try:
                        return self.send_raw_transaction(signed_tx.rawTransaction)
                    except TransactionAlreadyImported as e:
                        # Sometimes Parity 2.2.11 fails with Transaction already imported, even if it's not, but it's
                        # processed
                        tx_hash = signed_tx.hash
                        logger.error('Transaction with tx-hash=%s already imported: %s' % (tx_hash.hex(), str(e)))
                        return tx_hash
                elif public_key:
                    tx['from'] = address
                    return self.send_transaction(tx)
            except ReplacementTransactionUnderpriced as e:
                if not retry or not number_errors:
                    raise e
                logger.error('address=%s Tx with nonce=%d was already sent, retrying with nonce + 1',
                             address, tx['nonce'])
                tx['nonce'] += 1
            except InvalidNonce as e:
                if not retry or not number_errors:
                    raise e
                logger.error('address=%s Tx with invalid nonce=%d, retrying recovering nonce again',
                             address, tx['nonce'])
                tx['nonce'] = self.get_nonce_for_account(address, block_identifier=block_identifier)
                number_errors -= 1
def send_unsigned_transaction(self, tx: Dict[str, any], private_key: Optional[str] = None,
                                  public_key: Optional[str] = None, retry: bool = False,
                                  block_identifier: Optional[str] = None) -> bytes:
        """
        Send a tx using an unlocked public key in the node or a private key. Both `public_key` and
        `private_key` cannot be `None`
        :param tx:
        :param private_key:
        :param public_key:
        :param retry: Retry if a problem with nonce is found
        :param block_identifier:
        :return: tx hash
        """
        if private_key:
            address = self.private_key_to_address(private_key)
        elif public_key:
            address = public_key
        else:
            logger.error('No ethereum account provided. Need a public_key or private_key')
            raise ValueError("Ethereum account was not configured or unlocked in the node")

        if tx.get('nonce') is None:
            tx['nonce'] = self.get_nonce_for_account(address, block_identifier=block_identifier)

        number_errors = 5
        while number_errors >= 0:
            try:
                if private_key:
                    signed_tx = self.w3.eth.account.signTransaction(tx, private_key=private_key)
                    logger.debug('Sending %d wei from %s to %s', tx['value'], address, tx['to'])
                    try:
                        return self.send_raw_transaction(signed_tx.rawTransaction)
                    except TransactionAlreadyImported as e:
                        # Sometimes Parity 2.2.11 fails with Transaction already imported, even if it's not, but it's
                        # processed
                        tx_hash = signed_tx.hash
                        logger.error('Transaction with tx-hash=%s already imported: %s' % (tx_hash.hex(), str(e)))
                        return tx_hash
                elif public_key:
                    tx['from'] = address
                    return self.send_transaction(tx)
            except ReplacementTransactionUnderpriced as e:
                if not retry or not number_errors:
                    raise e
                logger.error('address=%s Tx with nonce=%d was already sent, retrying with nonce + 1',
                             address, tx['nonce'])
                tx['nonce'] += 1
            except InvalidNonce as e:
                if not retry or not number_errors:
                    raise e
                logger.error('address=%s Tx with invalid nonce=%d, retrying recovering nonce again',
                             address, tx['nonce'])
                tx['nonce'] = self.get_nonce_for_account(address, block_identifier=block_identifier)
                number_errors -= 1
def send_unsigned_transaction ( self , tx : Dict [ str , any ] , private_key : Optional [ str ] = None , public_key : Optional [ str ] = None , retry : bool = False , block_identifier : Optional [ str ] = None ) -> bytes : if private_key : address = self . private_key_to_address ( private_key ) elif public_key : address = public_key else : logger . error ( 'No ethereum account provided. Need a public_key or private_key' ) raise ValueError ( "Ethereum account was not configured or unlocked in the node" ) if tx . get ( 'nonce' ) is None : tx [ 'nonce' ] = self . get_nonce_for_account ( address , block_identifier = block_identifier ) number_errors = 5 while number_errors >= 0 : try : if private_key : signed_tx = self . w3 . eth . account . signTransaction ( tx , private_key = private_key ) logger . debug ( 'Sending %d wei from %s to %s' , tx [ 'value' ] , address , tx [ 'to' ] ) try : return self . send_raw_transaction ( signed_tx . rawTransaction ) except TransactionAlreadyImported as e : # Sometimes Parity 2.2.11 fails with Transaction already imported, even if it's not, but it's # processed tx_hash = signed_tx . hash logger . error ( 'Transaction with tx-hash=%s already imported: %s' % ( tx_hash . hex ( ) , str ( e ) ) ) return tx_hash elif public_key : tx [ 'from' ] = address return self . send_transaction ( tx ) except ReplacementTransactionUnderpriced as e : if not retry or not number_errors : raise e logger . error ( 'address=%s Tx with nonce=%d was already sent, retrying with nonce + 1' , address , tx [ 'nonce' ] ) tx [ 'nonce' ] += 1 except InvalidNonce as e : if not retry or not number_errors : raise e logger . error ( 'address=%s Tx with invalid nonce=%d, retrying recovering nonce again' , address , tx [ 'nonce' ] ) tx [ 'nonce' ] = self . get_nonce_for_account ( address , block_identifier = block_identifier ) number_errors -= 1
Send a tx using an unlocked public key in the node or a private key. Both `public_key` and
        `private_key` cannot be `None`
        :param tx:
        :param private_key:
        :param public_key:
        :param retry: Retry if a problem with nonce is found
        :param block_identifier:
        :return: tx hash
Send a tx using an unlocked public key in the node or a private key . Both public_key and private_key cannot be None : param tx : : param private_key : : param public_key : : param retry : Retry if a problem with nonce is found : param block_identifier : : return : tx hash