-
Notifications
You must be signed in to change notification settings - Fork 16
/
proxytoken.cpp
55 lines (46 loc) · 1.64 KB
/
proxytoken.cpp
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
#include <eosiolib/eosio.hpp>
#include <eosiolib/currency.hpp>
#include <eosio.token.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
using namespace eosio;
using std::string;
class proxytoken : contract {
private:
string getAccountNameFromMemo(const string& str){
std::vector<std::string> words;
boost::split(words, str, boost::is_any_of(" "), boost::token_compress_on);
return words[0];
}
public:
using contract::contract;
proxytoken( name self ) : contract(self){}
void empty(){}
void receivedTokens( const currency::transfer& t, account_name code ) {
if( t.to == _self ) {
string cMemo = t.memo;
string stringName(getAccountNameFromMemo(cMemo));
account_name to = string_to_name(stringName.c_str());
string memo = cMemo.replace(0, cMemo.size() > stringName.size() ? stringName.size()+1 : stringName.size(), "");
INLINE_ACTION_SENDER(eosio::token, transfer)( code, {{_self,N(active)}}, {_self, to, t.quantity, memo} );
}
}
void apply( account_name contract, account_name action ) {
if( action == N(transfer) ) {
receivedTokens( unpack_action_data<eosio::currency::transfer>(), contract );
return;
}
if( contract != _self ) return;
auto& thiscontract = *this;
switch( action ) {
EOSIO_API( proxytoken, (empty) )
};
}
};
extern "C" {
[[noreturn]] void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
proxytoken c( receiver );
c.apply( code, action );
eosio_exit(0);
}
}