Skip to content

Commit 8ef5635

Browse files
committed
Fixed #1719
1 parent 168c27b commit 8ef5635

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

libraries/chain/include/graphene/chain/proposal_object.hpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,17 @@ class required_approval_index : public secondary_index
7373
public:
7474
virtual void object_inserted( const object& obj ) override;
7575
virtual void object_removed( const object& obj ) override;
76-
virtual void about_to_modify( const object& before ) override{};
77-
virtual void object_modified( const object& after ) override{};
78-
79-
void remove( account_id_type a, proposal_id_type p );
76+
virtual void about_to_modify( const object& before ) override;
77+
virtual void object_modified( const object& after ) override;
8078

8179
map<account_id_type, set<proposal_id_type> > _account_to_proposals;
80+
81+
private:
82+
void remove( account_id_type a, proposal_id_type p );
83+
void insert_or_remove_delta( proposal_id_type p, const flat_set<account_id_type>& before,
84+
const flat_set<account_id_type>& after );
85+
flat_set<account_id_type> available_active_before_modify;
86+
flat_set<account_id_type> available_owner_before_modify;
8287
};
8388

8489
struct by_expiration{};

libraries/chain/proposal_object.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,44 @@ void required_approval_index::object_removed( const object& obj )
9191
remove( a, p.id );
9292
}
9393

94+
void required_approval_index::insert_or_remove_delta( proposal_id_type p,
95+
const flat_set<account_id_type>& before,
96+
const flat_set<account_id_type>& after )
97+
{
98+
auto b = before.begin();
99+
auto a = after.begin();
100+
while( b != before.end() || a != after.end() )
101+
{
102+
if( a == after.end() || (b != before.end() && *b < *a) )
103+
{
104+
remove( *b, p );
105+
++b;
106+
}
107+
else if( b == before.end() || (a != after.end() && *a < *b) )
108+
{
109+
_account_to_proposals[*a].insert( p );
110+
++a;
111+
}
112+
else // *a == *b
113+
{
114+
++a;
115+
++b;
116+
}
117+
}
118+
}
119+
120+
void required_approval_index::about_to_modify( const object& before )
121+
{
122+
const proposal_object& p = static_cast<const proposal_object&>(before);
123+
available_active_before_modify = p.available_active_approvals;
124+
available_owner_before_modify = p.available_owner_approvals;
125+
}
126+
127+
void required_approval_index::object_modified( const object& after )
128+
{
129+
const proposal_object& p = static_cast<const proposal_object&>(after);
130+
insert_or_remove_delta( p.id, available_active_before_modify, p.available_active_approvals );
131+
insert_or_remove_delta( p.id, available_owner_before_modify, p.available_owner_approvals );
132+
}
133+
94134
} } // graphene::chain

0 commit comments

Comments
 (0)