Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom operation related changes #2108

Merged
merged 12 commits into from
Feb 28, 2020
14 changes: 6 additions & 8 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ namespace graphene { namespace app {
return *_debug_api;
}

fc::api<custom_operations_api> login_api::custom() const
fc::api<custom_operations_api> login_api::custom_operations() const
{
FC_ASSERT(_custom_operations_api);
return *_custom_operations_api;
Expand Down Expand Up @@ -676,7 +676,7 @@ namespace graphene { namespace app {
max_price = std::max( std::min( max_price, *start ), min_price );

auto itr = limit_groups.lower_bound( limit_order_group_key( group, max_price ) );
// use an end itrator to try to avoid expensive price comparison
// use an end iterator to try to avoid expensive price comparison
auto end = limit_groups.upper_bound( limit_order_group_key( group, min_price ) );
while( itr != end && result.size() < limit )
{
Expand All @@ -696,12 +696,10 @@ namespace graphene { namespace app {
const auto account_id = database_api.get_account_id_from_string(account_id_or_name);
vector<account_storage_object> results;
const auto& storage_index = _app.chain_database()->get_index_type<account_storage_index>();
const auto& by_account_catalog_idx = storage_index.indices().get<by_account_catalog>();
auto itr = by_account_catalog_idx.lower_bound(make_tuple(account_id, catalog));
while(itr != by_account_catalog_idx.end() && itr->account == account_id && itr->catalog == catalog) {
results.push_back(*itr);
++itr;
}
const auto& by_account_catalog_idx = storage_index.indices().get<by_account_catalog_key>();
auto range = by_account_catalog_idx.equal_range(make_tuple(account_id, catalog));
for( const account_storage_object& aso : boost::make_iterator_range( range.first, range.second ) )
results.push_back(aso);
return results;
}

Expand Down
8 changes: 4 additions & 4 deletions libraries/app/include/graphene/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,12 @@ namespace graphene { namespace app {
/**
* @brief Get all stored objects of an account in a particular catalog
*
* @param account Account name to get info from
* @param account Account name or ID to get info from
* @param catalog Category classification. Each account can store multiple catalogs.
*
* @return The vector of objects of the account or empty
*/
vector<account_storage_object> get_storage_info(std::string account, std::string catalog)const;
vector<account_storage_object> get_storage_info(std::string account_id_or_name, std::string catalog)const;

private:
application& _app;
Expand Down Expand Up @@ -598,7 +598,7 @@ namespace graphene { namespace app {
/// @brief Retrieve the debug API (if available)
fc::api<graphene::debug_witness::debug_api> debug()const;
/// @brief Retrieve the custom operations API
fc::api<custom_operations_api> custom()const;
fc::api<custom_operations_api> custom_operations()const;

/// @brief Called to enable an API, not reflected.
void enable_api( const string& api_name );
Expand Down Expand Up @@ -695,5 +695,5 @@ FC_API(graphene::app::login_api,
(asset)
(orders)
(debug)
(custom)
(custom_operations)
)
6 changes: 3 additions & 3 deletions libraries/plugins/custom_operations/custom_evaluators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vector<object_id_type> custom_generic_evaluator::do_apply(const account_storage_
for(auto const& row: op.key_values) {
if(row.first.length() > CUSTOM_OPERATIONS_MAX_KEY_SIZE)
{
dlog("Key can't be bigger than ${max} characters", ("max", CUSTOM_OPERATIONS_MAX_KEY_SIZE));
wlog("Key can't be bigger than ${max} characters", ("max", CUSTOM_OPERATIONS_MAX_KEY_SIZE));
continue;
}
auto itr = index.find(make_tuple(_account, op.catalog, row.first));
Expand All @@ -70,7 +70,7 @@ vector<object_id_type> custom_generic_evaluator::do_apply(const account_storage_
});
results.push_back(created.id);
}
catch(const fc::parse_error_exception& e) { dlog(e.to_detail_string()); }
catch(const fc::parse_error_exception& e) { wlog(e.to_detail_string()); }
}
else
{
Expand All @@ -84,7 +84,7 @@ vector<object_id_type> custom_generic_evaluator::do_apply(const account_storage_
});
results.push_back(itr->id);
}
catch(const fc::parse_error_exception& e) { dlog((e.to_detail_string())); }
catch(const fc::parse_error_exception& e) { wlog((e.to_detail_string())); }
}
}
}
Expand Down
23 changes: 18 additions & 5 deletions libraries/plugins/custom_operations/custom_operations_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class custom_operations_plugin_impl
{ }
virtual ~custom_operations_plugin_impl();

void onBlock( const signed_block& b );
void onBlock();

graphene::chain::database& database()
{
Expand All @@ -49,6 +49,8 @@ class custom_operations_plugin_impl

custom_operations_plugin& _self;

uint32_t _after_block = 1;

private:

};
Expand All @@ -69,7 +71,7 @@ struct custom_op_visitor
}
};

void custom_operations_plugin_impl::onBlock( const signed_block& b )
void custom_operations_plugin_impl::onBlock()
{
graphene::chain::database& db = database();
const vector<optional< operation_history_object > >& hist = db.get_applied_operations();
Expand All @@ -88,8 +90,8 @@ void custom_operations_plugin_impl::onBlock( const signed_block& b )
custom_op_visitor vtor(db, custom_op.fee_payer());
unpacked.visit(vtor);
}
catch (fc::exception e) { // only api node will know if the unpack, validate or apply fails
dlog("Custom operations plugin serializing error: ${ex} in operation: ${op}",
catch (fc::exception& e) { // only api node will know if the unpack, validate or apply fails
wlog("Custom operations plugin serializing error: ${ex} in operation: ${op}",
("ex", e.to_detail_string())("op", fc::json::to_string(custom_op)));
continue;
}
Expand Down Expand Up @@ -126,14 +128,25 @@ void custom_operations_plugin::plugin_set_program_options(
boost::program_options::options_description& cfg
)
{
cli.add_options()
("custom-operations-start-after-block", boost::program_options::value<uint32_t>(),
"Start processing custom operations transactions with the plugin only after this block(1)")
;
cfg.add(cli);

}

void custom_operations_plugin::plugin_initialize(const boost::program_options::variables_map& options)
{
database().add_index< primary_index< account_storage_index > >();

if (options.count("custom-operations-start-after-block")) {
my->_after_block = options["elasticsearch-bulk-replay"].as<uint32_t>();
}

database().applied_block.connect( [this]( const signed_block& b) {
my->onBlock(b);
if( b.block_num() >= my->_after_block )
my->onBlock();
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,13 @@ struct account_storage_object : public abstract_object<account_storage_object>
};

struct by_custom_id;
struct by_custom_account;
struct by_account_catalog;
struct by_account_catalog_key;

typedef multi_index_container<
account_storage_object,
indexed_by<
ordered_non_unique< tag<by_custom_id>, member< object, object_id_type, &object::id > >,
ordered_non_unique< tag<by_custom_account>,
member< account_storage_object, account_id_type, &account_storage_object::account > >,
ordered_non_unique< tag<by_account_catalog>,
composite_key< account_storage_object,
member< account_storage_object, account_id_type, &account_storage_object::account >,
member< account_storage_object, string, &account_storage_object::catalog >
>
>,
ordered_non_unique< tag<by_account_catalog_key>,
ordered_unique< tag<by_custom_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_account_catalog_key>,
composite_key< account_storage_object,
member< account_storage_object, account_id_type, &account_storage_object::account >,
member< account_storage_object, string, &account_storage_object::catalog >,
Expand Down
2 changes: 1 addition & 1 deletion libraries/wallet/wallet_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace graphene { namespace wallet { namespace detail {
_remote_hist(rapi->history())
{
try {
_custom_operations = rapi->custom();
_custom_operations = rapi->custom_operations();
}
catch(const fc::exception& e)
{
Expand Down