Skip to content

Commit

Permalink
Court: Map court terms (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo authored Dec 18, 2019
1 parent 9d5d6ab commit 16048f9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Binary file modified model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ type CourtConfig @entity {
configGovernor: Bytes
modulesGovernor: Bytes
modules: [CourtModule!] @derivedFrom(field: "court")
terms: [CourtTerm!] @derivedFrom(field: "court")
}

type CourtTerm @entity {
id: ID!
startTime: BigInt!
randomnessBN: BigInt!
randomness: Bytes
court: CourtConfig!
createdAt: BigInt!
}

type ERC20 @entity {
Expand Down
29 changes: 28 additions & 1 deletion src/AragonCourt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AragonCourt } from '../types/AragonCourt/AragonCourt'
import { ERC20 as ERC20Contract } from '../types/AragonCourt/ERC20'
import { BigInt, Address, EthereumEvent } from '@graphprotocol/graph-ts'
import { ERC20, CourtModule, CourtConfig } from '../types/schema'
import { ERC20, CourtModule, CourtConfig, CourtTerm } from '../types/schema'
import { JurorsRegistry as JurorsRegistryContract } from '../types/templates/JurorsRegistry/JurorsRegistry'
import { ANJ, DisputeManager, JurorsRegistry, Treasury, Voting, Subscriptions } from '../types/templates'
import { Heartbeat, ModuleSet, FundsGovernorChanged, ConfigGovernorChanged, ModulesGovernorChanged } from '../types/AragonCourt/AragonCourt'
Expand All @@ -27,6 +27,22 @@ export function handleHeartbeat(event: Heartbeat): void {
config.configGovernor = court.getConfigGovernor()
config.modulesGovernor = court.getModulesGovernor()
config.save()

let previousTerm = loadOrCreateTerm(event.params.previousTermId, event)
let previousTermResult = court.getTerm(event.params.previousTermId)
previousTerm.court = event.address.toHex()
previousTerm.startTime = previousTermResult.value0
previousTerm.randomnessBN = previousTermResult.value1
previousTerm.randomness = previousTermResult.value2
previousTerm.save()

let currentTerm = loadOrCreateTerm(event.params.currentTermId, event)
let currentTermResult = court.getTerm(event.params.currentTermId)
currentTerm.court = event.address.toHex()
currentTerm.startTime = currentTermResult.value0
currentTerm.randomnessBN = currentTermResult.value1
currentTerm.randomness = currentTermResult.value2
currentTerm.save()
}

export function handleFundsGovernorChanged(event: FundsGovernorChanged): void {
Expand Down Expand Up @@ -137,3 +153,14 @@ function loadOrCreateConfig(courtAddress: Address, event: EthereumEvent): CourtC

return config
}

function loadOrCreateTerm(id: BigInt, event: EthereumEvent): CourtTerm | null {
let term = CourtTerm.load(id.toString())

if (term === null) {
term = new CourtTerm(id.toString())
term.createdAt = event.block.timestamp
}

return term
}

0 comments on commit 16048f9

Please sign in to comment.