Skip to content

Commit 5aac2d7

Browse files
committed
feat: improved ChangePermissions message handling in the subgraph
1 parent bb05b63 commit 5aac2d7

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

packages/subgraph/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type ChangePermissionsMessage implements Message @entity {
5252
block: MessageBlock!
5353
data: Bytes
5454
address: String!
55+
validThrough: BigInt!
5556
oldPermissions: [String!]!
5657
newPermissions: [String!]!
5758
}

packages/subgraph/src/mapping.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,20 @@ function executeChangePermissionsMessage(
592592
let message = cache.getChangePermissionsMessage(id);
593593
let address = reader.advance(20).toHexString(); // address should always be 20 bytes
594594

595+
// Get valid_through
596+
let validThrough = decodeU64(reader) as i32;
597+
if (!reader.ok) {
598+
return;
599+
}
600+
595601
// Get the length of the new premissions list
596602
let permissionsListLength = decodeU64(reader) as i32;
597603
if (!reader.ok) {
598604
return;
599605
}
600606

601607
let permissionEntry = cache.getPermissionListEntry(address);
608+
permissionEntry.validThrough = BigInt.fromI32(validThrough)
602609
let oldPermissionList = permissionEntry.permissions;
603610
let newPermissionList = new Array<String>();
604611

@@ -609,17 +616,20 @@ function executeChangePermissionsMessage(
609616

610617
message.block = messageBlock.id;
611618
message.address = address;
619+
message.validThrough = validThrough;
612620
message.oldPermissions = oldPermissionList;
613621
message.newPermissions = newPermissionList;
614622
message.data = reader.diff(snapshot);
615623

616624

617625
let list = globalState.permissionList;
618-
list.push(permissionEntry.id);
626+
if(!list.includes(permissionEntry.id)) {
627+
list.push(permissionEntry.id);
628+
} else if (permissionsListLength == 0) {
629+
// this will remove the now empty permission entry from the list, preventing spam
630+
list.splice(list.indexOf(permissionEntry.id), 1)
631+
}
619632
globalState.permissionList = list;
620-
621-
// might want to remove it from the "allow list" if the new permission list length is 0
622-
// Right now the address won't be able to execute anything on that case, but it can spam
623633
}
624634

625635
function executeResetStateMessage(

packages/subgraph/src/store-cache.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ export class StoreCache {
9494

9595
getPermissionListEntry(id: String): PermissionListEntry {
9696
if (this.permissionListEntries.safeGet(id) == null) {
97-
let permissionListyEntry = PermissionListEntry.load(id);
98-
if (permissionListyEntry == null) {
99-
permissionListyEntry = new PermissionListEntry(id);
97+
let permissionListEntry = PermissionListEntry.load(id);
98+
if (permissionListEntry == null) {
99+
permissionListEntry = new PermissionListEntry(id);
100+
permissionListEntry.permissions = [];
101+
permissionListEntry.validThrough = BigInt.fromI32(0);
100102
}
101-
this.permissionListEntries.set(id, permissionListyEntry);
103+
this.permissionListEntries.set(id, permissionListEntry);
102104
}
103105
return this.permissionListEntries.safeGet(id)!;
104106
}

0 commit comments

Comments
 (0)