提交 cbc7793a 编写于 作者: D Daniel Larimer

progress

上级 4cfcb97b
......@@ -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<message_object, by_scope_name>( 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<permission_index>();
add_index<action_code_index>();
add_index<action_permission_index>();
add_index<message_index>();
add_index<global_property_multi_index>();
add_index<dynamic_global_property_multi_index>();
......
......@@ -63,14 +63,13 @@ namespace eos { namespace chain {
class permission_object : public chainbase::object<permission_object_type, permission_object>
{
OBJECT_CTOR(permission_object, (name))
OBJECT_CTOR(permission_object, (auth) )
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
permission_name name;
shared_authority auth; ///< TODO
};
......@@ -93,7 +92,7 @@ namespace eos { namespace chain {
member<permission_object, permission_object::id_type, &permission_object::id>
>
>,
ordered_unique<tag<by_name>, member<permission_object, shared_string, &permission_object::name>, chainbase::strcmp_less>
ordered_unique<tag<by_name>, member<permission_object, permission_name, &permission_object::name> >
>
>;
......@@ -103,14 +102,13 @@ namespace eos { namespace chain {
*/
class action_code_object : public chainbase::object<action_code_object_type, action_code_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<tag<by_scope_action>,
composite_key< action_code_object,
member<action_code_object, account_id_type, &action_code_object::scope>,
member<action_code_object, shared_string, &action_code_object::action>
>,
composite_key_compare< std::less<account_id_type>, chainbase::strcmp_less >
member<action_code_object, message_type, &action_code_object::action>
>
>
>
>;
......@@ -180,14 +177,38 @@ namespace eos { namespace chain {
>
>;
struct message_object : public chainbase::object<message_object_type, message_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<tag<by_id>, member<message_object, message_object::id_type, &message_object::id>>,
ordered_unique<tag<by_scope_name>,
composite_key< message_object,
member<message_object, account_name, &message_object::scope>,
member<message_object, message_type, &message_object::name>
>
>
>
>;
} } // 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) )
......@@ -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<session> _pending_tx_session;
......
......@@ -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)
......
......@@ -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() }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册