Commit 60a04f3c authored by Conner Fromknecht's avatar Conner Fromknecht

feat: inline/simplify receive modifiers

parent fdc3006e
......@@ -11,51 +11,36 @@ contract TeleportrDeposit {
address public owner;
uint256 public maxDepositAmount;
uint256 public maxBalance;
bool public canReceiveDeposit;
// Events
event OwnerSet(address indexed oldOwner, address indexed newOwner);
event MaxDepositAmountSet(uint256 previousAmount, uint256 newAmount);
event CanReceiveDepositSet(bool canReceiveDeposit);
event MaxBalanceSet(uint256 previousBalance, uint256 newBalance);
event BalanceWithdrawn(address indexed owner, uint256 balance);
event EtherReceived(address indexed emitter, uint256 amount);
// Modifiers
modifier isLowerThanMaxDepositAmount() {
require(msg.value <= maxDepositAmount, "Deposit amount is too big");
_;
}
modifier isOwner() {
require(msg.sender == owner, "Caller is not owner");
_;
}
modifier canReceive() {
require(canReceiveDeposit == true, "Contract is not allowed to receive ether");
_;
}
modifier isLowerThanMaxBalance() {
require(address(this).balance <= maxBalance, "Contract reached the max balance allowed");
_;
}
constructor(
uint256 _maxDepositAmount,
uint256 _maxBalance,
bool _canReceiveDeposit
) {
constructor(uint256 _maxDepositAmount, uint256 _maxBalance) {
owner = msg.sender;
maxDepositAmount = _maxDepositAmount;
maxBalance = _maxBalance;
canReceiveDeposit = _canReceiveDeposit;
emit OwnerSet(address(0), msg.sender);
emit MaxDepositAmountSet(0, _maxDepositAmount);
emit MaxBalanceSet(0, _maxBalance);
emit CanReceiveDepositSet(_canReceiveDeposit);
}
// Receive function which reverts if amount > maxDepositAmount and canReceiveDeposit = false
receive() external payable isLowerThanMaxDepositAmount canReceive isLowerThanMaxBalance {
// Receive function which reverts if the amount is greater than
// maxDepositAmount, or the amount would put the contract over its
// maxBalance.
receive() external payable {
require(msg.value <= maxDepositAmount, "Deposit amount is too big");
require(address(this).balance <= maxBalance, "Contract max balance exceeded");
emit EtherReceived(msg.sender, msg.value);
}
......@@ -77,11 +62,6 @@ contract TeleportrDeposit {
owner = newOwner;
}
function setCanReceiveDeposit(bool _canReceiveDeposit) external isOwner {
emit CanReceiveDepositSet(_canReceiveDeposit);
canReceiveDeposit = _canReceiveDeposit;
}
function setMaxBalance(uint256 _maxBalance) external isOwner {
emit MaxBalanceSet(maxBalance, _maxBalance);
maxBalance = _maxBalance;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment