Skip to content

Commit

Permalink
Fix #496
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-kaufman committed Mar 15, 2020
1 parent e275cfc commit 40e8a6d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 43 deletions.
89 changes: 58 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/mappings/Controller/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function insertScheme(
controllerScheme.numberOfPreBoostedProposals = BigInt.fromI32(0);
controllerScheme.numberOfBoostedProposals = BigInt.fromI32(0);
controllerScheme.numberOfExpiredInQueueProposals = BigInt.fromI32(0);
controllerScheme.isRegistered = true;
}
controllerScheme.dao = avatarAddress.toHex();
controllerScheme.paramsHash = paramsHash;
Expand All @@ -91,11 +92,12 @@ function insertScheme(
controllerScheme.save();
}

function deleteScheme(avatarAddress: Address, scheme: Address): void {
store.remove(
'ControllerScheme',
crypto.keccak256(concat(avatarAddress, scheme)).toHex(),
);
function unregisterScheme(avatarAddress: Address, scheme: Address): void {
let controllerScheme = ControllerScheme.load(crypto.keccak256(concat(avatarAddress, scheme)).toHex());
if (controllerScheme != null) {
controllerScheme.isRegistered = false;
controllerScheme.save();
}
}

function insertOrganization(
Expand Down Expand Up @@ -215,7 +217,7 @@ export function handleRegisterScheme(event: RegisterScheme): void {
export function handleUnregisterScheme(event: UnregisterScheme): void {
let controller = Controller.bind(event.address);
let avatar = controller.avatar();
deleteScheme(avatar, event.params._scheme);
unregisterScheme(avatar, event.params._scheme);

let ent = new ControllerUnregisterScheme(eventId(event));
ent.txHash = event.transaction.hash;
Expand Down
1 change: 1 addition & 0 deletions src/mappings/Controller/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ControllerScheme @entity {
numberOfPreBoostedProposals: BigInt!
numberOfBoostedProposals: BigInt!
numberOfExpiredInQueueProposals: BigInt!
isRegistered: Boolean!
}

type ControllerGlobalConstraint @entity {
Expand Down
14 changes: 8 additions & 6 deletions src/mappings/UController/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function insertScheme(
controllerScheme.numberOfPreBoostedProposals = BigInt.fromI32(0);
controllerScheme.numberOfBoostedProposals = BigInt.fromI32(0);
controllerScheme.numberOfExpiredInQueueProposals = BigInt.fromI32(0);
controllerScheme.isRegistered = true;
}
controllerScheme.dao = avatarAddress.toHex();
controllerScheme.paramsHash = paramsHash;
Expand All @@ -75,11 +76,12 @@ function insertScheme(
controllerScheme.save();
}

function deleteScheme(avatarAddress: Address, scheme: Address): void {
store.remove(
'ControllerScheme',
crypto.keccak256(concat(avatarAddress, scheme)).toHex(),
);
function unregisterScheme(avatarAddress: Address, scheme: Address): void {
let controllerScheme = ControllerScheme.load(crypto.keccak256(concat(avatarAddress, scheme)).toHex());
if (controllerScheme != null) {
controllerScheme.isRegistered = false;
controllerScheme.save();
}
}

function insertOrganization(
Expand Down Expand Up @@ -200,7 +202,7 @@ export function handleRegisterScheme(event: RegisterScheme): void {
}

export function handleUnregisterScheme(event: UnregisterScheme): void {
deleteScheme(event.params._avatar, event.params._scheme);
unregisterScheme(event.params._avatar, event.params._scheme);

let ent = new UControllerUnregisterScheme(eventId(event));
ent.txHash = event.transaction.hash;
Expand Down
Loading

0 comments on commit 40e8a6d

Please sign in to comment.