Skip to content

Commit

Permalink
lock multi trading by answer ids
Browse files Browse the repository at this point in the history
resolves MAN-1631
  • Loading branch information
sipec committed Oct 14, 2024
1 parent 337f729 commit a898a81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
13 changes: 12 additions & 1 deletion backend/api/src/multi-sell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ import { convertBet } from 'common/supabase/bets'
import { betsQueue } from 'shared/helpers/fn-queue'
import { getAnswersForContract } from 'shared/supabase/answers'
import { getContractMetrics } from 'shared/helpers/user-contract-metrics'
import { buildArray } from 'common/util/array'
import { createSupabaseDirectClient } from 'shared/supabase/init'

export const multiSell: APIHandler<'multi-sell'> = async (props, auth, req) => {
const pg = createSupabaseDirectClient()
const c = await pg.oneOrNone(
`select data->'shouldAnswersSumToOne')::boolean as sum_to_one from contracts where id = $1`,
[props.contractId]
)

return await betsQueue.enqueueFn(
() => multiSellMain(props, auth, req),
[props.contractId, auth.uid]
buildArray(
auth.uid,
!c || c.sum_to_one ? props.contractId : props.answerIds
)
)
}

Expand Down
15 changes: 13 additions & 2 deletions backend/api/src/place-multi-bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ import {
import { log } from 'shared/utils'
import { runShortTrans } from 'shared/short-transaction'
import { betsQueue } from 'shared/helpers/fn-queue'
import { buildArray } from 'common/util/array'
import { createSupabaseDirectClient } from 'shared/supabase/init'

export const placeMultiBet: APIHandler<'multi-bet'> = async (props, auth) => {
const isApi = auth.creds.kind === 'key'

const pg = createSupabaseDirectClient()
const c = await pg.oneOrNone(
`select data->'shouldAnswersSumToOne')::boolean as sum_to_one from contracts where id = $1`,
[props.contractId]
)

return await betsQueue.enqueueFn(
() => placeMultiBetMain(props, auth.uid, isApi),
[auth.uid, props.contractId]
buildArray(
auth.uid,
!c || c.sum_to_one ? props.contractId : props.answerIds
)
)
}

// Note: this returns a continuation function that should be run for consistency.
export const placeMultiBetMain = async (
const placeMultiBetMain = async (
body: ValidatedAPIParams<'multi-bet'>,
uid: string,
isApi: boolean
Expand Down

0 comments on commit a898a81

Please sign in to comment.