tangled
alpha
login
or
join now
ciaran.co.za
/
cumulus
0
fork
atom
A Prediction Market on the AT Protocol
0
fork
atom
overview
issues
pulls
pipelines
feat(core.api.ts): prevent indexing bets on closed markets
Ciaran
1 week ago
cde4ce14
ca393937
+7
-5
1 changed file
expand all
collapse all
unified
split
src
core
api.ts
+7
-5
src/core/api.ts
···
95
95
const existing = await db.query.betsTable.findFirst({ where: eq(betsTable.uri, uri) });
96
96
if (existing) return;
97
97
98
98
+
const indexedMarket = await db.query.marketsTable.findFirst({ where: eq(marketsTable.uri, market.uri), columns: { closesAt: true } });
99
99
+
if (!indexedMarket || (new Date() > indexedMarket.closesAt)) return;
100
100
+
98
101
const betData: typeof betsTable.$inferInsert = {
99
102
uri, did, rev, rkey, cid, position, marketUri: market.uri, record, createdAt
100
103
}
···
119
122
const { answer, market } = record;
120
123
const createdAt = new Date(record.createdAt);
121
124
122
122
-
const indexedMarket = await db.query.marketsTable.findFirst({ where: eq(marketsTable.uri, market.uri), columns: { did: true }});
125
125
+
const existing = await db.query.resolutionsTable.findFirst({ where: eq(resolutionsTable.uri, uri) });
126
126
+
if (existing) return;
127
127
+
128
128
+
const indexedMarket = await db.query.marketsTable.findFirst({ where: eq(marketsTable.uri, market.uri), columns: { did: true } });
123
129
if (!indexedMarket) return;
124
130
125
131
const canUserEdit = did === indexedMarket.did;
126
132
if (!canUserEdit) return;
127
127
-
128
128
-
const existing = await db.query.resolutionsTable.findFirst({ where: eq(resolutionsTable.uri, uri) });
129
129
-
if (existing) return;
130
130
-
131
133
132
134
const resolutionData: typeof resolutionsTable.$inferInsert = {
133
135
uri, did, rev, rkey, cid, answer, marketUri: market.uri, record, createdAt