Skip to content

Commit

Permalink
Fix private_message plugin interface GolosChain#529
Browse files Browse the repository at this point in the history
  • Loading branch information
zxcat committed Apr 10, 2018
1 parent 7f0cd80 commit dcc0fa2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 90 deletions.
38 changes: 19 additions & 19 deletions libraries/protocol/include/golos/protocol/operation_util.hpp
@@ -1,4 +1,3 @@

#pragma once

#include <golos/protocol/authority.hpp>
Expand All @@ -14,21 +13,22 @@
// Place DECLARE_OPERATION_TYPE in a .hpp file to declare
// functions related to your operation type
//
#define DECLARE_OPERATION_TYPE(OperationType) \
namespace fc { \
\
void to_variant( const OperationType&, fc::variant& ); \
void from_variant( const fc::variant&, OperationType& ); \
\
} /* fc */ \
\
namespace golos { namespace protocol { \
\
void operation_validate( const OperationType& o ); \
void operation_get_required_authorities( const OperationType& op, \
flat_set< account_name_type >& active, \
flat_set< account_name_type >& owner, \
flat_set< account_name_type >& posting, \
vector< authority >& other ); \
\
} } /* steemit::protocol */
#define DECLARE_OPERATION_TYPE(OperationType) \
namespace fc { \
\
void to_variant(const OperationType&, fc::variant&); \
void from_variant(const fc::variant&, OperationType&); \
\
} /* fc */ \
\
namespace golos { namespace protocol { \
\
void operation_validate(const OperationType&); \
void operation_get_required_authorities( \
const OperationType& op, \
flat_set<account_name_type>& active, \
flat_set<account_name_type>& owner, \
flat_set<account_name_type>& posting, \
vector<authority>& other); \
\
} } /* golos::protocol */
Expand Up @@ -140,4 +140,4 @@ void operation_get_required_authorities( const OperationType& op, \
op.visit( golos::protocol::operation_get_required_auth_visitor( active, owner, posting, other ) ); \
} \
\
} } /* steemit::protocol */
} } /* golos::protocol */
31 changes: 4 additions & 27 deletions plugins/follow/include/golos/plugins/follow/follow_operations.hpp
Expand Up @@ -15,8 +15,7 @@ namespace golos {
std::set<std::string> what; /// blog, mute

void validate() const;

void get_required_posting_authorities(flat_set<account_name_type> &a) const {
void get_required_posting_authorities(flat_set<account_name_type>& a) const {
a.insert(follower);
}
};
Expand All @@ -27,14 +26,12 @@ namespace golos {
std::string permlink;

void validate() const;

void get_required_posting_authorities(flat_set<account_name_type> &a) const {
void get_required_posting_authorities(flat_set<account_name_type>& a) const {
a.insert(account);
}
};

typedef fc::static_variant<follow_operation, reblog_operation> follow_plugin_operation;

using follow_plugin_operation = fc::static_variant<follow_operation, reblog_operation>;

}
}
Expand All @@ -43,25 +40,5 @@ namespace golos {
FC_REFLECT((golos::plugins::follow::follow_operation), (follower)(following)(what));
FC_REFLECT((golos::plugins::follow::reblog_operation), (account)(author)(permlink));

namespace fc {

void to_variant(const golos::plugins::follow::follow_plugin_operation &, fc::variant &);

void from_variant(const fc::variant &, golos::plugins::follow::follow_plugin_operation &);

} /* fc */

namespace golos {
namespace protocol {

void operation_validate(const plugins::follow::follow_plugin_operation &o);

void operation_get_required_authorities(const plugins::follow::follow_plugin_operation &op,
flat_set<account_name_type> &active, flat_set<account_name_type> &owner,
flat_set<account_name_type> &posting, std::vector<authority> &other);

}
}

FC_REFLECT_TYPENAME((golos::plugins::follow::follow_plugin_operation));

DECLARE_OPERATION_TYPE(golos::plugins::follow::follow_plugin_operation)
@@ -1,10 +1,8 @@
#pragma once

#include <appbase/plugin.hpp>
#include <golos/chain/evaluator.hpp>

#include <golos/plugins/private_message/private_message_objects.hpp>
#include <golos/plugins/private_message/private_message_plugin.hpp>
#include <golos/chain/database.hpp>
#include <golos/chain/evaluator.hpp>

namespace golos {
Expand Down
Expand Up @@ -104,45 +104,53 @@ namespace golos {

using namespace boost::multi_index;

typedef multi_index_container <
message_object,
indexed_by<
ordered_unique < tag < by_id>, member<message_object, message_id_type, &message_object::id>>,
ordered_unique <tag<by_to_date>,
composite_key<message_object,
member < message_object, account_name_type, &message_object::to>,
member<message_object, time_point_sec, &message_object::receive_time>,
member<message_object, message_id_type, &message_object::id>
>,
composite_key_compare<std::less<string>, std::greater<time_point_sec>, std::less<message_id_type>>
>,
ordered_unique <tag<by_from_date>,
composite_key<message_object,
member < message_object, account_name_type, &message_object::from>,
member<message_object, time_point_sec, &message_object::receive_time>,
member<message_object, message_id_type, &message_object::id>
>,
composite_key_compare<std::less<string>, std::greater<time_point_sec>, std::less<message_id_type>>
>
>,
allocator <message_object>
>
message_index;

struct private_message_operation
: public golos::protocol::base_operation {
protocol::account_name_type from;
protocol::account_name_type to;
protocol::public_key_type from_memo_key;
protocol::public_key_type to_memo_key;
using message_index = multi_index_container<
message_object,
indexed_by<
ordered_unique<
tag<by_id>,
member<message_object, message_id_type, &message_object::id>
>,
ordered_unique<
tag<by_to_date>,
composite_key<
message_object,
member<message_object, account_name_type, &message_object::to>,
member<message_object, time_point_sec, &message_object::receive_time>,
member<message_object, message_id_type, &message_object::id>
>,
composite_key_compare<std::less<string>, std::greater<time_point_sec>, std::less<message_id_type>>
>,
ordered_unique<
tag<by_from_date>,
composite_key<
message_object,
member<message_object, account_name_type, &message_object::from>,
member<message_object, time_point_sec, &message_object::receive_time>,
member<message_object, message_id_type, &message_object::id>
>,
composite_key_compare<std::less<string>, std::greater<time_point_sec>, std::less<message_id_type>>
>
>,
allocator<message_object>
>;

struct private_message_operation: public base_operation {
account_name_type from;
account_name_type to;
public_key_type from_memo_key;
public_key_type to_memo_key;
uint64_t sent_time = 0; /// used as seed to secret generation
uint32_t checksum = 0;
std::vector<char> encrypted_message;

void validate() const;
void get_required_posting_authorities(flat_set<account_name_type>& a) const {
a.insert(from);
}
};

typedef fc::static_variant <private_message_operation> private_message_plugin_operation;
using private_message_plugin_operation = fc::static_variant<private_message_operation>;

}
}
Expand All @@ -151,12 +159,5 @@ namespace golos {
FC_REFLECT((golos::plugins::private_message::private_message_operation),
(from)(to)(from_memo_key)(to_memo_key)(sent_time)(checksum)(encrypted_message))

namespace fc {

void to_variant(const golos::plugins::private_message::private_message_plugin_operation &, fc::variant &);

void from_variant(const fc::variant &, golos::plugins::private_message::private_message_plugin_operation &);

} /* fc */

FC_REFLECT_TYPENAME((golos::plugins::private_message::private_message_plugin_operation))
DECLARE_OPERATION_TYPE(golos::plugins::private_message::private_message_plugin_operation)

0 comments on commit dcc0fa2

Please sign in to comment.