Ejemplo n.º 1
0
    def set_nonce_sign_and_save_tx(self, sign_tx: Callable[[Transaction],
                                                           None],
                                   tx: Transaction) -> None:
        """
        Sets the next nonce for the transaction, invokes the callback for
        signing and saves it to the storage.
        """
        global_transaction_state = self._get_locked_global_transaction_state()

        tx.nonce = self._get_nonce()
        sign_tx(tx)
        logger.info(
            'Saving transaction %s, nonce=%d',
            encode_hex(tx.hash),
            tx.nonce,
        )

        pending_ethereum_transaction = PendingEthereumTransaction(
            nonce=tx.nonce,
            gasprice=tx.gasprice,
            startgas=tx.startgas,
            value=tx.value,
            v=tx.v,
            r=tx.r,
            s=tx.s,
            data=tx.data,
            to=tx.to,
        )
        pending_ethereum_transaction.full_clean()
        pending_ethereum_transaction.save()

        global_transaction_state.nonce += 1
        global_transaction_state.full_clean()
        global_transaction_state.save()
 def set_nonce_sign_and_save_tx(self, sign_tx: Callable[[Transaction],
                                                        None],
                                tx: Transaction) -> None:
     tx.nonce = self._data['nonce']
     sign_tx(tx)
     logger.info(
         'Saving transaction %s, nonce=%d',
         encode_hex(tx.hash),
         tx.nonce,
     )
     # Use temporary copy because we don't want to modify the state if
     # writing to the file fails
     new_data = dict(self._data)
     new_data['nonce'] = tx.nonce + 1
     new_data['tx'][tx.nonce] = {
         'nonce': tx.nonce,
         'gasprice': tx.gasprice,
         'startgas': tx.startgas,
         'to': HexBytes(tx.to).hex(),
         'value': tx.value,
         'data': HexBytes(tx.data).hex(),
         'v': tx.v,
         'r': tx.r,
         's': tx.s,
     }
     self._save(new_data)
     self._data = new_data