@ercworldio/blockchain-shared 1.0.5-dev.8-PLAT300.7 → 1.0.5-dev.8-PLAT304.4

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.
Files changed (43) hide show
  1. package/build/chains/networks_dev.json +12 -2
  2. package/build/chains/networks_stg-dz.json +10 -1
  3. package/build/contracts/Escrow.d.ts +2 -0
  4. package/build/contracts/Escrow.d.ts.map +1 -1
  5. package/build/contracts/Escrow.js +63 -0
  6. package/build/contracts/contract-events/EscrowEvents.d.ts +14 -14
  7. package/build/contracts/contract-events/EscrowEvents.d.ts.map +1 -1
  8. package/build/contracts/contract-events/EscrowEvents.js +5 -5
  9. package/build/contracts/typechain-types/contracts/escrow/Escrow.d.ts +31 -17
  10. package/build/contracts/typechain-types/contracts/escrow/Escrow.d.ts.map +1 -1
  11. package/build/contracts/typechain-types/factories/contracts/escrow/EscrowAccessControl__factory.d.ts +1 -1
  12. package/build/contracts/typechain-types/factories/contracts/escrow/EscrowAccessControl__factory.js +1 -1
  13. package/build/contracts/typechain-types/factories/contracts/escrow/EscrowSignature__factory.d.ts +1 -1
  14. package/build/contracts/typechain-types/factories/contracts/escrow/EscrowSignature__factory.js +1 -1
  15. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.d.ts +67 -9
  16. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.d.ts.map +1 -1
  17. package/build/contracts/typechain-types/factories/contracts/escrow/Escrow__factory.js +88 -11
  18. package/build/contracts/typechain-types/factories/contracts/lib/MultisigLib__factory.d.ts +1 -1
  19. package/build/contracts/typechain-types/factories/contracts/lib/MultisigLib__factory.js +1 -1
  20. package/build/index.d.ts +1 -0
  21. package/build/index.d.ts.map +1 -1
  22. package/build/index.js +4 -2
  23. package/build/services/AzureEventHubHandler.d.ts.map +1 -1
  24. package/build/services/AzureEventHubHandler.js +4 -1
  25. package/build/services/db/multisig/MultisigService.d.ts +26 -1
  26. package/build/services/db/multisig/MultisigService.d.ts.map +1 -1
  27. package/build/services/db/multisig/MultisigService.js +70 -0
  28. package/build/services/db/timelock/ScheduleTransactionService.d.ts +16 -2
  29. package/build/services/db/timelock/ScheduleTransactionService.d.ts.map +1 -1
  30. package/build/services/db/timelock/ScheduleTransactionService.js +265 -1
  31. package/build/services/solana/escrow/idl/escrow.json +528 -17
  32. package/build/services/solana/escrow/types/escrow.d.ts +528 -17
  33. package/build/services/solana/escrow/types/escrow.d.ts.map +1 -1
  34. package/build/services/types/azure_event_hub_handler.d.ts +3 -1
  35. package/build/services/types/azure_event_hub_handler.d.ts.map +1 -1
  36. package/build/services/types/azure_event_hub_handler.js +3 -0
  37. package/build/services/types/claim.d.ts +1 -0
  38. package/build/services/types/claim.d.ts.map +1 -1
  39. package/build/services/types/db/multisig_service.d.ts +70 -0
  40. package/build/services/types/db/multisig_service.d.ts.map +1 -1
  41. package/build/services/types/db/timelock.d.ts +56 -0
  42. package/build/services/types/db/timelock.d.ts.map +1 -1
  43. package/package.json +1 -1
@@ -2,12 +2,15 @@ import { ScheduleJobStatus, ScheduleTransactionJob } from "../../../entities/Sch
2
2
  import { ClaimJobLockMetadata } from "../../types";
3
3
  import { Pool } from "pg";
4
4
  import { OperationType } from "../../../contracts/types/escrow";
5
- import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails } from "../../types/db";
5
+ import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails, ScheduleJobFilters, ScheduleJobListItem, ScheduleJobHistoryFilters, ScheduleJobHistoryItem } from "../../types/db";
6
+ import { Paginated } from "../../types/claim_job_service";
6
7
  import { RequeueJobConfiguration } from "../../types/watchdog";
7
8
  declare class ScheduleTransactionService {
8
9
  static get_and_lock_available_jobs: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJob[]>;
9
- /** Locks and returns available jobs with full withdrawal details via DB function. */
10
+ /** Locks and returns available jobs with full withdrawal details via inline SQL (bypasses DB function). */
10
11
  static get_and_lock_available_jobs_with_details: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
12
+ /** Locks and returns available jobs with full withdrawal details via DB function. */
13
+ static get_and_lock_available_jobs_with_details_depr: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
11
14
  /**
12
15
  * Requeues all jobs in the given status to "queued"
13
16
  */
@@ -27,6 +30,17 @@ declare class ScheduleTransactionService {
27
30
  sent_at: Date;
28
31
  }[]) => Promise<void>;
29
32
  static mark_complete: (pool: Pool, payloads: MarkCompleteScheduleJob[]) => Promise<void>;
33
+ /**
34
+ * Paginated list of current schedule-transaction jobs, newest first, with the
35
+ * status resolved to text and (for withdrawal operation types) the receiver/token/
36
+ * amount joined in. All filters are optional and combine with AND.
37
+ */
38
+ static list_jobs_paginated: (pool: Pool, page: number, page_size?: number, filters?: ScheduleJobFilters) => Promise<Paginated<ScheduleJobListItem[]>>;
39
+ /**
40
+ * Paginated schedule-transaction job history (append-only status transitions),
41
+ * newest first. All filters are optional and combine with AND.
42
+ */
43
+ static list_history_paginated: (pool: Pool, page: number, page_size?: number, filters?: ScheduleJobHistoryFilters) => Promise<Paginated<ScheduleJobHistoryItem[]>>;
30
44
  }
31
45
  export default ScheduleTransactionService;
32
46
  //# sourceMappingURL=ScheduleTransactionService.d.ts.map
