Skip to content

Commit

Permalink
Fix passport score association for linked entities
Browse files Browse the repository at this point in the history
  • Loading branch information
ifavo committed Oct 27, 2024
1 parent d730ac1 commit fb21d97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
21 changes: 17 additions & 4 deletions generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9327,17 +9327,30 @@ export class PassportScore extends Entity {
this.set("id", Value.fromString(value));
}

get account(): Bytes {
let value = this.get("account");
get user(): Bytes {
let value = this.get("user");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBytes();
}
}

set account(value: Bytes) {
this.set("account", Value.fromBytes(value));
set user(value: Bytes) {
this.set("user", Value.fromBytes(value));
}

get passport(): Bytes {
let value = this.get("passport");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBytes();
}
}

set passport(value: Bytes) {
this.set("passport", Value.fromBytes(value));
}

get round(): string {
Expand Down
5 changes: 3 additions & 2 deletions src/Passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function handleRegisteredAction(event: RegisteredActionEvent): void {
appRoundSummary.save()

// stats for scores + Account + Round
const accountRoundSustainability = fetchAccountRoundSustainability(event.params.user, app, round)
const accountRoundSustainability = fetchAccountRoundSustainability(event.params.passport, app, round)
accountRoundSustainability.passportScore = accountRoundSustainability.passportScore.plus(event.params.actionScore)
accountRoundSustainability.save()

Expand All @@ -148,7 +148,8 @@ export function handleRegisteredAction(event: RegisteredActionEvent): void {
stats.save()

const passportScore = new PassportScore(events.id(event))
passportScore.account = fetchAccount(event.params.user).id
passportScore.user = fetchAccount(event.params.user).id
passportScore.passport = fetchAccount(event.params.passport).id
passportScore.round = round.id
passportScore.app = app.id
passportScore.score = event.params.actionScore
Expand Down
5 changes: 3 additions & 2 deletions subgraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ type Account @entity {
passportDelegatee: PassportDelegation @derivedFrom(field: "delegatee")

passportEntities: [PassportEntityLink!]! @derivedFrom(field: "passport")
passportScores: [PassportScore!]! @derivedFrom(field: "account")
passportScores: [PassportScore!]! @derivedFrom(field: "passport")
}

"""
Expand Down Expand Up @@ -984,7 +984,8 @@ type PassportBlacklist @entity {
type PassportScore implements Event @entity(immutable: true) {
id: ID!

account: Account!
user: Account!
passport: Account!
round: Round!
app: App!
score: BigInt!
Expand Down

0 comments on commit fb21d97

Please sign in to comment.