@moneypot/hub 1.22.2 → 1.22.3

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.
@@ -1,5 +1,9 @@
1
1
  import { exactlyOneRow } from "../../db/util.js";
2
2
  export async function dbCreateLiability(pgClient, { lockedBankrollId, casinoId, experienceId, userId, currencyKey, refId, refType, maxPayout, deadline, }) {
3
+ await pgClient.query({
4
+ text: `SELECT 1 FROM hub.bankroll WHERE id = $1 FOR UPDATE`,
5
+ values: [lockedBankrollId],
6
+ });
3
7
  const row = await pgClient
4
8
  .query({
5
9
  text: `
@@ -39,6 +43,17 @@ export async function dbCreateLiability(pgClient, { lockedBankrollId, casinoId,
39
43
  }
40
44
  export async function dbResolveLiabilityByRef(pgClient, { refType, refId, lockedBankrollId, }) {
41
45
  const _proofOfGoodBehavior = lockedBankrollId;
46
+ await pgClient.query({
47
+ text: `
48
+ SELECT 1 FROM hub.bankroll
49
+ WHERE id = (
50
+ SELECT bankroll_id FROM hub.liability
51
+ WHERE ref_type = $1 AND ref_id = $2
52
+ )
53
+ FOR UPDATE
54
+ `,
55
+ values: [refType, refId],
56
+ });
42
57
  const result = await pgClient.query({
43
58
  text: `
44
59
  WITH resolved AS (
@@ -178,13 +178,18 @@ export async function processTakeRequests({ abortSignal, controllerId, casinoId,
178
178
  if (abortSignal.aborted) {
179
179
  break;
180
180
  }
181
- await processSingleTakeRequest({
182
- mpTakeRequestId: takeRequest.id,
183
- mpTakeRequest: takeRequest,
184
- casinoId,
185
- graphqlClient,
186
- pool,
187
- });
181
+ try {
182
+ await processSingleTakeRequest({
183
+ mpTakeRequestId: takeRequest.id,
184
+ mpTakeRequest: takeRequest,
185
+ casinoId,
186
+ graphqlClient,
187
+ pool,
188
+ });
189
+ }
190
+ catch (error) {
191
+ logger.error(error, `[processTakeRequests] Failed to process take request ${takeRequest.id}`);
192
+ }
188
193
  }
189
194
  await processPendingTransferCompletions({
190
195
  casinoId,
@@ -252,7 +257,11 @@ async function createAndProcessNewTakeRequest({ pgClient, mpTakeRequest, casinoI
252
257
  currencyKey: mpTakeRequest.currencyKey,
253
258
  casinoId,
254
259
  });
255
- assert(dbUser && dbExperience && dbCurrency && dbBalance, "Required entities not found");
260
+ if (!dbUser || !dbExperience || !dbCurrency || !dbBalance) {
261
+ logger.warn(`[createAndProcessNewTakeRequest] Rejecting take request ${mpTakeRequest.id}: no hub balance`);
262
+ await rejectMpTakeRequest(pgClient, graphqlClient, mpTakeRequest.id);
263
+ return null;
264
+ }
256
265
  const amountToTransfer = Math.floor(typeof mpTakeRequest.amount === "number"
257
266
  ? Math.min(mpTakeRequest.amount, dbBalance.amount)
258
267
  : dbBalance.amount);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.22.2",
3
+ "version": "1.22.3",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [