Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/PaymentGateway.sol": {
"content": "// SPDX-License-Identifier: MIT\r
pragma solidity ^0.8.20;\r
\r
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";\r
\r
/*\r
ETH PAYMENT GATEWAY\r
Secure fund pooling, owner control, backup recovery\r
Email hashing for cheaper storage + privacy\r
Enhanced with ReentrancyGuard for security\r
*/\r
\r
contract PaymentPoolETH is ReentrancyGuard {\r
\r
address public owner;\r
address public backupOwner;\r
\r
struct Payment {\r
uint256 amount;\r
uint256 timestamp;\r
address wallet;\r
}\r
\r
mapping(bytes32 => Payment[]) private payments;\r
\r
event PaymentReceived(bytes32 indexed emailHash, address indexed wallet, uint256 amount, uint256 timestamp);\r
event OwnerWithdraw(address indexed to, uint256 amount);\r
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);\r
event EmergencyOwnerRecovered(address indexed recoveredBy);\r
event EmergencyWithdrawDone(address indexed to, uint256 amount);\r
event ETHReceivedDirect(address indexed from, uint256 amount, uint256 timestamp);\r
\r
modifier onlyOwner() {\r
require(msg.sender == owner, "Not authorized");\r
_;\r
}\r
\r
modifier onlyBackupOwner() {\r
require(msg.sender == backupOwner, "Not authorized");\r
_;\r
}\r
\r
constructor(address _backupOwner) {\r
require(_backupOwner != address(0), "Invalid backup owner");\r
owner = msg.sender;\r
backupOwner = _backupOwner;\r
}\r
\r
// Deposit ETH with email tracking\r
function deposit(string memory email) external payable {\r
require(msg.value > 0, "Payment must be > 0");\r
bytes32 emailHash = keccak256(abi.encodePacked(email));\r
payments[emailHash].push(Payment({\r
amount: msg.value,\r
timestamp: block.timestamp,\r
wallet: msg.sender\r
}));\r
emit PaymentReceived(emailHash, msg.sender, msg.value, block.timestamp);\r
}\r
\r
// Owner withdraws pooled funds for trading\r
function withdraw(uint256 amount) external onlyOwner nonReentrant {\r
require(address(this).balance >= amount, "Insufficient balance");\r
(bool success, ) = payable(owner).call{value: amount}("");\r
require(success, "Transfer failed");\r
emit OwnerWithdraw(owner, amount);\r
}\r
\r
// Standard ownership handover\r
function transferOwnership(address newOwner) external onlyOwner {\r
require(newOwner != address(0), "Invalid owner");\r
emit OwnershipTransferred(owner, newOwner);\r
owner = newOwner;\r
}\r
\r
// Backup admin takes over if owner loses wallet\r
function emergencyRecoverOwnership() external onlyBackupOwner {\r
emit EmergencyOwnerRecovered(msg.sender);\r
owner = backupOwner;\r
}\r
\r
// Backup admin empties pool in critical situations\r
function emergencyWithdraw() external onlyBackupOwner nonReentrant {\r
uint256 total = address(this).balance;\r
require(total > 0, "Nothing to withdraw");\r
(bool success, ) = payable(backupOwner).call{value: total}("");\r
require(success, "Emergency transfer failed");\r
emit EmergencyWithdrawDone(backupOwner, total);\r
}\r
\r
// Transparency for depositors\r
function getPayments(string memory email) external view returns(Payment[] memory) {\r
bytes32 emailHash = keccak256(abi.encodePacked(email));\r
return payments[emailHash];\r
}\r
\r
// View contract pool balance\r
function getBalance() external view returns(uint256) {\r
return address(this).balance;\r
}\r
\r
// Accept plain ETH transfers\r
receive() external payable {\r
emit ETHReceivedDirect(msg.sender, msg.value, block.timestamp);\r
}\r
}\r
"
},
"@openzeppelin/contracts/security/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.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.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being 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 percentage 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.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @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 making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-10-27 11:55:06
Comments
Log in to comment.
No comments yet.