JIN SEONG KIM avatar

simple.token Action 구현

blowist

Published: 18 Sept 2018 › Updated: 18 Sept 2018simple.token Action 구현

simple.token Action 구현

#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");
}

Leave simple.token Action 구현 to:

Written by

Read more #eos posts


Best Posts From JIN SEONG KIM

We have not curated any of blowist's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From JIN SEONG KIM