提交 8af3a16f 编写于 作者: D Daniel Larimer

Defining helper macros to simplify code.

上级 8d245066
......@@ -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<uint64_t,N(eosio)> 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<N(unused),system_code,account_table,account,uint64_t>;
/**
* 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) )
......@@ -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<CODE, ::eosio::string_to_name(#NAME) >
......@@ -6,6 +6,7 @@
#include <eoslib/system.h>
#include <eoslib/memory.h>
namespace eosio {
/**
* @brief A data stream for reading and writing data in the form of bytes
......@@ -380,4 +381,7 @@ inline datastream<Stream>& operator>>(datastream<Stream>& ds, uint8_t& d) {
return ds;
}
}
\ No newline at end of file
}
......@@ -4,6 +4,7 @@
#include <eoslib/token.hpp>
#include <eoslib/asset.hpp>
#include <eoslib/dispatcher.hpp>
#include <eoslib/serialize.hpp>
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<code,N(issue)> {
ACTION( code, issue ) {
typedef action_meta<code,N(issue)> meta;
account_name to;
asset quantity;
template<typename DataStream>
friend DataStream& operator << ( DataStream& ds, const issue& t ){
return ds << t.to << t.quantity;
}
template<typename DataStream>
friend DataStream& operator >> ( DataStream& ds, issue& t ){
return ds >> t.to >> t.quantity;
}
EOSLIB_SERIALIZE( issue, (to)(quantity) )
};
struct transfer : action_meta<code,N(transfer)> {
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<typename DataStream>
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<typename DataStream>
friend DataStream& operator << ( DataStream& ds, const transfer_memo& t ){
ds << static_cast<const transfer&>(t);
return ds << t.memo;
}
template<typename DataStream>
friend DataStream& operator >> ( DataStream& ds, transfer_memo& t ){
ds >> static_cast<transfer&>(t);
return ds >> t.memo;
}
EOSLIB_SERIALIZE_DERIVED( transfer_memo, transfer, (memo) )
};
struct account {
uint64_t symbol = token_type::symbol;
token_type balance;
template<typename DataStream>
friend DataStream& operator << ( DataStream& ds, const account& t ){
return ds << t.symbol << t.balance;
}
template<typename DataStream>
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<typename DataStream>
friend DataStream& operator << ( DataStream& ds, const currency_stats& t ){
return ds << t.symbol << t.supply;
}
template<typename DataStream>
friend DataStream& operator >> ( DataStream& ds, currency_stats& t ){
return ds >> t.symbol >> t.supply;
}
EOSLIB_SERIALIZE( currency_stats, (symbol)(supply) )
};
/**
......
#include <eoslib/preprocessor/seq/for_each.hpp>
#include <eoslib/preprocessor/seq/enum.hpp>
#include <eoslib/preprocessor/seq/size.hpp>
#include <eoslib/preprocessor/seq/seq.hpp>
#include <eoslib/preprocessor/stringize.hpp>
#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<typename DataStream> \
friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\
}\
template<typename DataStream> \
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<typename DataStream> \
friend DataStream& operator << ( DataStream& ds, const TYPE& t ){ \
ds << static_cast<const BASE&>(t); \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, <<, MEMBERS );\
}\
template<typename DataStream> \
friend DataStream& operator >> ( DataStream& ds, TYPE& t ){ \
ds >> static_cast<BASE&>(t); \
return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, >>, MEMBERS );\
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册