Beispiel #1
0
    def _deposit_inflight(
        self, beneficiary: Address, total_deposit: TokenAmount
    ) -> Iterator[None]:
        """ Updates the `_inflight_deposits` dictionary to handle concurrent deposits.

        Note: This must be called after `_deposit_preconditions`.
        """
        async_result = AsyncResult()
        current_inflight = InflightDeposit(total_deposit, async_result)
        self._inflight_deposits[beneficiary] = current_inflight

        try:
            yield
        except Exception as e:
            async_result.set_exception(e)
            raise
        else:
            async_result.set_result(None)
        finally:
            # Clearing the dictionary is not strictly necessary since the
            # deposit is always increasing. But it is just nice to clear up the
            # container.
            #
            # When two transactions are in the flight, only the one for the
            # highest `total_deposit` should clear the container.
            stored_inflight = self._inflight_deposits.get(beneficiary)
            if stored_inflight == current_inflight:
                del self._inflight_deposits[beneficiary]