33 lines
872 B
Solidity
33 lines
872 B
Solidity
pragma solidity ^0.4.18;
|
|
|
|
|
|
/**
|
|
* @title Helps contracts guard agains reentrancy attacks.
|
|
* @author Remco Bloemen <remco@2π.com>
|
|
* @notice If you mark a function `nonReentrant`, you should also
|
|
* mark it `external`.
|
|
*/
|
|
contract ReentrancyGuard {
|
|
|
|
/**
|
|
* @dev We use a single lock for the whole contract.
|
|
*/
|
|
bool private reentrancy_lock = false;
|
|
|
|
/**
|
|
* @dev Prevents a contract from calling itself, directly or indirectly.
|
|
* @notice If you mark a function `nonReentrant`, you should also
|
|
* mark it `external`. Calling one nonReentrant function from
|
|
* another is not supported. Instead, you can implement a
|
|
* `private` function doing the actual work, and a `external`
|
|
* wrapper marked as `nonReentrant`.
|
|
*/
|
|
modifier nonReentrant() {
|
|
require(!reentrancy_lock);
|
|
reentrancy_lock = true;
|
|
_;
|
|
reentrancy_lock = false;
|
|
}
|
|
|
|
}
|