Created
January 8, 2022 15:03
-
-
Save MCarlomagno/d3823b0c91997e32b9c04fd383c8ef5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void token::issue( const name& to, const asset& quantity, const string& memo ) | |
{ | |
auto sym = quantity.symbol; | |
check( sym.is_valid(), "invalid symbol name" ); | |
check( memo.size() <= 256, "memo has more than 256 bytes" ); | |
stats statstable( get_self(), sym.code().raw() ); | |
auto existing = statstable.find( sym.code().raw() ); | |
check( existing != statstable.end(), "token with symbol does not exist, create token before issue" ); | |
const auto& st = *existing; | |
check( to == st.issuer, "tokens can only be issued to issuer account" ); | |
require_auth( st.issuer ); | |
check( quantity.is_valid(), "invalid quantity" ); | |
check( quantity.amount > 0, "must issue positive quantity" ); | |
check( quantity.symbol == st.supply.symbol, "symbol precision mismatch" ); | |
check( quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply"); | |
statstable.modify( st, same_payer, [&]( auto& s ) { | |
s.supply += quantity; | |
}); | |
add_balance( st.issuer, quantity, st.issuer ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment