ReentrancyGuard.sol 866 B

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