Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
Merged
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
20 changes: 20 additions & 0 deletions sum-reward/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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