Skip to content

Commit

Permalink
add more details to transfer (event and extrinsic Id's)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Aug 27, 2024
1 parent 41fdc41 commit 5a57c3e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 deletions.
9 changes: 5 additions & 4 deletions indexers/accounts-squid/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion indexers/accounts-squid/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ type Account @entity {

type Transfer @entity {
id: ID! @index
extrinsicId: String! @index
eventId: String! @index
from: String! @index
to: String! @index
value: BigInt!
fee: BigInt!
success: Boolean!
timestamp: BigInt! @index
date: DateTime! @index
createdAt: Int! @index
Expand All @@ -22,4 +25,4 @@ type Transfer @entity {
type SlackMessage @entity {
id: ID! @index
messageId: String! @index
}
}
2 changes: 1 addition & 1 deletion indexers/accounts-squid/squid.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
manifestVersion: subsquid.io/v0.1
name: accounts-squid
version: 4
version: 5
description: Autonomys - Astral - Accounts Indexer
build:
deploy:
Expand Down
56 changes: 31 additions & 25 deletions indexers/accounts-squid/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { processor } from './processor'
import { getOrCreateAccount, getOrCreateTransfer } from './storage'
import { events } from './types'
import { account } from './types/system/storage'
import {
getBlockNumber,
hexToAccount,
logBlock
} from './utils'
import { getBlockNumber, hexToAccount, logBlock } from './utils'
import { Cache, LastSlackMsg, load, save } from './utils/cache'
import { sendSlackStatsMessage } from './utils/slack'

Expand All @@ -36,12 +32,19 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => {
const logMsg = logBlock(ctx.blocks)
const lastSlackMsgKey: LastSlackMsg = 'lastSlackMsg'
const lastSlackMsg = cache.slackMessages.get(lastSlackMsgKey)
const slackMsg = await sendSlackStatsMessage(logMsg, lastSlackMsg ? lastSlackMsg.messageId : undefined)
if (slackMsg) cache.slackMessages.set(lastSlackMsgKey, new SlackMessage({
id: lastSlackMsgKey,
messageId: slackMsg,
}))
cache.isModified = true
const slackMsg = await sendSlackStatsMessage(
logMsg,
lastSlackMsg ? lastSlackMsg.messageId : undefined,
)
if (slackMsg)
cache.slackMessages.set(
lastSlackMsgKey,
new SlackMessage({
id: lastSlackMsgKey,
messageId: slackMsg,
}),
)
cache.isModified = true

for (let block of ctx.blocks) {
for (const extrinsic of block.extrinsics) {
Expand All @@ -58,31 +61,34 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => {

if (fromAct) {
const fromAccount = getOrCreateAccount(cache, block, from)
fromAccount.nonce = BigInt(fromAct.nonce)
fromAccount.free = fromAct.data.free
fromAccount.reserved = fromAct.data.reserved
fromAccount.total = fromAct.data.free + fromAct.data.reserved
fromAccount.updatedAt = blockNumber
cache.accounts.set(fromAccount.id, fromAccount)
fromAccount.nonce = BigInt(fromAct.nonce)
fromAccount.free = fromAct.data.free
fromAccount.reserved = fromAct.data.reserved
fromAccount.total = fromAct.data.free + fromAct.data.reserved
fromAccount.updatedAt = blockNumber

cache.accounts.set(fromAccount.id, fromAccount)
}

if (toAct) {
const toAccount = getOrCreateAccount(cache, block, to)
toAccount.nonce = BigInt(toAct.nonce)
toAccount.free = toAct.data.free
toAccount.reserved = toAct.data.reserved
toAccount.total = toAct.data.free + toAct.data.reserved
toAccount.updatedAt = blockNumber
cache.accounts.set(toAccount.id, toAccount)
toAccount.nonce = BigInt(toAct.nonce)
toAccount.free = toAct.data.free
toAccount.reserved = toAct.data.reserved
toAccount.total = toAct.data.free + toAct.data.reserved
toAccount.updatedAt = blockNumber

cache.accounts.set(toAccount.id, toAccount)
}

const transfer = getOrCreateTransfer(cache, block, event.id, {
extrinsicId: extrinsic.id,
eventId: event.id,
from,
to,
value: amount,
fee: BigInt(extrinsic.fee ?? 0),
success: extrinsic.success,
timestamp: BigInt(block.header.timestamp ?? 0),
})
cache.transfers.set(transfer.id, transfer)
Expand Down
3 changes: 3 additions & 0 deletions indexers/accounts-squid/src/storage/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export const createTransfer = (
const blockNumber = getBlockNumber(block)
return new Transfer({
id: id,
extrinsicId: props.extrinsicId ?? '',
eventId: props.eventId ?? '',
from: props.from ?? '',
to: props.to ?? '',
value: props.value ?? BigInt(0),
fee: props.fee ?? BigInt(0),
success: props.success ?? false,
timestamp: props.timestamp ?? BigInt(0),
date: props.date ?? getTimestamp(block),
createdAt: blockNumber,
Expand Down

0 comments on commit 5a57c3e

Please sign in to comment.