diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index af2dac9b5ddd94019f7d6a1952e3b1901d6ac165..b2cafe14b18fc37b592e34f4a2f5f7ebd92446bf 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -10,136 +10,6 @@ namespace eosiosystem { - /** - * @defgroup eosio.system EOSIO System Contract - * @brief Defines the wasm components of the system contract - * - */ - - /** - * We create the native EOSIO token type - */ - typedef eosio::token native_tokens; - const account_name system_code = N(eosio.system); - const table_name account_table = N(account); - - /** - * transfer requires that the sender and receiver be the first two - * accounts notified and that the sender has provided authorization. - * @abi action - */ - struct transfer { - /** - * account to transfer from - */ - account_name from; - /** - * account to transfer to - */ - account_name to; - /** - * quantity to transfer - */ - native_tokens quantity; - }; - - struct transfer_memo : public transfer { - string memo; - }; - - - /** - * This will transfer tokens from from.balance to to.vote_stake - */ - struct stakevote { - account_name from; - account_name to; - native_tokens quantity; - }; - - - - /** - * This table is used to track an individual user's token balance and vote stake. - * - * - * Location: - * - * { - * code: system_code - * scope: ${owner_account_name} - * table: N(singlton) - * key: N(account) - * } - */ - struct account { - /** - Constructor with default zero quantity (balance). - */ - account( native_tokens b = native_tokens() ):balance(b){} - - /** - * The key is constant because there is only one record per scope/currency/accounts - */ - const uint64_t key = N(account); - - /** - * Balance number of tokens in account - **/ - native_tokens balance; - native_tokens vote_stake; - native_tokens proxied_vote_stake; - uint64_t last_vote_weight = 0; - //time_point last_stake_withdraw; - account_name proxy; - - - /** - Method to check if accoutn is empty. - @return true if account balance is zero. - **/ - bool is_empty()const { return balance.quantity == 0; } - }; - - - - struct producer { - account_name key; /// producer name - uint64_t votes; /// total votes received by producer - /// producer config... - }; - - struct producer_vote { - account_name voter; - account_name producer; - uint64_t voteweight = 0; - }; - - /** - Defines the database table for account information - **/ - using accounts = eosio::table; - - /** - * accounts information for owner is stored: - * - * owner/TOKEN_NAME/account/account -> account - * - * This API is made available for 3rd parties wanting read access to - * the users balance. If the account doesn't exist a default constructed - * account will be returned. - * @param owner The account owner - * @return account instance - */ - inline account get_account( account_name owner ) { - account owned_account; - /// scope, record - accounts::get( owned_account, owner ); - return owned_account; - } } /// eosiosystem -EOSLIB_REFLECT( eosiosystem::account, (balance)(vote_stake)(proxied_vote_stake)(last_vote_weight)(proxy) ) -EOSLIB_REFLECT( eosiosystem::transfer, (from)(to)(quantity) ) -EOSLIB_REFLECT( eosiosystem::stakevote, (from)(to)(quantity) ) diff --git a/contracts/eoslib/action.hpp b/contracts/eoslib/action.hpp index 72968d2d9a671626d0a3cb48d8b1973c6019f661..ce3815928fdf6c96adf55551d1122b52ca064d32 100644 --- a/contracts/eoslib/action.hpp +++ b/contracts/eoslib/action.hpp @@ -165,3 +165,6 @@ namespace eosio { EOSLIB_REFLECT( eosio::permission_level, (actor)(permission) ) EOSLIB_REFLECT( eosio::action, (account)(name)(authorization)(data) ) + + +#define ACTION( CODE, NAME ) struct NAME : action_meta diff --git a/contracts/eoslib/datastream.hpp b/contracts/eoslib/datastream.hpp index ca04f637e3aebd4ff8ac7498d959a16fc97e81a9..f3ebde28f3f36e0eda19ead4cfc53d6706d40a4e 100644 --- a/contracts/eoslib/datastream.hpp +++ b/contracts/eoslib/datastream.hpp @@ -6,6 +6,7 @@ #include #include + namespace eosio { /** * @brief A data stream for reading and writing data in the form of bytes @@ -380,4 +381,7 @@ inline datastream& operator>>(datastream& ds, uint8_t& d) { return ds; } -} \ No newline at end of file +} + + + diff --git a/contracts/eoslib/generic_currency.hpp b/contracts/eoslib/generic_currency.hpp index 9a1b15f24111512bcd5623747b0f3387020a6199..1a75f136c833b79820fc47dad2fdaaf50cd0be00 100644 --- a/contracts/eoslib/generic_currency.hpp +++ b/contracts/eoslib/generic_currency.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace eosio { @@ -16,22 +17,15 @@ namespace eosio { static const uint64_t accounts_table_name = N(account); static const uint64_t stats_table_name = N(stat); - struct issue : action_meta { + ACTION( code, issue ) { typedef action_meta meta; account_name to; asset quantity; - template - friend DataStream& operator << ( DataStream& ds, const issue& t ){ - return ds << t.to << t.quantity; - } - template - friend DataStream& operator >> ( DataStream& ds, issue& t ){ - return ds >> t.to >> t.quantity; - } + EOSLIB_SERIALIZE( issue, (to)(quantity) ) }; - struct transfer : action_meta { + ACTION( code, transfer ) { transfer(){} transfer( account_name f, account_name t, token_type q ):from(f),to(t),quantity(q){} @@ -39,8 +33,6 @@ namespace eosio { account_name to; asset quantity; - //EOSLIB_SERIALIZE( transfer, (from)(to)(quantity)(symbol) ) - template friend DataStream& operator << ( DataStream& ds, const transfer& t ){ return ds << t.from << t.to << t.quantity; @@ -60,44 +52,21 @@ namespace eosio { string memo; - template - friend DataStream& operator << ( DataStream& ds, const transfer_memo& t ){ - ds << static_cast(t); - return ds << t.memo; - } - template - friend DataStream& operator >> ( DataStream& ds, transfer_memo& t ){ - ds >> static_cast(t); - return ds >> t.memo; - } + EOSLIB_SERIALIZE_DERIVED( transfer_memo, transfer, (memo) ) }; struct account { uint64_t symbol = token_type::symbol; token_type balance; - template - friend DataStream& operator << ( DataStream& ds, const account& t ){ - return ds << t.symbol << t.balance; - } - template - friend DataStream& operator >> ( DataStream& ds, account& t ){ - return ds >> t.symbol >> t.balance; - } + EOSLIB_SERIALIZE( account, (symbol)(balance) ) }; struct currency_stats { uint64_t symbol = token_type::symbol; token_type supply; - template - friend DataStream& operator << ( DataStream& ds, const currency_stats& t ){ - return ds << t.symbol << t.supply; - } - template - friend DataStream& operator >> ( DataStream& ds, currency_stats& t ){ - return ds >> t.symbol >> t.supply; - } + EOSLIB_SERIALIZE( currency_stats, (symbol)(supply) ) }; /** diff --git a/contracts/eoslib/serialize.hpp b/contracts/eoslib/serialize.hpp new file mode 100644 index 0000000000000000000000000000000000000000..554d476e4b89b07c3f7163834c77a0494b23feac --- /dev/null +++ b/contracts/eoslib/serialize.hpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#define EOSLIB_REFLECT_MEMBER_OP( r, OP, elem ) \ + OP t.elem + +/** + * @def EOSLIB_SERIALIZE(TYPE,MEMBERS) + * + * @brief Specializes eosio::reflector for TYPE where + * type inherits other reflected classes + * + * @param INHERITS - a sequence of base class names (basea)(baseb)(basec) + * @param MEMBERS - a sequence of member names. (field1)(field2)(field3) + */ +#define EOSLIB_SERIALIZE( TYPE, MEMBERS ) \ + template \ + friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \ + return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\ + }\ + template \ + friend DataStream& operator >> ( DataStream& ds, TYPE& t ){ \ + return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, >>, MEMBERS );\ + } + + +#define EOSLIB_SERIALIZE_DERIVED( TYPE, BASE, MEMBERS ) \ + template \ + friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \ + ds << static_cast(t); \ + return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\ + }\ + template \ + friend DataStream& operator >> ( DataStream& ds, TYPE& t ){ \ + ds >> static_cast(t); \ + return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, >>, MEMBERS );\ + }