File tree 2 files changed +49
-4
lines changed
2 files changed +49
-4
lines changed Original file line number Diff line number Diff line change @@ -73,12 +73,17 @@ class required_approval_index : public secondary_index
73
73
public:
74
74
virtual void object_inserted ( const object& obj ) override ;
75
75
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 ;
80
78
81
79
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;
82
87
};
83
88
84
89
struct by_expiration {};
Original file line number Diff line number Diff line change @@ -91,4 +91,44 @@ void required_approval_index::object_removed( const object& obj )
91
91
remove ( a, p.id );
92
92
}
93
93
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
+
94
134
} } // graphene::chain
You can’t perform that action at this time.
0 commit comments