Move some code from hpp file to cpp file
This commit is contained in:
parent
d4c7c97f4c
commit
46be31644b
2 changed files with 162 additions and 163 deletions
|
|
@ -229,6 +229,113 @@ void elasticsearch_plugin_impl::getOperationType(const optional <operation_histo
|
|||
op_type = oho->op.which();
|
||||
}
|
||||
|
||||
struct adaptor_struct
|
||||
{
|
||||
variant adapt(const variant_object& op)
|
||||
{
|
||||
fc::mutable_variant_object o(op);
|
||||
vector<string> keys_to_rename;
|
||||
for (auto i = o.begin(); i != o.end(); ++i)
|
||||
{
|
||||
auto& element = (*i).value();
|
||||
if (element.is_object())
|
||||
{
|
||||
const string& name = (*i).key();
|
||||
auto& vo = element.get_object();
|
||||
if (vo.contains(name.c_str()))
|
||||
keys_to_rename.emplace_back(name);
|
||||
element = adapt(vo);
|
||||
}
|
||||
else if (element.is_array())
|
||||
adapt(element.get_array());
|
||||
}
|
||||
for (const auto& i : keys_to_rename)
|
||||
{
|
||||
string new_name = i + "_";
|
||||
o[new_name] = variant(o[i]);
|
||||
o.erase(i);
|
||||
}
|
||||
|
||||
if (o.find("memo") != o.end())
|
||||
{
|
||||
auto& memo = o["memo"];
|
||||
if (memo.is_string())
|
||||
{
|
||||
o["memo_"] = o["memo"];
|
||||
o.erase("memo");
|
||||
}
|
||||
else if (memo.is_object())
|
||||
{
|
||||
fc::mutable_variant_object tmp(memo.get_object());
|
||||
if (tmp.find("nonce") != tmp.end())
|
||||
{
|
||||
tmp["nonce"] = tmp["nonce"].as_string();
|
||||
o["memo"] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (o.find("new_parameters") != o.end())
|
||||
{
|
||||
auto& tmp = o["new_parameters"];
|
||||
if (tmp.is_object())
|
||||
{
|
||||
fc::mutable_variant_object tmp2(tmp.get_object());
|
||||
if (tmp2.find("current_fees") != tmp2.end())
|
||||
{
|
||||
tmp2.erase("current_fees");
|
||||
o["new_parameters"] = tmp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (o.find("owner") != o.end() && o["owner"].is_string())
|
||||
{
|
||||
o["owner_"] = o["owner"].as_string();
|
||||
o.erase("owner");
|
||||
}
|
||||
if (o.find("proposed_ops") != o.end())
|
||||
{
|
||||
o["proposed_ops"] = fc::json::to_string(o["proposed_ops"]);
|
||||
}
|
||||
if (o.find("initializer") != o.end())
|
||||
{
|
||||
o["initializer"] = fc::json::to_string(o["initializer"]);
|
||||
}
|
||||
if (o.find("policy") != o.end())
|
||||
{
|
||||
o["policy"] = fc::json::to_string(o["policy"]);
|
||||
}
|
||||
if (o.find("predicates") != o.end())
|
||||
{
|
||||
o["predicates"] = fc::json::to_string(o["predicates"]);
|
||||
}
|
||||
if (o.find("active_special_authority") != o.end())
|
||||
{
|
||||
o["active_special_authority"] = fc::json::to_string(o["active_special_authority"]);
|
||||
}
|
||||
if (o.find("owner_special_authority") != o.end())
|
||||
{
|
||||
o["owner_special_authority"] = fc::json::to_string(o["owner_special_authority"]);
|
||||
}
|
||||
|
||||
variant v;
|
||||
fc::to_variant(o, v, FC_PACK_MAX_DEPTH);
|
||||
return v;
|
||||
}
|
||||
|
||||
void adapt(fc::variants& v)
|
||||
{
|
||||
for (auto& array_element : v)
|
||||
{
|
||||
if (array_element.is_object())
|
||||
array_element = adapt(array_element.get_object());
|
||||
else if (array_element.is_array())
|
||||
adapt(array_element.get_array());
|
||||
else
|
||||
array_element = array_element.as_string();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void elasticsearch_plugin_impl::doOperationHistory(const optional <operation_history_object>& oho)
|
||||
{
|
||||
os.trx_in_block = oho->trx_in_block;
|
||||
|
|
@ -255,6 +362,61 @@ void elasticsearch_plugin_impl::doBlock(uint32_t trx_in_block, const signed_bloc
|
|||
bs.trx_id = trx_id;
|
||||
}
|
||||
|
||||
struct operation_visitor
|
||||
{
|
||||
typedef void result_type;
|
||||
|
||||
share_type fee_amount;
|
||||
asset_id_type fee_asset;
|
||||
|
||||
asset_id_type transfer_asset_id;
|
||||
share_type transfer_amount;
|
||||
account_id_type transfer_from;
|
||||
account_id_type transfer_to;
|
||||
|
||||
void operator()( const graphene::chain::transfer_operation& o )
|
||||
{
|
||||
fee_asset = o.fee.asset_id;
|
||||
fee_amount = o.fee.amount;
|
||||
|
||||
transfer_asset_id = o.amount.asset_id;
|
||||
transfer_amount = o.amount.amount;
|
||||
transfer_from = o.from;
|
||||
transfer_to = o.to;
|
||||
}
|
||||
|
||||
object_id_type fill_order_id;
|
||||
account_id_type fill_account_id;
|
||||
asset_id_type fill_pays_asset_id;
|
||||
share_type fill_pays_amount;
|
||||
asset_id_type fill_receives_asset_id;
|
||||
share_type fill_receives_amount;
|
||||
//double fill_fill_price;
|
||||
//bool fill_is_maker;
|
||||
|
||||
void operator()( const graphene::chain::fill_order_operation& o )
|
||||
{
|
||||
fee_asset = o.fee.asset_id;
|
||||
fee_amount = o.fee.amount;
|
||||
|
||||
fill_order_id = o.order_id;
|
||||
fill_account_id = o.account_id;
|
||||
fill_pays_asset_id = o.pays.asset_id;
|
||||
fill_pays_amount = o.pays.amount;
|
||||
fill_receives_asset_id = o.receives.asset_id;
|
||||
fill_receives_amount = o.receives.amount;
|
||||
//fill_fill_price = o.fill_price.to_real();
|
||||
//fill_is_maker = o.is_maker;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void operator()( const T& o )
|
||||
{
|
||||
fee_asset = o.fee.asset_id;
|
||||
fee_amount = o.fee.amount;
|
||||
}
|
||||
};
|
||||
|
||||
void elasticsearch_plugin_impl::doVisitor(const optional <operation_history_object>& oho)
|
||||
{
|
||||
graphene::chain::database& db = database();
|
||||
|
|
|
|||
|
|
@ -79,62 +79,6 @@ class elasticsearch_plugin : public graphene::app::plugin
|
|||
graphene::utilities::ES prepareHistoryQuery(string query);
|
||||
};
|
||||
|
||||
|
||||
struct operation_visitor
|
||||
{
|
||||
typedef void result_type;
|
||||
|
||||
share_type fee_amount;
|
||||
asset_id_type fee_asset;
|
||||
|
||||
asset_id_type transfer_asset_id;
|
||||
share_type transfer_amount;
|
||||
account_id_type transfer_from;
|
||||
account_id_type transfer_to;
|
||||
|
||||
void operator()( const graphene::chain::transfer_operation& o )
|
||||
{
|
||||
fee_asset = o.fee.asset_id;
|
||||
fee_amount = o.fee.amount;
|
||||
|
||||
transfer_asset_id = o.amount.asset_id;
|
||||
transfer_amount = o.amount.amount;
|
||||
transfer_from = o.from;
|
||||
transfer_to = o.to;
|
||||
}
|
||||
|
||||
object_id_type fill_order_id;
|
||||
account_id_type fill_account_id;
|
||||
asset_id_type fill_pays_asset_id;
|
||||
share_type fill_pays_amount;
|
||||
asset_id_type fill_receives_asset_id;
|
||||
share_type fill_receives_amount;
|
||||
//double fill_fill_price;
|
||||
//bool fill_is_maker;
|
||||
|
||||
void operator()( const graphene::chain::fill_order_operation& o )
|
||||
{
|
||||
fee_asset = o.fee.asset_id;
|
||||
fee_amount = o.fee.amount;
|
||||
|
||||
fill_order_id = o.order_id;
|
||||
fill_account_id = o.account_id;
|
||||
fill_pays_asset_id = o.pays.asset_id;
|
||||
fill_pays_amount = o.pays.amount;
|
||||
fill_receives_asset_id = o.receives.asset_id;
|
||||
fill_receives_amount = o.receives.amount;
|
||||
//fill_fill_price = o.fill_price.to_real();
|
||||
//fill_is_maker = o.is_maker;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void operator()( const T& o )
|
||||
{
|
||||
fee_asset = o.fee.asset_id;
|
||||
fee_amount = o.fee.amount;
|
||||
}
|
||||
};
|
||||
|
||||
struct operation_history_struct {
|
||||
int trx_in_block;
|
||||
int op_in_trx;
|
||||
|
|
@ -197,113 +141,6 @@ struct bulk_struct {
|
|||
optional<visitor_struct> additional_data;
|
||||
};
|
||||
|
||||
struct adaptor_struct {
|
||||
variant adapt(const variant_object& op)
|
||||
{
|
||||
fc::mutable_variant_object o(op);
|
||||
vector<string> keys_to_rename;
|
||||
for (auto i = o.begin(); i != o.end(); ++i)
|
||||
{
|
||||
auto& element = (*i).value();
|
||||
if (element.is_object())
|
||||
{
|
||||
const string& name = (*i).key();
|
||||
auto& vo = element.get_object();
|
||||
if (vo.contains(name.c_str()))
|
||||
keys_to_rename.emplace_back(name);
|
||||
element = adapt(vo);
|
||||
}
|
||||
else if (element.is_array())
|
||||
adapt(element.get_array());
|
||||
}
|
||||
for (const auto& i : keys_to_rename)
|
||||
{
|
||||
string new_name = i + "_";
|
||||
o[new_name] = variant(o[i]);
|
||||
o.erase(i);
|
||||
}
|
||||
|
||||
if (o.find("memo") != o.end())
|
||||
{
|
||||
auto& memo = o["memo"];
|
||||
if (memo.is_string())
|
||||
{
|
||||
o["memo_"] = o["memo"];
|
||||
o.erase("memo");
|
||||
}
|
||||
else if (memo.is_object())
|
||||
{
|
||||
fc::mutable_variant_object tmp(memo.get_object());
|
||||
if (tmp.find("nonce") != tmp.end())
|
||||
{
|
||||
tmp["nonce"] = tmp["nonce"].as_string();
|
||||
o["memo"] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (o.find("new_parameters") != o.end())
|
||||
{
|
||||
auto& tmp = o["new_parameters"];
|
||||
if (tmp.is_object())
|
||||
{
|
||||
fc::mutable_variant_object tmp2(tmp.get_object());
|
||||
if (tmp2.find("current_fees") != tmp2.end())
|
||||
{
|
||||
tmp2.erase("current_fees");
|
||||
o["new_parameters"] = tmp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (o.find("owner") != o.end() && o["owner"].is_string())
|
||||
{
|
||||
o["owner_"] = o["owner"].as_string();
|
||||
o.erase("owner");
|
||||
}
|
||||
if (o.find("proposed_ops") != o.end())
|
||||
{
|
||||
o["proposed_ops"] = fc::json::to_string(o["proposed_ops"]);
|
||||
}
|
||||
if (o.find("initializer") != o.end())
|
||||
{
|
||||
o["initializer"] = fc::json::to_string(o["initializer"]);
|
||||
}
|
||||
if (o.find("policy") != o.end())
|
||||
{
|
||||
o["policy"] = fc::json::to_string(o["policy"]);
|
||||
}
|
||||
if (o.find("predicates") != o.end())
|
||||
{
|
||||
o["predicates"] = fc::json::to_string(o["predicates"]);
|
||||
}
|
||||
if (o.find("active_special_authority") != o.end())
|
||||
{
|
||||
o["active_special_authority"] = fc::json::to_string(o["active_special_authority"]);
|
||||
}
|
||||
if (o.find("owner_special_authority") != o.end())
|
||||
{
|
||||
o["owner_special_authority"] = fc::json::to_string(o["owner_special_authority"]);
|
||||
}
|
||||
|
||||
|
||||
variant v;
|
||||
fc::to_variant(o, v, FC_PACK_MAX_DEPTH);
|
||||
return v;
|
||||
}
|
||||
|
||||
void adapt(fc::variants& v)
|
||||
{
|
||||
for (auto& array_element : v)
|
||||
{
|
||||
if (array_element.is_object())
|
||||
array_element = adapt(array_element.get_object());
|
||||
else if (array_element.is_array())
|
||||
adapt(array_element.get_array());
|
||||
else
|
||||
array_element = array_element.as_string();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} } //graphene::elasticsearch
|
||||
|
||||
FC_REFLECT_ENUM( graphene::elasticsearch::mode, (only_save)(only_query)(all) )
|
||||
|
|
|
|||
Loading…
Reference in a new issue