@@ -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,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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,CAwBd;IAGF,MAAM,CAAC,aAAa,GAAU,MAAM,IAAI,EAAE,UAAU,uBAAuB,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAmB5F;CAEJ;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,EACH,uBAAuB,EACvB,iCAAiC,EACjC,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,cAAM,0BAA0B;IAE5B,MAAM,CAAC,2BAA2B,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,gBAAe,oBAA0F,KAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC,CA4CjP;IAGD,2GAA2G;IAC3G,MAAM,CAAC,wCAAwC,GAC3C,MAAM,IAAI,EACV,QAAO,MAAW,EAClB,YAAW,MAAY,EACvB,gBAAe,oBAA0F,KAC1G,OAAO,CAAC,iCAAiC,EAAE,CAAC,CAqH9C;IAGD,qFAAqF;IACrF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,CAAC,mBAAmB,GACtB,MAAM,IAAI,EACV,MAAM,MAAM,EACZ,YAAW,MAAW,EACtB,UAAS,kBAAuB,KACjC,OAAO,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAgE1C;IAGF;;;OAGG;IACH,MAAM,CAAC,sBAAsB,GACzB,MAAM,IAAI,EACV,MAAM,MAAM,EACZ,YAAW,MAAW,EACtB,UAAS,yBAA8B,KACxC,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAqD7C;CAEL;AAED,eAAe,0BAA0B,CAAC"}
@@ -52,8 +52,123 @@ ScheduleTransactionService.get_and_lock_available_jobs = (pool_1, ...args_1) =>
52
52
  `, [limit, ttlSeconds, lock_metadata.lock_owner, lock_metadata.lock_reason]);
53
53
  return res.rows;
54
54
  });
55
- /** Locks and returns available jobs with full withdrawal details via DB function. */
55
+ /** Locks and returns available jobs with full withdrawal details via inline SQL (bypasses DB function). */
56
56
  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" }) {
57
+ var _b, _c;
58
+ const result = yield pool.query(`
59
+ WITH status_ids AS (
60
+ SELECT
61
+ MAX(CASE WHEN status = 'queued' THEN id END) AS queued_id,
62
+ MAX(CASE WHEN status = 'processing' THEN id END) AS processing_id
63
+ FROM multisig.schedule_job_statuses
64
+ ),
65
+ candidates AS (
66
+ SELECT id
67
+ FROM multisig.schedule_transaction_jobs, status_ids
68
+ WHERE status_id = status_ids.queued_id
69
+ AND (lock_expires_at IS NULL OR lock_expires_at < NOW())
70
+ ORDER BY blockchain, chain_id ASC
71
+ LIMIT $1
72
+ FOR UPDATE SKIP LOCKED
73
+ ),
74
+ updated AS (
75
+ UPDATE multisig.schedule_transaction_jobs j
76
+ SET status_id = si.processing_id,
77
+ locked_at = NOW(),
78
+ lock_expires_at = NOW() + ($2 || ' seconds')::INTERVAL,
79
+ batch_group_id = gen_random_uuid(),
80
+ metadata = jsonb_set(
81
+ jsonb_set(
82
+ COALESCE(j.metadata, '{}'::jsonb),
83
+ '{lock_owner}', to_jsonb($3::text)
84
+ ),
85
+ '{lock_reason}', to_jsonb($4::text)
86
+ ),
87
+ updated_at = NOW()
88
+ FROM candidates c, status_ids si
89
+ WHERE j.id = c.id
90
+ RETURNING j.*
91
+ )
92
+ SELECT COALESCE(json_agg(json_build_object(
93
+ 'id', u.id,
94
+ 'requestId', u.request_id,
95
+ 'operationType', u.operation_type,
96
+ 'status', sjs.status,
97
+ 'blockchain', u.blockchain,
98
+ 'chainId', u.chain_id,
99
+ 'batchGroupId', u.batch_group_id,
100
+ 'lockExpiresAt', u.lock_expires_at,
101
+ 'lockedAt', u.locked_at,
102
+ 'txHash', u.tx_hash,
103
+ 'sentAt', u.sent_at,
104
+ 'confirmedAt', u.confirmed_at,
105
+ 'retryCount', u.retry_count,
106
+ 'errorMessage', u.error_message,
107
+ 'lastErrorAt', u.last_error_at,
108
+ 'metadata', u.metadata,
109
+ 'createdAt', u.created_at,
110
+ 'updatedAt', u.updated_at,
111
+ 'withdrawalDetails', json_build_object(
112
+ 'id', cw.id,
113
+ 'userId', cw.user_id,
114
+ 'status', LOWER(cws.status),
115
+ 'blockchain', LOWER(cwbt.blockchain),
116
+ 'receiver', cw.receiver_address,
117
+ 'receiverAddress', cw.receiver_address,
118
+ 'paymentType', LOWER(cwpt.type),
119
+ 'chainId', cw.chain_id,
120
+ 'token', cw.token_address,
121
+ 'amount', cw.amount,
122
+ 'amountInUsd', cw.amount * cr.rate,
123
+ 'destinationChainId', cw.destination_chain_id,
124
+ 'destinationToken', cw.destination_token_address,
125
+ 'destinationBlockchain', cw.destination_blockchain,
126
+ 'sigsExecutiveRequired', cw.sigs_executive_required,
127
+ 'sigsManagerRequired', cw.sigs_manager_required,
128
+ 'timeLockSeconds', cw.timelock_seconds,
129
+ 'multisigSignatures', (
130
+ SELECT COALESCE(json_agg(json_build_object(
131
+ 'name', COALESCE(role.role_alias, ''),
132
+ 'signerAddress', cs.signer_address,
133
+ 'contractAddress', cs.contract_address,
134
+ 'createdAt', cs.created_at,
135
+ 'updatedAt', cs.updated_at,
136
+ 'operationType', cs.operation_type,
137
+ 'v', cs.v,
138
+ 'r', cs.r,
139
+ 's', cs.s,
140
+ 'signature', cs.signature
141
+ )), '[]'::json)
142
+ FROM multisig.crypto_signatures cs
143
+ LEFT JOIN multisig.crypto_escrow_roles cer
144
+ ON LOWER(cer.wallet_address) = LOWER(cs.signer_address)
145
+ AND LOWER(cer.blockchain) = LOWER(cs.blockchain)
146
+ AND cer.chain_id = cs.chain_id
147
+ AND LOWER(cer.contract_address) = LOWER(cs.contract_address)
148
+ LEFT JOIN multisig.crypto_role role ON role.id = cer.role_id
149
+ WHERE cs.reference_id = cw.id
150
+ AND cs.operation_type = 1
151
+ AND (
152
+ (cs.v IS NOT NULL AND cs.r IS NOT NULL AND cs.s IS NOT NULL)
153
+ OR cs.signature IS NOT NULL
154
+ )
155
+ )
156
+ )
157
+ )), '[]'::json) AS result
158
+ FROM updated u
159
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = u.status_id
160
+ JOIN accounting.crypto_withdrawals cw ON cw.id = u.request_id
161
+ LEFT JOIN accounting.crypto_withdrawal_status cws ON cws.id = cw.status_id
162
+ LEFT JOIN accounting.crypto_withdrawal_blockchain_types cwbt ON cwbt.id = cw.blockchain_id
163
+ LEFT JOIN accounting.crypto_withdrawal_payment_types cwpt ON cwpt.id = cw.payment_type_id
164
+ LEFT JOIN usersmanagement.user_currency_mappings ucm ON ucm.currency_specific_user_id = cw.currency_specific_user_id
165
+ LEFT JOIN public.currencies cur ON cur.currencyid = ucm.currency_id
166
+ LEFT JOIN accounting.currencyrates cr ON cr.symbol = UPPER(cur.currency_code || 'USD')
167
+ `, [limit, job_ttl_s, lock_metadata.lock_owner, lock_metadata.lock_reason]);
168
+ return (_c = (_b = result.rows[0]) === null || _b === void 0 ? void 0 : _b.result) !== null && _c !== void 0 ? _c : [];
169
+ });
170
+ /** Locks and returns available jobs with full withdrawal details via DB function. */
171
+ ScheduleTransactionService.get_and_lock_available_jobs_with_details_depr = (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" }) {
57
172
  var _b;
58
173
  const result = yield pool.query(`SELECT multisig.fn_get_available_schedule_jobs_with_details($1::int, $2::int, $3::text, $4::text)`, [limit, job_ttl_s, lock_metadata.lock_owner, lock_metadata.lock_reason]);
59
174
  return (_b = result.rows[0].fn_get_available_schedule_jobs_with_details) !== null && _b !== void 0 ? _b : [];
@@ -209,4 +324,153 @@ ScheduleTransactionService.mark_complete = (pool, payloads) => __awaiter(void 0,
209
324
  AND t.operation_type = c.operation_type
210
325
  `, [requestIds, operationTypes]);
