From d90901b4e325a314d73a59c21f15caec2577de40 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 5 Aug 2022 05:03:47 -0600 Subject: [PATCH] Check creator balance again upon acceptance --- functions/src/accept-challenge.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions/src/accept-challenge.ts b/functions/src/accept-challenge.ts index fa98c8c6..eae6ab55 100644 --- a/functions/src/accept-challenge.ts +++ b/functions/src/accept-challenge.ts @@ -47,7 +47,7 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { const creatorDoc = firestore.doc(`users/${challenge.creatorId}`) const creatorSnap = await trans.get(creatorDoc) - if (!creatorSnap.exists) throw new APIError(400, 'User not found.') + if (!creatorSnap.exists) throw new APIError(400, 'Creator not found.') const creator = creatorSnap.data() as User const { @@ -61,6 +61,9 @@ export const acceptchallenge = newEndpoint({}, async (req, auth) => { if (user.balance < acceptorAmount) throw new APIError(400, 'Insufficient balance.') + if (creator.balance < creatorAmount) + throw new APIError(400, 'Creator has insufficient balance.') + const contract = anyContract as CPMMBinaryContract const shares = (1 / creatorOutcomeProb) * creatorAmount const createdTime = Date.now()