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:
35
example-app/server/api/pow/difficulty.put.ts
Normal file
35
example-app/server/api/pow/difficulty.put.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { defineEventHandler } from 'h3'
|
||||
import { ChallengeStrategy } from '@impost/lib';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
|
||||
let difficulty = body.difficulty;
|
||||
|
||||
switch (config.strategy) {
|
||||
case ChallengeStrategy.LeadingZeroes:
|
||||
if (!difficulty || difficulty < 1 || difficulty > 64) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Invalid request',
|
||||
});
|
||||
}
|
||||
|
||||
config.leading_zeroes.difficulty = difficulty;
|
||||
break;
|
||||
case ChallengeStrategy.TargetNumber:
|
||||
if (!difficulty || difficulty < 1 || difficulty > 100_000_000) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Invalid request',
|
||||
});
|
||||
}
|
||||
|
||||
config.target_number.max_number = difficulty;
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
message: 'Challenge difficulty set'
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user