forked from zyl1012/eidos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.hpp
84 lines (65 loc) · 3.01 KB
/
token.hpp
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
#pragma once
#include <eosio/asset.hpp>
#include <eosio/eosio.hpp>
#include <string>
namespace eosiosystem {
class system_contract;
}
namespace eosio {
using std::string;
class [[eosio::contract("token")]] token : public contract {
public:
using contract::contract;
[[eosio::action]]
void create( const name& issuer,
const asset& maximum_supply);
[[eosio::action]]
void issue( const name& to, const asset& quantity, const string& memo );
[[eosio::action]]
void retire( const asset& quantity, const string& memo );
[[eosio::action]]
void transfer( const name& from,
const name& to,
const asset& quantity,
const string& memo );
[[eosio::action]]
void open( const name& owner, const symbol& symbol, const name& ram_payer );
[[eosio::action]]
void close( const name& owner, const symbol& symbol );
[[eosio::on_notify("eosio.token::transfer")]]
void claim(name from, name to, eosio::asset quantity, std::string memo);
static asset get_supply( const name& token_contract_account, const symbol_code& sym_code )
{
stats statstable( token_contract_account, sym_code.raw() );
const auto& st = statstable.get( sym_code.raw() );
return st.supply;
}
static asset get_balance( const name& token_contract_account, const name& owner, const symbol_code& sym_code )
{
accounts accountstable( token_contract_account, owner.value );
const auto& ac = accountstable.get( sym_code.raw() );
return ac.balance;
}
using create_action = eosio::action_wrapper<"create"_n, &token::create>;
using issue_action = eosio::action_wrapper<"issue"_n, &token::issue>;
using retire_action = eosio::action_wrapper<"retire"_n, &token::retire>;
using transfer_action = eosio::action_wrapper<"transfer"_n, &token::transfer>;
using open_action = eosio::action_wrapper<"open"_n, &token::open>;
using close_action = eosio::action_wrapper<"close"_n, &token::close>;
private:
struct [[eosio::table]] account {
asset balance;
uint64_t primary_key()const { return balance.symbol.code().raw(); }
};
struct [[eosio::table]] currency_stats {
asset supply;
asset max_supply;
name issuer;
uint64_t primary_key()const { return supply.symbol.code().raw(); }
};
typedef eosio::multi_index< "accounts"_n, account > accounts;
typedef eosio::multi_index< "stat"_n, currency_stats > stats;
void sub_balance( const name& owner, const asset& value );
void add_balance( const name& owner, const asset& value, const name& ram_payer );
};
}