Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
handle new event naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ERussel committed Aug 25, 2021
1 parent 693bce6 commit 10db419
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
24 changes: 22 additions & 2 deletions sum-reward/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ repository: "https://github.com/subquery/subql-examples"
schema: "./schema.graphql"

network:
endpoint: "wss://polkadot.api.onfinality.io/public-ws"
endpoint: "wss://westend.api.onfinality.io/public-ws"

dataSources:
- name: runtime
kind: substrate/Runtime
startBlock: 1
startBlock: 7077018
mapping:
handlers:
- handler: handleBond
Expand All @@ -23,18 +23,38 @@ dataSources:
filter:
module: staking
method: Reward
- handler: handleRewarded
kind: substrate/EventHandler
filter:
module: staking
method: Rewarded
- handler: handleSlash
kind: substrate/EventHandler
filter:
module: staking
method: Slash
- handler: handleSlashed
kind: substrate/EventHandler
filter:
module: staking
method: Slashed
- handler: handleStakingReward
kind: substrate/EventHandler
filter:
module: staking
method: Reward
- handler: handleStakingRewarded
kind: substrate/EventHandler
filter:
module: staking
method: Rewarded
- handler: handleStakingSlash
kind: substrate/EventHandler
filter:
module: staking
method: Slash
- handler: handleStakingSlashed
kind: substrate/EventHandler
filter:
module: staking
method: Slashed
7 changes: 7 additions & 0 deletions sum-reward/src/mappings/Reward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export async function handleBond(event: SubstrateEvent): Promise<void> {
}
}

export async function handleRewarded(event: SubstrateEvent): Promise<void> {
await handleReward(event)
}

export async function handleReward(event: SubstrateEvent): Promise<void> {
const {event: {data: [account, newReward]}} = event;
Expand All @@ -37,6 +40,10 @@ export async function handleReward(event: SubstrateEvent): Promise<void> {
await entity.save();
}

export async function handleSlashed(event: SubstrateEvent): Promise<void> {
await handleSlash(event)
}

export async function handleSlash(event: SubstrateEvent): Promise<void> {
const {event: {data: [account, newSlash]}} = event;
let entity = await SumReward.get(account.toString());
Expand Down
7 changes: 7 additions & 0 deletions sum-reward/src/mappings/Staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {StakingReward, StakingSlash} from '../types/models';
import {SubstrateEvent} from "@subql/types";
import {Balance} from '@polkadot/types/interfaces';

export async function handleStakingRewarded(event: SubstrateEvent): Promise<void> {
await handleStakingReward(event)
}

export async function handleStakingReward(event: SubstrateEvent): Promise<void> {
const {event: {data: [account, newReward]}} = event;
Expand All @@ -12,6 +15,10 @@ export async function handleStakingReward(event: SubstrateEvent): Promise<void>
await entity.save();
}

export async function handleStakingSlashed(event: SubstrateEvent): Promise<void> {
await handleStakingSlash(event)
}

export async function handleStakingSlash(event: SubstrateEvent): Promise<void> {
const {event: {data: [account, newSlash]}} = event;
const entity = new StakingSlash(`${event.block.block.header.number}-${event.idx.toString()}`);
Expand Down

0 comments on commit 10db419

Please sign in to comment.