@ercworldio/blockchain-shared 1.0.5-dev.7-PROJ-1469.13 → 1.0.5-dev.7-PROJ-1469.14
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.
|
@@ -6,8 +6,10 @@ import { MarkCompleteScheduleJob, ScheduleTransactionJobWithDetails } from "../.
|
|
|
6
6
|
import { RequeueJobConfiguration } from "../../types/watchdog";
|
|
7
7
|
declare class ScheduleTransactionService {
|
|
8
8
|
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. */
|
|
9
|
+
/** Locks and returns available jobs with full withdrawal details via inline SQL (bypasses DB function). */
|
|
10
10
|
static get_and_lock_available_jobs_with_details: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
|
|
11
|
+
/** Locks and returns available jobs with full withdrawal details via DB function. */
|
|
12
|
+
static get_and_lock_available_jobs_with_details_depr: (pool: Pool, limit?: number, job_ttl_s?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ScheduleTransactionJobWithDetails[]>;
|
|
11
13
|
/**
|
|
12
14
|
* Requeues all jobs in the given status to "queued"
|
|
13
15
|
*/
|
|
@@ -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;AAC5F,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,
|
|
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;AAC5F,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,MAAM,CAAC,6CAA6C,GAChD,MAAM,IAAI,EACV,QAAO,MAAW,EAClB,YAAW,MAAY,EACvB,gBAAe,oBAA0F,KAC1G,OAAO,CAAC,iCAAiC,EAAE,CAAC,CAQ9C;IAGD;;O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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 : [];
|
package/package.json
CHANGED