Created
December 11, 2018 04:12
-
-
Save lukestokes/39180d103799e0bbaafedb928f19198b to your computer and use it in GitHub Desktop.
git diff v1.2.1...v1.5.1 eosio.token
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
| diff --git a/eosio.token/CMakeLists.txt b/eosio.token/CMakeLists.txt | |
| index 9ff728c..5582d04 100644 | |
| --- a/eosio.token/CMakeLists.txt | |
| +++ b/eosio.token/CMakeLists.txt | |
| @@ -1,11 +1,8 @@ | |
| -add_executable(eosio.token.wasm ${CMAKE_CURRENT_SOURCE_DIR}/src/eosio.token.cpp) | |
| +add_contract(eosio.token eosio.token ${CMAKE_CURRENT_SOURCE_DIR}/src/eosio.token.cpp) | |
| target_include_directories(eosio.token.wasm | |
| - PUBLIC | |
| + PUBLIC | |
| ${CMAKE_CURRENT_SOURCE_DIR}/include) | |
| set_target_properties(eosio.token.wasm | |
| PROPERTIES | |
| RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") | |
| - | |
| -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.token.abi" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) | |
| -#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include) | |
| diff --git a/eosio.token/abi/eosio.token.abi b/eosio.token/abi/eosio.token.abi | |
| deleted file mode 100644 | |
| index ce5861f..0000000 | |
| --- a/eosio.token/abi/eosio.token.abi | |
| +++ /dev/null | |
| @@ -1,100 +0,0 @@ | |
| -{ | |
| - "version": "eosio::abi/1.0", | |
| - "types": [{ | |
| - "new_type_name": "account_name", | |
| - "type": "name" | |
| - }], | |
| - "structs": [{ | |
| - "name": "transfer", | |
| - "base": "", | |
| - "fields": [ | |
| - {"name":"from", "type":"account_name"}, | |
| - {"name":"to", "type":"account_name"}, | |
| - {"name":"quantity", "type":"asset"}, | |
| - {"name":"memo", "type":"string"} | |
| - ] | |
| - },{ | |
| - "name": "create", | |
| - "base": "", | |
| - "fields": [ | |
| - {"name":"issuer", "type":"account_name"}, | |
| - {"name":"maximum_supply", "type":"asset"} | |
| - ] | |
| - },{ | |
| - "name": "issue", | |
| - "base": "", | |
| - "fields": [ | |
| - {"name":"to", "type":"account_name"}, | |
| - {"name":"quantity", "type":"asset"}, | |
| - {"name":"memo", "type":"string"} | |
| - ] | |
| - },{ | |
| - "name": "retire", | |
| - "base": "", | |
| - "fields": [ | |
| - {"name":"quantity", "type":"asset"}, | |
| - {"name":"memo", "type":"string"} | |
| - ] | |
| - },{ | |
| - "name": "close", | |
| - "base": "", | |
| - "fields": [ | |
| - {"name":"owner", "type":"account_name"}, | |
| - {"name":"symbol", "type":"symbol"} | |
| - ] | |
| - },{ | |
| - "name": "account", | |
| - "base": "", | |
| - "fields": [ | |
| - {"name":"balance", "type":"asset"} | |
| - ] | |
| - },{ | |
| - "name": "currency_stats", | |
| - "base": "", | |
| - "fields": [ | |
| - {"name":"supply", "type":"asset"}, | |
| - {"name":"max_supply", "type":"asset"}, | |
| - {"name":"issuer", "type":"account_name"} | |
| - ] | |
| - } | |
| - ], | |
| - "actions": [{ | |
| - "name": "transfer", | |
| - "type": "transfer", | |
| - "ricardian_contract": "" | |
| - },{ | |
| - "name": "issue", | |
| - "type": "issue", | |
| - "ricardian_contract": "" | |
| - },{ | |
| - "name": "retire", | |
| - "type": "retire", | |
| - "ricardian_contract": "" | |
| - }, { | |
| - "name": "create", | |
| - "type": "create", | |
| - "ricardian_contract": "" | |
| - }, { | |
| - "name": "close", | |
| - "type": "close", | |
| - "ricardian_contract": "" | |
| - } | |
| - | |
| - ], | |
| - "tables": [{ | |
| - "name": "accounts", | |
| - "type": "account", | |
| - "index_type": "i64", | |
| - "key_names" : ["currency"], | |
| - "key_types" : ["uint64"] | |
| - },{ | |
| - "name": "stat", | |
| - "type": "currency_stats", | |
| - "index_type": "i64", | |
| - "key_names" : ["currency"], | |
| - "key_types" : ["uint64"] | |
| - } | |
| - ], | |
| - "ricardian_clauses": [], | |
| - "abi_extensions": [] | |
| -} | |
| diff --git a/eosio.token/include/eosio.token/eosio.token.hpp b/eosio.token/include/eosio.token/eosio.token.hpp | |
| index 629524a..53130bd 100644 | |
| --- a/eosio.token/include/eosio.token/eosio.token.hpp | |
| +++ b/eosio.token/include/eosio.token/eosio.token.hpp | |
| @@ -17,70 +17,66 @@ namespace eosio { | |
| using std::string; | |
| - class token : public contract { | |
| + class [[eosio::contract("eosio.token")]] token : public contract { | |
| public: | |
| - token( account_name self ):contract(self){} | |
| + using contract::contract; | |
| - void create( account_name issuer, | |
| - asset maximum_supply); | |
| + [[eosio::action]] | |
| + void create( name issuer, | |
| + asset maximum_supply); | |
| - void issue( account_name to, asset quantity, string memo ); | |
| + [[eosio::action]] | |
| + void issue( name to, asset quantity, string memo ); | |
| + [[eosio::action]] | |
| void retire( asset quantity, string memo ); | |
| - void transfer( account_name from, | |
| - account_name to, | |
| - asset quantity, | |
| - string memo ); | |
| + [[eosio::action]] | |
| + void transfer( name from, | |
| + name to, | |
| + asset quantity, | |
| + string memo ); | |
| - void close( account_name owner, symbol_type symbol ); | |
| + [[eosio::action]] | |
| + void open( name owner, const symbol& symbol, name ram_payer ); | |
| - inline asset get_supply( symbol_name sym )const; | |
| - | |
| - inline asset get_balance( account_name owner, symbol_name sym )const; | |
| + [[eosio::action]] | |
| + void close( name owner, const symbol& symbol ); | |
| + | |
| + static asset get_supply( name token_contract_account, 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( name token_contract_account, name owner, symbol_code sym_code ) | |
| + { | |
| + accounts accountstable( token_contract_account, owner.value ); | |
| + const auto& ac = accountstable.get( sym_code.raw() ); | |
| + return ac.balance; | |
| + } | |
| private: | |
| - struct account { | |
| + struct [[eosio::table]] account { | |
| asset balance; | |
| - uint64_t primary_key()const { return balance.symbol.name(); } | |
| + uint64_t primary_key()const { return balance.symbol.code().raw(); } | |
| }; | |
| - struct currency_stats { | |
| - asset supply; | |
| - asset max_supply; | |
| - account_name issuer; | |
| + struct [[eosio::table]] currency_stats { | |
| + asset supply; | |
| + asset max_supply; | |
| + name issuer; | |
| - uint64_t primary_key()const { return supply.symbol.name(); } | |
| + uint64_t primary_key()const { return supply.symbol.code().raw(); } | |
| }; | |
| - typedef eosio::multi_index<N(accounts), account> accounts; | |
| - typedef eosio::multi_index<N(stat), currency_stats> stats; | |
| - | |
| - void sub_balance( account_name owner, asset value ); | |
| - void add_balance( account_name owner, asset value, account_name ram_payer ); | |
| + typedef eosio::multi_index< "accounts"_n, account > accounts; | |
| + typedef eosio::multi_index< "stat"_n, currency_stats > stats; | |
| - public: | |
| - struct transfer_args { | |
| - account_name from; | |
| - account_name to; | |
| - asset quantity; | |
| - string memo; | |
| - }; | |
| + void sub_balance( name owner, asset value ); | |
| + void add_balance( name owner, asset value, name ram_payer ); | |
| }; | |
| - asset token::get_supply( symbol_name sym )const | |
| - { | |
| - stats statstable( _self, sym ); | |
| - const auto& st = statstable.get( sym ); | |
| - return st.supply; | |
| - } | |
| - | |
| - asset token::get_balance( account_name owner, symbol_name sym )const | |
| - { | |
| - accounts accountstable( _self, owner ); | |
| - const auto& ac = accountstable.get( sym ); | |
| - return ac.balance; | |
| - } | |
| - | |
| } /// namespace eosio | |
| diff --git a/eosio.token/src/eosio.token.cpp b/eosio.token/src/eosio.token.cpp | |
| index ff25071..b18a68a 100644 | |
| --- a/eosio.token/src/eosio.token.cpp | |
| +++ b/eosio.token/src/eosio.token.cpp | |
| @@ -7,8 +7,8 @@ | |
| namespace eosio { | |
| -void token::create( account_name issuer, | |
| - asset maximum_supply ) | |
| +void token::create( name issuer, | |
| + asset maximum_supply ) | |
| { | |
| require_auth( _self ); | |
| @@ -17,8 +17,8 @@ void token::create( account_name issuer, | |
| eosio_assert( maximum_supply.is_valid(), "invalid supply"); | |
| eosio_assert( maximum_supply.amount > 0, "max-supply must be positive"); | |
| - stats statstable( _self, sym.name() ); | |
| - auto existing = statstable.find( sym.name() ); | |
| + stats statstable( _self, sym.code().raw() ); | |
| + auto existing = statstable.find( sym.code().raw() ); | |
| eosio_assert( existing == statstable.end(), "token with symbol already exists" ); | |
| statstable.emplace( _self, [&]( auto& s ) { | |
| @@ -29,15 +29,14 @@ void token::create( account_name issuer, | |
| } | |
| -void token::issue( account_name to, asset quantity, string memo ) | |
| +void token::issue( name to, asset quantity, string memo ) | |
| { | |
| auto sym = quantity.symbol; | |
| eosio_assert( sym.is_valid(), "invalid symbol name" ); | |
| eosio_assert( memo.size() <= 256, "memo has more than 256 bytes" ); | |
| - auto sym_name = sym.name(); | |
| - stats statstable( _self, sym_name ); | |
| - auto existing = statstable.find( sym_name ); | |
| + stats statstable( _self, sym.code().raw() ); | |
| + auto existing = statstable.find( sym.code().raw() ); | |
| eosio_assert( existing != statstable.end(), "token with symbol does not exist, create token before issue" ); | |
| const auto& st = *existing; | |
| @@ -48,14 +47,16 @@ void token::issue( account_name to, asset quantity, string memo ) | |
| eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" ); | |
| eosio_assert( quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply"); | |
| - statstable.modify( st, 0, [&]( auto& s ) { | |
| + statstable.modify( st, same_payer, [&]( auto& s ) { | |
| s.supply += quantity; | |
| }); | |
| add_balance( st.issuer, quantity, st.issuer ); | |
| if( to != st.issuer ) { | |
| - SEND_INLINE_ACTION( *this, transfer, {st.issuer,N(active)}, {st.issuer, to, quantity, memo} ); | |
| + SEND_INLINE_ACTION( *this, transfer, { {st.issuer, "active"_n} }, | |
| + { st.issuer, to, quantity, memo } | |
| + ); | |
| } | |
| } | |
| @@ -65,9 +66,8 @@ void token::retire( asset quantity, string memo ) | |
| eosio_assert( sym.is_valid(), "invalid symbol name" ); | |
| eosio_assert( memo.size() <= 256, "memo has more than 256 bytes" ); | |
| - auto sym_name = sym.name(); | |
| - stats statstable( _self, sym_name ); | |
| - auto existing = statstable.find( sym_name ); | |
| + stats statstable( _self, sym.code().raw() ); | |
| + auto existing = statstable.find( sym.code().raw() ); | |
| eosio_assert( existing != statstable.end(), "token with symbol does not exist" ); | |
| const auto& st = *existing; | |
| @@ -77,24 +77,24 @@ void token::retire( asset quantity, string memo ) | |
| eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" ); | |
| - statstable.modify( st, 0, [&]( auto& s ) { | |
| + statstable.modify( st, same_payer, [&]( auto& s ) { | |
| s.supply -= quantity; | |
| }); | |
| sub_balance( st.issuer, quantity ); | |
| } | |
| -void token::transfer( account_name from, | |
| - account_name to, | |
| - asset quantity, | |
| - string memo ) | |
| +void token::transfer( name from, | |
| + name to, | |
| + asset quantity, | |
| + string memo ) | |
| { | |
| eosio_assert( from != to, "cannot transfer to self" ); | |
| require_auth( from ); | |
| eosio_assert( is_account( to ), "to account does not exist"); | |
| - auto sym = quantity.symbol.name(); | |
| - stats statstable( _self, sym ); | |
| - const auto& st = statstable.get( sym ); | |
| + auto sym = quantity.symbol.code(); | |
| + stats statstable( _self, sym.raw() ); | |
| + const auto& st = statstable.get( sym.raw() ); | |
| require_recipient( from ); | |
| require_recipient( to ); | |
| @@ -110,10 +110,10 @@ void token::transfer( account_name from, | |
| add_balance( to, quantity, payer ); | |
| } | |
| -void token::sub_balance( account_name owner, asset value ) { | |
| - accounts from_acnts( _self, owner ); | |
| +void token::sub_balance( name owner, asset value ) { | |
| + accounts from_acnts( _self, owner.value ); | |
| - const auto& from = from_acnts.get( value.symbol.name(), "no balance object found" ); | |
| + const auto& from = from_acnts.get( value.symbol.code().raw(), "no balance object found" ); | |
| eosio_assert( from.balance.amount >= value.amount, "overdrawn balance" ); | |
| from_acnts.modify( from, owner, [&]( auto& a ) { | |
| @@ -121,24 +121,45 @@ void token::sub_balance( account_name owner, asset value ) { | |
| }); | |
| } | |
| -void token::add_balance( account_name owner, asset value, account_name ram_payer ) | |
| +void token::add_balance( name owner, asset value, name ram_payer ) | |
| { | |
| - accounts to_acnts( _self, owner ); | |
| - auto to = to_acnts.find( value.symbol.name() ); | |
| + accounts to_acnts( _self, owner.value ); | |
| + auto to = to_acnts.find( value.symbol.code().raw() ); | |
| if( to == to_acnts.end() ) { | |
| to_acnts.emplace( ram_payer, [&]( auto& a ){ | |
| a.balance = value; | |
| }); | |
| } else { | |
| - to_acnts.modify( to, 0, [&]( auto& a ) { | |
| + to_acnts.modify( to, same_payer, [&]( auto& a ) { | |
| a.balance += value; | |
| }); | |
| } | |
| } | |
| -void token::close( account_name owner, symbol_type symbol ) { | |
| - accounts acnts( _self, owner ); | |
| - auto it = acnts.find( symbol.name() ); | |
| +void token::open( name owner, const symbol& symbol, name ram_payer ) | |
| +{ | |
| + require_auth( ram_payer ); | |
| + | |
| + auto sym_code_raw = symbol.code().raw(); | |
| + | |
| + stats statstable( _self, sym_code_raw ); | |
| + const auto& st = statstable.get( sym_code_raw, "symbol does not exist" ); | |
| + eosio_assert( st.supply.symbol == symbol, "symbol precision mismatch" ); | |
| + | |
| + accounts acnts( _self, owner.value ); | |
| + auto it = acnts.find( sym_code_raw ); | |
| + if( it == acnts.end() ) { | |
| + acnts.emplace( ram_payer, [&]( auto& a ){ | |
| + a.balance = asset{0, symbol}; | |
| + }); | |
| + } | |
| +} | |
| + | |
| +void token::close( name owner, const symbol& symbol ) | |
| +{ | |
| + require_auth( owner ); | |
| + accounts acnts( _self, owner.value ); | |
| + auto it = acnts.find( symbol.code().raw() ); | |
| eosio_assert( it != acnts.end(), "Balance row already deleted or never existed. Action won't have any effect." ); | |
| eosio_assert( it->balance.amount == 0, "Cannot close because the balance is not zero." ); | |
| acnts.erase( it ); | |
| @@ -146,4 +167,4 @@ void token::close( account_name owner, symbol_type symbol ) { | |
| } /// namespace eosio | |
| -EOSIO_ABI( eosio::token, (create)(issue)(transfer)(close)(retire) ) | |
| +EOSIO_DISPATCH( eosio::token, (create)(issue)(transfer)(open)(close)(retire) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment