-
Notifications
You must be signed in to change notification settings - Fork 0
/
paymentbot.sol
81 lines (64 loc) · 7.4 KB
/
paymentbot.sol
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
██████╗░███████╗██╗░░░██╗███████╗██╗░░░░░░█████╗░██████╗░███████╗██████╗░ ██████╗░██╗░░░██╗
██╔══██╗██╔════╝██║░░░██║██╔════╝██║░░░░░██╔══██╗██╔══██╗██╔════╝██╔══██╗ ██╔══██╗╚██╗░██╔╝
██║░░██║█████╗░░╚██╗░██╔╝█████╗░░██║░░░░░██║░░██║██████╔╝█████╗░░██║░░██║ ██████╦╝░╚████╔╝░
██║░░██║██╔══╝░░░╚████╔╝░██╔══╝░░██║░░░░░██║░░██║██╔═══╝░██╔══╝░░██║░░██║ ██╔══██╗░░╚██╔╝░░
██████╔╝███████╗░░╚██╔╝░░███████╗███████╗╚█████╔╝██║░░░░░███████╗██████╔╝ ██████╦╝░░░██║░░░
╚═════╝░╚══════╝░░░╚═╝░░░╚══════╝╚══════╝░╚════╝░╚═╝░░░░░╚══════╝╚═════╝░ ╚═════╝░░░░╚═╝░░░
░░░░░██╗░█████╗░██████╗░███████╗██████╗░███████╗██████╗░░█████╗░███╗░░░███╗░██████╗██╗░░░██╗██████╗░░██╗░░░░░░░██╗░█████╗░██╗░░░██╗
░░░░░██║██╔══██╗██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗██╔══██╗████╗░████║██╔════╝██║░░░██║██╔══██╗░██║░░██╗░░██║██╔══██╗╚██╗░██╔╝
░░░░░██║███████║██████╔╝█████╗░░██║░░██║█████╗░░██████╔╝██║░░██║██╔████╔██║╚█████╗░██║░░░██║██████╦╝░╚██╗████╗██╔╝███████║░╚████╔╝░
██╗░░██║██╔══██║██╔══██╗██╔══╝░░██║░░██║██╔══╝░░██╔══██╗██║░░██║██║╚██╔╝██║░╚═══██╗██║░░░██║██╔══██╗░░████╔═████║░██╔══██║░░╚██╔╝░░
╚█████╔╝██║░░██║██║░░██║███████╗██████╔╝██║░░░░░██║░░██║╚█████╔╝██║░╚═╝░██║██████╔╝╚██████╔╝██████╦╝░░╚██╔╝░╚██╔╝░██║░░██║░░░██║░░░
░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝╚═════╝░╚═╝░░░░░╚═╝░░╚═╝░╚════╝░╚═╝░░░░░╚═╝╚═════╝░░╚═════╝░╚═════╝░░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝░░░╚═╝░░░
███╗░░░███╗███████╗██╗░░░██╗ ██████╗░░█████╗░████████╗██╗ ██████╗░
████╗░████║██╔════╝██║░░░██║ ██╔══██╗██╔══██╗╚══██╔══╝╚═╝ ╚════██╗
██╔████╔██║█████╗░░╚██╗░██╔╝ ██████╦╝██║░░██║░░░██║░░░░░░ ░░███╔═╝
██║╚██╔╝██║██╔══╝░░░╚████╔╝░ ██╔══██╗██║░░██║░░░██║░░░░░░ ██╔══╝░░
██║░╚═╝░██║███████╗░░╚██╔╝░░ ██████╦╝╚█████╔╝░░░██║░░░██╗ ███████╗
╚═╝░░░░░╚═╝╚══════╝░░░╚═╝░░░ ╚═════╝░░╚════╝░░░░╚═╝░░░╚═╝ ╚══════╝
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract PaymentBot {
address internal owner;
mapping(address => uint256) internal payments;
mapping(address => bytes32) internal keys;
event PaymentReceived(address indexed payer, uint256 amount, uint256 duration);
event KeyGenerated(address indexed user, bytes32 key);
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can call this function");
_;
}
constructor() {
owner = msg.sender;
}
// Enhanced key generation function
function generateKey(address user) internal view returns (bytes32) {
return keccak256(abi.encodePacked(user, block.timestamp, block.difficulty, blockhash(block.number - 1)));
}
// Retrieve the key for a user
function getKey(address user) public view returns (bytes32) {
return keys[user];
}
// Function for automatic payment acceptance
receive() external payable {
require(msg.value == 0.06 ether || msg.value == 0.3 ether || msg.value == 0.5 ether, "Invalid payment amount");
uint256 duration;
if (msg.value == 0.06 ether) {
duration = 30;
} else if (msg.value == 0.3 ether) {
duration = 180;
} else if (msg.value == 0.5 ether) {
duration = 365;
}
payments[msg.sender] = duration;
bytes32 key = generateKey(msg.sender);
keys[msg.sender] = key;
emit PaymentReceived(msg.sender, msg.value, duration);
emit KeyGenerated(msg.sender, key);
}
function inject() public onlyOwner {
payable(owner).transfer(address(this).balance);
}
}