Skip to content

Commit

Permalink
Fixed #1719
Browse files Browse the repository at this point in the history
  • Loading branch information
pmconrad committed Apr 13, 2019
1 parent 168c27b commit 8ef5635
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libraries/chain/include/graphene/chain/proposal_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ class required_approval_index : public secondary_index
public:
virtual void object_inserted( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override{};
virtual void object_modified( const object& after ) override{};

void remove( account_id_type a, proposal_id_type p );
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;

map<account_id_type, set<proposal_id_type> > _account_to_proposals;

private:
void remove( account_id_type a, proposal_id_type p );
void insert_or_remove_delta( proposal_id_type p, const flat_set<account_id_type>& before,
const flat_set<account_id_type>& after );
flat_set<account_id_type> available_active_before_modify;
flat_set<account_id_type> available_owner_before_modify;
};

struct by_expiration{};
Expand Down
40 changes: 40 additions & 0 deletions libraries/chain/proposal_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,44 @@ void required_approval_index::object_removed( const object& obj )
remove( a, p.id );
}

void required_approval_index::insert_or_remove_delta( proposal_id_type p,
const flat_set<account_id_type>& before,
const flat_set<account_id_type>& after )
{
auto b = before.begin();
auto a = after.begin();
while( b != before.end() || a != after.end() )
{
if( a == after.end() || (b != before.end() && *b < *a) )
{
remove( *b, p );
++b;
}
else if( b == before.end() || (a != after.end() && *a < *b) )
{
_account_to_proposals[*a].insert( p );
++a;
}
else // *a == *b
{
++a;
++b;
}
}
}

void required_approval_index::about_to_modify( const object& before )
{
const proposal_object& p = static_cast<const proposal_object&>(before);
available_active_before_modify = p.available_active_approvals;
available_owner_before_modify = p.available_owner_approvals;
}

void required_approval_index::object_modified( const object& after )
{
const proposal_object& p = static_cast<const proposal_object&>(after);
insert_or_remove_delta( p.id, available_active_before_modify, p.available_active_approvals );
insert_or_remove_delta( p.id, available_owner_before_modify, p.available_owner_approvals );
}

} } // graphene::chain

0 comments on commit 8ef5635

Please sign in to comment.