|
1 |
| -import { onchainTable } from 'ponder' |
2 |
| - |
3 |
| -const contracts = [ |
4 |
| - 'TopTournamentFactory', |
5 |
| - 'MiddleTournamentFactory', |
6 |
| - 'BottomTournamentFactory', |
7 |
| - 'MultiLevelTournamentFactory', |
8 |
| - 'InputBox', //not sure about that one! |
9 |
| - 'DaveConsensus', |
10 |
| - 'TopTournament', |
11 |
| - 'MiddleTournament', |
12 |
| - 'BottomTournament', |
13 |
| -] |
14 |
| - |
15 |
| -export const example = onchainTable('example', (t) => ({ |
16 |
| - id: t.text().primaryKey(), |
17 |
| - name: t.text(), |
18 |
| -})) |
| 1 | +import { onchainEnum, onchainTable, relations } from 'ponder'; |
| 2 | + |
| 3 | +export const matchStatus = onchainEnum('match_status', ['STARTED', 'FINISHED']); |
| 4 | +export const commitmentStatus = onchainEnum('commitment_status', [ |
| 5 | + 'WAITING', |
| 6 | + 'PLAYING', |
| 7 | + 'WON', |
| 8 | + 'LOST', |
| 9 | +]); |
| 10 | + |
| 11 | +export const tournament = onchainTable('tournament', (t) => ({ |
| 12 | + id: t.hex().primaryKey(), |
| 13 | + timestamp: t.bigint().notNull(), |
| 14 | + level: t.bigint().default(0n), |
| 15 | + parentId: t.hex(), |
| 16 | + matchId: t.hex(), |
| 17 | +})); |
| 18 | + |
| 19 | +//matchCreated(p1_keccak256(lNode + rNode), p2_keccak256(lnode + rnode), p2LeftNodeHash) |
| 20 | +export const match = onchainTable('match', (t) => ({ |
| 21 | + id: t.hex().primaryKey(), |
| 22 | + commitmentOne: t.hex().notNull(), |
| 23 | + commitmentTwo: t.hex().notNull(), |
| 24 | + leftOfTwo: t.hex().notNull(), |
| 25 | + status: matchStatus('match_status').default('STARTED'), |
| 26 | + tournamentId: t.hex().notNull(), |
| 27 | + timestamp: t.bigint().notNull(), |
| 28 | +})); |
| 29 | + |
| 30 | +// represent matchAdvanced(matchId_hash, parent_node_hash, left_node_hash) |
| 31 | +export const step = onchainTable('step', (t) => ({ |
| 32 | + id: t.hex().primaryKey(), |
| 33 | + advancedBy: t.hex().notNull(), |
| 34 | + parentNodeHash: t.hex().notNull(), |
| 35 | + leftNodeHash: t.hex().notNull(), |
| 36 | + matchId: t.hex().notNull(), |
| 37 | + timestamp: t.bigint().notNull(), |
| 38 | + input: t.jsonb().notNull(), |
| 39 | +})); |
| 40 | + |
| 41 | +// commitmentJoined(rootHash(keccak256(lNode, rNode))) |
| 42 | +// holds information about the sender, transaction and event-emitted |
| 43 | +// Adding the machine-hash when for matching arbitration result after a game is finished |
| 44 | +export const commitment = onchainTable('commitment', (t) => ({ |
| 45 | + id: t.hex().primaryKey(), |
| 46 | + commitmentHash: t.hex().notNull(), |
| 47 | + status: commitmentStatus('commitment_status').default('WAITING'), |
| 48 | + timestamp: t.bigint().notNull(), |
| 49 | + tournamentId: t.hex().notNull(), |
| 50 | + matchId: t.hex(), |
| 51 | + // tx information |
| 52 | + playerAddress: t.hex().notNull(), |
| 53 | + machineHash: t.hex().notNull(), |
| 54 | + proof: t.jsonb().notNull(), |
| 55 | + lNode: t.hex().notNull(), |
| 56 | + rNode: t.hex().notNull(), |
| 57 | +})); |
| 58 | + |
| 59 | +export const tournamentRelations = relations(tournament, ({ many, one }) => ({ |
| 60 | + parent: one(tournament, { |
| 61 | + fields: [tournament.parentId], |
| 62 | + references: [tournament.id], |
| 63 | + }), |
| 64 | + innerTournaments: many(tournament), |
| 65 | + matches: many(match), |
| 66 | + commitments: many(commitment), |
| 67 | +})); |
| 68 | + |
| 69 | +export const commitmentRelations = relations(commitment, ({ one }) => ({ |
| 70 | + tournament: one(tournament, { |
| 71 | + fields: [commitment.tournamentId], |
| 72 | + references: [tournament.id], |
| 73 | + }), |
| 74 | + match: one(match, { |
| 75 | + fields: [commitment.matchId], |
| 76 | + references: [match.id], |
| 77 | + }), |
| 78 | +})); |
| 79 | + |
| 80 | +export const matchesRelations = relations(match, ({ one, many }) => ({ |
| 81 | + tournament: one(tournament, { |
| 82 | + fields: [match.tournamentId], |
| 83 | + references: [tournament.id], |
| 84 | + }), |
| 85 | + steps: many(step), |
| 86 | +})); |
| 87 | + |
| 88 | +export const stepsRelations = relations(step, ({ one }) => ({ |
| 89 | + match: one(match, { fields: [step.matchId], references: [match.id] }), |
| 90 | +})); |
0 commit comments