Skip to content

Commit fddf08d

Browse files
committed
add limit order objects
1 parent fe4e87b commit fddf08d

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

libraries/plugins/es_objects/es_objects.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <graphene/chain/proposal_object.hpp>
3636
#include <boost/algorithm/string/join.hpp>
3737
#include <graphene/chain/balance_object.hpp>
38+
#include <graphene/chain/market_object.hpp>
3839

3940

4041
namespace graphene { namespace es_objects {
@@ -65,6 +66,7 @@ class es_objects_plugin_impl
6566
bool _es_objects_accounts = true;
6667
bool _es_objects_assets = true;
6768
bool _es_objects_balances = true;
69+
bool _es_objects_limit_orders = true;
6870
bool _es_objects_logs = true;
6971
CURL *curl; // curl handler
7072
vector <string> bulk;
@@ -73,6 +75,7 @@ class es_objects_plugin_impl
7375
void PrepareAccount(const account_object* account_object);
7476
void PrepareAsset(const asset_object* asset_object);
7577
void PrepareBalance(const balance_object* balance_object);
78+
void PrepareLimit(const limit_order_object* limit_object);
7679
void SendBulk();
7780
void createBulk(std::string type, std::string data, std::string id);
7881
};
@@ -120,6 +123,12 @@ void es_objects_plugin_impl::updateDatabase( const vector<object_id_type>& ids ,
120123
if(b != nullptr)
121124
PrepareBalance(b);
122125
}
126+
else if(value.is<limit_order_object>() && _es_objects_limit_orders) {
127+
auto obj = db.find_object(value);
128+
auto l = static_cast<const limit_order_object*>(obj);
129+
if(l != nullptr)
130+
PrepareLimit(l);
131+
}
123132
}
124133
}
125134

@@ -259,6 +268,19 @@ void es_objects_plugin_impl::PrepareBalance(const balance_object* balance_object
259268
createBulk("balance", data, fc::json::to_string(balance_object->owner));
260269
}
261270

271+
void es_objects_plugin_impl::PrepareLimit(const limit_order_object* limit_object)
272+
{
273+
limit_order_struct limit;
274+
limit.expiration = limit_object->expiration;
275+
limit.seller = limit_object->seller;
276+
limit.for_sale = limit_object->for_sale;
277+
limit.sell_price = limit_object->sell_price;
278+
limit.deferred_fee = limit_object->deferred_fee;
279+
280+
std::string data = fc::json::to_string(limit);
281+
createBulk("limitorder", data, fc::json::to_string(limit_object->id));
282+
}
283+
262284
es_objects_plugin_impl::~es_objects_plugin_impl()
263285
{
264286
return;
@@ -298,7 +320,8 @@ void es_objects_plugin::plugin_set_program_options(
298320
("es-objects-proposals", boost::program_options::value<bool>(), "Store proposal objects")
299321
("es-objects-accounts", boost::program_options::value<bool>(), "Store account objects")
300322
("es-objects-assets", boost::program_options::value<bool>(), "Store asset objects")
301-
("es-objects-balances", boost::program_options::value<bool>(), "Store balances object")
323+
("es-objects-balances", boost::program_options::value<bool>(), "Store balances objects")
324+
("es-objects-limit-orders", boost::program_options::value<bool>(), "Store limit order objects")
302325

303326
;
304327
cfg.add(cli);
@@ -333,6 +356,9 @@ void es_objects_plugin::plugin_initialize(const boost::program_options::variable
333356
if (options.count("es-objects-balances")) {
334357
my->_es_objects_balances = options["es-objects-balances"].as<bool>();
335358
}
359+
if (options.count("es-objects-limit-orders")) {
360+
my->_es_objects_limit_orders = options["es-objects-limit-orders"].as<bool>();
361+
}
336362
}
337363

338364
void es_objects_plugin::plugin_startup()

libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,19 @@ struct balance_struct {
101101
asset_id_type asset_id;
102102
share_type amount;
103103
};
104+
struct limit_order_struct {
105+
limit_order_id_type id;
106+
time_point_sec expiration;
107+
account_id_type seller;
108+
share_type for_sale;
109+
price sell_price;
110+
share_type deferred_fee;
111+
};
104112

105113
} } //graphene::es_objects
106114

107115
FC_REFLECT( graphene::es_objects::proposal_struct, (id)(expiration_time)(review_period_time)(proposed_transaction)(required_active_approvals)(available_active_approvals)(required_owner_approvals)(available_owner_approvals)(available_key_approvals) )
108116
FC_REFLECT( graphene::es_objects::account_struct, (id)(membership_expiration_date)(registrar)(referrer)(lifetime_referrer)(network_fee_percentage)(lifetime_referrer_fee_percentage)(referrer_rewards_percentage)(name)(owner_account_auths)(owner_key_auths)(owner_address_auths)(active_account_auths)(active_key_auths)(active_address_auths)(voting_account) )
109117
FC_REFLECT( graphene::es_objects::asset_struct, (id)(symbol)(issuer) )
110-
FC_REFLECT( graphene::es_objects::balance_struct, (id)(owner)(asset_id)(amount) )
118+
FC_REFLECT( graphene::es_objects::balance_struct, (id)(owner)(asset_id)(amount) )
119+
FC_REFLECT( graphene::es_objects::limit_order_struct, (id)(expiration)(seller)(for_sale)(sell_price)(deferred_fee) )

0 commit comments

Comments
 (0)