@ercworldio/blockchain-shared 1.0.3-dev.3-PROJ-1296.25 → 1.0.3-dev.3-PROJ-1296.27

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.
@@ -48,7 +48,16 @@
48
48
  "type": "Escrow",
49
49
  "version": "1",
50
50
  "startingBlock": 24496423,
51
- "escrowAlchemyWebhooks": [],
51
+ "escrowAlchemyWebhooks": [
52
+ {
53
+ "chainId": "1",
54
+ "network_symbol": "eth",
55
+ "network": "ETH_MAINNET",
56
+ "type": "GRAPHQL",
57
+ "endpoint": "webhook/alchemy/escrow-events",
58
+ "source": "contract"
59
+ }
60
+ ],
52
61
  "addresses": [
53
62
  "0xB28BE79Ffe7CC1f352a8EFF3E3E8f4faFD05a881"
54
63
  ]
@@ -157,7 +166,16 @@
157
166
  "type": "Escrow",
158
167
  "version": "1",
159
168
  "startingBlock": 82263026,
160
- "escrowAlchemyWebhooks": [],
169
+ "escrowAlchemyWebhooks": [
170
+ {
171
+ "chainId": "56",
172
+ "network_symbol": "bnb",
173
+ "network": "BNB_MAINNET",
174
+ "type": "GRAPHQL",
175
+ "endpoint": "webhook/alchemy/escrow-events",
176
+ "source": "contract"
177
+ }
178
+ ],
161
179
  "addresses": [
162
180
  "0xa4f0f80b1f4b2dBDD7cE553342Ad5542ba7758Ec"
163
181
  ]
@@ -357,7 +375,16 @@
357
375
  "type": "Escrow",
358
376
  "version": "1",
359
377
  "startingBlock": 82937871,
360
- "escrowAlchemyWebhooks": [],
378
+ "escrowAlchemyWebhooks": [
379
+ {
380
+ "chainId": "137",
381
+ "network_symbol": "pol",
382
+ "network": "MATIC_MAINNET",
383
+ "type": "GRAPHQL",
384
+ "endpoint": "webhook/alchemy/escrow-events",
385
+ "source": "contract"
386
+ }
387
+ ],
361
388
  "addresses": [
362
389
  "0x0074D8ed3168bEF415337064670e0bf90981A1F5"
363
390
  ]
@@ -452,7 +479,16 @@
452
479
  "type": "Escrow",
453
480
  "version": "1",
454
481
  "startingBlock": 78523433,
455
- "escrowAlchemyWebhooks": [],
482
+ "escrowAlchemyWebhooks": [
483
+ {
484
+ "chainId": "43114",
485
+ "network_symbol": "avax",
486
+ "network": "AVAX_MAINNET",
487
+ "type": "GRAPHQL",
488
+ "endpoint": "webhook/alchemy/escrow-events",
489
+ "source": "contract"
490
+ }
491
+ ],
456
492
  "addresses": [
457
493
  "0x28DE9CeCd83D9b20Ee6A438d39114Add08ED5FF7"
458
494
  ]
@@ -48,7 +48,16 @@
48
48
  "type": "Escrow",
49
49
  "version": "1",
50
50
  "startingBlock": 24754256,
51
- "escrowAlchemyWebhooks": [],
51
+ "escrowAlchemyWebhooks": [
52
+ {
53
+ "chainId": "1",
54
+ "network_symbol": "eth",
55
+ "network": "ETH_MAINNET",
56
+ "type": "GRAPHQL",
57
+ "endpoint": "webhook/alchemy/escrow-events",
58
+ "source": "contract"
59
+ }
60
+ ],
52
61
  "addresses": [
53
62
  "0xBC88D756b866854C02410c8d3e62E5648279dc70"
54
63
  ]
@@ -157,7 +166,16 @@
157
166
  "type": "Escrow",
158
167
  "version": "1",
159
168
  "startingBlock": 89178576,
