@moneypot/hub 1.3.0-dev.5 → 1.3.0-dev.6
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,15 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { Result } from "../util.js";
|
|
3
|
+
declare const OutcomeSchema: z.ZodObject<{
|
|
4
|
+
weight: z.ZodNumber;
|
|
5
|
+
profit: z.ZodNumber;
|
|
6
|
+
}, "strict", z.ZodTypeAny, {
|
|
7
|
+
weight: number;
|
|
8
|
+
profit: number;
|
|
9
|
+
}, {
|
|
10
|
+
weight: number;
|
|
11
|
+
profit: number;
|
|
12
|
+
}>;
|
|
3
13
|
declare const InputSchema: z.ZodObject<{
|
|
4
14
|
kind: z.ZodString;
|
|
5
15
|
wager: z.ZodNumber;
|
|
@@ -50,10 +60,18 @@ declare const InputSchema: z.ZodObject<{
|
|
|
50
60
|
metadata?: Record<string, any> | undefined;
|
|
51
61
|
}>;
|
|
52
62
|
type Input = z.infer<typeof InputSchema>;
|
|
63
|
+
type Outcome = z.infer<typeof OutcomeSchema>;
|
|
64
|
+
type FinalizeMetadataData = {
|
|
65
|
+
clientSeed: string;
|
|
66
|
+
hash: Uint8Array;
|
|
67
|
+
outcomes: Outcome[];
|
|
68
|
+
outcomeIdx: number;
|
|
69
|
+
};
|
|
53
70
|
export type OutcomeBetConfig = {
|
|
54
71
|
houseEdge: number;
|
|
55
72
|
saveOutcomes: boolean;
|
|
56
|
-
|
|
73
|
+
initializeMetadata?: (input: Input) => Result<Record<string, any>, string>;
|
|
74
|
+
finalizeMetadata?: (input: Input, metadata: Record<string, any>, data: FinalizeMetadataData) => Record<string, any>;
|
|
57
75
|
};
|
|
58
76
|
export type OutcomeBetConfigMap<BetKind extends string> = {
|
|
59
77
|
[betKind in BetKind]: OutcomeBetConfig;
|
|
@@ -52,10 +52,11 @@ const BetConfigsSchema = z.record(BetKindSchema, z.object({
|
|
|
52
52
|
.gte(0, "House edge must be >= 0")
|
|
53
53
|
.lte(1, "House edge must be <= 1"),
|
|
54
54
|
saveOutcomes: z.boolean(),
|
|
55
|
-
|
|
55
|
+
initializeMetadata: z
|
|
56
|
+
.function()
|
|
57
|
+
.optional(),
|
|
58
|
+
finalizeMetadata: z
|
|
56
59
|
.function()
|
|
57
|
-
.args(InputSchema)
|
|
58
|
-
.returns(z.record(z.string(), z.any()))
|
|
59
60
|
.optional(),
|
|
60
61
|
}));
|
|
61
62
|
export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
@@ -121,8 +122,8 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
121
122
|
throw new GraphQLError(`Invalid bet kind`);
|
|
122
123
|
}
|
|
123
124
|
let validatedMetadata;
|
|
124
|
-
if (betConfig.
|
|
125
|
-
const result = betConfig.
|
|
125
|
+
if (betConfig.initializeMetadata) {
|
|
126
|
+
const result = betConfig.initializeMetadata(input);
|
|
126
127
|
if (result.ok) {
|
|
127
128
|
validatedMetadata = result.value;
|
|
128
129
|
}
|
|
@@ -273,6 +274,15 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
273
274
|
input.wager,
|
|
274
275
|
],
|
|
275
276
|
});
|
|
277
|
+
const immutableData = structuredClone({
|
|
278
|
+
clientSeed: dbHashChain.client_seed,
|
|
279
|
+
hash: betHashResult.hash,
|
|
280
|
+
outcomes: input.outcomes,
|
|
281
|
+
outcomeIdx,
|
|
282
|
+
});
|
|
283
|
+
const finalizedMetadata = betConfig.finalizeMetadata
|
|
284
|
+
? betConfig.finalizeMetadata(input, validatedMetadata, immutableData)
|
|
285
|
+
: validatedMetadata;
|
|
276
286
|
const newBet = {
|
|
277
287
|
kind: rawInput.kind,
|
|
278
288
|
wager: input.wager,
|
|
@@ -282,7 +292,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
282
292
|
user_id: session.user_id,
|
|
283
293
|
casino_id: session.casino_id,
|
|
284
294
|
experience_id: session.experience_id,
|
|
285
|
-
metadata:
|
|
295
|
+
metadata: finalizedMetadata,
|
|
286
296
|
...(betConfig.saveOutcomes
|
|
287
297
|
? {
|
|
288
298
|
outcomes: input.outcomes,
|