Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::token Class Reference

#include <sysio.token.hpp>

Inheritance diagram for sysio::token:
Collaboration diagram for sysio::token:

Public Types

using create_action = sysio::action_wrapper<"create"_n, &token::create>
 
using issue_action = sysio::action_wrapper<"issue"_n, &token::issue>
 
using retire_action = sysio::action_wrapper<"retire"_n, &token::retire>
 
using transfer_action = sysio::action_wrapper<"transfer"_n, &token::transfer>
 
using open_action = sysio::action_wrapper<"open"_n, &token::open>
 
using close_action = sysio::action_wrapper<"close"_n, &token::close>
 

Public Member Functions

void create (const name &issuer, const asset &maximum_supply)
 
void issue (const name &to, const asset &quantity, const string &memo)
 
void retire (const asset &quantity, const string &memo)
 
void transfer (const name &from, const name &to, const asset &quantity, const string &memo)
 
void open (const name &owner, const symbol &symbol, const name &ram_payer)
 
void close (const name &owner, const symbol &symbol)
 

Static Public Member Functions

static asset get_supply (const name &token_contract_account, const symbol_code &sym_code)
 
static asset get_balance (const name &token_contract_account, const name &owner, const symbol_code &sym_code)
 

Detailed Description

The sysio.token sample system contract defines the structures and actions that allow users to create, issue, and manage tokens for EOSIO based blockchains. It demonstrates one way to implement a smart contract which allows for creation and management of tokens. It is possible for one to create a similar contract which suits different needs. However, it is recommended that if one only needs a token with the below listed actions, that one uses the sysio.token contract instead of developing their own.

The sysio.token contract class also implements two useful public static methods: get_supply and get_balance. The first allows one to check the total supply of a specified token, created by an account and the second allows one to check the balance of a token for a specified account (the token creator account has to be specified as well).

The sysio.token contract manages the set of tokens, accounts and their corresponding balances, by using two internal multi-index structures: the accounts and stats. The accounts multi-index table holds, for each row, instances of account object and the account object holds information about the balance of one token. The accounts table is scoped to an EOSIO account, and it keeps the rows indexed based on the token's symbol. This means that when one queries the accounts multi-index table for an account name the result is all the tokens that account holds at the moment.

Similarly, the stats multi-index table, holds instances of currency_stats objects for each row, which contains information about current supply, maximum supply, and the creator account for a symbol token. The stats table is scoped to the token symbol. Therefore, when one queries the stats table for a token symbol the result is one single entry/row corresponding to the queried symbol token if it was previously created, or nothing, otherwise.

Definition at line 25 of file sysio.token.hpp.

Member Typedef Documentation

◆ close_action

using sysio::token::close_action = sysio::action_wrapper<"close"_n, &token::close>

Definition at line 123 of file sysio.token.hpp.

◆ create_action

using sysio::token::create_action = sysio::action_wrapper<"create"_n, &token::create>

Definition at line 118 of file sysio.token.hpp.

◆ issue_action

using sysio::token::issue_action = sysio::action_wrapper<"issue"_n, &token::issue>

Definition at line 119 of file sysio.token.hpp.

◆ open_action

using sysio::token::open_action = sysio::action_wrapper<"open"_n, &token::open>

Definition at line 122 of file sysio.token.hpp.

◆ retire_action

using sysio::token::retire_action = sysio::action_wrapper<"retire"_n, &token::retire>

Definition at line 120 of file sysio.token.hpp.

◆ transfer_action

using sysio::token::transfer_action = sysio::action_wrapper<"transfer"_n, &token::transfer>

Definition at line 121 of file sysio.token.hpp.

Member Function Documentation

◆ close()

void sysio::token::close ( const name & owner,
const symbol & symbol )

This action is the opposite for open, it closes the account owner for token symbol.

Parameters
owner- the owner account to execute the close action for,
symbol- the symbol of the token to execute the close action for.
Precondition
The pair of owner plus symbol has to exist otherwise no action is executed,
If the pair of owner plus symbol exists, the balance has to be zero.

Definition at line 148 of file sysio.token.cpp.

149{
150 require_auth( owner );
151 accounts acnts( get_self(), owner.value );
152 auto it = acnts.find( symbol.code().raw() );
153 check( it != acnts.end(), "Balance row already deleted or never existed. Action won't have any effect." );
154 check( it->balance.amount == 0, "Cannot close because the balance is not zero." );
155 acnts.erase( it );
156}

◆ create()

void sysio::token::create ( const name & issuer,
const asset & maximum_supply )

Allows issuer account to create a token in supply of maximum_supply. If validation is successful a new entry in statstable for token symbol scope gets created.

Parameters
issuer- the account that creates the token,
maximum_supply- the maximum supply set for the token created.
Precondition
Token symbol has to be valid,
Token symbol must not be already created,
maximum_supply has to be smaller than the maximum supply allowed by the system: 1^62 - 1.
Maximum supply must be positive;

Definition at line 5 of file sysio.token.cpp.

7{
8 require_auth( get_self() );
9
10 auto sym = maximum_supply.symbol;
11 check( maximum_supply.is_valid(), "invalid supply");
12 check( maximum_supply.amount > 0, "max-supply must be positive");
13
14 stats statstable( get_self(), sym.code().raw() );
15 auto existing = statstable.find( sym.code().raw() );
16 check( existing == statstable.end(), "token with symbol already exists" );
17
18 statstable.emplace( get_self(), [&]( auto& s ) {
19 s.supply.symbol = maximum_supply.symbol;
20 s.max_supply = maximum_supply;
21 s.issuer = issuer;
22 });
23}
char * s
Here is the call graph for this function:

