add jackpot entity

This commit is contained in:
Max Alekseenko 2020-04-08 12:49:45 +03:00
parent c36b0fe080
commit 926dcc82fb
2 changed files with 17 additions and 3 deletions

View File

@ -11,4 +11,12 @@ type Round @entity {
prizes: [BigInt!]!
roundCloser: Bytes!
roundCloserReward: BigInt!
jackpot: Jackpot
}
type Jackpot @entity {
id: ID!
round: Round
winner: Bytes!
prize: BigInt!
}

View File

@ -2,11 +2,11 @@ import { BigInt, Bytes, Address } from '@graphprotocol/graph-ts';
import {
Contract,
Deposited,
Jackpot,
Jackpot as JackpotEvent,
Rewarded,
Withdrawn
} from '../generated/Contract/Contract';
import { User, Round } from '../generated/schema';
import { User, Round, Jackpot } from '../generated/schema';
function deposit(userAddress: Address, amount: BigInt): void {
let user = User.load(userAddress.toHex());
@ -28,7 +28,12 @@ export function handleWithdrawn(event: Withdrawn): void {
user.save();
}
export function handleJackpot(event: Jackpot): void {
export function handleJackpot(event: JackpotEvent): void {
let jackpot = new Jackpot(event.params.roundId.toString());
jackpot.round = event.params.roundId.toString();
jackpot.winner = event.params.winner;
jackpot.prize = event.params.prize;
jackpot.save();
deposit(event.params.winner, event.params.prize);
}
@ -52,5 +57,6 @@ export function handleRewarded(event: Rewarded): void {
round.prizes = prizes;
round.roundCloser = event.params.executor;
round.roundCloserReward = event.params.executorReward;
round.jackpot = null;
round.save();
}