Skip to content

Commit

Permalink
Revert accidentally pushed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Dec 3, 2024
1 parent 211fefd commit 588285c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 45 deletions.
26 changes: 13 additions & 13 deletions Kusama/kusama-starter/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const project: SubstrateProject = {
dataSources: [
{
kind: SubstrateDatasourceKind.Runtime,
startBlock: 25845986,
startBlock: 1,
mapping: {
file: "./dist/index.js",
handlers: [
Expand All @@ -55,21 +55,21 @@ const project: SubstrateProject = {
modulo: 100,
},
},*/
{
/*{
kind: SubstrateHandlerKind.Call,
handler: "handleCall",
// filter: {
// module: "balances",
// },
filter: {
module: "balances",
},
},*/
{
kind: SubstrateHandlerKind.Event,
handler: "handleEvent",
filter: {
module: "balances",
method: "Transfer",
},
},
// {
// kind: SubstrateHandlerKind.Event,
// handler: "handleEvent",
// // filter: {
// // module: "balances",
// // method: "Transfer",
// // },
// },
],
},
},
Expand Down
55 changes: 23 additions & 32 deletions Kusama/kusama-starter/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,47 @@ import { Account, Transfer } from "../types";
import { Balance } from "@polkadot/types/interfaces";
import { decodeAddress } from "@polkadot/util-crypto";

let lastTransfer: Transfer;

export async function handleBlock(block: SubstrateBlock): Promise<void> {
// Do something with each block handler here
}

export async function handleCall(extrinsic: SubstrateExtrinsic): Promise<void> {
logger.info(`Handle extrinsic ${extrinsic.idx}`)
// Do something with a call handler here
}

export async function handleEvent(event: SubstrateEvent): Promise<void> {
logger.info()
// logger.info(
// `New transfer event found at block ${event.block.block.header.number.toString()}`,
// );
logger.info(
`New transfer event found at block ${event.block.block.header.number.toString()}`,
);

// Get data from the event
// The balances.transfer event has the following payload \[from, to, value\]
// logger.info(JSON.stringify(event));
// const {
// event: {
// data: [from, to, amount],
// },
// } = event;

// const blockNumber: number = event.block.block.header.number.toNumber();
const {
event: {
data: [from, to, amount],
},
} = event;

// const fromAccount = await checkAndGetAccount(from.toString(), blockNumber);
// const toAccount = await checkAndGetAccount(to.toString(), blockNumber);
const blockNumber: number = event.block.block.header.number.toNumber();

// // Create the new transfer entity
// const transfer = Transfer.create({
// id: `${event.block.block.header.number.toNumber()}-${event.idx}`,
// blockNumber,
// date: event.block.timestamp,
// fromId: fromAccount.id,
// toId: toAccount.id,
// amount: (amount as Balance).toBigInt(),
// });
const fromAccount = await checkAndGetAccount(from.toString(), blockNumber);
const toAccount = await checkAndGetAccount(to.toString(), blockNumber);

// fromAccount.lastTransferBlock = blockNumber;
// toAccount.lastTransferBlock = blockNumber;
// Create the new transfer entity
const transfer = Transfer.create({
id: `${event.block.block.header.number.toNumber()}-${event.idx}`,
blockNumber,
date: event.block.timestamp,
fromId: fromAccount.id,
toId: toAccount.id,
amount: (amount as Balance).toBigInt(),
});

// if (lastTransfer) {
// await Transfer.remove(lastTransfer.id);
// lastTransfer = transfer
// }
fromAccount.lastTransferBlock = blockNumber;
toAccount.lastTransferBlock = blockNumber;

// await Promise.all([fromAccount.save(), toAccount.save(), transfer.save()]);
await Promise.all([fromAccount.save(), toAccount.save(), transfer.save()]);
}

async function checkAndGetAccount(
Expand Down

0 comments on commit 588285c

Please sign in to comment.