@@ -11,7 +11,8 @@ namespace tonomysystem
1111 tonomy::tonomy (name receiver, name code, eosio::datastream<const char *> ds) : native(receiver, code, ds),
1212 // instantiate multi-index instance as data member (find it defined below)
1313 _people (receiver, receiver.value),
14- _apps(receiver, receiver.value)
14+ _apps(receiver, receiver.value),
15+ _appsv2(receiver, receiver.value)
1516 {
1617 }
1718
@@ -153,22 +154,18 @@ namespace tonomysystem
153154 row.version = 1 ; });
154155 }
155156
156- void tonomy::newapp (
157- string app_name,
158- string description,
159- checksum256 username_hash,
160- string logo_url,
161- string origin,
162- public_key key)
157+ void tonomy::newapp (string json_data,
158+ checksum256 username_hash,
159+ string origin,
160+ public_key key)
163161 {
164162 // TODO: in the future only an organization type can create an app
165163 // check the transaction is signed by the `id.tmy` account
166- eosio::require_auth (get_self ());
167-
168- checksum256 description_hash = eosio::sha256 (description.c_str (), description.length ());
164+ eosio::require_auth (get_self ());
169165
170166 // generate new random account name
171- const eosio::name random_name = random_account_name (username_hash, description_hash, enum_account_type::App);
167+ auto json_hash = eosio::sha256 (json_data.c_str (), std::strlen (json_data.c_str ()));
168+ const eosio::name random_name = random_account_name (username_hash, json_hash, enum_account_type::App);
172169
173170 // use the password_key public key for the owner authority
174171 authority owner_authority = create_authority_with_account (app_controller_account);
@@ -180,7 +177,7 @@ namespace tonomysystem
180177 newaccountaction.send (get_self (), random_name, owner_authority, active_authority);
181178
182179 // Check the username is not already taken
183- auto apps_by_username_hash_itr = _apps .get_index <" usernamehash" _n>();
180+ auto apps_by_username_hash_itr = _appsv2 .get_index <" usernamehash" _n>();
184181 const auto username_itr = apps_by_username_hash_itr.find (username_hash);
185182 if (username_itr != apps_by_username_hash_itr.end ())
186183 {
@@ -189,7 +186,7 @@ namespace tonomysystem
189186
190187 // Check the origin is not already taken
191188 auto origin_hash = eosio::sha256 (origin.c_str (), std::strlen (origin.c_str ()));
192- auto apps_by_origin_hash_itr = _apps .get_index <" originhash" _n>();
189+ auto apps_by_origin_hash_itr = _appsv2 .get_index <" originhash" _n>();
193190 const auto origin_itr = apps_by_origin_hash_itr.find (origin_hash);
194191 if (origin_itr != apps_by_origin_hash_itr.end ())
195192 {
@@ -203,14 +200,15 @@ namespace tonomysystem
203200 _resource_config.set (config, get_self ());
204201
205202 // Store the password_salt and hashed username in table
206- _apps.emplace (get_self (), [&](auto &app_itr)
207- {
208- app_itr.account_name = random_name;
209- app_itr.app_name = app_name;
210- app_itr.description = description;
211- app_itr.logo_url = logo_url;
212- app_itr.origin = origin;
213- app_itr.username_hash = username_hash; });
203+ // Store the app details in JSON format
204+ _appsv2.emplace (get_self (), [&](auto &app_itr)
205+ {
206+ app_itr.account_name = random_name;
207+ app_itr.json_data = json_data;
208+ app_itr.version = 2 ;
209+ app_itr.username_hash = username_hash;
210+ app_itr.origin = origin;
211+ });
214212
215213 // Store the account type in the account_type table
216214 account_type_table account_type (get_self (), get_self ().value );
@@ -221,11 +219,19 @@ namespace tonomysystem
221219 row.version = 1 ; });
222220 }
223221
222+ void tonomy::eraseoldapps () {
223+ eosio::require_auth (get_self ());
224+
225+ // Delete all items in the v1 table
226+ while (_apps.begin () != _apps.end ()) {
227+ _apps.erase (_apps.begin ());
228+ }
229+ }
224230
225231 void tonomy::check_app_username (const checksum256 &username_hash)
226232 {
227233 // Check the username is not already taken
228- auto apps_by_username_hash_itr = _apps .get_index <" usernamehash" _n>();
234+ auto apps_by_username_hash_itr = _appsv2 .get_index <" usernamehash" _n>();
229235 const auto username_itr = apps_by_username_hash_itr.find (username_hash);
230236 if (username_itr != apps_by_username_hash_itr.end ())
231237 {
@@ -235,7 +241,7 @@ namespace tonomysystem
235241 void tonomy::check_app_origin (const string &origin) {
236242 // Check the origin is not already taken
237243 auto origin_hash = eosio::sha256 (origin.c_str (), std::strlen (origin.c_str ()));
238- auto apps_by_origin_hash_itr = _apps .get_index <" originhash" _n>();
244+ auto apps_by_origin_hash_itr = _appsv2 .get_index <" originhash" _n>();
239245 const auto origin_itr = apps_by_origin_hash_itr.find (origin_hash);
240246 if (origin_itr != apps_by_origin_hash_itr.end ())
241247 {
@@ -244,12 +250,10 @@ namespace tonomysystem
244250 }
245251
246252 void tonomy::adminsetapp (
247- name account_name,
248- string app_name,
249- string description,
250- checksum256 username_hash,
251- string logo_url,
252- string origin)
253+ name account_name,
254+ string json_data,
255+ checksum256 username_hash,
256+ string origin)
253257 {
254258 eosio::require_auth (get_self ()); // signed by tonomy@active permission
255259
@@ -267,34 +271,32 @@ namespace tonomysystem
267271 }
268272
269273 // Check the account name is not already used
270- auto apps_itr = _apps .find (account_name.value );
274+ auto apps_itr = _appsv2 .find (account_name.value );
271275
272- if (apps_itr != _apps .end ())
276+ if (apps_itr != _appsv2 .end ())
273277 {
274278 if (apps_itr->origin != origin) {
275279 check_app_origin (origin);
276280 }
277281 if (apps_itr->username_hash != username_hash) {
278282 check_app_username (username_hash);
279283 }
280- _apps .modify (apps_itr, get_self (), [&](auto &app_itr) {
284+ _appsv2 .modify (apps_itr, get_self (), [&](auto &app_itr) {
281285 app_itr.account_name = account_name;
282- app_itr.app_name = app_name;
283- app_itr.description = description;
284- app_itr.logo_url = logo_url;
285286 app_itr.origin = origin;
286287 app_itr.username_hash = username_hash;
288+ app_itr.json_data = json_data;
289+ app_itr.version = 2 ;
287290 });
288291 } else {
289292 check_app_username (username_hash);
290293 check_app_origin (origin);
291- _apps .emplace (get_self (), [&](auto &app_itr) {
294+ _appsv2 .emplace (get_self (), [&](auto &app_itr) {
292295 app_itr.account_name = account_name;
293- app_itr.app_name = app_name;
294- app_itr.description = description;
295- app_itr.logo_url = logo_url;
296296 app_itr.origin = origin;
297297 app_itr.username_hash = username_hash;
298+ app_itr.json_data = json_data;
299+ app_itr.version = 2 ;
298300 });
299301 }
300302 }
@@ -374,8 +376,8 @@ namespace tonomysystem
374376 // eosio::require_auth(account); // this is not needed as tonomy::tonomy::updateauth_action checks the permission
375377
376378 // check the app exists and is registered with status
377- auto app_itr = _apps .find (app.value );
378- check (app_itr != _apps .end (), " App does not exist" );
379+ auto app_itr = _appsv2 .find (app.value );
380+ check (app_itr != _appsv2 .end (), " App does not exist" );
379381
380382 // TODO: uncomment when apps have status
381383 // check(app_itr->status == tonomy::enum_account_status::Active_Status, "App is not active");
0 commit comments