add handleAddGiver call handler

This commit is contained in:
Barry Gitarts 2019-11-01 16:10:42 -04:00
parent ed76fd5ecd
commit 22b5179bc2
7 changed files with 45 additions and 2 deletions

View File

@ -32,6 +32,7 @@ type Pledge @entity {
intendedProject: BigInt!
pledgeState: Int!
creationTime: BigInt!
oldPledge: Pledge
}
type ProjectInfo @entity {

View File

@ -45,6 +45,8 @@ dataSources:
callHandlers:
- function: addProject(string,string,address,uint64,uint64,address)
handler: handleAddProject
- function: addGiver(address,string,string,uint64,address)
handler: handleAddGiver
- function: donate(uint64,uint64,address,uint256)
handler: handleDonate
file: Contract/Contract.wasm

View File

@ -335,6 +335,23 @@ export class Pledge extends Entity {
set creationTime(value: BigInt) {
this.set("creationTime", Value.fromBigInt(value));
}
get oldPledge(): string | null {
let value = this.get("oldPledge");
if (value === null) {
return null;
} else {
return value.toString();
}
}
set oldPledge(value: string | null) {
if (value === null) {
this.unset("oldPledge");
} else {
this.set("oldPledge", Value.fromString(value as string));
}
}
}
export class ProjectInfo extends Entity {

View File

@ -32,6 +32,7 @@ type Pledge @entity {
intendedProject: BigInt!
pledgeState: Int!
creationTime: BigInt!
oldPledge: Pledge
}
type ProjectInfo @entity {

View File

@ -10,11 +10,30 @@ import {
ProjectAdded,
ProjectUpdated,
AddProjectCall,
AddGiverCall,
DonateCall,
AddGiverAndDonateCall,
} from "../generated/Contract/Contract"
import { Profile, PledgesInfo, Pledge, ProjectInfo } from "../generated/schema"
export function handleAddGiver(call: AddGiverCall): void {
log.info(
'handleAddGiver triggered. idGiver: {}',
[call.outputs.idGiver.toString()]
)
let id = call.outputs.idGiver
let timestamp = call.block.timestamp
let profile = new Profile(id.toHex())
profile.url = call.inputs.url
profile.name = call.inputs.name
profile.addr = call.inputs.addr
profile.commitTime = call.inputs.commitTime
profile.canceled = false
profile.type = 'GIVER'
profile.profileId = id
profile.creationTime = timestamp
profile.save()
}
export function handleAddProject(call: AddProjectCall): void {
let id = call.outputs.idProject
@ -211,6 +230,7 @@ function createOrUpdatePledge(event: Transfer): void {
toPledge.pledgeState = pledgeState
toPledge.nDelegates = ndelegates
toPledge.creationTime = timestamp
toPledge.oldPledge = event.params.from.toHex()
toPledge.save()
}
@ -262,10 +282,10 @@ export function handleTransfer(event: Transfer): void {
// - contract.vault(...)
}
export function handleCancelProject(event: CancelProject): void {}
export function handleGiverAdded(event: GiverAdded): void {}
export function handleCancelProject(event: CancelProject): void {}
export function handleGiverUpdated(event: GiverUpdated): void {}
export function handleDelegateAdded(event: DelegateAdded): void {}

View File

@ -45,6 +45,8 @@ dataSources:
callHandlers:
- function: addProject(string,string,address,uint64,uint64,address)
handler: handleAddProject
- function: addGiver(address,string,string,uint64,address)
handler: handleAddGiver
- function: donate(uint64,uint64,address,uint256)
handler: handleDonate
file: ./src/mapping.ts