From 14762062e6e7b76909087eaea5b380992160c01e Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Wed, 2 Aug 2017 12:15:43 -0500 Subject: [PATCH 1/8] Added account history plugin --- .../account_history_api_plugin/CMakeLists.txt | 16 +++ .../account_history_api_plugin.cpp | 48 +++++++ .../account_history_api_plugin.hpp | 28 ++++ plugins/account_history_plugin/CMakeLists.txt | 16 +++ .../account_history_plugin.cpp | 130 ++++++++++++++++++ .../account_history_plugin.hpp | 74 ++++++++++ 6 files changed, 312 insertions(+) create mode 100644 plugins/account_history_api_plugin/CMakeLists.txt create mode 100644 plugins/account_history_api_plugin/account_history_api_plugin.cpp create mode 100644 plugins/account_history_api_plugin/include/eos/account_history_api_plugin/account_history_api_plugin.hpp create mode 100644 plugins/account_history_plugin/CMakeLists.txt create mode 100644 plugins/account_history_plugin/account_history_plugin.cpp create mode 100644 plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp diff --git a/plugins/account_history_api_plugin/CMakeLists.txt b/plugins/account_history_api_plugin/CMakeLists.txt new file mode 100644 index 00000000000..f6938efd6a5 --- /dev/null +++ b/plugins/account_history_api_plugin/CMakeLists.txt @@ -0,0 +1,16 @@ +file(GLOB HEADERS "include/eos/account_history_api_plugin/*.hpp") +add_library( account_history_api_plugin + account_history_api_plugin.cpp + ${HEADERS} ) + +target_link_libraries( account_history_api_plugin account_history_plugin chain_plugin http_plugin appbase ) +target_include_directories( account_history_api_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + +install( TARGETS + account_history_api_plugin + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +install( FILES ${HEADERS} DESTINATION "include/eos/account_history_api_plugin" ) diff --git a/plugins/account_history_api_plugin/account_history_api_plugin.cpp b/plugins/account_history_api_plugin/account_history_api_plugin.cpp new file mode 100644 index 00000000000..aea78844be0 --- /dev/null +++ b/plugins/account_history_api_plugin/account_history_api_plugin.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +#include + +namespace eos { + +using namespace eos; + +account_history_api_plugin::account_history_api_plugin(){} +account_history_api_plugin::~account_history_api_plugin(){} + +void account_history_api_plugin::set_program_options(options_description&, options_description&) {} +void account_history_api_plugin::plugin_initialize(const variables_map&) {} + +#define CALL(api_name, api_handle, api_namespace, call_name) \ +{std::string("/v1/" #api_name "/" #call_name), \ + [this, api_handle](string, string body, url_response_callback cb) mutable { \ + try { \ + if (body.empty()) body = "{}"; \ + auto result = api_handle.call_name(fc::json::from_string(body).as()); \ + cb(200, fc::json::to_string(result)); \ + } catch (fc::eof_exception) { \ + cb(400, "Invalid arguments"); \ + elog("Unable to parse arguments: ${args}", ("args", body)); \ + } catch (fc::exception& e) { \ + cb(500, e.to_detail_string()); \ + elog("Exception encountered while processing ${call}: ${e}", ("call", #api_name "." #call_name)("e", e)); \ + } \ + }} + +#define CHAIN_RO_CALL(call_name) CALL(account_history, ro_api, account_history_apis::read_only, call_name) +#define CHAIN_RW_CALL(call_name) CALL(account_history, rw_api, account_history_apis::read_write, call_name) + +void account_history_api_plugin::plugin_startup() { + ilog( "starting account_history_api_plugin" ); + auto ro_api = app().get_plugin().get_read_only_api(); + auto rw_api = app().get_plugin().get_read_write_api(); + + app().get_plugin().add_api({ + CHAIN_RO_CALL(get_transaction) + }); +} + +void account_history_api_plugin::plugin_shutdown() {} + +} diff --git a/plugins/account_history_api_plugin/include/eos/account_history_api_plugin/account_history_api_plugin.hpp b/plugins/account_history_api_plugin/include/eos/account_history_api_plugin/account_history_api_plugin.hpp new file mode 100644 index 00000000000..dc2d7684bea --- /dev/null +++ b/plugins/account_history_api_plugin/include/eos/account_history_api_plugin/account_history_api_plugin.hpp @@ -0,0 +1,28 @@ +#pragma once +#include +#include +#include + +#include + +namespace eos { + + using namespace appbase; + + class account_history_api_plugin : public plugin { + public: + APPBASE_PLUGIN_REQUIRES((account_history_plugin)(chain_plugin)(http_plugin)) + + account_history_api_plugin(); + virtual ~account_history_api_plugin(); + + virtual void set_program_options(options_description&, options_description&) override; + + void plugin_initialize(const variables_map&); + void plugin_startup(); + void plugin_shutdown(); + + private: + }; + +} diff --git a/plugins/account_history_plugin/CMakeLists.txt b/plugins/account_history_plugin/CMakeLists.txt new file mode 100644 index 00000000000..86e820ca14c --- /dev/null +++ b/plugins/account_history_plugin/CMakeLists.txt @@ -0,0 +1,16 @@ +file(GLOB HEADERS "include/eos/account_history_plugin/*.hpp") +add_library( account_history_plugin + account_history_plugin.cpp + ${HEADERS} ) + +target_link_libraries( account_history_plugin chain_plugin eos_chain appbase ) +target_include_directories( account_history_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + +install( TARGETS + account_history_plugin + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +install( FILES ${HEADERS} DESTINATION "include/eos/account_history_plugin" ) diff --git a/plugins/account_history_plugin/account_history_plugin.cpp b/plugins/account_history_plugin/account_history_plugin.cpp new file mode 100644 index 00000000000..f8c05ad3d0d --- /dev/null +++ b/plugins/account_history_plugin/account_history_plugin.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +namespace eos { + +using namespace eos; +using chain::block_id_type; +using chain::ProcessedTransaction; +using chain::signed_block; +using boost::multi_index_container; +using namespace boost::multi_index; + +struct block_data { + block_id_type block_id; + transaction_id_type transaction_id; +}; + +class account_history_plugin_impl { +public: + ProcessedTransaction get_transaction(const chain::transaction_id_type& transaction_id) const; + void applied_block(const signed_block&); + chain_plugin* chain_plug; +private: + + struct trx_id; + typedef multi_index_container< + block_data, + indexed_by< + hashed_unique, member, std::hash> + > + > block_multi_index_type; + + block_multi_index_type _block_index; +}; + +ProcessedTransaction account_history_plugin_impl::get_transaction(const chain::transaction_id_type& transaction_id) const +{ + const auto& by_trx_idx = _block_index.get(); + auto itr = by_trx_idx.find( transaction_id ); + if( itr != by_trx_idx.end() ) + { + auto block = chain_plug->chain().fetch_block_by_id_backwards(itr->block_id); + if (block.valid()) + { + for (const auto& cycle : block->cycles) + for (const auto& thread : cycle) + for (const auto& trx : thread.user_input) + if (trx.id() == transaction_id) + return trx; + } + + // ERROR in indexing logic + std::string msg = "transaction_id=" + transaction_id.str() + " indexed with block_id=" + itr->block_id.str() + ", but "; + if (!block) + msg += "block was not found"; + else + msg += "transaction was not found in the block"; + BOOST_THROW_EXCEPTION( std::runtime_error( msg ) ); + } + +#warning TODO: lookup of recent transactions + FC_THROW_EXCEPTION(chain::unknown_transaction_exception, + "Could not find transaction for: ${id}", ("id", transaction_id.str())); +} + +void account_history_plugin_impl::applied_block(const signed_block& block) +{ + auto block_id = block.id(); + for (const auto& cycle : block.cycles) + for (const auto& thread : cycle) + for (const auto& trx : thread.user_input) + _block_index.insert({block_id, trx.id()}); +} + + +account_history_plugin::account_history_plugin() +:my(new account_history_plugin_impl()) +{ +} + +account_history_plugin::~account_history_plugin() +{ +} + +void account_history_plugin::set_program_options(options_description& cli, options_description& cfg) +{ +} + +void account_history_plugin::plugin_initialize(const variables_map& options) +{ +} + +void account_history_plugin::plugin_startup() +{ + my->chain_plug = app().find_plugin(); + my->chain_plug->chain().applied_block.connect ([&impl = my](const signed_block& block) { + impl->applied_block(block); + }); +} + +void account_history_plugin::plugin_shutdown() +{ +} + +namespace account_history_apis { + +read_only::get_transaction_results read_only::get_transaction(const read_only::get_transaction_params& params) const +{ + auto trx = account_history->get_transaction(params.transaction_id); + return { account_history->chain_plug->chain().transaction_to_variant(trx) }; +} + +} // namespace account_history_apis +} // namespace eos diff --git a/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp b/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp new file mode 100644 index 00000000000..007f147f868 --- /dev/null +++ b/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp @@ -0,0 +1,74 @@ +#pragma once +#include +#include + +#include + +namespace fc { class variant; } + +namespace eos { + using chain::chain_controller; + using chain::transaction_id_type; + using std::shared_ptr; + using namespace appbase; + using chain::Name; + using fc::optional; + using chain::uint128_t; + + typedef shared_ptr account_history_ptr; + typedef shared_ptr account_history_const_ptr; + +namespace account_history_apis { +struct empty{}; + +class read_only { + account_history_const_ptr account_history; + +public: + read_only(account_history_const_ptr&& account_history) + : account_history(account_history) {} + + struct get_transaction_params { + chain::transaction_id_type transaction_id; + }; + struct get_transaction_results { + fc::variant transaction; + }; + + get_transaction_results get_transaction(const get_transaction_params& params) const; + +}; + +class read_write { + account_history_ptr account_history; + +public: + read_write(account_history_ptr account_history) : account_history(account_history) {} +}; +} // namespace account_history_apis + +class account_history_plugin : public plugin { +public: + APPBASE_PLUGIN_REQUIRES((chain_plugin)) + + account_history_plugin(); + virtual ~account_history_plugin(); + + virtual void set_program_options(options_description& cli, options_description& cfg) override; + + void plugin_initialize(const variables_map& options); + void plugin_startup(); + void plugin_shutdown(); + + account_history_apis::read_only get_read_only_api() const { return account_history_apis::read_only(account_history_const_ptr(my)); } + account_history_apis::read_write get_read_write_api() { return account_history_apis::read_write(my); } + +private: + account_history_ptr my; +}; + +} + +FC_REFLECT(eos::account_history_apis::empty, ) +FC_REFLECT(eos::account_history_apis::read_only::get_transaction_params, (transaction_id) ) +FC_REFLECT(eos::account_history_apis::read_only::get_transaction_results, (transaction) ) From 991165e6e8083821d09956408853b06da3c05b9c Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Wed, 2 Aug 2017 12:16:53 -0500 Subject: [PATCH 2/8] Added account history processing to applications --- libraries/chain/include/eos/chain/exceptions.hpp | 1 + programs/eosc/main.cpp | 3 +++ programs/eosd/CMakeLists.txt | 2 +- programs/eosd/main.cpp | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/chain/include/eos/chain/exceptions.hpp b/libraries/chain/include/eos/chain/exceptions.hpp index d9acb6f49f1..ab200fed3ab 100644 --- a/libraries/chain/include/eos/chain/exceptions.hpp +++ b/libraries/chain/include/eos/chain/exceptions.hpp @@ -52,6 +52,7 @@ namespace eos { namespace chain { FC_DECLARE_DERIVED_EXCEPTION( tx_missing_scope, eos::chain::transaction_exception, 3030008, "missing required scope" ) FC_DECLARE_DERIVED_EXCEPTION( tx_missing_recipient, eos::chain::transaction_exception, 3030009, "missing required recipient" ) FC_DECLARE_DERIVED_EXCEPTION( checktime_exceeded, eos::chain::transaction_exception, 3030010, "allotted processing time was exceeded" ) + FC_DECLARE_DERIVED_EXCEPTION( unknown_transaction_exception, eos::chain::transaction_exception, 3030011, "unknown transaction" ) FC_DECLARE_DERIVED_EXCEPTION( invalid_pts_address, eos::chain::utility_exception, 3060001, "invalid pts address" ) FC_DECLARE_DERIVED_EXCEPTION( insufficient_feeds, eos::chain::chain_exception, 37006, "insufficient feeds" ) diff --git a/programs/eosc/main.cpp b/programs/eosc/main.cpp index 5f0b18823e5..199a816fad0 100644 --- a/programs/eosc/main.cpp +++ b/programs/eosc/main.cpp @@ -264,6 +264,9 @@ int main( int argc, char** argv ) { } else if( command == "do" ) { + } else if( command == "transaction" ) { + FC_ASSERT( args.size() == 3 ); + std::cout << fc::json::to_pretty_string( call( "localhost", 8888, "/v1/account_history/get_transaction", fc::mutable_variant_object( "transaction_id", args[2]) ) ); } } catch ( const fc::exception& e ) { std::cerr << e.to_detail_string() <<"\n"; diff --git a/programs/eosd/CMakeLists.txt b/programs/eosd/CMakeLists.txt index 3377b284e5d..e29f68199ca 100644 --- a/programs/eosd/CMakeLists.txt +++ b/programs/eosd/CMakeLists.txt @@ -10,7 +10,7 @@ if( GPERFTOOLS_FOUND ) endif() target_link_libraries( eosd - PRIVATE appbase chain_api_plugin producer_plugin chain_plugin net_plugin http_plugin eos_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + PRIVATE appbase account_history_api_plugin account_history_plugin chain_api_plugin producer_plugin chain_plugin net_plugin http_plugin eos_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) install( TARGETS eosd diff --git a/programs/eosd/main.cpp b/programs/eosd/main.cpp index a317fb317b7..9203f9a92b7 100644 --- a/programs/eosd/main.cpp +++ b/programs/eosd/main.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include @@ -22,6 +24,8 @@ int main(int argc, char** argv) app().register_plugin(); app().register_plugin(); app().register_plugin(); + app().register_plugin(); + app().register_plugin(); if(!app().initialize(argc, argv)) return -1; app().startup(); From 65c1ceb7e8453657e80412efcff20d529203cf05 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Wed, 2 Aug 2017 16:13:58 -0500 Subject: [PATCH 3/8] Added plugins to cmake and removed unintended commit --- plugins/CMakeLists.txt | 2 ++ plugins/account_history_plugin/account_history_plugin.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 9b0480effa2..85eaccbaafb 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -4,3 +4,5 @@ add_subdirectory(database_plugin) add_subdirectory(chain_plugin) add_subdirectory(chain_api_plugin) add_subdirectory(producer_plugin) +add_subdirectory(account_history_plugin) +add_subdirectory(account_history_api_plugin) diff --git a/plugins/account_history_plugin/account_history_plugin.cpp b/plugins/account_history_plugin/account_history_plugin.cpp index f8c05ad3d0d..6b71d02f26e 100644 --- a/plugins/account_history_plugin/account_history_plugin.cpp +++ b/plugins/account_history_plugin/account_history_plugin.cpp @@ -55,7 +55,7 @@ ProcessedTransaction account_history_plugin_impl::get_transaction(const chain::t auto itr = by_trx_idx.find( transaction_id ); if( itr != by_trx_idx.end() ) { - auto block = chain_plug->chain().fetch_block_by_id_backwards(itr->block_id); + auto block = chain_plug->chain().fetch_block_by_id(itr->block_id); if (block.valid()) { for (const auto& cycle : block->cycles) From a251af2f4c9f5357110bc5f3f7822f03181e65e9 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 4 Aug 2017 12:20:18 -0500 Subject: [PATCH 4/8] Moved transaction tracking into database --- libraries/chain/include/eos/chain/types.hpp | 2 + .../account_history_plugin.cpp | 85 ++++++++++++------- .../account_history_plugin.hpp | 2 - 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/libraries/chain/include/eos/chain/types.hpp b/libraries/chain/include/eos/chain/types.hpp index 62949e704a7..8813e7c560a 100644 --- a/libraries/chain/include/eos/chain/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -171,6 +171,7 @@ namespace eos { namespace chain { transaction_object_type, producer_object_type, chain_property_object_type, + transaction_history_object_type, balance_object_type, ///< Defined by native_contract library staked_balance_object_type, ///< Defined by native_contract library producer_votes_object_type, ///< Defined by native_contract library @@ -216,6 +217,7 @@ FC_REFLECT_ENUM(eos::chain::object_type, (transaction_object_type) (producer_object_type) (chain_property_object_type) + (transaction_history_object_type) (balance_object_type) (staked_balance_object_type) (producer_votes_object_type) diff --git a/plugins/account_history_plugin/account_history_plugin.cpp b/plugins/account_history_plugin/account_history_plugin.cpp index 6b71d02f26e..4a263aab27e 100644 --- a/plugins/account_history_plugin/account_history_plugin.cpp +++ b/plugins/account_history_plugin/account_history_plugin.cpp @@ -1,36 +1,47 @@ #include -#include -#include -#include -#include +#include #include +#include +#include #include +#include #include #include -#include -#include -#include #include #include - -#include +#include namespace eos { -using namespace eos; using chain::block_id_type; using chain::ProcessedTransaction; using chain::signed_block; using boost::multi_index_container; +using chain::transaction_id_type; using namespace boost::multi_index; -struct block_data { - block_id_type block_id; +class transaction_history_object : public chainbase::object { + OBJECT_CTOR(transaction_history_object) + + id_type id; + block_id_type block_id; transaction_id_type transaction_id; }; +struct by_id; +struct by_trx_id; +using transaction_history_multi_index = chainbase::shared_multi_index_container< + transaction_history_object, + indexed_by< + ordered_unique, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_history_object::id_type, id)>, + hashed_unique, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_id_type, transaction_id), std::hash> + > +>; + +typedef chainbase::generic_index transaction_history_index; + class account_history_plugin_impl { public: ProcessedTransaction get_transaction(const chain::transaction_id_type& transaction_id) const; @@ -38,24 +49,28 @@ class account_history_plugin_impl { chain_plugin* chain_plug; private: - struct trx_id; - typedef multi_index_container< - block_data, - indexed_by< - hashed_unique, member, std::hash> - > - > block_multi_index_type; - - block_multi_index_type _block_index; + optional find_block_id(const transaction_id_type& transaction_id) const; }; +optional account_history_plugin_impl::find_block_id(const transaction_id_type& transaction_id) const +{ + const auto& db = chain_plug->chain().get_database(); + optional block_id; + db.with_read_lock( [&]() { + const auto& trx_idx = db.get_index(); + auto transaction_history = trx_idx.find( transaction_id ); + if (transaction_history != trx_idx.end()) + block_id = transaction_history->block_id; + } ); + return block_id; +} + ProcessedTransaction account_history_plugin_impl::get_transaction(const chain::transaction_id_type& transaction_id) const { - const auto& by_trx_idx = _block_index.get(); - auto itr = by_trx_idx.find( transaction_id ); - if( itr != by_trx_idx.end() ) + auto block_id = find_block_id(transaction_id); + if( block_id.valid() ) { - auto block = chain_plug->chain().fetch_block_by_id(itr->block_id); + auto block = chain_plug->chain().fetch_block_by_id(*block_id); if (block.valid()) { for (const auto& cycle : block->cycles) @@ -66,7 +81,7 @@ ProcessedTransaction account_history_plugin_impl::get_transaction(const chain::t } // ERROR in indexing logic - std::string msg = "transaction_id=" + transaction_id.str() + " indexed with block_id=" + itr->block_id.str() + ", but "; + std::string msg = "transaction_id=" + transaction_id.str() + " indexed with block_id=" + block_id->str() + ", but "; if (!block) msg += "block was not found"; else @@ -81,11 +96,16 @@ ProcessedTransaction account_history_plugin_impl::get_transaction(const chain::t void account_history_plugin_impl::applied_block(const signed_block& block) { - auto block_id = block.id(); + const auto block_id = block.id(); + auto& db = chain_plug->chain().get_mutable_database(); for (const auto& cycle : block.cycles) for (const auto& thread : cycle) - for (const auto& trx : thread.user_input) - _block_index.insert({block_id, trx.id()}); + for (const auto& trx : thread.user_input) { + db.create([&block_id,&trx](transaction_history_object& transaction_history) { + transaction_history.block_id = block_id; + transaction_history.transaction_id = trx.id(); + }); + } } @@ -109,6 +129,9 @@ void account_history_plugin::plugin_initialize(const variables_map& options) void account_history_plugin::plugin_startup() { my->chain_plug = app().find_plugin(); + auto& db = my->chain_plug->chain().get_mutable_database(); + db.add_index(); + my->chain_plug->chain().applied_block.connect ([&impl = my](const signed_block& block) { impl->applied_block(block); }); @@ -128,3 +151,7 @@ read_only::get_transaction_results read_only::get_transaction(const read_only::g } // namespace account_history_apis } // namespace eos + +CHAINBASE_SET_INDEX_TYPE( eos::transaction_history_object, eos::transaction_history_multi_index ) + +FC_REFLECT( eos::transaction_history_object, (block_id)(transaction_id) ) diff --git a/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp b/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp index 007f147f868..a1acdfcc770 100644 --- a/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp +++ b/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_plugin.hpp @@ -1,13 +1,11 @@ #pragma once #include -#include #include namespace fc { class variant; } namespace eos { - using chain::chain_controller; using chain::transaction_id_type; using std::shared_ptr; using namespace appbase; From 3122cabb39bf5f219a4b6517416d9162413b19d0 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Fri, 4 Aug 2017 12:59:59 -0500 Subject: [PATCH 5/8] Updating chainbase submodule --- libraries/chainbase | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chainbase b/libraries/chainbase index f1a150f97bf..d48ebabf56b 160000 --- a/libraries/chainbase +++ b/libraries/chainbase @@ -1 +1 @@ -Subproject commit f1a150f97bfde1b10113b77c22206e5c00158205 +Subproject commit d48ebabf56b4115753fcabb7648a0ffcf3b0f5e9 From 4a4026eb83679535fd690c8ec238d7f433c6fe0c Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 8 Aug 2017 12:20:20 -0500 Subject: [PATCH 6/8] Moved object and multi index definition to its own header file and added type comment --- libraries/chain/include/eos/chain/types.hpp | 2 +- .../account_history_plugin.cpp | 27 ++------------ .../account_history_object.hpp | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 plugins/account_history_plugin/include/eos/account_history_plugin/account_history_object.hpp diff --git a/libraries/chain/include/eos/chain/types.hpp b/libraries/chain/include/eos/chain/types.hpp index 8813e7c560a..a121d3c199f 100644 --- a/libraries/chain/include/eos/chain/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -171,7 +171,7 @@ namespace eos { namespace chain { transaction_object_type, producer_object_type, chain_property_object_type, - transaction_history_object_type, + transaction_history_object_type, ///< Defined by account history plugin library balance_object_type, ///< Defined by native_contract library staked_balance_object_type, ///< Defined by native_contract library producer_votes_object_type, ///< Defined by native_contract library diff --git a/plugins/account_history_plugin/account_history_plugin.cpp b/plugins/account_history_plugin/account_history_plugin.cpp index 4a263aab27e..9c1a2f57f61 100644 --- a/plugins/account_history_plugin/account_history_plugin.cpp +++ b/plugins/account_history_plugin/account_history_plugin.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -13,6 +14,8 @@ #include #include +namespace fc { class variant; } + namespace eos { using chain::block_id_type; @@ -22,26 +25,6 @@ using boost::multi_index_container; using chain::transaction_id_type; using namespace boost::multi_index; -class transaction_history_object : public chainbase::object { - OBJECT_CTOR(transaction_history_object) - - id_type id; - block_id_type block_id; - transaction_id_type transaction_id; -}; - -struct by_id; -struct by_trx_id; -using transaction_history_multi_index = chainbase::shared_multi_index_container< - transaction_history_object, - indexed_by< - ordered_unique, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_history_object::id_type, id)>, - hashed_unique, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_id_type, transaction_id), std::hash> - > ->; - -typedef chainbase::generic_index transaction_history_index; - class account_history_plugin_impl { public: ProcessedTransaction get_transaction(const chain::transaction_id_type& transaction_id) const; @@ -151,7 +134,3 @@ read_only::get_transaction_results read_only::get_transaction(const read_only::g } // namespace account_history_apis } // namespace eos - -CHAINBASE_SET_INDEX_TYPE( eos::transaction_history_object, eos::transaction_history_multi_index ) - -FC_REFLECT( eos::transaction_history_object, (block_id)(transaction_id) ) diff --git a/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_object.hpp b/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_object.hpp new file mode 100644 index 00000000000..2b6ab38a7a1 --- /dev/null +++ b/plugins/account_history_plugin/include/eos/account_history_plugin/account_history_object.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include + +namespace eos { +using chain::block_id_type; +using chain::transaction_id_type; +using namespace boost::multi_index; + +class transaction_history_object : public chainbase::object { + OBJECT_CTOR(transaction_history_object) + + id_type id; + block_id_type block_id; + transaction_id_type transaction_id; +}; + +struct by_id; +struct by_trx_id; +using transaction_history_multi_index = chainbase::shared_multi_index_container< + transaction_history_object, + indexed_by< + ordered_unique, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_history_object::id_type, id)>, + hashed_unique, BOOST_MULTI_INDEX_MEMBER(transaction_history_object, transaction_id_type, transaction_id), std::hash> + > +>; + +typedef chainbase::generic_index transaction_history_index; + +} + +CHAINBASE_SET_INDEX_TYPE( eos::transaction_history_object, eos::transaction_history_multi_index ) + +FC_REFLECT( eos::transaction_history_object, (block_id)(transaction_id) ) + From 91da03039e3e2722927e624a781c7c89b407f200 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 8 Aug 2017 13:13:51 -0500 Subject: [PATCH 7/8] Minor review fixes --- libraries/chain/include/eos/chain/types.hpp | 2 +- plugins/account_history_plugin/account_history_plugin.cpp | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/libraries/chain/include/eos/chain/types.hpp b/libraries/chain/include/eos/chain/types.hpp index a121d3c199f..f731f548a32 100644 --- a/libraries/chain/include/eos/chain/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -171,7 +171,7 @@ namespace eos { namespace chain { transaction_object_type, producer_object_type, chain_property_object_type, - transaction_history_object_type, ///< Defined by account history plugin library + transaction_history_object_type, ///< Defined by account_history_plugin library balance_object_type, ///< Defined by native_contract library staked_balance_object_type, ///< Defined by native_contract library producer_votes_object_type, ///< Defined by native_contract library diff --git a/plugins/account_history_plugin/account_history_plugin.cpp b/plugins/account_history_plugin/account_history_plugin.cpp index 9c1a2f57f61..d8e891b7bb4 100644 --- a/plugins/account_history_plugin/account_history_plugin.cpp +++ b/plugins/account_history_plugin/account_history_plugin.cpp @@ -64,12 +64,8 @@ ProcessedTransaction account_history_plugin_impl::get_transaction(const chain::t } // ERROR in indexing logic - std::string msg = "transaction_id=" + transaction_id.str() + " indexed with block_id=" + block_id->str() + ", but "; - if (!block) - msg += "block was not found"; - else - msg += "transaction was not found in the block"; - BOOST_THROW_EXCEPTION( std::runtime_error( msg ) ); + FC_ASSERT(block, "Transaction with ID ${tid} was indexed as being in block ID ${bid}, but no such block was found", ("tid", transaction_id)("bid", block_id)); + FC_THROW("Transaction with ID ${tid} was indexed as being in block ID ${bid}, but was not found in that block", ("tid", transaction_id)("bid", block_id)); } #warning TODO: lookup of recent transactions From 809bb82345ce0c6b6c1139ac1e61c2bd1c29a6a8 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 8 Aug 2017 13:46:03 -0500 Subject: [PATCH 8/8] Removed erroneous word in comment --- libraries/chain/include/eos/chain/types.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/include/eos/chain/types.hpp b/libraries/chain/include/eos/chain/types.hpp index f731f548a32..0cfb844caa5 100644 --- a/libraries/chain/include/eos/chain/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -171,7 +171,7 @@ namespace eos { namespace chain { transaction_object_type, producer_object_type, chain_property_object_type, - transaction_history_object_type, ///< Defined by account_history_plugin library + transaction_history_object_type, ///< Defined by account_history_plugin balance_object_type, ///< Defined by native_contract library staked_balance_object_type, ///< Defined by native_contract library producer_votes_object_type, ///< Defined by native_contract library