ReentrancyGuard.sol 878 B

12345678910111213141516171819202122232425262728
  1. pragma solidity ^0.4.8;
  2. /// @title Helps contracts guard agains rentrancy attacks.
  3. /// @author Remco Bloemen <remco@2π.com>
  4. /// @notice If you mark a function `nonReentrant`, you should also
  5. /// mark it `external`.
  6. contract ReentrancyGuard {
  7. /// @dev We use a single lock for the whole contract.
  8. bool private rentrancy_lock = false;
  9. /// Prevent contract from calling itself, directly or indirectly.
  10. /// @notice If you mark a function `nonReentrant`, you should also
  11. /// mark it `external`. Calling one nonReentrant function from
  12. /// another is not supported. Instead, you can implement a
  13. /// `private` function doing the actual work, and a `external`
  14. /// wrapper marked as `nonReentrant`.
  15. modifier nonReentrant() {
  16. if(rentrancy_lock == false) {
  17. rentrancy_lock = true;
  18. _;
  19. rentrancy_lock = false;
  20. } else {
  21. throw;
  22. }
  23. }
  24. }