From cbc7793aaf50d819bcfd3b2a099e7084aebe0706 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 26 Apr 2017 15:52:48 -0400 Subject: [PATCH] progress --- libraries/chain/database.cpp | 12 +++++ .../include/eos/chain/account_object.hpp | 51 +++++++++++++------ .../chain/include/eos/chain/database.hpp | 1 + .../include/eos/chain/protocol/types.hpp | 2 + tests/tests/block_tests.cpp | 5 +- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 6005a5597..af051dc01 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -508,6 +508,16 @@ void database::validate_referenced_accounts( const signed_transaction& trx )cons } } } + +void database::validate_message_types( const signed_transaction& trx )const { +try { + for( const auto& msg : trx.messages ) { + try { + get( boost::make_tuple(msg.recipient, msg.type) ); + } FC_CAPTURE_AND_RETHROW( (msg.recipient)(msg.type) ) + } +} FC_CAPTURE_AND_RETHROW( (trx) ) } + void database::validate_transaction( const signed_transaction& trx )const { try { FC_ASSERT( trx.messages.size() > 0, "A transaction must have at least one message" ); @@ -515,6 +525,7 @@ try { validate_uniqueness( trx ); validate_tapos( trx ); validate_referenced_accounts( trx ); + validate_message_types( trx ); for( const auto& m : trx.messages ) { /// TODO: this loop can be processed in parallel message_validate_context mvc( trx, m ); @@ -686,6 +697,7 @@ void database::initialize_indexes() { add_index(); add_index(); add_index(); + add_index(); add_index(); add_index(); diff --git a/libraries/chain/include/eos/chain/account_object.hpp b/libraries/chain/include/eos/chain/account_object.hpp index a1925da76..a12decd3b 100644 --- a/libraries/chain/include/eos/chain/account_object.hpp +++ b/libraries/chain/include/eos/chain/account_object.hpp @@ -63,14 +63,13 @@ namespace eos { namespace chain { class permission_object : public chainbase::object { - OBJECT_CTOR(permission_object, (name)) - - id_type id; - account_id_type owner; ///< the account this permission belongs to - id_type parent; ///< parent permission - shared_string name; -#warning TODO - add shared_authority to permission object - // shared_authority auth; ///< TODO + OBJECT_CTOR(permission_object, (auth) ) + + id_type id; + account_id_type owner; ///< the account this permission belongs to + id_type parent; ///< parent permission + permission_name name; + shared_authority auth; ///< TODO }; @@ -93,7 +92,7 @@ namespace eos { namespace chain { member > >, - ordered_unique, member, chainbase::strcmp_less> + ordered_unique, member > > >; @@ -103,14 +102,13 @@ namespace eos { namespace chain { */ class action_code_object : public chainbase::object { - OBJECT_CTOR(action_code_object, (action)(validate_action)(validate_precondition)(apply) ) + OBJECT_CTOR(action_code_object, (validate_action)(validate_precondition)(apply) ) id_type id; account_id_type scope; permission_object::id_type permission; -#warning TODO: convert action name to fixed with string - shared_string action; ///< the name of the action (defines serialization) + message_type action; ///< the name of the action (defines serialization) shared_string validate_action; ///< read only access to action shared_string validate_precondition; ///< read only access to state shared_string apply; ///< the code that executes the state transition @@ -125,9 +123,8 @@ namespace eos { namespace chain { ordered_unique, composite_key< action_code_object, member, - member - >, - composite_key_compare< std::less, chainbase::strcmp_less > + member + > > > >; @@ -180,14 +177,38 @@ namespace eos { namespace chain { > >; + struct message_object : public chainbase::object { + public: + id_type id; + account_name scope; + message_type name; + }; + + struct by_scope_name; + using message_index = chainbase::shared_multi_index_container< + message_object, + indexed_by< + ordered_unique, member>, + ordered_unique, + composite_key< message_object, + member, + member + > + > + > + >; + + } } // eos::chain CHAINBASE_SET_INDEX_TYPE(eos::chain::account_object, eos::chain::account_index) CHAINBASE_SET_INDEX_TYPE(eos::chain::permission_object, eos::chain::permission_index) CHAINBASE_SET_INDEX_TYPE(eos::chain::action_code_object, eos::chain::action_code_index) CHAINBASE_SET_INDEX_TYPE(eos::chain::action_permission_object, eos::chain::action_permission_index) +CHAINBASE_SET_INDEX_TYPE(eos::chain::message_object, eos::chain::message_index) FC_REFLECT(eos::chain::account_object, (id)(name)(balance)(votes)(converting_votes)(last_vote_conversion) ) FC_REFLECT(eos::chain::permission_object, (id)(owner)(parent)(name) ) FC_REFLECT(eos::chain::action_code_object, (id)(scope)(permission)(action)(validate_action)(validate_precondition)(apply) ) FC_REFLECT(eos::chain::action_permission_object, (id)(owner)(owner_permission)(scope_permission) ) +FC_REFLECT(eos::chain::message_object, (id)(scope)(name) ) diff --git a/libraries/chain/include/eos/chain/database.hpp b/libraries/chain/include/eos/chain/database.hpp index 3e02eaa27..e459d0f21 100644 --- a/libraries/chain/include/eos/chain/database.hpp +++ b/libraries/chain/include/eos/chain/database.hpp @@ -317,6 +317,7 @@ namespace eos { namespace chain { void validate_transaction(const signed_transaction& trx)const; void validate_tapos( const signed_transaction& trx )const; void validate_referenced_accounts( const signed_transaction& trx )const; + void validate_message_types( const signed_transaction& trx )const; optional _pending_tx_session; diff --git a/libraries/chain/include/eos/chain/protocol/types.hpp b/libraries/chain/include/eos/chain/protocol/types.hpp index 1f746892c..2f4b87f5a 100644 --- a/libraries/chain/include/eos/chain/protocol/types.hpp +++ b/libraries/chain/include/eos/chain/protocol/types.hpp @@ -125,6 +125,7 @@ namespace eos { namespace chain { account_object_type, permission_object_type, action_code_object_type, + message_object_type, action_permission_object_type, global_property_object_type, dynamic_global_property_object_type, @@ -192,6 +193,7 @@ FC_REFLECT_ENUM( eos::chain::object_type, (account_object_type) (permission_object_type) (action_code_object_type) + (message_object_type) (action_permission_object_type) (global_property_object_type) (dynamic_global_property_object_type) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 9d66ec83c..faa626306 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -70,6 +70,9 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture) trx.set_expiration( db.head_block_time() ); trx.messages[0].sender = "init1"; trx.messages[0].recipient = "sys"; + trx.messages[0].type = "Undefined"; + BOOST_REQUIRE_THROW( db.push_transaction(trx), fc::assert_exception ); // "Type Undefined is not defined" + trx.messages[0].type = "Transfer"; trx.messages[0].set( "Transfer", eos::chain::Transfer{ "init2", 100, "memo" } ); BOOST_REQUIRE_THROW( db.push_transaction(trx), fc::assert_exception ); // "fail to notify receiver, init2" @@ -83,8 +86,6 @@ BOOST_FIXTURE_TEST_CASE(transfer, testing_fixture) BOOST_REQUIRE_THROW( db.push_transaction(trx), fc::assert_exception ); /// no messages - - } FC_LOG_AND_RETHROW() } -- GitLab