Initial commit
Once again a weird place to commit, I have already done a lot of work, but I am just bad at using git, okay.
This commit is contained in:
42
example-app/server/utils/config.ts
Normal file
42
example-app/server/utils/config.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { load } from 'js-toml';
|
||||
import z from 'zod';
|
||||
import { ChallengeStrategy } from "@impost/lib";
|
||||
|
||||
const LeadingZeroesSchema = z.object({
|
||||
strategy: z.literal(ChallengeStrategy.LeadingZeroes),
|
||||
leading_zeroes: z.object({
|
||||
difficulty: z.number().int().min(1).max(64),
|
||||
}),
|
||||
});
|
||||
|
||||
const TargetNumberSchema = z.object({
|
||||
strategy: z.literal(ChallengeStrategy.TargetNumber),
|
||||
target_number: z.object({
|
||||
max_number: z.number().int().min(1).max(100_000),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
export type Config = z.infer<typeof Config>;
|
||||
|
||||
export const Config = z.discriminatedUnion('strategy', [
|
||||
LeadingZeroesSchema,
|
||||
TargetNumberSchema,
|
||||
]);
|
||||
|
||||
export let config: Config;
|
||||
|
||||
try {
|
||||
config = Config.parse(load(readFileSync('./config.toml', 'utf-8')));
|
||||
} catch (error: any) {
|
||||
if (error instanceof z.ZodError) {
|
||||
console.error("Failed to parse config:");
|
||||
for (const issue of error.issues) {
|
||||
console.error(issue.message, issue.path);
|
||||
}
|
||||
} else {
|
||||
console.error("Failed to parse config:", error);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
6
example-app/server/utils/pow.ts
Normal file
6
example-app/server/utils/pow.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Challenge } from "@impost/lib";
|
||||
|
||||
export const outstandingChallenges = new Map<string, { challenge: Challenge, timeout: NodeJS.Timeout }>();
|
||||
|
||||
// 1 hour
|
||||
export const CHALLENGE_TIMEOUT_MS = 3600000;
|
||||
Reference in New Issue
Block a user