◆ get_balance()

static asset sysio::token::get_balance ( const name & token_contract_account,
const name & owner,
const symbol_code & sym_code )
inlinestatic

Definition at line 111 of file sysio.token.hpp.

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 }

◆ get_supply()

static asset sysio::token::get_supply ( const name & token_contract_account,
const symbol_code & sym_code )
inlinestatic

Definition at line 104 of file sysio.token.hpp.

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 }
Here is the caller graph for this function:

◆ issue()

void sysio::token::issue ( const name & to,
const asset & quantity,
const string & memo )

This action issues to to account a quantity of tokens.

Parameters
to- the account to issue tokens to, it must be the same as the issuer,
quantity- the amount of tokens to be issued, @memo - the memo string that accompanies the token issue transaction.

Definition at line 26 of file sysio.token.cpp.

27{
28 auto sym = quantity.symbol;
29 check( sym.is_valid(), "invalid symbol name" );
30 check( memo.size() <= 256, "memo has more than 256 bytes" );
31
32 stats statstable( get_self(), sym.code().raw() );
33 auto existing = statstable.find( sym.code().raw() );
34 check( existing != statstable.end(), "token with symbol does not exist, create token before issue" );
35 const auto& st = *existing;
36 check( to == st.issuer, "tokens can only be issued to issuer account" );
37
38 require_auth( st.issuer );
39 check( quantity.is_valid(), "invalid quantity" );
40 check( quantity.amount > 0, "must issue positive quantity" );
41
42 check( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
43 check( quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply");
44
45 statstable.modify( st, same_payer, [&]( auto& s ) {
46 s.supply += quantity;
47 });
48
49 add_balance( st.issuer, quantity, st.issuer );
50}
Here is the call graph for this function:

◆ open()

void sysio::token::open ( const name & owner,
const symbol & symbol,
const name & ram_payer )

Allows ram_payer to create an account owner with zero balance for token symbol at the expense of ram_payer.

Parameters
owner- the account to be created,
symbol- the token to be payed with by ram_payer,
ram_payer- the account that supports the cost of this action.

More information can be read here and here.

Definition at line 128 of file sysio.token.cpp.

129{
130 require_auth( ram_payer );
131
132 check( is_account( owner ), "owner account does not exist" );
133
134 auto sym_code_raw = symbol.code().raw();
135 stats statstable( get_self(), sym_code_raw );
136 const auto& st = statstable.get( sym_code_raw, "symbol does not exist" );
137 check( st.supply.symbol == symbol, "symbol precision mismatch" );
138
139 accounts acnts( get_self(), owner.value );
140 auto it = acnts.find( sym_code_raw );
141 if( it == acnts.end() ) {
142 acnts.emplace( ram_payer, [&]( auto& a ){
143 a.balance = asset{0, symbol};
144 });
145 }
146}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181

◆ retire()

void sysio::token::retire ( const asset & quantity,
const string & memo )

The opposite for create action, if all validations succeed, it debits the statstable.supply amount.

Parameters
quantity- the quantity of tokens to retire,
memo- the memo string to accompany the transaction.

Definition at line 52 of file sysio.token.cpp.

53{
54 auto sym = quantity.symbol;
55 check( sym.is_valid(), "invalid symbol name" );
56 check( memo.size() <= 256, "memo has more than 256 bytes" );
57
58 stats statstable( get_self(), sym.code().raw() );
59 auto existing = statstable.find( sym.code().raw() );
60 check( existing != statstable.end(), "token with symbol does not exist" );
61 const auto& st = *existing;
62
63 require_auth( st.issuer );
64 check( quantity.is_valid(), "invalid quantity" );
65 check( quantity.amount > 0, "must retire positive quantity" );
66
67 check( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
68
69 statstable.modify( st, same_payer, [&]( auto& s ) {
70 s.supply -= quantity;
71 });
72
73 sub_balance( st.issuer, quantity );
74}
Here is the call graph for this function:

◆ transfer()

void sysio::token::transfer ( const name & from,
const name & to,
const asset & quantity,
const string & memo )

Allows from account to transfer to to account the quantity tokens. One account is debited and the other is credited with quantity tokens.

Parameters
from- the account to transfer from,
to- the account to be transferred to,
quantity- the quantity of tokens to be transferred,
memo- the memo string to accompany the transaction.

Definition at line 76 of file sysio.token.cpp.

80{
81 check( from != to, "cannot transfer to self" );
82 require_auth( from );
83 check( is_account( to ), "to account does not exist");
84 auto sym = quantity.symbol.code();
85 stats statstable( get_self(), sym.raw() );
86 const auto& st = statstable.get( sym.raw() );
87
88 require_recipient( from );
89 require_recipient( to );
90
91 check( quantity.is_valid(), "invalid quantity" );
92 check( quantity.amount > 0, "must transfer positive quantity" );
93 check( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
94 check( memo.size() <= 256, "memo has more than 256 bytes" );
95
96 auto payer = has_auth( to ) ? to : from;
97
98 sub_balance( from, quantity );
99 add_balance( to, quantity, payer );
100}
Here is the call graph for this function:

The documentation for this class was generated from the following files: