You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
2.0 KiB
51 lines
2.0 KiB
pragma solidity ^0.5.0;
|
|
|
|
/**
|
|
* @dev Contract module that helps prevent reentrant calls to a function.
|
|
*
|
|
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
|
|
* available, which can be applied to functions to make sure there are no nested
|
|
* (reentrant) calls to them.
|
|
*
|
|
* Note that because there is a single `nonReentrant` guard, functions marked as
|
|
* `nonReentrant` may not call one another. This can be worked around by making
|
|
* those functions `private`, and then adding `external` `nonReentrant` entry
|
|
* points to them.
|
|
*
|
|
* _Since v2.5.0:_ this module is now much more gas efficient, given net gas
|
|
* metering changes introduced in the Istanbul hardfork.
|
|
*/
|
|
contract ReentrancyGuard {
|
|
bool private _notEntered;
|
|
|
|
constructor () internal {
|
|
// Storing an initial non-zero value makes deployment a bit more
|
|
// expensive, but in exchange the refund on every call to nonReentrant
|
|
// will be lower in amount. Since refunds are capped to a percetange of
|
|
// the total transaction's gas, it is best to keep them low in cases
|
|
// like this one, to increase the likelihood of the full refund coming
|
|
// into effect.
|
|
_notEntered = true;
|
|
}
|
|
|
|
/**
|
|
* @dev Prevents a contract from calling itself, directly or indirectly.
|
|
* Calling a `nonReentrant` function from another `nonReentrant`
|
|
* function is not supported. It is possible to prevent this from happening
|
|
* by making the `nonReentrant` function external, and make it call a
|
|
* `private` function that does the actual work.
|
|
*/
|
|
modifier nonReentrant() {
|
|
// On the first call to nonReentrant, _notEntered will be true
|
|
require(_notEntered, "ReentrancyGuard: reentrant call");
|
|
|
|
// Any calls to nonReentrant after this point will fail
|
|
_notEntered = false;
|
|
|
|
_;
|
|
|
|
// By storing the original value once again, a refund is triggered (see
|
|
// https://eips.ethereum.org/EIPS/eip-2200)
|
|
_notEntered = true;
|
|
}
|
|
}
|
|
|