211
326
  });
327
+ // ── BO read views ────────────────────────────────────────────────────────
328
+ /**
329
+ * Paginated list of current schedule-transaction jobs, newest first, with the
330
+ * status resolved to text and (for withdrawal operation types) the receiver/token/
331
+ * amount joined in. All filters are optional and combine with AND.
332
+ */
333
+ ScheduleTransactionService.list_jobs_paginated = (pool_1, page_1, ...args_1) => __awaiter(void 0, [pool_1, page_1, ...args_1], void 0, function* (pool, page, page_size = 20, filters = {}) {
334
+ var _b, _c;
335
+ if (page < 1)
336
+ page = 1;
337
+ const clauses = [];
338
+ const params = [];
339
+ let i = 1;
340
+ if (filters.status) {
341
+ clauses.push(`sjs.status = $${i++}`);
342
+ params.push(filters.status);
343
+ }
344
+ if (filters.blockchain) {
345
+ clauses.push(`j.blockchain = $${i++}`);
346
+ params.push(filters.blockchain);
347
+ }
348
+ if (filters.chainId) {
349
+ clauses.push(`j.chain_id = $${i++}`);
350
+ params.push(filters.chainId);
351
+ }
352
+ if (filters.operationType !== undefined) {
353
+ clauses.push(`j.operation_type = $${i++}`);
354
+ params.push(filters.operationType);
355
+ }
356
+ if (filters.requestId !== undefined) {
357
+ clauses.push(`j.request_id = $${i++}`);
358
+ params.push(filters.requestId);
359
+ }
360
+ if (filters.txHash) {
361
+ clauses.push(`j.tx_hash = $${i++}`);
362
+ params.push(filters.txHash);
363
+ }
364
+ const where = clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
365
+ const countRes = yield pool.query(`SELECT COUNT(*)::bigint AS count
366
+ FROM multisig.schedule_transaction_jobs j
367
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = j.status_id
368
+ ${where}`, params);
369
+ const total_count = Number((_c = (_b = countRes.rows[0]) === null || _b === void 0 ? void 0 : _b.count) !== null && _c !== void 0 ? _c : 0);
370
+ const limitParam = i++;
371
+ const offsetParam = i++;
372
+ const rowsRes = yield pool.query(`SELECT
373
+ j.id,
374
+ j.request_id AS "requestId",
375
+ j.operation_type AS "operationType",
376
+ sjs.status AS status,
377
+ j.blockchain,
378
+ j.chain_id AS "chainId",
379
+ j.tx_hash AS "txHash",
380
+ j.locked_at AS "lockedAt",
381
+ j.lock_expires_at AS "lockExpiresAt",
382
+ j.sent_at AS "sentAt",
383
+ j.confirmed_at AS "confirmedAt",
384
+ j.retry_count AS "retryCount",
385
+ j.error_message AS "errorMessage",
386
+ j.last_error_at AS "lastErrorAt",
387
+ j.metadata,
388
+ j.created_at AS "createdAt",
389
+ j.updated_at AS "updatedAt",
390
+ cw.receiver_address AS "receiverAddress",
391
+ cw.token_address AS "tokenAddress",
392
+ cw.amount AS "amount"
393
+ FROM multisig.schedule_transaction_jobs j
394
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = j.status_id
395
+ LEFT JOIN accounting.crypto_withdrawals cw
396
+ ON cw.id = j.request_id AND j.operation_type IN (1, 3)
397
+ ${where}
398
+ ORDER BY j.created_at DESC
399
+ LIMIT $${limitParam} OFFSET $${offsetParam}`, [...params, page_size, (page - 1) * page_size]);
400
+ return {
401
+ total_count,
402
+ pages_count: Math.ceil(total_count / page_size),
403
+ current_page: page,
404
+ has_next: total_count > page * page_size,
405
+ items: rowsRes.rows
406
+ };
407
+ });
408
+ /**
409
+ * Paginated schedule-transaction job history (append-only status transitions),
410
+ * newest first. All filters are optional and combine with AND.
411
+ */
412
+ ScheduleTransactionService.list_history_paginated = (pool_1, page_1, ...args_1) => __awaiter(void 0, [pool_1, page_1, ...args_1], void 0, function* (pool, page, page_size = 20, filters = {}) {
413
+ var _b, _c;
414
+ if (page < 1)
415
+ page = 1;
416
+ const clauses = [];
417
+ const params = [];
418
+ let i = 1;
419
+ if (filters.jobId !== undefined) {
420
+ clauses.push(`h.job_id = $${i++}`);
421
+ params.push(filters.jobId);
422
+ }
423
+ if (filters.requestId !== undefined) {
424
+ clauses.push(`h.request_id = $${i++}`);
425
+ params.push(filters.requestId);
426
+ }
427
+ if (filters.operationType !== undefined) {
428
+ clauses.push(`h.operation_type = $${i++}`);
429
+ params.push(filters.operationType);
430
+ }
431
+ if (filters.status) {
432
+ clauses.push(`sjs.status = $${i++}`);
433
+ params.push(filters.status);
434
+ }
435
+ if (filters.blockchain) {
436
+ clauses.push(`h.blockchain = $${i++}`);
437
+ params.push(filters.blockchain);
438
+ }
439
+ if (filters.chainId) {
440
+ clauses.push(`h.chain_id = $${i++}`);
441
+ params.push(filters.chainId);
442
+ }
443
+ const where = clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
444
+ const countRes = yield pool.query(`SELECT COUNT(*)::bigint AS count
445
+ FROM multisig.schedule_transaction_jobs_history h
446
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = h.status_id
447
+ ${where}`, params);
448
+ const total_count = Number((_c = (_b = countRes.rows[0]) === null || _b === void 0 ? void 0 : _b.count) !== null && _c !== void 0 ? _c : 0);
449
+ const limitParam = i++;
450
+ const offsetParam = i++;
451
+ const rowsRes = yield pool.query(`SELECT
452
+ h.id,
453
+ h.job_id AS "jobId",
454
+ h.request_id AS "requestId",
455
+ h.operation_type AS "operationType",
456
+ sjs.status AS status,
457
+ h.blockchain,
458
+ h.chain_id AS "chainId",
459
+ h.tx_hash AS "txHash",
460
+ h.retry_count AS "retryCount",
461
+ h.error_message AS "errorMessage",
462
+ h.created_at AS "createdAt"
463
+ FROM multisig.schedule_transaction_jobs_history h
464
+ JOIN multisig.schedule_job_statuses sjs ON sjs.id = h.status_id
465
+ ${where}
466
+ ORDER BY h.created_at DESC
467
+ LIMIT $${limitParam} OFFSET $${offsetParam}`, [...params, page_size, (page - 1) * page_size]);
468
+ return {
469
+ total_count,
470
+ pages_count: Math.ceil(total_count / page_size),
471
+ current_page: page,
472
+ has_next: total_count > page * page_size,
473
+ items: rowsRes.rows
474
+ };
475
+ });
212
476
  exports.default = ScheduleTransactionService;