-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_contract.sol
152 lines (124 loc) · 4.98 KB
/
mod_contract.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8;
contract mod_contract {
mapping(address => bool) private verified_contracts;
address public auth_addr;
uint256 public base_price;
uint256 public tax_rate;
mapping(address => bytes) private user_pk;
mapping(address => bytes) private ecdh_pub;
mapping(address => bytes) private ecdk_pk;
mapping(bytes32 => address) private address_links;
mapping(address => address) private refferal_addr;
constructor(){
base_price = 1e18;
tax_rate = 10;
auth_addr = msg.sender;
}
receive() external payable {}
modifier requireAuth(){
require(msg.sender == auth_addr);
_;
}
function migrateInternalAuthAddr(address new_owner) external requireAuth{
auth_addr = new_owner;
}
function setVerifiedContractStatus(address c_addr, bool status) external requireAuth {
verified_contracts[c_addr] = status;
}
function setBasePrice(uint256 new_bp) external requireAuth {
base_price = new_bp;
}
function sendFunds(uint256 amount, address addr) external requireAuth {
payable(addr).transfer(amount);
}
function setTaxRate(uint256 new_rate) external requireAuth {
tax_rate = new_rate;
}
function externalCallAuth(address c_addr, bytes calldata data) external requireAuth {
require(verified_contracts[c_addr]);
(bool success, ) = c_addr.call(data);
require(success);
}
function setString(bytes calldata new_string) internal {
user_pk[msg.sender] = new_string;
}
function setReferrer(address ref) internal {
if(ref != 0x0000000000000000000000000000000000000000)
refferal_addr[msg.sender] = ref;
}
function initAccount(bytes calldata new_string, bytes32 link_hash, string calldata link_str, bytes calldata new_priv, bytes calldata new_pub, address new_ref) external payable {
setReferrer(new_ref);
createAddressLink(link_hash, link_str);
setString(new_string);
setPair(new_priv, new_pub);
}
function setPair(bytes calldata new_priv, bytes calldata new_pub) public {
ecdk_pk[msg.sender] = new_priv;
ecdh_pub[msg.sender] = new_pub;
}
function createAddressLink(bytes32 link_hash, string memory link_str) public payable {
require(address_links[link_hash] == 0x0000000000000000000000000000000000000000, "link in use");
require(link_hash == keccak256(abi.encodePacked(link_str)));
uint256 str_len = strlen(link_str);
if(str_len >= 5)
require(msg.value >= base_price/100);
else if(str_len == 4)
require(msg.value >= base_price/10);
else if(str_len == 3)
require(msg.value >= base_price);
else if(str_len == 2)
require(msg.value >= base_price*10);
else if(str_len == 1)
require(msg.value >= base_price*100);
address_links[link_hash] = msg.sender;
if(refferal_addr[msg.sender] != 0x0000000000000000000000000000000000000000)
payable(refferal_addr[msg.sender]).transfer((msg.value / 100)*30);
}
function migrateAddressLink(bytes32 link_hash, address new_addr) external payable {
require(msg.value >= base_price/100);
require(address_links[link_hash] == msg.sender);
address_links[link_hash] = new_addr;
if(refferal_addr[msg.sender] != 0x0000000000000000000000000000000000000000)
payable(refferal_addr[msg.sender]).transfer((msg.value / 100)*30);
}
function getReferrer(address addr) external view returns (address) {
return refferal_addr[addr];
}
function getPrivString(address addr) external view returns (bytes memory){
return ecdk_pk[addr];
}
function getPubString(address addr) external view returns (bytes memory){
return ecdh_pub[addr];
}
function getString(address addr) external view returns (bytes memory){
return user_pk[addr];
}
function getAddressLink(bytes32 addr_link) external view returns (address){
return address_links[addr_link];
}
function isVerifiedContract(address c_addr) external view returns (bool) {
return verified_contracts[c_addr];
}
function strlen(string memory link_str) internal pure returns (uint256) {
uint256 len;
uint256 i = 0;
uint256 bytelength = bytes(link_str).length;
for (len = 0; i < bytelength; len++) {
bytes1 b = bytes(link_str)[i];
if (b < 0x80)
i += 1;
else if (b < 0xE0)
i += 2;
else if (b < 0xF0)
i += 3;
else if (b < 0xF8)
i += 4;
else if (b < 0xFC)
i += 5;
else
i += 6;
}
return len;
}
}