Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio.token.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <sysio/asset.hpp>
4#include <sysio/sysio.hpp>
5
6#include <string>
7
8namespace sysiosystem {
9 class system_contract;
10}
11
12namespace sysio {
13
14 using std::string;
15
25 class [[sysio::contract("sysio.token")]] token : public contract {
26 public:
27 using contract::contract;
28
41 void create( const name& issuer,
42 const asset& maximum_supply);
51 void issue( const name& to, const asset& quantity, const string& memo );
52
61 void retire( const asset& quantity, const string& memo );
62
73 void transfer( const name& from,
74 const name& to,
75 const asset& quantity,
76 const string& memo );
89 void open( const name& owner, const symbol& symbol, const name& ram_payer );
90
101 [[sysio::action]]
102 void close( const name& owner, const symbol& symbol );
103
104 static asset get_supply( const name& token_contract_account, const symbol_code& sym_code )
105 {
106 stats statstable( token_contract_account, sym_code.raw() );
107 const auto& st = statstable.get( sym_code.raw(), "invalid supply symbol code" );
108 return st.supply;
109 }
110
111 static asset get_balance( const name& token_contract_account, const name& owner, const symbol_code& sym_code )
112 {
113 accounts accountstable( token_contract_account, owner.value );
114 const auto& ac = accountstable.get( sym_code.raw(), "no balance with specified symbol" );
115 return ac.balance;
116 }
117
118 using create_action = sysio::action_wrapper<"create"_n, &token::create>;
119 using issue_action = sysio::action_wrapper<"issue"_n, &token::issue>;
120 using retire_action = sysio::action_wrapper<"retire"_n, &token::retire>;
121 using transfer_action = sysio::action_wrapper<"transfer"_n, &token::transfer>;
122 using open_action = sysio::action_wrapper<"open"_n, &token::open>;
123 using close_action = sysio::action_wrapper<"close"_n, &token::close>;
124 private:
125 struct [[sysio::table]] account {
126 asset balance;
127
128 uint64_t primary_key()const { return balance.symbol.code().raw(); }
129 };
130
131 struct [[sysio::table]] currency_stats {
132 asset supply;
133 asset max_supply;
134 name issuer;
135
136 uint64_t primary_key()const { return supply.symbol.code().raw(); }
137 };
138
139 typedef sysio::multi_index< "accounts"_n, account > accounts;
140 typedef sysio::multi_index< "stat"_n, currency_stats > stats;
141
142 void sub_balance( const name& owner, const asset& value );
143 void add_balance( const name& owner, const asset& value, const name& ram_payer );
144 };
145
146}
std::string name
sysio::action_wrapper<"issue"_n, &token::issue > issue_action
static asset get_balance(const name &token_contract_account, const name &owner, const symbol_code &sym_code)
sysio::action_wrapper<"create"_n, &token::create > create_action
sysio::action_wrapper<"transfer"_n, &token::transfer > transfer_action
sysio::action_wrapper<"open"_n, &token::open > open_action
static asset get_supply(const name &token_contract_account, const symbol_code &sym_code)
sysio::action_wrapper<"close"_n, &token::close > close_action
sysio::action_wrapper<"retire"_n, &token::retire > retire_action
void close(T *e, websocketpp::connection_hdl hdl)
#define value
Definition pkcs11.h:157
unsigned __int64 uint64_t
Definition stdint.h:136
Immutable except for fc::from_variant.
Definition name.hpp:43