#include "simple.token.hpp"
#include <eosiolib/eosio.hpp>
#include <eosiolib/asset.hpp>
void token::add_balance(account_name payer,account_name to,asset q,std::string memo){
_accounts acc(_self,_self);
auto toitr = acc.find(to);
if( toitr == acc.end() ) {
acc.emplace (payer,[&](auto& a) {
a.owner =to;
a.balance =q;
});
} else {
acc.modify(toitr,0, [&](auto& a){
a.owner = to;
a.balance = q;
});
}
}
void token::sub_balance(account_name payer, account_name to, asset q, std::string memo){
_accounts acc(_self,_self);
auto toitr = acc.find(to);
acc.modify(toitr,0,[&](auto& a){
eosio_assert(a.balance >= q,"Not enough token balance");
a.balance -= q;
});
}
void token::issue(account_name to,asset q, std::string memo){
add_balance(_self,to,q,"Issue");
}
void token::transfer(account_name from, account_name to, asset q, std::string memo){
add_balance(from,to,q,"Received");
sub_balance(to,from,q,"Transferred");
}
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
If you enjoyed what you read here, create your account today and start earning FREE STEEM!