Skip to content

Commit f9f5970

Browse files
committed
feat: add submitter entity, handlers
1 parent d7e0701 commit f9f5970

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

schema.graphql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,14 @@ type HasPaidAppealFee @entity {
447447
"Timestamp of the event"
448448
timestamp: BigInt!
449449
}
450+
451+
type Submitter @entity {
452+
"Lower-cased 0x address"
453+
id: ID!
454+
"How many requests this address has ever opened (first time only)."
455+
totalSubmissions: BigInt!
456+
"Open requests = still waiting for a final status."
457+
ongoingSubmissions: BigInt!
458+
"Finished requests (item ended up Absent/Removed or Registered)."
459+
pastSubmissions: BigInt!
460+
}

src/LightGeneralizedTCRMapping.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
EvidenceGroup,
1616
Evidence,
1717
LArbitrator,
18+
Submitter
1819
} from '../generated/schema';
1920
import {
2021
AppealPossible,
@@ -104,6 +105,26 @@ CONTRACT_STATUS_NAMES.set(REGISTERED_CODE, 'Registered');
104105
CONTRACT_STATUS_NAMES.set(REGISTRATION_REQUESTED_CODE, 'RegistrationRequested');
105106
CONTRACT_STATUS_NAMES.set(CLEARING_REQUESTED_CODE, 'ClearingRequested');
106107

108+
function loadOrCreateSubmitter(addr: Address): Submitter {
109+
let id = addr.toHexString().toLowerCase();
110+
let s = Submitter.load(id);
111+
if (s == null) {
112+
s = new Submitter(id);
113+
s.totalSubmissions = BigInt.fromI32(0);
114+
s.ongoingSubmissions = BigInt.fromI32(0);
115+
s.pastSubmissions = BigInt.fromI32(0);
116+
s.save();
117+
}
118+
return s as Submitter;
119+
}
120+
121+
function moveRequestToPast(requester: Address): void {
122+
let s = loadOrCreateSubmitter(requester);
123+
s.ongoingSubmissions = s.ongoingSubmissions.minus(BigInt.fromI32(1));
124+
s.pastSubmissions = s.pastSubmissions.plus(BigInt.fromI32(1));
125+
s.save();
126+
}
127+
107128
function getExtendedStatus(disputed: boolean, status: string): number {
108129
if (disputed) {
109130
if (status == CONTRACT_STATUS_NAMES.get(REGISTRATION_REQUESTED_CODE))
@@ -359,6 +380,11 @@ export function handleRequestSubmitted(event: RequestSubmitted): void {
359380
updateCounters(previousStatus, newStatus, event.address);
360381
}
361382

383+
let submitter = loadOrCreateSubmitter(request.requester as Address);
384+
submitter.totalSubmissions = submitter.totalSubmissions.plus(BigInt.fromI32(1));
385+
submitter.ongoingSubmissions = submitter.ongoingSubmissions.plus(BigInt.fromI32(1));
386+
submitter.save();
387+
362388
round.save();
363389
request.save();
364390
item.save();
@@ -653,6 +679,11 @@ export function handleStatusUpdated(event: ItemStatusChange): void {
653679
// requestInfo.value6 is request.ruling.
654680
request.disputeOutcome = getFinalRuling(requestInfo.value6);
655681

682+
if (item.status == REGISTERED || item.status == ABSENT) {
683+
// request just moved to a “finished” final state
684+
moveRequestToPast(request.requester as Address);
685+
}
686+
656687
// Iterate over every contribution and mark it as withdrawable if it is.
657688
// Start from the second round as the first is automatically withdrawn
658689
// when the request resolves.

0 commit comments

Comments
 (0)