Update API and remove SPAM
subscribe_to_objects now returns the initial value of the objects, this makes it easy for someone to fetch and subscribe in a single atomic step rather than having to call get and then subscribe which could lead to some inconsistencies if the object was modified after get but before subscribe.
This commit is contained in:
parent
39c99fd0a7
commit
87d3d1a198
4 changed files with 10 additions and 21 deletions
|
|
@ -288,7 +288,6 @@ namespace graphene { namespace app {
|
|||
});
|
||||
results[account_name_or_id] = acnt;
|
||||
}
|
||||
wdump((results));
|
||||
return results;
|
||||
}
|
||||
|
||||
|
|
@ -709,7 +708,6 @@ namespace graphene { namespace app {
|
|||
result.push_back( aobj->owner );
|
||||
break;
|
||||
} case impl_account_statistics_object_type:{
|
||||
elog( "stats object" );
|
||||
const auto& aobj = dynamic_cast<const account_statistics_object*>(obj);
|
||||
assert( aobj != nullptr );
|
||||
result.push_back( aobj->owner );
|
||||
|
|
@ -760,7 +758,6 @@ namespace graphene { namespace app {
|
|||
_broadcast_removed_complete = fc::async([=](){
|
||||
for( const auto& item : broadcast_queue )
|
||||
{
|
||||
idump((item.first)(item.second) );
|
||||
auto sub = _account_subscriptions.find(item.first);
|
||||
if( sub != _account_subscriptions.end() )
|
||||
sub->second( fc::variant(item.second ) );
|
||||
|
|
@ -797,13 +794,11 @@ namespace graphene { namespace app {
|
|||
|
||||
void database_api::on_objects_changed(const vector<object_id_type>& ids)
|
||||
{
|
||||
idump((ids)(_account_subscriptions.size()));
|
||||
vector<object_id_type> my_objects;
|
||||
map<account_id_type, vector<variant> > broadcast_queue;
|
||||
map< pair<asset_id_type, asset_id_type>, vector<variant> > market_broadcast_queue;
|
||||
for(auto id : ids)
|
||||
{
|
||||
edump((id)(_account_subscriptions.size()));
|
||||
if(_subscriptions.find(id) != _subscriptions.end())
|
||||
my_objects.push_back(id);
|
||||
|
||||
|
|
@ -814,7 +809,6 @@ namespace graphene { namespace app {
|
|||
if( obj )
|
||||
{
|
||||
vector<account_id_type> relevant = get_relevant_accounts( obj );
|
||||
edump(("relevant accounts")(relevant)(obj->id));
|
||||
for( const auto& r : relevant )
|
||||
{
|
||||
auto sub = _account_subscriptions.find(r);
|
||||
|
|
@ -848,9 +842,6 @@ namespace graphene { namespace app {
|
|||
/// if a connection hangs then this could get backed up and result in
|
||||
/// a failure to exit cleanly.
|
||||
_broadcast_changes_complete = fc::async([=](){
|
||||
for( const auto& item : broadcast_queue )
|
||||
edump((item.second));
|
||||
|
||||
for( const auto& item : broadcast_queue )
|
||||
{
|
||||
edump( (item) );
|
||||
|
|
@ -932,11 +923,11 @@ namespace graphene { namespace app {
|
|||
}
|
||||
|
||||
|
||||
bool database_api::subscribe_to_objects( const std::function<void(const fc::variant&)>& callback, const vector<object_id_type>& ids)
|
||||
vector<variant> database_api::subscribe_to_objects( const std::function<void(const fc::variant&)>& callback, const vector<object_id_type>& ids)
|
||||
{
|
||||
FC_ASSERT( _subscriptions.size() < 1024 );
|
||||
for(auto id : ids) _subscriptions[id] = callback;
|
||||
return true;
|
||||
return get_objects( ids );
|
||||
}
|
||||
|
||||
bool database_api::unsubscribe_from_objects(const vector<object_id_type>& ids)
|
||||
|
|
|
|||
|
|
@ -251,8 +251,9 @@ namespace graphene { namespace app {
|
|||
* @brief Request notifications when some object(s) change
|
||||
* @param callback Callback method which is called with the new version of a changed object
|
||||
* @param ids The set of object IDs to watch
|
||||
* @return get_objects(ids)
|
||||
*/
|
||||
bool subscribe_to_objects(const std::function<void(const fc::variant&)>& callback,
|
||||
vector<variant> subscribe_to_objects(const std::function<void(const fc::variant&)>& callback,
|
||||
const vector<object_id_type>& ids);
|
||||
/**
|
||||
* @brief Stop receiving notifications for some object(s)
|
||||
|
|
|
|||
|
|
@ -85,9 +85,6 @@ void_result account_create_evaluator::do_evaluate( const account_create_operatio
|
|||
|
||||
object_id_type account_create_evaluator::do_apply( const account_create_operation& o )
|
||||
{ try {
|
||||
const auto& stats_obj = db().create<account_statistics_object>( [&]( account_statistics_object& ){
|
||||
});
|
||||
|
||||
const auto& new_acnt_object = db().create<account_object>( [&]( account_object& obj ){
|
||||
obj.registrar = o.registrar;
|
||||
obj.referrer = o.referrer;
|
||||
|
|
@ -101,8 +98,8 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
|
|||
obj.name = o.name;
|
||||
obj.owner = o.owner;
|
||||
obj.active = o.active;
|
||||
obj.statistics = stats_obj.id;
|
||||
obj.options = o.options;
|
||||
obj.statistics = db().create<account_statistics_object>([&](account_statistics_object& s){s.owner = obj.id;}).id;
|
||||
});
|
||||
|
||||
const auto& dynamic_properties = db().get_dynamic_global_properties();
|
||||
|
|
|
|||
|
|
@ -234,12 +234,12 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
n.owner.weight_threshold = 1;
|
||||
n.active.weight_threshold = 1;
|
||||
n.name = "committee-account";
|
||||
n.statistics = create<account_statistics_object>( [&](account_statistics_object& b){}).id;
|
||||
n.statistics = create<account_statistics_object>( [&](account_statistics_object& s){ s.owner = n.id; }).id;
|
||||
});
|
||||
FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT);
|
||||
FC_ASSERT(create<account_object>([this](account_object& a) {
|
||||
a.name = "witness-account";
|
||||
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
|
||||
a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id;
|
||||
a.owner.weight_threshold = 1;
|
||||
a.active.weight_threshold = 1;
|
||||
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_WITNESS_ACCOUNT;
|
||||
|
|
@ -249,7 +249,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
}).get_id() == GRAPHENE_WITNESS_ACCOUNT);
|
||||
FC_ASSERT(create<account_object>([this](account_object& a) {
|
||||
a.name = "relaxed-committee-account";
|
||||
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
|
||||
a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id;
|
||||
a.owner.weight_threshold = 1;
|
||||
a.active.weight_threshold = 1;
|
||||
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_RELAXED_COMMITTEE_ACCOUNT;
|
||||
|
|
@ -259,7 +259,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
}).get_id() == GRAPHENE_RELAXED_COMMITTEE_ACCOUNT);
|
||||
FC_ASSERT(create<account_object>([this](account_object& a) {
|
||||
a.name = "null-account";
|
||||
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
|
||||
a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id;
|
||||
a.owner.weight_threshold = 1;
|
||||
a.active.weight_threshold = 1;
|
||||
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_NULL_ACCOUNT;
|
||||
|
|
@ -269,7 +269,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
}).get_id() == GRAPHENE_NULL_ACCOUNT);
|
||||
FC_ASSERT(create<account_object>([this](account_object& a) {
|
||||
a.name = "temp-account";
|
||||
a.statistics = create<account_statistics_object>([](account_statistics_object&){}).id;
|
||||
a.statistics = create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id;
|
||||
a.owner.weight_threshold = 0;
|
||||
a.active.weight_threshold = 0;
|
||||
a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_TEMP_ACCOUNT;
|
||||
|
|
|
|||
Loading…
Reference in a new issue