-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifier.sol
More file actions
54 lines (43 loc) · 1.21 KB
/
Copy pathmodifier.sol
File metadata and controls
54 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract OnlineStoreVault {
address public owner;
bool public paused;
error NotOwner();
error ContractPaused();
constructor() {
owner = msg.sender;
}
// Only the owner can call the function
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
// Function can execute only when contract is active
modifier whenNotPaused() {
if (paused) revert ContractPaused();
_;
}
// Customers pay for products
function buyProduct() external payable {
require(msg.value > 0, "Send ETH");
}
// Owner can pause the contract
function pause() external onlyOwner {
paused = true;
}
// Owner can resume the contract
function unpause() external onlyOwner {
paused = false;
}
// Owner withdraws all collected payments
function withdraw()
external
onlyOwner
whenNotPaused
{
uint256 balance = address(this).balance;
(bool success, ) = payable(owner).call{value: balance}("");
require(success, "Transfer failed");
}
}