Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Contract Versioning #207

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
1 change: 1 addition & 0 deletions Implementations/Subgraph/daostar/build/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type RegistrationInstance @entity {
activityLogURI: String
managerAddress: String
contractsRegistryURI: String
contractVersion: String
}

type RegistrationNetwork @entity {
Expand Down
16 changes: 8 additions & 8 deletions Implementations/Subgraph/daostar/build/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ features:
templates:
- name: EIP4824Registration
kind: ethereum/contract
network: arbitrum-one
network: optimism-goerli
source:
abi: EIP4824Registration
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
file: EIP4824Index/EIP4824Index.wasm
file: EIP4824Index\EIP4824Index.wasm
entities:
- Registration
abis:
- name: EIP4824Registration
file: EIP4824Registration/abis/EIP4824Registration.json
file: EIP4824Registration\abis\EIP4824Registration.json
eventHandlers:
- event: DAOURIUpdate(address,string)
handler: handleNewURI
dataSources:
- kind: ethereum
name: EIP4824Index
network: arbitrum-one
network: optimism-goerli
source:
abi: EIP4824Index
address: "0x18CbB356cd64193b1a0CA49911fc72CB3D02a5E4"
startBlock: 171329384
address: "0x9Aff4e5e7A7Ae449B89162EF4798b2Bb60DC92c0"
startBlock: 13115254
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand All @@ -39,8 +39,8 @@ dataSources:
- RegistrationInstance
abis:
- name: EIP4824Index
file: EIP4824Index/abis/EIP4824Index.json
file: EIP4824Index\abis\EIP4824Index.json
eventHandlers:
- event: DAOURIRegistered(address)
handler: handleNewRegistration
file: EIP4824Index/EIP4824Index.wasm
file: EIP4824Index\EIP4824Index.wasm
115 changes: 87 additions & 28 deletions Implementations/Subgraph/daostar/generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export class RegistrationInstance extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));

this.set("registrationAddress", Value.fromBytes(Bytes.empty()));
this.set("daoAddress", Value.fromBytes(Bytes.empty()));
this.set("daoURI", Value.fromString(""));
this.set("registrationNetwork", Value.fromString(""));
}

save(): void {
Expand All @@ -34,6 +29,12 @@ export class RegistrationInstance extends Entity {
}
}

static loadInBlock(id: string): RegistrationInstance | null {
return changetype<RegistrationInstance | null>(
store.get_in_block("RegistrationInstance", id)
);
}

static load(id: string): RegistrationInstance | null {
return changetype<RegistrationInstance | null>(
store.get("RegistrationInstance", id)
Expand All @@ -42,7 +43,11 @@ export class RegistrationInstance extends Entity {

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

set id(value: string) {
Expand All @@ -51,7 +56,11 @@ export class RegistrationInstance extends Entity {

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

set registrationAddress(value: Bytes) {
Expand All @@ -60,7 +69,11 @@ export class RegistrationInstance extends Entity {

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

set daoAddress(value: Bytes) {
Expand All @@ -69,7 +82,11 @@ export class RegistrationInstance extends Entity {

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

set daoURI(value: string) {
Expand All @@ -95,7 +112,11 @@ export class RegistrationInstance extends Entity {

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

set registrationNetwork(value: string) {
Expand Down Expand Up @@ -237,14 +258,29 @@ export class RegistrationInstance extends Entity {
this.set("contractsRegistryURI", Value.fromString(<string>value));
}
}

get contractVersion(): string | null {
let value = this.get("contractVersion");
if (!value || value.kind == ValueKind.NULL) {
return null;
} else {
return value.toString();
}
}

set contractVersion(value: string | null) {
if (!value) {
this.unset("contractVersion");
} else {
this.set("contractVersion", Value.fromString(<string>value));
}
}
}

export class RegistrationNetwork extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));

this.set("chainId", Value.fromString(""));
}

save(): void {
Expand All @@ -259,6 +295,12 @@ export class RegistrationNetwork extends Entity {
}
}

static loadInBlock(id: string): RegistrationNetwork | null {
return changetype<RegistrationNetwork | null>(
store.get_in_block("RegistrationNetwork", id)
);
}

static load(id: string): RegistrationNetwork | null {
return changetype<RegistrationNetwork | null>(
store.get("RegistrationNetwork", id)
Expand All @@ -267,36 +309,53 @@ export class RegistrationNetwork extends Entity {

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

set id(value: string) {
this.set("id", Value.fromString(value));
}

get registrations(): Array<string> | null {
let value = this.get("registrations");
get registrations(): RegistrationInstanceLoader {
return new RegistrationInstanceLoader(
"RegistrationNetwork",
this.get("id")!.toString(),
"registrations"
);
}

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

set registrations(value: Array<string> | null) {
if (!value) {
this.unset("registrations");
} else {
this.set("registrations", Value.fromStringArray(<Array<string>>value));
}
set chainId(value: string) {
this.set("chainId", Value.fromString(value));
}
}

get chainId(): string {
let value = this.get("chainId");
return value!.toString();
export class RegistrationInstanceLoader extends Entity {
_entity: string;
_field: string;
_id: string;

constructor(entity: string, id: string, field: string) {
super();
this._entity = entity;
this._id = id;
this._field = field;
}

set chainId(value: string) {
this.set("chainId", Value.fromString(value));
load(): RegistrationInstance[] {
let value = store.loadRelated(this._entity, this._id, this._field);
return changetype<RegistrationInstance[]>(value);
}
}
Loading