forked from AlohaEOS/valueproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbptracking.cpp
More file actions
executable file
·108 lines (93 loc) · 4 KB
/
Copy pathbptracking.cpp
File metadata and controls
executable file
·108 lines (93 loc) · 4 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
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
#include "bptracking.hpp"
void bptracking::registeracc(name account, asset max_outgo, std::string weblink) {
require_auth(account);
check(max_outgo.symbol == symbol(symbol_code("EOS"), 4),"symbol must be EOS");
check(weblink != "","missing weblink");
whitelist_index whitelist(_self, _self.value);
auto whitelistitr = whitelist.find(account.value);
check(whitelistitr != whitelist.end(), "account name needs to be whitelisted first before registering");
registration_index registrations(_self, _self.value);
auto itr = registrations.find(account.value);
if (itr == registrations.end()) {
registrations.emplace(_self, [&](auto &e) {
e.account_name = account;
e.total_eos = asset(0, symbol(symbol_code("EOS"), 4));
e.max_outgo = max_outgo;
e.weblink = weblink;
});
} else {
registrations.modify(itr, _self, [&](auto &e) {
e.max_outgo = max_outgo;
e.weblink = weblink;
});
}
}
void bptracking::removereg(name account) {
check(has_auth(_self) || has_auth(account), "missing required authority of contract account or registering account");
registration_index registrations(_self, _self.value);
auto itr = registrations.find(account.value);
check(itr != registrations.end(), "account not found");
check(itr->total_eos.amount == 0, "balance must be zero before removal");
registrations.erase(itr);
}
void bptracking::whitelistacc(name username) {
require_auth(_self);
whitelist_index whitelist(_self, _self.value);
auto itr = whitelist.find(username.value);
check(itr == whitelist.end(), "account name already whitelisted");
whitelist.emplace(_self, [&](auto &e) {
e.username = username;
});
}
void bptracking::reclaim(name username, asset amount) {
require_auth(username);
registration_index registrations(_self, _self.value);
auto itr = registrations.find(username.value);
check(itr != registrations.end(), "account name is not registered yet");
check(itr->total_eos >= amount, "Reaclaim amount is greater than available total eos for this account");
action(
permission_level{_self, "active"_n},
"eosio.token"_n, "transfer"_n,
std::make_tuple(_self, itr->account_name, amount, std::string("reclaim transfer")))
.send();
registrations.modify(itr, _self, [&](auto &e) {
e.total_eos -= amount;
});
}
void bptracking::deduct(name username, asset amount, std::string memo) {
require_auth(_self);
registration_index registrations(_self, _self.value);
auto itr = registrations.find(username.value);
check(itr != registrations.end(), "Account name is not registered");
check(itr->total_eos >= amount, "Deduct amount is greater than available total eos for this account");
registrations.modify(itr, _self, [&](auto &e) {
e.total_eos -= amount;
});
}
void bptracking::transfer(name payer, name reciever, asset value, std::string memo) {
if (reciever == _self) {
vector<string> memo_split = split(memo, ":");
name account = name(memo_split[1].c_str());
print("acc name ==>", account);
if (!account) {
account = payer;
}
registration_index registrations(_self, _self.value);
auto itr = registrations.find(account.value);
check(itr != registrations.end(), "account name is not registered yet to send EOS");
if (itr != registrations.end()) {
registrations.modify(itr, _self, [&](auto &e) {
e.total_eos += value;
});
}
}
}
extern "C" void apply(uint64_t receiver, uint64_t code, uint64_t action) {
if (action == "transfer"_n.value && code != receiver && code == name("eosio.token").value) {
execute_action(name(receiver), name(code), &bptracking::transfer);
} else if (code == receiver) {
switch (action) {
EOSIO_DISPATCH_HELPER(bptracking, (registeracc)(removereg)(whitelistacc)(reclaim)(deduct))
}
}
}