add addProject call handler
This commit is contained in:
parent
d96b41d755
commit
d6aca7389d
Binary file not shown.
Binary file not shown.
|
@ -4,3 +4,14 @@ type ExampleEntity @entity {
|
|||
from: BigInt! # uint256
|
||||
to: BigInt! # uint256
|
||||
}
|
||||
|
||||
type Profile @entity {
|
||||
id: ID!
|
||||
addr: Bytes!
|
||||
canceled: Boolean!
|
||||
commitTime: BigInt!
|
||||
type: String!
|
||||
url: String!
|
||||
name: String!
|
||||
profileId: BigInt!
|
||||
}
|
|
@ -21,6 +21,7 @@ dataSources:
|
|||
- DelegateUpdated
|
||||
- ProjectAdded
|
||||
- ProjectUpdated
|
||||
- Profile
|
||||
abis:
|
||||
- name: Contract
|
||||
file: Contract/abis/Contract.json
|
||||
|
@ -41,4 +42,7 @@ dataSources:
|
|||
handler: handleProjectAdded
|
||||
- event: ProjectUpdated(indexed uint64,string)
|
||||
handler: handleProjectUpdated
|
||||
callHandlers:
|
||||
- function: addProject(string,string,address,uint64,uint64,address)
|
||||
handler: handleAddProject
|
||||
file: Contract/Contract.wasm
|
||||
|
|
|
@ -69,3 +69,97 @@ export class ExampleEntity extends Entity {
|
|||
this.set("to", Value.fromBigInt(value));
|
||||
}
|
||||
}
|
||||
|
||||
export class Profile extends Entity {
|
||||
constructor(id: string) {
|
||||
super();
|
||||
this.set("id", Value.fromString(id));
|
||||
}
|
||||
|
||||
save(): void {
|
||||
let id = this.get("id");
|
||||
assert(id !== null, "Cannot save Profile entity without an ID");
|
||||
assert(
|
||||
id.kind == ValueKind.STRING,
|
||||
"Cannot save Profile entity with non-string ID. " +
|
||||
'Considering using .toHex() to convert the "id" to a string.'
|
||||
);
|
||||
store.set("Profile", id.toString(), this);
|
||||
}
|
||||
|
||||
static load(id: string): Profile | null {
|
||||
return store.get("Profile", id) as Profile | null;
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
let value = this.get("id");
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
set id(value: string) {
|
||||
this.set("id", Value.fromString(value));
|
||||
}
|
||||
|
||||
get addr(): Bytes {
|
||||
let value = this.get("addr");
|
||||
return value.toBytes();
|
||||
}
|
||||
|
||||
set addr(value: Bytes) {
|
||||
this.set("addr", Value.fromBytes(value));
|
||||
}
|
||||
|
||||
get canceled(): boolean {
|
||||
let value = this.get("canceled");
|
||||
return value.toBoolean();
|
||||
}
|
||||
|
||||
set canceled(value: boolean) {
|
||||
this.set("canceled", Value.fromBoolean(value));
|
||||
}
|
||||
|
||||
get commitTime(): BigInt {
|
||||
let value = this.get("commitTime");
|
||||
return value.toBigInt();
|
||||
}
|
||||
|
||||
set commitTime(value: BigInt) {
|
||||
this.set("commitTime", Value.fromBigInt(value));
|
||||
}
|
||||
|
||||
get type(): string {
|
||||
let value = this.get("type");
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
set type(value: string) {
|
||||
this.set("type", Value.fromString(value));
|
||||
}
|
||||
|
||||
get url(): string {
|
||||
let value = this.get("url");
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
set url(value: string) {
|
||||
this.set("url", Value.fromString(value));
|
||||
}
|
||||
|
||||
get name(): string {
|
||||
let value = this.get("name");
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
set name(value: string) {
|
||||
this.set("name", Value.fromString(value));
|
||||
}
|
||||
|
||||
get profileId(): BigInt {
|
||||
let value = this.get("profileId");
|
||||
return value.toBigInt();
|
||||
}
|
||||
|
||||
set profileId(value: BigInt) {
|
||||
this.set("profileId", Value.fromBigInt(value));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,3 +4,14 @@ type ExampleEntity @entity {
|
|||
from: BigInt! # uint256
|
||||
to: BigInt! # uint256
|
||||
}
|
||||
|
||||
type Profile @entity {
|
||||
id: ID!
|
||||
addr: Bytes!
|
||||
canceled: Boolean!
|
||||
commitTime: BigInt!
|
||||
type: String!
|
||||
url: String!
|
||||
name: String!
|
||||
profileId: BigInt!
|
||||
}
|
|
@ -8,9 +8,31 @@ import {
|
|||
DelegateAdded,
|
||||
DelegateUpdated,
|
||||
ProjectAdded,
|
||||
ProjectUpdated
|
||||
ProjectUpdated,
|
||||
AddProjectCall,
|
||||
} from "../generated/Contract/Contract"
|
||||
import { ExampleEntity } from "../generated/schema"
|
||||
import { ExampleEntity, Profile } from "../generated/schema"
|
||||
|
||||
|
||||
export function handleAddProject(call: AddProjectCall): void {
|
||||
let id = call.outputs.idProject
|
||||
let profile = new Profile(id.toHex())
|
||||
profile.url = call.inputs.url
|
||||
profile.name = call.inputs.name
|
||||
profile.addr = call.inputs.projectAdmin
|
||||
profile.commitTime = call.inputs.commitTime
|
||||
profile.canceled = false
|
||||
profile.type = 'PROJECT'
|
||||
profile.profileId = id
|
||||
profile.save()
|
||||
}
|
||||
|
||||
export function handleProjectAdded(event: ProjectAdded): void {
|
||||
// let profileId = event.params.idProject.toHex()
|
||||
// let profile = new Profile(profileId)
|
||||
// profile.url = event.params.url
|
||||
// profile.save()
|
||||
}
|
||||
|
||||
export function handleTransfer(event: Transfer): void {
|
||||
// Entities can be loaded from the store using a string ID; this ID
|
||||
|
@ -90,6 +112,5 @@ export function handleDelegateAdded(event: DelegateAdded): void {}
|
|||
|
||||
export function handleDelegateUpdated(event: DelegateUpdated): void {}
|
||||
|
||||
export function handleProjectAdded(event: ProjectAdded): void {}
|
||||
|
||||
export function handleProjectUpdated(event: ProjectUpdated): void {}
|
||||
|
|
|
@ -21,6 +21,7 @@ dataSources:
|
|||
- DelegateUpdated
|
||||
- ProjectAdded
|
||||
- ProjectUpdated
|
||||
- Profile
|
||||
abis:
|
||||
- name: Contract
|
||||
file: ./abis/Contract.json
|
||||
|
@ -41,4 +42,7 @@ dataSources:
|
|||
handler: handleProjectAdded
|
||||
- event: ProjectUpdated(indexed uint64,string)
|
||||
handler: handleProjectUpdated
|
||||
callHandlers:
|
||||
- function: addProject(string,string,address,uint64,uint64,address)
|
||||
handler: handleAddProject
|
||||
file: ./src/mapping.ts
|
||||
|
|
Loading…
Reference in New Issue