(profile *types.SQLChainProfile)
| 312 | } |
| 313 | |
| 314 | func updateShardChain(profile *types.SQLChainProfile) storageProcedure { |
| 315 | var ( |
| 316 | enc *bytes.Buffer |
| 317 | err error |
| 318 | ) |
| 319 | if enc, err = utils.EncodeMsgPack(profile); err != nil { |
| 320 | return errPass(err) |
| 321 | } |
| 322 | return func(tx *sql.Tx) (err error) { |
| 323 | log.WithFields(log.Fields{ |
| 324 | "profile_owner": profile.Owner.String(), |
| 325 | "profile_address": profile.Address.String(), |
| 326 | "profile_database_id": profile.ID, |
| 327 | "profile_token_type": profile.TokenType, |
| 328 | "profile_miners_number": len(profile.Miners), |
| 329 | }).Debug("updating profile") |
| 330 | _, err = tx.Exec(`INSERT OR REPLACE INTO "shardChain" ("address", "id", "encoded") |
| 331 | VALUES (?, ?, ?)`, |
| 332 | profile.Address.String(), |
| 333 | string(profile.ID), |
| 334 | enc.Bytes()) |
| 335 | if err != nil { |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | for _, u := range profile.Users { |
| 340 | if u.Permission.Role == types.Void { |
| 341 | // remove index |
| 342 | _, err = tx.Exec(`DELETE FROM "indexed_shardChains" WHERE "account" = ? AND "address" = ?`, |
| 343 | u.Address.String(), |
| 344 | profile.Address.String()) |
| 345 | } else { |
| 346 | _, err = tx.Exec(`INSERT OR REPLACE INTO "indexed_shardChains" ("account", "address", "id") |
| 347 | VALUES(?, ?, ?)`, |
| 348 | u.Address.String(), |
| 349 | profile.Address.String(), |
| 350 | profile.ID) |
| 351 | } |
| 352 | |
| 353 | if err != nil { |
| 354 | return |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | return |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | func deleteShardChain(id proto.DatabaseID) storageProcedure { |
| 363 | return func(tx *sql.Tx) (err error) { |
no test coverage detected