@ercworldio/blockchain-shared 1.0.1-dev.7 → 1.0.1-dev.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,5 +62,5 @@ __decorate([
62
62
  ], DepositAddressArchive.prototype, "archived_reason", void 0);
63
63
  exports.DepositAddressArchive = DepositAddressArchive = __decorate([
64
64
  (0, typeorm_1.Entity)({ name: "deposit_addresses_archive", schema: "usersmanagement" }),
65
- (0, typeorm_1.Unique)(['original_id'])
65
+ (0, typeorm_1.Unique)(['blockchain', 'address'])
66
66
  ], DepositAddressArchive);
@@ -227,7 +227,7 @@ class BalanceService extends errors_1.default {
227
227
  (original_id, user_id, blockchain, parent_index, child_index, address, transaction_count, expires_at, archived_at, archived_reason)
228
228
  SELECT id, user_id, blockchain, parent_index, child_index, address, transaction_count, expires_at, now(), 'renewed'
229
229
  FROM old_address
230
- ON CONFLICT (original_id) DO NOTHING
230
+ ON CONFLICT (blockchain,address) DO NOTHING
231
231
  ),
232
232
  updated_address AS (
233
233
  UPDATE usersmanagement.deposit_addresses
@@ -238,12 +238,7 @@ class BalanceService extends errors_1.default {
238
238
  WHERE user_id = $1 AND blockchain = $2
239
239
  RETURNING id, user_id, blockchain, parent_index, child_index, address, transaction_count, expires_at, created_at, updated_at
240
240
  ),
241
- deleted_balances AS (
242
- DELETE FROM usersmanagement.deposit_wallet_balance
243
- WHERE wallet_id = (SELECT id FROM updated_address)
244
- AND blockchain = $2
245
- ),
246
- inserted_balances AS (
241
+ upserted_balances AS (
247
242
  INSERT INTO usersmanagement.deposit_wallet_balance
248
243
  (wallet_id, blockchain, chain_id, token, decimals, balance, transaction_count, created_at, updated_at)
249
244
  SELECT
@@ -258,6 +253,11 @@ class BalanceService extends errors_1.default {
258
253
  unnest($7::text[]) AS token,
259
254
  unnest($8::int[]) AS decimals
260
255
  ) AS v
256
+ ON CONFLICT (blockchain, chain_id, wallet_id, token) DO UPDATE SET
257
+ decimals = EXCLUDED.decimals,
258
+ balance = 0,
259
+ transaction_count = 0,
260
+ updated_at = now()
261
261
  )
262
262
  SELECT * FROM updated_address;
263
263
  `, [userId, blockchain, newChildIndex, newAddress, newExpiresAt.toISOString(), chainIds, tokens, decimals]);
@@ -55,7 +55,7 @@ class DepositAddressArchiveService {
55
55
  INSERT INTO usersmanagement.deposit_addresses_archive
56
56
  (original_id, user_id, blockchain, parent_index, child_index, address, transaction_count, expires_at, archived_at, archived_reason)
57
57
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8, now(), $9)
58
- ON CONFLICT (original_id) DO NOTHING
58
+ ON CONFLICT (blockchain, address) DO NOTHING
59
59
  RETURNING *
60
60
  `, [
61
61
  address.id,
@@ -70,7 +70,7 @@ class DepositAddressArchiveService {
70
70
  ]);
71
71
  // If conflict (already archived), return the existing record
72
72
  if (rows.length === 0) {
73
- return repo.findOneOrFail({ where: { original_id: address.id } });
73
+ return repo.findOneOrFail({ where: { blockchain: address.blockchain, address: address.address } });
74
74
  }
75
75
  return rows[0];
76
76
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ercworldio/blockchain-shared",
3
- "version": "1.0.1-dev.7",
3
+ "version": "1.0.1-dev.9",
4
4
  "description": "Shared library for blockchain projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",