@moneypot/hub 1.3.0-dev.10 → 1.3.0-dev.11
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.
- package/dist/src/db/index.d.ts +1 -0
- package/dist/src/db/index.js +1 -0
- package/dist/src/hash-chain/db-hash-chain.d.ts +2 -2
- package/dist/src/hash-chain/db-hash-chain.js +2 -2
- package/dist/src/plugins/hub-make-outcome-bet.d.ts +2 -2
- package/dist/src/plugins/hub-make-outcome-bet.js +5 -5
- package/package.json +1 -1
package/dist/src/db/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as pg from "pg";
|
|
|
2
2
|
import stream from "node:stream";
|
|
3
3
|
import { DbCasino, DbExperience, DbSession, DbTransferStatusKind, DbUser, DbWithdrawal } from "./types.js";
|
|
4
4
|
import { TransferStatusKind } from "../__generated__/graphql.js";
|
|
5
|
+
export * from "../hash-chain/db-hash-chain.js";
|
|
5
6
|
export * from "./types.js";
|
|
6
7
|
export * from "./public.js";
|
|
7
8
|
export * from "./util.js";
|
package/dist/src/db/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { exactlyOneRow, maybeOneRow } from "./util.js";
|
|
|
5
5
|
import { logger } from "../logger.js";
|
|
6
6
|
import { setTimeout } from "node:timers/promises";
|
|
7
7
|
import { assert } from "tsafe";
|
|
8
|
+
export * from "../hash-chain/db-hash-chain.js";
|
|
8
9
|
export * from "./types.js";
|
|
9
10
|
export * from "./public.js";
|
|
10
11
|
export * from "./util.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DbCasino, DbExperience, DbHash, DbHashChain, DbUser } from "../db/types.js";
|
|
2
2
|
import { PgClientInTransaction } from "../db/index.js";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function dbLockHubHashChain(pgClient: PgClientInTransaction, { userId, experienceId, casinoId, hashChainId, }: {
|
|
4
4
|
userId: DbUser["id"];
|
|
5
5
|
experienceId: DbExperience["id"];
|
|
6
6
|
casinoId: DbCasino["id"];
|
|
7
7
|
hashChainId: DbHashChain["id"];
|
|
8
8
|
}): Promise<DbHashChain | null>;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function dbInsertHubHash(pgClient: PgClientInTransaction, { hashChainId, kind, digest, iteration, metadata, }: {
|
|
10
10
|
hashChainId: DbHashChain["id"];
|
|
11
11
|
kind: DbHash["kind"];
|
|
12
12
|
digest: DbHash["digest"];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exactlyOneRow, maybeOneRow, } from "../db/index.js";
|
|
2
2
|
import { assert } from "tsafe";
|
|
3
|
-
export async function
|
|
3
|
+
export async function dbLockHubHashChain(pgClient, { userId, experienceId, casinoId, hashChainId, }) {
|
|
4
4
|
assert(pgClient._inTransaction, "dbLockHashChain must be called in a transaction");
|
|
5
5
|
return pgClient
|
|
6
6
|
.query(`
|
|
@@ -17,7 +17,7 @@ export async function dbLockHashChain(pgClient, { userId, experienceId, casinoId
|
|
|
17
17
|
.then(maybeOneRow)
|
|
18
18
|
.then((row) => row ?? null);
|
|
19
19
|
}
|
|
20
|
-
export async function
|
|
20
|
+
export async function dbInsertHubHash(pgClient, { hashChainId, kind, digest, iteration, metadata = {}, }) {
|
|
21
21
|
assert(pgClient._inTransaction, "dbInsertHash must be called in a transaction");
|
|
22
22
|
return pgClient
|
|
23
23
|
.query(`
|
|
@@ -40,8 +40,8 @@ declare const InputSchema: z.ZodObject<{
|
|
|
40
40
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
41
41
|
}, "strict", z.ZodTypeAny, {
|
|
42
42
|
currency: string;
|
|
43
|
-
kind: string;
|
|
44
43
|
hashChainId: string;
|
|
44
|
+
kind: string;
|
|
45
45
|
wager: number;
|
|
46
46
|
outcomes: {
|
|
47
47
|
weight: number;
|
|
@@ -50,8 +50,8 @@ declare const InputSchema: z.ZodObject<{
|
|
|
50
50
|
metadata?: Record<string, any> | undefined;
|
|
51
51
|
}, {
|
|
52
52
|
currency: string;
|
|
53
|
-
kind: string;
|
|
54
53
|
hashChainId: string;
|
|
54
|
+
kind: string;
|
|
55
55
|
wager: number;
|
|
56
56
|
outcomes: {
|
|
57
57
|
weight: number;
|
|
@@ -4,7 +4,7 @@ import { z } from "zod";
|
|
|
4
4
|
import { GraphQLError } from "graphql";
|
|
5
5
|
import { DbHashKind, exactlyOneRow, maybeOneRow, superuserPool, withPgPoolTransaction, } from "../db/index.js";
|
|
6
6
|
import { assert } from "tsafe";
|
|
7
|
-
import {
|
|
7
|
+
import { dbInsertHubHash, dbLockHubHashChain, } from "../hash-chain/db-hash-chain.js";
|
|
8
8
|
import { getIntermediateHash, getPreimageHash, } from "../hash-chain/get-hash.js";
|
|
9
9
|
const FLOAT_EPSILON = 1e-10;
|
|
10
10
|
function sum(ns) {
|
|
@@ -128,7 +128,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
128
128
|
initializedMetadata = result.value;
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
|
-
throw new GraphQLError(`Invalid
|
|
131
|
+
throw new GraphQLError(`Invalid input: ${result.error}`);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
const houseEV = calculateHouseEV(input.outcomes);
|
|
@@ -181,7 +181,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
181
181
|
if (maxPotentialPayout > maxAllowablePayout) {
|
|
182
182
|
throw new GraphQLError(`House risk limit exceeded. Max payout: ${maxPotentialPayout.toFixed(4)}`);
|
|
183
183
|
}
|
|
184
|
-
const dbHashChain = await
|
|
184
|
+
const dbHashChain = await dbLockHubHashChain(pgClient, {
|
|
185
185
|
userId: session.user_id,
|
|
186
186
|
experienceId: session.experience_id,
|
|
187
187
|
casinoId: session.casino_id,
|
|
@@ -225,7 +225,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
225
225
|
throw new Error(`Unknown bet hash result: ${_exhaustiveCheck}`);
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
await
|
|
228
|
+
await dbInsertHubHash(pgClient, {
|
|
229
229
|
hashChainId: dbHashChain.id,
|
|
230
230
|
kind: DbHashKind.INTERMEDIATE,
|
|
231
231
|
digest: betHashResult.hash,
|
|
@@ -451,7 +451,7 @@ async function finishHashChainInBackground({ hashChainId, }) {
|
|
|
451
451
|
iteration: 0,
|
|
452
452
|
});
|
|
453
453
|
await withPgPoolTransaction(superuserPool, async (pgClient) => {
|
|
454
|
-
await
|
|
454
|
+
await dbInsertHubHash(pgClient, {
|
|
455
455
|
hashChainId,
|
|
456
456
|
kind: DbHashKind.PREIMAGE,
|
|
457
457
|
digest: preimageHashResult.hash,
|