160
- "escrowAlchemyWebhooks": [],
169
+ "escrowAlchemyWebhooks": [
170
+ {
171
+ "chainId": "56",
172
+ "network_symbol": "bnb",
173
+ "network": "BNB_MAINNET",
174
+ "type": "GRAPHQL",
175
+ "endpoint": "webhook/alchemy/escrow-events",
176
+ "source": "contract"
177
+ }
178
+ ],
161
179
  "addresses": [
162
180
  "0x0074D8ed3168bEF415337064670e0bf90981A1F5"
163
181
  ]
@@ -357,7 +375,16 @@
357
375
  "type": "Escrow",
358
376
  "version": "1",
359
377
  "startingBlock": 84779780,
360
- "escrowAlchemyWebhooks": [],
378
+ "escrowAlchemyWebhooks": [
379
+ {
380
+ "chainId": "137",
381
+ "network_symbol": "pol",
382
+ "network": "MATIC_MAINNET",
383
+ "type": "GRAPHQL",
384
+ "endpoint": "webhook/alchemy/escrow-events",
385
+ "source": "contract"
386
+ }
387
+ ],
361
388
  "addresses": [
362
389
  "0x251824258e218293d79036Be1423388bf3476Ef4"
363
390
  ]
@@ -452,7 +479,16 @@
452
479
  "type": "Escrow",
453
480
  "version": "1",
454
481
  "startingBlock": 81474572,
455
- "escrowAlchemyWebhooks": [],
482
+ "escrowAlchemyWebhooks": [
483
+ {
484
+ "chainId": "43114",
485
+ "network_symbol": "avax",
486
+ "network": "AVAX_MAINNET",
487
+ "type": "GRAPHQL",
488
+ "endpoint": "webhook/alchemy/escrow-events",
489
+ "source": "contract"
490
+ }
491
+ ],
456
492
  "addresses": [
457
493
  "0x6d47B7230F5D466677795E271db3aEE4C59c0B47"
458
494
  ]
@@ -74,6 +74,7 @@ export declare const ErrorMessages: {
74
74
  readonly UNDEFINED_DESTINATION_DETAILS: "Lightning withdrawal has no destination payment details";
75
75
  readonly UNDEFINED_WITHDRAWAL_TOKEN: "Token address does not exist in withdraw request";
76
76
  readonly MISSING_WITHDRAWAL_DETAILS: "Withdraw request details is missing";
77
+ readonly REQUEST_ALREADY_FULFILLED: "Withdraw request is already fulfilled";
77
78
  };
78
79
  export declare const ErrorCodes: {
79
80
  readonly INTERNAL_SERVER: "error.internal_server_error";
@@ -144,6 +145,7 @@ export declare const ErrorCodes: {
144
145
  readonly UNDEFINED_DESTINATION_DETAILS: "error.undefined_destination_details";
145
146
  readonly UNDEFINED_WITHDRAWAL_TOKEN: "error.undefined_withdrawawal_token";
146
147
  readonly MISSING_WITHDRAWAL_DETAILS: "error.invalid_withdraw_request";
148
+ readonly REQUEST_ALREADY_FULFILLED: "error.request_already_fulfilled";
147
149
  };
148
150
  export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
149
151
  export interface ErrorCodeEntry {
@@ -238,6 +240,7 @@ declare class BaseErrors {
238
240
  MissingWithdrawDetails(): "Withdraw request details is missing";
239
241
  UndefinedWithdrawalToken(): "Token address does not exist in withdraw request";
240
242
  UndefinedDestinationDetails(): "Lightning withdrawal has no destination payment details";
243
+ RequestAlreadyFulfilled(): "Withdraw request is already fulfilled";
241
244
  /** Handler methods */
242
245
  handle_error: (error: any, source_method: string) => ErrorHandlerResponse;
243
246
  get_error_code_base: (message: string) => ErrorCodeEntry | null;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAqFtB,2BAA2B;;;;IAK3B,sBAAsB;;;;;;;;;;;;;;;;;;;CA0BhB,CAAC;AAEX,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,OAAO,UAAU,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEnE,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,SAAS,CAAC;CACzB;AAED,UAAU,oBAAoB;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,cAAc,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,cAAc;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,UAAU,EAAE,SAAS,GAAG,IAAI,CAAC;IAC7B,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;CACjB;AAGD,cAAM,UAAU;IACL,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAQX;IAED,yDAAyD;IAClD,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG;IACpB,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG;IACxB,YAAY,CAAC,CAAC,CAAC,EAA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YAAY,GAAI,OAAO,GAAG,EAAE,eAAe,MAAM,KAAG,oBAAoB,CAuB9E;IAEM,mBAAmB,GAAI,SAAS,MAAM,KAAG,cAAc,GAAG,IAAI,CA8CpE;CACJ;AAED,eAAe,UAAU,CAAC"}
@@ -113,6 +113,7 @@ exports.ErrorMessages = {
113
113
  UNDEFINED_DESTINATION_DETAILS: `Lightning withdrawal has no destination payment details`,
114
114
  UNDEFINED_WITHDRAWAL_TOKEN: `Token address does not exist in withdraw request`,
115
115
  MISSING_WITHDRAWAL_DETAILS: `Withdraw request details is missing`,
116
+ REQUEST_ALREADY_FULFILLED: `Withdraw request is already fulfilled`,
116
117
  };
117
118
  exports.ErrorCodes = {
118
119
  INTERNAL_SERVER: 'error.internal_server_error',
@@ -190,6 +191,7 @@ exports.ErrorCodes = {
190
191
  UNDEFINED_DESTINATION_DETAILS: `error.undefined_destination_details`,
191
192
  UNDEFINED_WITHDRAWAL_TOKEN: `error.undefined_withdrawawal_token`,
192
193
  MISSING_WITHDRAWAL_DETAILS: `error.invalid_withdraw_request`,
194
+ REQUEST_ALREADY_FULFILLED: `error.request_already_fulfilled`,
193
195
  };
194
196
  class BaseErrors {
195
197
  constructor() {
@@ -313,6 +315,8 @@ class BaseErrors {
313
315
  return Object.assign(Object.assign({}, this.codes[500]), { error_code: exports.ErrorCodes.UNDEFINED_WITHDRAWAL_TOKEN });
314
316
  if (message.includes(exports.ErrorMessages.MISSING_WITHDRAWAL_DETAILS))
315
317
  return Object.assign(Object.assign({}, this.codes[500]), { error_code: exports.ErrorCodes.MISSING_WITHDRAWAL_DETAILS });
318
+ if (message.includes(exports.ErrorMessages.REQUEST_ALREADY_FULFILLED))
319
+ return Object.assign(Object.assign({}, this.codes[500]), { error_code: exports.ErrorCodes.REQUEST_ALREADY_FULFILLED });
316
320
  return null;
317
321
  };
318
322
  }
@@ -400,5 +404,8 @@ class BaseErrors {
400
404
  UndefinedWithdrawalToken() { return exports.ErrorMessages.UNDEFINED_WITHDRAWAL_TOKEN; }
401
405
  ;
402
406
  UndefinedDestinationDetails() { return exports.ErrorMessages.UNDEFINED_DESTINATION_DETAILS; }
407
+ ;
408
+ RequestAlreadyFulfilled() { return exports.ErrorMessages.REQUEST_ALREADY_FULFILLED; }
409
+ ;
403
410
  }
404
411
  exports.default = BaseErrors;
@@ -4,22 +4,21 @@ import { Pool } from "pg";
4
4
  import { OperationType } from "../../../contracts/types/escrow";
5
5
  import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails } from "../../types/db";
6
6
  declare class ScheduleTransactionService {
7
- static get_available_jobs: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJob[]>;
7
+ static get_and_lock_available_jobs: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJob[]>;
8
8
  /** Same as get_available_jobs but joins withdrawal details from accounting for each job. */
9
- static get_available_jobs_with_details: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
9
+ static get_and_lock_available_jobs_with_details: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
10
10
  /**
11
- * Requeues all jobs in the given status to "queued"
12
- * @param pool
13
- * @param current_status
14
- * @param limit
15
- * @param lock_owner
16
- * @param lock_reason
17
- * @param max_retries
18
- * @returns
11
+ * Requeues all jobs in the given status to "queued"
19
12
  */
20
13
  static requeue_expired_jobs: (pool: Pool, current_status: ScheduleJobStatus, limit: number, lock_owner: string, lock_reason: string, max_retries: number) => Promise<ScheduleTransactionJob[]>;
21
14
  static batch_update_status: (pool: Pool, operation_type: OperationType, request_ids: number[], new_status: ScheduleJobStatus) => Promise<void>;
22
- static batch_update_failed_jobs: (pool: Pool, request_ids: number[], new_status: ScheduleJobStatus, error_message?: string, retryable?: boolean) => Promise<void>;
15
+ static batch_update_failed_jobs: (pool: Pool, operation_type: OperationType, request_ids: number[], new_status: ScheduleJobStatus, error_message?: string, retryable?: boolean) => Promise<void>;
16
+ static batch_update_failed_jobs_custom_error: (pool: Pool, operation_type: OperationType, jobs: {
17
+ request_id: number;
18
+ new_status: ScheduleJobStatus;
19
+ error_message: string;
20
+ retryable: boolean;
21
+ }[]) => Promise<void>;
23
22
  static batch_update_executed_jobs: (pool: Pool, data: {
24
23
  operation_type: OperationType;
25
24
  request_id: number;
@@ -1 +1 @@
1
- {"version":3,"file":"ScheduleTransactionService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/timelock/ScheduleTransactionService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAE5F,cAAM,0BAA0B;IAE5B,MAAM,CAAC,kBAAkB,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,gBAAe,oBAA0F,KAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAwCxO;IAGD,4FAA4F;IAC5F,MAAM,CAAC,+BAA+B,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,gBAAe,oBAA0F,KAAG,OAAO,CAAC,iCAAiC,EAAE,CAAC,CA4ChQ;IAGD;;;;;;;;;OASG;IACH,MAAM,CAAC,oBAAoB,GACvB,MAAM,IAAI,EACV,gBAAgB,iBAAiB,EACjC,OAAO,MAAM,EACb,YAAY,MAAM,EAClB,aAAa,MAAM,EACnB,aAAa,MAAM,KACpB,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAwClC;IAIF,MAAM,CAAC,mBAAmB,GAAU,MAAM,IAAI,EAAE,gBAAgB,aAAa,EAAE,aAAa,MAAM,EAAE,EAAE,YAAY,iBAAiB,KAAG,OAAO,CAAC,IAAI,CAAC,CAUjJ;IAGF,MAAM,CAAC,wBAAwB,GAC3B,MAAM,IAAI,EACV,aAAa,MAAM,EAAE,EACrB,YAAY,iBAAiB,EAC7B,gBAAgB,MAAM,EACtB,YAAY,OAAO,KACpB,OAAO,CAAC,IAAI,CAAC,CAwBd;IAGF,MAAM,CAAC,0BAA0B,GAC7B,MAAM,IAAI,EACV,MAAM;QAAE,cAAc,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAE,EAAE,KAC9F,OAAO,CAAC,IAAI,CAAC,CAyBd;IAGF,MAAM,CAAC,aAAa,GAAU,MAAM,IAAI,EAAE,UAAU,uBAAuB,EAAE,mBAuB5E;CAGJ;AAED,eAAe,0BAA0B,CAAC"}
1
+ {"version":3,"file":"ScheduleTransactionService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/timelock/ScheduleTransactionService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAE5F,cAAM,0BAA0B;IAE5B,MAAM,CAAC,2BAA2B,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,gBAAe,oBAA0F,KAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC,CA8CjP;IAGD,4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AE,KAAG,OAAO,CAAC,IAAI,CAAC,CAmB5F;CAEJ;AAED,eAAe,0BAA0B,CAAC"}
@@ -14,25 +14,31 @@ const uuid_1 = require("uuid");
14
14
  class ScheduleTransactionService {
15
15
  }
16
16
  _a = ScheduleTransactionService;
17
- ScheduleTransactionService.get_available_jobs = (pool_1, ...args_1) => __awaiter(void 0, [pool_1, ...args_1], void 0, function* (pool, limit = 10, job_ttl_s = 120, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "process_queued" }) {
17
+ ScheduleTransactionService.get_and_lock_available_jobs = (pool_1, ...args_1) => __awaiter(void 0, [pool_1, ...args_1], void 0, function* (pool, limit = 10, job_ttl_s = 120, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "process_queued" }) {
18
18
  const ttlSeconds = job_ttl_s;
19
19
  const batchGroupId = (0, uuid_1.v4)();
20
20
  const res = yield pool.query(`
21
- WITH candidates AS (
22
- SELECT id
23
- FROM multisig.schedule_transaction_jobs
24
- WHERE status = 'queued'
25
- AND (lock_expires_at IS NULL OR lock_expires_at < now())
26
- ORDER BY blockchain, chain_id ASC
21
+ WITH status_ids AS (
22
+ SELECT
23
+ MAX(CASE WHEN status = 'queued' THEN id END) AS queued_id,
24
+ MAX(CASE WHEN status = 'processing' THEN id END) AS processing_id
25
+ FROM multisig.schedule_job_statuses
26
+ ),
27
+ candidates AS (
28
+ SELECT cj.id
29
+ FROM multisig.schedule_transaction_jobs cj, status_ids
30
+ WHERE cj.status_id = status_ids.queued_id
31
+ AND (cj.lock_expires_at IS NULL OR cj.lock_expires_at < now())
32
+ ORDER BY cj.blockchain, cj.chain_id ASC
27
33
  LIMIT $1
28
34
  FOR UPDATE SKIP LOCKED
29
35
  )
30
36
  UPDATE multisig.schedule_transaction_jobs cj
31
37
  SET
32
- status = 'processing',
33
- locked_at = now(),
38
+ status_id = si.processing_id,
39
+ locked_at = now(),
34
40
  lock_expires_at = now() + ($2 || ' seconds')::interval,
35
- batch_group_id = $3,
41
+ batch_group_id = $3,
36
42
  metadata = jsonb_set(
37
43
  jsonb_set(
38
44
  coalesce(cj.metadata, '{}'::jsonb),
@@ -43,33 +49,39 @@ ScheduleTransactionService.get_available_jobs = (pool_1, ...args_1) => __awaiter
43
49
  to_jsonb($5::text)
44
50
  ),
45
51
  updated_at = now()
46
- FROM candidates c
52
+ FROM candidates c, status_ids si
47
53
  WHERE cj.id = c.id
48
54
  RETURNING cj.*;
49
55
  `, [limit, ttlSeconds, batchGroupId, lock_metadata.lock_owner, lock_metadata.lock_reason]);
50
56
  return res.rows;
51
57
  });
52
58
  /** Same as get_available_jobs but joins withdrawal details from accounting for each job. */
53
- ScheduleTransactionService.get_available_jobs_with_details = (pool_1, ...args_1) => __awaiter(void 0, [pool_1, ...args_1], void 0, function* (pool, limit = 10, job_ttl_s = 120, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "process_queued" }) {
59
+ ScheduleTransactionService.get_and_lock_available_jobs_with_details = (pool_1, ...args_1) => __awaiter(void 0, [pool_1, ...args_1], void 0, function* (pool, limit = 10, job_ttl_s = 120, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "process_queued" }) {
54
60
  const ttlSeconds = job_ttl_s;
55
61
  const batchGroupId = (0, uuid_1.v4)();
56
62
  const res = yield pool.query(`
57
- WITH candidates AS (
58
- SELECT id
59
- FROM multisig.schedule_transaction_jobs
60
- WHERE status = 'queued'
61
- AND (lock_expires_at IS NULL OR lock_expires_at < now())
62
- ORDER BY blockchain, chain_id ASC
63
+ WITH status_ids AS (
64
+ SELECT
65
+ MAX(CASE WHEN status = 'queued' THEN id END) AS queued_id,
66
+ MAX(CASE WHEN status = 'processing' THEN id END) AS processing_id
67
+ FROM multisig.schedule_job_statuses
68
+ ),
69
+ candidates AS (
70
+ SELECT cj.id
71
+ FROM multisig.schedule_transaction_jobs cj, status_ids
72
+ WHERE cj.status_id = status_ids.queued_id
73
+ AND (cj.lock_expires_at IS NULL OR cj.lock_expires_at < now())
74
+ ORDER BY cj.blockchain, cj.chain_id ASC
63
75
  LIMIT $1
64
76
  FOR UPDATE SKIP LOCKED
65
77
  ),
66
78
  updated AS (
67
79
  UPDATE multisig.schedule_transaction_jobs cj
68
80
  SET
69
- status = 'processing',
70
- locked_at = now(),
81
+ status_id = si.processing_id,
82
+ locked_at = now(),
71
83
  lock_expires_at = now() + ($2 || ' seconds')::interval,
72
- batch_group_id = $3,
84
+ batch_group_id = $3,
73
85
  metadata = jsonb_set(
74
86
  jsonb_set(
75
87
  coalesce(cj.metadata, '{}'::jsonb),
@@ -80,44 +92,44 @@ ScheduleTransactionService.get_available_jobs_with_details = (pool_1, ...args_1)
80
92
  to_jsonb($5::text)
81
93
  ),
82
94
  updated_at = now()
83
- FROM candidates c
95
+ FROM candidates c, status_ids si
84
96
  WHERE cj.id = c.id
85
97
  RETURNING cj.*
86
98
  )
87
- SELECT u.*, accounting.fn_get_crypto_withdrawal_details(u.request_id) AS withdrawal_details
88
- FROM updated u;
99
+ SELECT u.*, sjs.status, accounting.fn_get_crypto_withdrawal_details(u.request_id) AS withdrawal_details
100
+ FROM updated u
101
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = u.status_id
89
102
  `, [limit, ttlSeconds, batchGroupId, lock_metadata.lock_owner, lock_metadata.lock_reason]);
90
103
  return res.rows;
91
104
  });
92
105
  /**
93
- * Requeues all jobs in the given status to "queued"
94
- * @param pool
95
- * @param current_status
96
- * @param limit
97
- * @param lock_owner
98
- * @param lock_reason
99
- * @param max_retries
100
- * @returns
106
+ * Requeues all jobs in the given status to "queued"
101
107
  */
102
108
  ScheduleTransactionService.requeue_expired_jobs = (pool, current_status, limit, lock_owner, lock_reason, max_retries) => __awaiter(void 0, void 0, void 0, function* () {
103
109
  const res = yield pool.query(`
104
- WITH expired AS (
105
- SELECT id
106
- FROM multisig.schedule_transaction_jobs
107
- WHERE status = $4
110
+ WITH status_ids AS (
111
+ SELECT
112
+ MAX(CASE WHEN status = $4::text THEN id END) AS current_status_id,
113
+ MAX(CASE WHEN status = 'queued' THEN id END) AS queued_id
114
+ FROM multisig.schedule_job_statuses
115
+ ),
116
+ expired AS (
117
+ SELECT sj.id
118
+ FROM multisig.schedule_transaction_jobs sj, status_ids
119
+ WHERE sj.status_id = status_ids.current_status_id
108
120
  AND (
109
- lock_expires_at IS NULL
110
- OR lock_expires_at < now()
121
+ sj.lock_expires_at IS NULL
122
+ OR sj.lock_expires_at < now()
111
123
  )
112
- AND retry_count < $5
113
- ORDER BY lock_expires_at ASC
124
+ AND sj.retry_count < $5
125
+ ORDER BY sj.lock_expires_at ASC
114
126
  LIMIT $1
115
127
  FOR UPDATE SKIP LOCKED
116
128
  )
117
129
  UPDATE multisig.schedule_transaction_jobs cj
118
130
  SET
119
- status = 'queued',
120
- locked_at = NULL,
131
+ status_id = si.queued_id,
132
+ locked_at = NULL,
121
133
  lock_expires_at = NULL,
122
134
  metadata = jsonb_set(
123
135
  jsonb_set(
@@ -131,44 +143,74 @@ ScheduleTransactionService.requeue_expired_jobs = (pool, current_status, limit,
131
143
  true
132
144
  ),
133
145
  updated_at = now()
134
- FROM expired e
146
+ FROM expired e, status_ids si
135
147
  WHERE cj.id = e.id
136
148
  RETURNING cj.*;
137
149
  `, [limit, lock_owner, lock_reason, current_status, max_retries]);
138
150
  return res.rows;
139
151
  });
140
152
  ScheduleTransactionService.batch_update_status = (pool, operation_type, request_ids, new_status) => __awaiter(void 0, void 0, void 0, function* () {
141
- const status = new_status;
142
153
  yield pool.query(`
143
154
  UPDATE multisig.schedule_transaction_jobs
144
- SET status = $1, updated_at = CURRENT_TIMESTAMP
145
- WHERE operation_type = $2::int AND request_id = ANY($2)
146
- `, [status, operation_type, request_ids]);
147
- return;
155
+ SET
156
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = $1),
157
+ updated_at = CURRENT_TIMESTAMP
158
+ WHERE operation_type = $2::int
159
+ AND request_id = ANY($3)
160
+ `, [new_status, operation_type, request_ids]);
148
161
  });
149
- ScheduleTransactionService.batch_update_failed_jobs = (pool, request_ids, new_status, error_message, retryable) => __awaiter(void 0, void 0, void 0, function* () {
162
+ ScheduleTransactionService.batch_update_failed_jobs = (pool, operation_type, request_ids, new_status, error_message, retryable) => __awaiter(void 0, void 0, void 0, function* () {
150
163
  yield pool.query(`
151
164
  UPDATE multisig.schedule_transaction_jobs
152
- SET
153
- status = $1,
154
- updated_at = CURRENT_TIMESTAMP,
165
+ SET
166
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = $1),
167
+ updated_at = CURRENT_TIMESTAMP,
155
168
  error_message = COALESCE($2, error_message),
156
- last_error_at = CASE
169
+ last_error_at = CASE
157
170
  WHEN $2 IS NOT NULL THEN CURRENT_TIMESTAMP
158
171
  ELSE last_error_at
159
172
  END,
160
- retry_count = CASE
161
- WHEN $3 = true THEN retry_count + 1
162
- ELSE retry_count
163
- END
164
- WHERE request_id = ANY($4)
173
+ retry_count = CASE
174
+ WHEN $3 = true THEN retry_count + 1
175
+ ELSE retry_count
176
+ END
177
+ WHERE operation_type = $5
178
+ AND request_id = ANY($4)
165
179
  `, [
166
180
  new_status,
167
181
  error_message || null,
168
182
  retryable === true,
169
- request_ids
183
+ request_ids,
184
+ operation_type,
170
185
  ]);
171
186
  });
187
+ ScheduleTransactionService.batch_update_failed_jobs_custom_error = (pool, operation_type, jobs) => __awaiter(void 0, void 0, void 0, function* () {
188
+ const operationTypes = jobs.map(() => operation_type);
189
+ const requestIds = jobs.map(j => j.request_id);
190
+ const newStatuses = jobs.map(j => j.new_status);
191
+ const errorMessages = jobs.map(j => j.error_message);
192
+ const retryables = jobs.map(j => j.retryable);
193
+ yield pool.query(`
194
+ UPDATE multisig.schedule_transaction_jobs AS t
195
+ SET
196
+ status_id = sjs.id,
197
+ error_message = c.error_message,
198
+ last_error_at = CURRENT_TIMESTAMP,
199
+ retry_count = CASE WHEN c.retryable THEN t.retry_count + 1 ELSE t.retry_count END,
200
+ updated_at = CURRENT_TIMESTAMP
201
+ FROM (
202
+ SELECT
203
+ UNNEST($1::int[]) AS operation_type,
204
+ UNNEST($2::int[]) AS request_id,
205
+ UNNEST($3::text[]) AS status,
206
+ UNNEST($4::text[]) AS error_message,
207
+ UNNEST($5::boolean[]) AS retryable
208
+ ) AS c
209
+ JOIN multisig.schedule_job_statuses sjs ON sjs.status = c.status
210
+ WHERE t.operation_type = c.operation_type
211
+ AND t.request_id = c.request_id
212
+ `, [operationTypes, requestIds, newStatuses, errorMessages, retryables]);
213
+ });
172
214
  ScheduleTransactionService.batch_update_executed_jobs = (pool, data) => __awaiter(void 0, void 0, void 0, function* () {
173
215
  const requestIds = data.map(d => d.request_id);
174
216
  const operationTypes = data.map(d => d.operation_type);
@@ -176,21 +218,21 @@ ScheduleTransactionService.batch_update_executed_jobs = (pool, data) => __awaite
176
218
  const sentAts = data.map(d => d.sent_at);
177
219
  yield pool.query(`
178
220
  UPDATE multisig.schedule_transaction_jobs AS t
179
- SET
180
- tx_hash = c.tx_hash,
181
- sent_at = c.sent_at,
182
- status = 'confirming',
221
+ SET
222
+ tx_hash = c.tx_hash,
223
+ sent_at = c.sent_at,
224
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = 'confirming'),
183
225
  updated_at = CURRENT_TIMESTAMP
184
226
  FROM (
185
- SELECT
186
- UNNEST($1::int[]) AS operation_type,
187
- UNNEST($2::int[]) AS request_id,
188
- UNNEST($3::text[]) AS tx_hash,
227
+ SELECT
228
+ UNNEST($1::int[]) AS operation_type,
229
+ UNNEST($2::int[]) AS request_id,
230
+ UNNEST($3::text[]) AS tx_hash,
189
231
  UNNEST($4::timestamptz[]) AS sent_at
190
232
  ) AS c
191
233
  WHERE t.request_id = c.request_id
192
- AND t.operation_type = c.operation_type
193
- `, [operationTypes, requestIds, txHashes, sentAts]);
234
+ AND t.operation_type = c.operation_type
235
+ `, [operationTypes, requestIds, txHashes, sentAts]);
194
236
  });
195
237
  ScheduleTransactionService.mark_complete = (pool, payloads) => __awaiter(void 0, void 0, void 0, function* () {
196
238
  if (payloads.length === 0)
@@ -200,15 +242,15 @@ ScheduleTransactionService.mark_complete = (pool, payloads) => __awaiter(void 0,
200
242
  yield pool.query(`
201
243
  UPDATE multisig.schedule_transaction_jobs AS t
202
244
  SET
203
- status = 'completed',
245
+ status_id = (SELECT id FROM multisig.schedule_job_statuses WHERE status = 'completed'),
204
246
  updated_at = CURRENT_TIMESTAMP
205
247
  FROM (
206
248
  SELECT
207
249
  UNNEST($1::int[]) AS request_id,
208
- UNNEST($2::int[]) AS operation_type,
250
+ UNNEST($2::int[]) AS operation_type
209
251
  ) AS c
210
252
  WHERE t.request_id = c.request_id
211
- AND t.operation_type = c.operation_type
212
- `, [requestIds, operationTypes]);
253
+ AND t.operation_type = c.operation_type
254
+ `, [requestIds, operationTypes]);
213
255
  });
214
256
  exports.default = ScheduleTransactionService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ercworldio/blockchain-shared",
3
- "version": "1.0.3-dev.3-PROJ-1296.25",
3
+ "version": "1.0.3-dev.3-PROJ-1296.27",
4
4
  "description": "Shared library for blockchain projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",