提交 016636ae 编写于 作者: W Wang Zhi

hddpool contract: code formatting

上级 098ae99f
此差异已折叠。
...@@ -3,142 +3,145 @@ ...@@ -3,142 +3,145 @@
#include <eosiolib/time.hpp> #include <eosiolib/time.hpp>
#include <eosiolib/singleton.hpp> #include <eosiolib/singleton.hpp>
using eosio::contract;
using eosio::name;
using eosio::asset; using eosio::asset;
using eosio::symbol_type;
using eosio::indexed_by;
using eosio::const_mem_fun; using eosio::const_mem_fun;
using eosio::microseconds; using eosio::contract;
using eosio::datastream; using eosio::datastream;
using eosio::indexed_by;
using eosio::microseconds;
using eosio::multi_index; using eosio::multi_index;
using eosio::name;
using eosio::symbol_type;
typedef double real_type; typedef double real_type;
//copy from eosio.system //copy from eosio.system
/** /**
* Uses Bancor math to create a 50/50 relay between two asset types. The state of the * Uses Bancor math to create a 50/50 relay between two asset types. The state of the
* bancor exchange is entirely contained within this struct. There are no external * bancor exchange is entirely contained within this struct. There are no external
* side effects associated with using this API. * side effects associated with using this API.
*/ */
struct exchange_state { struct exchange_state
asset supply; {
asset supply;
struct connector { struct connector
asset balance; {
double weight = .5; asset balance;
double weight = .5;
EOSLIB_SERIALIZE( connector, (balance)(weight) ) EOSLIB_SERIALIZE(connector, (balance)(weight))
}; };
connector base; connector base;
connector quote; connector quote;
uint64_t primary_key()const { return supply.symbol; } uint64_t primary_key() const { return supply.symbol; }
asset convert_to_exchange( connector& c, asset in ); asset convert_to_exchange(connector &c, asset in);
asset convert_from_exchange( connector& c, asset in ); asset convert_from_exchange(connector &c, asset in);
asset convert( asset from, symbol_type to ); asset convert(asset from, symbol_type to);
EOSLIB_SERIALIZE( exchange_state, (supply)(base)(quote) ) EOSLIB_SERIALIZE(exchange_state, (supply)(base)(quote))
}; };
//comment old style declaration //comment old style declaration
typedef multi_index<N(hmarket), exchange_state> hmarket_table; typedef multi_index<N(hmarket), exchange_state> hmarket_table;
class hddpool : public contract
{
class hddpool : public contract { public:
public: using contract::contract;
using contract::contract;
hddpool(account_name s);
hddpool( account_name s); ~hddpool();
~hddpool();
void getbalance(name user);
void getbalance( name user ); void buyhdd(name user, asset quant);
void buyhdd( name user , asset quant); //void buyhdd( name user , int64_t amount);
//void buyhdd( name user , int64_t amount); void sellhdd(name user, int64_t amount);
void sellhdd( name user, int64_t amount); void sethfee(name user, int64_t fee);
void sethfee( name user, int64_t fee); void subbalance(name user, int64_t balance);
void subbalance ( name user, int64_t balance); void addhspace(name user, uint64_t space);
void addhspace(name user, uint64_t space); void subhspace(name user, uint64_t space);
void subhspace(name user, uint64_t space); void newmaccount(name owner, uint64_t minerid);
void newmaccount(name owner, uint64_t minerid); void addmprofit(name owner, uint64_t minerid, uint64_t space);
void addmprofit(name owner, uint64_t minerid, uint64_t space); void clearall();
void clearall(); void calcmbalance(name owner, uint64_t minerid);
void calcmbalance(name owner, uint64_t minerid);
private:
private: struct userhdd
{
struct userhdd { name account_name; //账户名
name account_name; //账户名 int64_t hdd_balance; //余额
int64_t hdd_balance; //余额 int64_t hdd_per_cycle_fee; //每周期费用
int64_t hdd_per_cycle_fee; //每周期费用 int64_t hdd_per_cycle_profit; //每周期收益
int64_t hdd_per_cycle_profit; //每周期收益 uint64_t hdd_space; //占用存储空间
uint64_t hdd_space; //占用存储空间 uint64_t last_hdd_time; //上次余额计算时间 microseconds from 1970
uint64_t last_hdd_time; //上次余额计算时间 microseconds from 1970 uint64_t primary_key() const { return account_name.value; }
uint64_t primary_key() const { return account_name.value; } };
}; typedef multi_index<N(userhdd), userhdd> userhdd_index;
typedef multi_index<N(userhdd), userhdd> userhdd_index;
struct maccount
struct maccount { {
uint64_t minerid; //矿机id uint64_t minerid; //矿机id
name owner; //拥有矿机的矿主的账户名 name owner; //拥有矿机的矿主的账户名
uint64_t space; //生产空间 uint64_t space; //生产空间
int64_t hdd_per_cycle_profit; //每周期收益 int64_t hdd_per_cycle_profit; //每周期收益
int64_t hdd_balance; //余额 int64_t hdd_balance; //余额
uint64_t last_hdd_time; //上次余额计算时间 microseconds from 1970 uint64_t last_hdd_time; //上次余额计算时间 microseconds from 1970
uint64_t primary_key() const { return minerid; } uint64_t primary_key() const { return minerid; }
//uint64_t get_owner() const { return owner.value; } //uint64_t get_owner() const { return owner.value; }
}; };
typedef multi_index< N(maccount), maccount > maccount_index; typedef multi_index<N(maccount), maccount> maccount_index;
struct hdd_global_state
struct hdd_global_state { {
int64_t hdd_total_balance = 10000000000; int64_t hdd_total_balance = 10000000000;
}; };
struct hdd_global_state2 { struct hdd_global_state2
uint64_t hdd_total_user = 4; {
}; uint64_t hdd_total_user = 4;
};
struct hdd_global_state3 {
uint64_t hdd_macc_user = 2; struct hdd_global_state3
}; {
uint64_t hdd_macc_user = 2;
struct hdd_global_price { };
int64_t price = 70;
}; struct hdd_global_price
{
int64_t price = 70;
typedef eosio::singleton<N(hddglobal), hdd_global_state> global_state_singleton; };
typedef eosio::singleton<N(gusercount), hdd_global_state2> gusercount_singleton;
typedef eosio::singleton<N(gmacccount), hdd_global_state3> gmacccount_singleton; typedef eosio::singleton<N(hddglobal), hdd_global_state> global_state_singleton;
typedef eosio::singleton<N(ghddprice), hdd_global_price> ghddprice_singleton; typedef eosio::singleton<N(gusercount), hdd_global_state2> gusercount_singleton;
typedef eosio::singleton<N(gmacccount), hdd_global_state3> gmacccount_singleton;
global_state_singleton _global; typedef eosio::singleton<N(ghddprice), hdd_global_price> ghddprice_singleton;
hdd_global_state _gstate;
global_state_singleton _global;
gusercount_singleton _global2; hdd_global_state _gstate;
hdd_global_state2 _gstate2;
gusercount_singleton _global2;
gmacccount_singleton _global3; hdd_global_state2 _gstate2;
hdd_global_state3 _gstate3;
gmacccount_singleton _global3;
ghddprice_singleton _ghddprice; hdd_global_state3 _gstate3;
hdd_global_price _ghddpriceState;
ghddprice_singleton _ghddprice;
hmarket_table _hmarket; hdd_global_price _ghddpriceState;
hmarket_table _hmarket;
bool is_bp_account(uint64_t uservalue);
bool is_bp_account(uint64_t uservalue);
bool calculate_balance(int64_t oldbalance, int64_t hdd_per_cycle_fee,
int64_t hdd_per_cycle_profit, uint64_t last_hdd_time, uint64_t current_time, bool calculate_balance(int64_t oldbalance, int64_t hdd_per_cycle_fee,
int64_t &new_balance); int64_t hdd_per_cycle_profit, uint64_t last_hdd_time, uint64_t current_time,
int64_t &new_balance);
void update_hddofficial( const int64_t _balance,
const int64_t _fee, const int64_t _profit, void update_hddofficial(const int64_t _balance,
const int64_t _space ); const int64_t _fee, const int64_t _profit,
const int64_t _space);
void update_total_hdd_balance( int64_t _balance_delta );
void update_total_hdd_balance(int64_t _balance_delta);
}; };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册